chatgpt/letter-to-GPT.memo

50 lines
1.5 KiB
Plaintext
Raw Normal View History

2022-12-17 22:39:21 +02:00
I would like to have a program that contors to these rules:
1. written in python3
2. singe file
And then makes these things:
1. record the bitcoin price
1.1. by fetching:
source = 'http://api.binance.com/api/v3/avgPrice'
payload = {'symbol': 'BTCUSDT'}
response = requests.get(source, params=payload)
binance api response is like:
{
"mins": 5,
"price: "170.20"
}
1.2. and storing it in sqlite3 or other embedded database
The database should hold these informations:
* timestamp as unix timestamp
* value of the symbol
* name of the symbol
* source of the symbol
1.3
Fetch the price every "mins" minutes, something like:
time_delta = time.now() - timestamp_of_last_record
if time_delta <= mins_from_last_record
fetch_new_price_data()
2. serve a http/json api to send the gathered price data forward
Every response from this api should contain sha256 checksum as last element it is json document.
This api should be accessible by token authentication.
2.1 allow full dump of the database as json document
2.2 allow partial dump by getting limiting timestamp as of attribure from the http get reqeust
3. Hold the sice of the files under control
The database that holds the price data should be rotated every midnight.
So that we dont end up with large database files on the server.
Can you generate this?
I think to make this work there needs to be threading. One thread for the data gathering and another for the api serving.