I am a day trader who is new to python and learning every day. I have written a basic script or maybe you call it a function? but some basic python code that pulls the best bid/offer data from an API for me on repeat every 5 seconds
I now want a rolling average of the data coming in the from the API every 5 seconds so i can compare the current data against the rolling average
My problem is I have no idea where to start or what I should be looking to learn. Any help would be great! Even just to point me in the right direction.
Does the data need to be stored into a .csv that is updated each 5 seconds? or can all this be done within the code?
Thanks in advance for any help, code is below
import time
from binance.client import Client
api_key = "###"
api_secret = "###"
while True:
client = Client(api_key, api_secret)
ticker_info = (client.get_ticker(symbol="ETHUSDT"))
bid_qty = int(float(ticker_info['bidQty']))
ask_qty = int(float(ticker_info['askQty']))
bbo_delta = ask_qty-bid_qty
print("Ask=")
print(ask_qty)
print("Bid=")
print(bid_qty)
print("Delta=")
print(bbo_delta)
print("-")
time.sleep(5)
Actually, this types of quires may have various possibilities. As per your explanation, I got to know that, You want to fetch the data that get generated every five second.
So, you can scrape the data via beautiful soup if you are using python.
As the data is updated in every five second, after some times, it may be huge too . So, in that case properly stored data maybe in a csv or in a excel or in a database , It would be great help for you too.
Just scrape the data and store the data in a csv format or if you are using API, store that in a proper dataframe.
My suggestion would be use Beautiful Soup (BS4) and read some documentation and just in a few lines of code, store the data in a csv.
Documentation: https://www.crummy.com/software/BeautifulSoup/bs4/doc/