sammchardy / python-binance

Binance Exchange API python implementation for automated trading
https://python-binance.readthedocs.io/en/latest/
MIT License
6.09k stars 2.21k forks source link

Iterate through pd.DataFrame(client.get_historical_klines()) #310

Closed BrentLewis closed 5 years ago

BrentLewis commented 6 years ago

This is the code I'm using to try to pull out all the symbols 5min kline data for the length of the market I got it to the point where it will iterate through all of get_historical_klines, but it returns: 400 Duplicate values for a parameter detected. for the every row in the iteration. I'm not sure what to do with this, or if I got the args for get_historical_klines or .iteritems() wrong. I'm also confused as to why the for loop worked fine on tick, but needed the extra steps to run on tickers. I know lambda is probably a lot better for trying this, but I don't know it well enough, I'm still fairly new. If parts of it aren't shit, and you use it feel free to lemme know, or show me improvements. pip install jupyter import pandas as pd import numpy as np from binance.client import Client from binance.exceptions import BinanceAPIException t_df = pd.DataFrame(client.get_all_tickers()) tick = t_df.loc[:, ['symbol']] for i in tick: tick_df = pd.DataFrame(client.get_ticker())

isolates the symbol and volume

tickers = tick_df.loc[:, ['symbol', 'volume']]

floats volume

tickers['volume'] = tickers.loc[:, ['volume']].astype(float)

volume dtype = int

tickers['volume'] = tickers.loc[:, ['volume']].astype(int)

delets all symbols below 20,000 in volume, returns on the symbol column

tickers_1 = tickers.loc[tickers['volume'] >= 20000, 'symbol']

for row in tickers_1.iteritems(): try: klines = pd.DataFrame(client.get_historical_klines(row, client.KLINE_INTERVAL_5MINUTE, "21 July, 2018")) except BinanceAPIException as e: print(e.status_code) print(e.message)for row in tickers_1.iteritems(): try: klines = pd.DataFrame(client.get_historical_klines(row, client.KLINE_INTERVAL_5MINUTE, "21 July, 2018")) except BinanceAPIException as e: print(e.status_code) print(e.message)

K-Kit commented 6 years ago

`for row in tickers_1.iteritems():

try:

klines = pd.DataFrame(client.get_historical_klines(row['symbol'], client.KLINE_INTERVAL_5MINUTE, "21 July, 2018"))

except BinanceAPIException as e:

print(e.status_code) print(e.message)`

BrentLewis commented 6 years ago

iteritems might work, but I didn't mess around with it enough to figure out how to get it to stop returning only one symbol. pd.DataFrame(client.get_historical_klines(i, client.KLINE_INTERVAL_30MINUTE, "29 June, 2018")) for i in tickers ^This loop ended up working pretty well