-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathget_data.py
27 lines (24 loc) · 931 Bytes
/
get_data.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import pandas as pd
from binance.client import Client
import api
client = Client(api_key=api.Pkey, api_secret=api.Skey)
columns = ['Date','Open','High','Low','Close' ,'Volume','IGNORE','Quote_Volume','Trades_Count','BUY_VOL','BUY_VOL_VAL','x']
def get_klines(pair, interval, depth):
data = client.get_historical_klines(pair, interval, depth)
df = pd.DataFrame(data)
if not df.empty:
df.columns = columns
df['Date'] = pd.to_datetime(df['Date'],unit='ms')
df = df.set_index('Date')
del df['IGNORE']
del df['Trades_Count']
del df['x']
df["Close"] = pd.to_numeric(df["Close"])
df["Open"] = pd.to_numeric(df["Open"])
df["High"] = pd.to_numeric(df["High"])
df["Low"] = pd.to_numeric(df["Low"])
df['Volume'] = pd.to_numeric(df['Volume'])
df["Quote_Volume"] = pd.to_numeric(df["Quote_Volume"])
df["BUY_VOL"] = pd.to_numeric(df["BUY_VOL"])
df["BUY_VOL_VAL"] = pd.to_numeric(df["BUY_VOL_VAL"])
return df