Skip to content

Instantly share code, notes, and snippets.

@ugik
Last active August 7, 2022 20:53
Show Gist options
  • Save ugik/e06e267b9773d6c46b3cf524e21c6012 to your computer and use it in GitHub Desktop.
Save ugik/e06e267b9773d6c46b3cf524e21c6012 to your computer and use it in GitHub Desktop.
client = Client(config.BINANCE_API_KEY, config.BINANCE_API_SECRET, tld='us')
def getPositionInfo(startDate=None, exchange='BTCUSDT'):
if not startDate:
return
candlesticks = client.get_historical_klines(exchange, Client.KLINE_INTERVAL_1HOUR, str(startDate))
# trim each candle
for candle in candlesticks:
del candle[-6:]
df = pd.DataFrame(candlesticks, columns=['date', 'O', 'H', 'L', 'C', 'V'])
df['date'] = pd.to_datetime(df['date'], unit='ms')
df[exchange[:3]] = df['O'].astype(float)
# use 1-hour delta as API uses tick beginning time
df['date'] = df['date'] + pd.to_timedelta(1, unit='h')
#df = df.set_index('date')
return df
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment