掘金社区

如何看到我自己读取的数据?Pinned highlighted

139012***030 发表在策略研究 2020-09-12 23:47:45

策略研究
202
3
0

如题,我如何能看到我读取的数据呢?尚未成功。!

coding=utf-8

from future import print_function, absolute_import, unicode_literals
from gmtrade.api import *
set_token('c3cc2a5c1f2e552ea12254da3c84bd207081d041')

#def on_tick(history, tick):

a=history(symbol='SHFE.ag2012', frequency='tick', start_time='2020-09-01 09:00:00', end_time='2020-09-01 23:00:00', fields='open,high,low,close', df=True)

df = pd.DataFrame()

for tick in a:

df = df.append(pd.DataFrame({'symbol': tick.symbol, 'open': tick.open, 'high': tick.high}, index=[1]))

def on_tick(context, tick):
a=context.data(symbol='SHFE.ag2012', frequency='tick',count=500)
df = pd.DataFrame()
for tick in a:
df = df.append(pd.DataFrame({'symbol': tick.symbol, 'open': tick.open, 'high': tick.high}, index=[1]))

0_1599925623543_批注 2020-09-12 234645.jpg

评论: 3
  • set_token('c3cc2a5c1f2e552ea12254da3c84bd207081d041')
    data = history(symbol = 'SHFE.ag2012',frequency = 'tick',start_time= '2020-09-01 09:00:00',end_time= '2020-09-01 23:00:00',df = True)
    print(data)

    输出结果:
    0_1600239522935_结果.png
    如果想保存到本地,可以加一句:
    data.to_csv('ag2012.csv')
    就能得到csv文件啦。

    2020-09-16 14:59:19
  • @四两 感谢你的答复。另外,如果想单独引用quotes里面的bid_p,或者让quotes分成单独四列显示,应如何操作呢?

    2020-09-20 19:04:36
  • @139012-030
    b = pd.DataFrame({'bid_p': data['quotes'].apply(lambda x: x[0]['bid_p']),
    'bid_v': data['quotes'].apply(lambda x: x[0]['bid_v']),
    'ask_p': data['quotes'].apply(lambda x: x[0]['ask_p']),
    'ask_v': data['quotes'].apply(lambda x: x[0]['ask_v'])})
    结果如图:
    0_1600944400873_d936fd2c-a200-47b1-8bd6-554e9e252c3c-image.png

    2020-09-24 18:47:12

Looks like your connection to 掘金量化社区 - 量化交易者的策略交流学习社区 was lost, please wait while we try to reconnect.