掘金社区

订阅实时行情数据按照我的理解应该是最新的数据,为什么测试结果却是2020年的行情?Pinned highlighted

喜数女 发表在策略研究 2021-05-10 13:41:38

策略研究
332
1
0

coding=utf-8

from future import print_function, absolute_import
from gm.api import *
import talib
import datetime as dt
#这里只研究数据和策略没关系

def init(context):
context.ma5 = 5 # 短周期均线
context.ma30 = 30 # 长周期均线
context.ma240 = 1000 # 长周期均线

context.symbol = 'SHFE.rb2101'                                 # 订阅交易标的
context.period = context.ma240+1                             # 订阅数据滑窗长度
context.open_long = False                                      # 开多单标记
context.open_short = False                                     # 开空单标记
subscribe(context.symbol, '1800s', count=context.period)         # 订阅行情
prices = context.data(context.symbol,'1800s', context.period, fields='eob,open,close,high,low')

print(prices) 

--------------------运行结束如下-------------------
[
eob open close high low
0 2020-01-15 21:30:00+08:00 3281.0 3282.0 3290.0 3241.0
1 2020-01-15 22:00:00+08:00 3282.0 3281.0 3283.0 3277.0
2 2020-01-15 22:30:00+08:00 3281.0 3287.0 3288.0 3280.0
3 2020-01-15 23:00:00+08:00 3287.0 3288.0 3291.0 3283.0
4 2020-01-16 09:30:00+08:00 3291.0 3288.0 3294.0 3286.0
.. ... ... ... ... ...
403 2020-03-31 11:15:00+08:00 3159.0 3147.0 3163.0 3142.0
404 2020-03-31 13:45:00+08:00 3147.0 3145.0 3157.0 3139.0
405 2020-03-31 14:15:00+08:00 3145.0 3142.0 3150.0 3139.0
406 2020-03-31 14:45:00+08:00 3142.0 3145.0 3154.0 3141.0
407 2020-03-31 15:00:00+08:00 3146.0 3141.0 3147.0 3137.0

评论: 1

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