-
Notifications
You must be signed in to change notification settings - Fork 35
Description
Currently the price is calculated by getting the data for 60s from binance and then an average is made from these 60s.
Thus for every trade 3 calls are made to binance if i'm correct (buy/sell/fee) wouldn't it be easier to get the data for a larger timeframe for some coins (e.g bnb for fees and comissions) generate a lot of small transactions within a time frame.
I do not know when exactly the prices are calculated but a simple idea from my side:
1.group transactions of one coin in timeranges which are under one hour (max range on binance)
2.download the needed timerange
3.select the 60s needed for the calculation of the prices and calculate the prices and save to the db
4. maybe cache the api timerange if needed again (dunno if useful)
this could reduce the amount of api calls from for ex. bnb from 1 per entry to about 1 api request per 5-6 entries for bnb
if you have many entries (for ex 8000, around half or more are bnb,mostly due to comissions and fees) it would take around 5-6hours for the prices to load (2s per call) and if it would be possible to optimize that with stated algorithm it would maybe only take 3h)
if there is a better way to get this data would also be good for example get the ohlcv data from binance for the 1m timerange, cctx is a good lib for that, it works with many exhanges or just use: https://binance-docs.github.io/apidocs/spot/en/#kline-candlestick-data . on binance you can request 1000 1min candles with a single request if i'm not wrong, which would be alto faster.