Zihao

Make small but daily progress

0%

Python的Pandas模块hdf5追加保存

hdf5存储格式会根据data存储到不同的表,请注意。

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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from OkcoinSpotAPI import OKCoinSpot
from OkcoinFutureAPI import OKCoinFuture
import time

import numpy as np
import pandas as pd
# 引入 datetime 模块
import datetime

def getYesterday():
today=datetime.date.today()
oneday=datetime.timedelta(days=1)
yesterday=today-oneday
return yesterday

#初始化apikey,secretkey,url
apikey = 'XXXX'
secretkey = 'XXXXX'
okcoinRESTURL = 'www.okcoin.com' #请求注意:国内账号需要 修改为 www.okcoin.cn

#现货API
okcoinSpot = OKCoinSpot(okcoinRESTURL,apikey,secretkey)

#期货API
okcoinFuture = OKCoinFuture(okcoinRESTURL,apikey,secretkey)

# 昨日开始时间
print(u' 开始时间 ')
yesterdayTime = int(time.mktime(getYesterday().timetuple()) * 1000)
print (getYesterday())
print (yesterdayTime)
# print (u' 现货行情 ')
# print (okcoinSpot.ticker('btc_usd'))
print (u' okCoin Com 期货 当周 Kline 日线 ')
thisWeekArr = okcoinFuture.future_kline('btc_usd','1day','this_week', 2, yesterdayTime)
print (thisWeekArr)
b = pd.DataFrame(thisWeekArr)
# b.columns = [['时间戳','开','高','低','收','交易量','交易量转化BTC或LTC数量']]
# 存储到hdf5
h5 = pd.HDFStore('../data/test1.h5','a')
h5.append('df',b)
h5.close()

### 读取数据
h5 = pd.HDFStore('../data/test1.h5','r')
print (h5)
e = h5['df']
h5.close()
print (e)

欢迎关注我的其它发布渠道