![]() This data is crucial to make a strategy and calculate some technical indicators, we will use them in a near future. You have now a nice Table containing The Date, The Open price, High, Low, Close price and Volume executed. df= pd.DataFrame(client.get_historical_klines(asset, timeframe,start,end)) df=df.iloc df.columns= df=df.set_index("Date") df.index=pd.to_datetime(df.index,unit="ms") df=df.astype("float") print(df) These will select the columns that are interesant in the DataFrame and convert the data in a readable format. To clean a bit and have a nice Table I suggest adding these few lines. This will return a table with all the data of the asset (BTC/USDT) between the 1st October 2021 and 1st November 2021 with a 1-day timeframe. import pandas as pd asset="BTCUSDT" start="2021.10.1" end="2021.11.1" timeframe="1d" df =pd.DataFrame(assert,timeframe,start,end) The timeframe will be the delta between the two price data. To execute this function we will specify an asset, a start date, an end date, and a timeframe. We will cover how to backtest strategy to find the best parameters in a future article. This function is crucial if you want to have the historic prices of a specific asset to backtest a strategy or just plot it on a graph. Output: price 62228.99 Name: BTCUSDT, dtype: float64 Get Historical Price To isolate a specific price for a precise asset just use: print(df.loc) import pandas as pd df=pd.DataFrame(client.get_all_tickers()) df=df.set_index("symbol") df=df.astype("float") df.index=df.index.astype("string") print(df) We will just add a few lines of code to select the data type of the columns, and add an index in the DataFrame. Just install and import pandas in the python document with: pip install pandas To work with this data we’ll use the python library pandas to stock these in a DataFrame. If this returns an empty dictionary, this means that all is correct and that you are ready for the next steps. To verify that your keys are correct and that you’re connected to Binance, execute this function that will ping the server. from python-binance import Client api_key = "your api key" api_secret = "your api secret key" client=Client(api_key,api_secret) To connect to the client just define your API and secret key variable and execute the client function. Then we will import the library to the python file and connect it to the Binance client. Install it with the following command: pip install python-binance #and then import it in your python file with from binance.client import Client To use and manage Binance API easily we will use a python library. ![]() Now that you have your key, you are ready for the next steps. These two will be used in our python program. The important information you will need is your API Keys and your secret Keys.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |