import requests
import json
import time
from datetime import datetime
import pandas as pd
def get_polonix() :
time_depth = 500
start_day = 500
st_time=time.time()-start_day*24*60*60
end_time=st_time+time_depth*60*60*24
pair = 'USDT_BTC'
#resource=requests.get("https://poloniex.com/public?command=returnChartData¤cyPair=%s&start=%s&end=%s&period=1800" % (pair,st_time,end_time))
#resource=requests.get("https://poloniex.com/public?command=returnChartData¤cyPair=%s&start=%s&end=%s&period=14400" % (pair,st_time,end_time))
resource=requests.get("https://poloniex.com/public?command=returnChartData¤cyPair=%s&start=%s&end=%s&period=300" % (pair,st_time,end_time))
#resource=requests.get("https://poloniex.com/public?command=returnChartData¤cyPair=%s&start=%s&end=%s&period=86400" % (pair,st_time,end_time))
#resource=requests.get("https://poloniex.com/public?command=returnChartData¤cyPair=%s&start=%s&end=%s&period=21600" % (pair,st_time,end_time))
data=[]
chart_data={}
chart_data = json.loads(resource.text)
for elems in chart_data:
data.append(elems)
df = pd.DataFrame(data, columns=['date', 'open', 'high', 'low', 'close', 'volume'])
df['datetime']= df['date']
df['datetime'] = pd.to_datetime(df['datetime'], unit='s')
#df = df[(df['date'] > '2018-1-1') & (df['date'] <= '2018-2-1')]
#df = df[(df['date'] > '2017-9-1') & (df['date'] <= '2018-1-1')]
#df = df[(df['datetime'] >= '2018-6-1')]
df = df[(df['datetime'] >= '2018-6-29')]
df['date'] = 0
df['<TIME>'] = 0
#df['<TICKER>'] = 'USDTBTC'
df['<TICKER>'] = 'EURUSD'
#<TICKER>,<DTYYYYMMDD>,<TIME>,<OPEN>,<HIGH>,<LOW>,<CLOSE>,<VOL>
dict = df.to_dict('records')
for index, elems in enumerate(dict):
dict[index]['date'] = dict[index]['datetime'].strftime("%Y%m%d")
dict[index]['<TIME>'] = dict[index]['datetime'].strftime("%H%M%S")
col = (['<TICKER>','date', '<TIME>', 'open', 'high', 'low', 'close', 'volume'])
df = pd.DataFrame(dict, columns=col)
#df = df.set_index('date')
df = df.rename(columns={'date': '<DTYYYYMMDD>', 'open': '<OPEN>', 'high': '<HIGH>', 'low': '<LOW>', 'close': '<CLOSE>', 'volume': '<VOL>'})
#df = df.set_index('<DTYYYYMMDD>')
df = df.set_index('<TICKER>')
return df
#################################################
df = get_polonix()
#df.to_csv('USDTBTC.txt')
df.to_csv('EURUSD.txt')
import json
import time
from datetime import datetime
import pandas as pd
def get_polonix() :
time_depth = 500
start_day = 500
st_time=time.time()-start_day*24*60*60
end_time=st_time+time_depth*60*60*24
pair = 'USDT_BTC'
#resource=requests.get("https://poloniex.com/public?command=returnChartData¤cyPair=%s&start=%s&end=%s&period=1800" % (pair,st_time,end_time))
#resource=requests.get("https://poloniex.com/public?command=returnChartData¤cyPair=%s&start=%s&end=%s&period=14400" % (pair,st_time,end_time))
resource=requests.get("https://poloniex.com/public?command=returnChartData¤cyPair=%s&start=%s&end=%s&period=300" % (pair,st_time,end_time))
#resource=requests.get("https://poloniex.com/public?command=returnChartData¤cyPair=%s&start=%s&end=%s&period=86400" % (pair,st_time,end_time))
#resource=requests.get("https://poloniex.com/public?command=returnChartData¤cyPair=%s&start=%s&end=%s&period=21600" % (pair,st_time,end_time))
data=[]
chart_data={}
chart_data = json.loads(resource.text)
for elems in chart_data:
data.append(elems)
df = pd.DataFrame(data, columns=['date', 'open', 'high', 'low', 'close', 'volume'])
df['datetime']= df['date']
df['datetime'] = pd.to_datetime(df['datetime'], unit='s')
#df = df[(df['date'] > '2018-1-1') & (df['date'] <= '2018-2-1')]
#df = df[(df['date'] > '2017-9-1') & (df['date'] <= '2018-1-1')]
#df = df[(df['datetime'] >= '2018-6-1')]
df = df[(df['datetime'] >= '2018-6-29')]
df['date'] = 0
df['<TIME>'] = 0
#df['<TICKER>'] = 'USDTBTC'
df['<TICKER>'] = 'EURUSD'
#<TICKER>,<DTYYYYMMDD>,<TIME>,<OPEN>,<HIGH>,<LOW>,<CLOSE>,<VOL>
dict = df.to_dict('records')
for index, elems in enumerate(dict):
dict[index]['date'] = dict[index]['datetime'].strftime("%Y%m%d")
dict[index]['<TIME>'] = dict[index]['datetime'].strftime("%H%M%S")
col = (['<TICKER>','date', '<TIME>', 'open', 'high', 'low', 'close', 'volume'])
df = pd.DataFrame(dict, columns=col)
#df = df.set_index('date')
df = df.rename(columns={'date': '<DTYYYYMMDD>', 'open': '<OPEN>', 'high': '<HIGH>', 'low': '<LOW>', 'close': '<CLOSE>', 'volume': '<VOL>'})
#df = df.set_index('<DTYYYYMMDD>')
df = df.set_index('<TICKER>')
return df
#################################################
df = get_polonix()
#df.to_csv('USDTBTC.txt')
df.to_csv('EURUSD.txt')
Комментариев нет:
Отправить комментарий