掘金社区

这是什么原因我的代码拿不到数据?Pinned highlighted

chenney_huang 发表在策略研究 2021-06-17 17:20:44

策略研究
145
2
0

from future import print_function, absolute_import
from gm.api import *
import talib

def init(context):
context.symbol = 'CFFEX.ic2106'
context.long = 10
context.period = context.long + 1
# 赫尔均线快线的设置参数
context.fast = 12
# 赫尔均线慢线的设置参数
context.slow = 100
context.long_cost = 0
context.short_cost = 0

# mark down the how many times to load the positions
context.load_position_count = 0
time = context.now.strftime('%h:%M:%S')

if '09:00:00' < time < '15:00:00':
    algo(context)
schedule(schedule_func=algo, date_rule='1d', time_rule='09:00:00')

subscribe(symbols=context.symbol, frequency='1d', count=context.period)

def algo(context):

# context.history_data = history_n(symbol=context.symbol, frequency='60s', end_time=context.now,
#                                  fields='symbol,open,high,low', count=context.period, df=True)
# print(context.history_data.head())
if context.mode == 2:
    context.history_data = history_n(symbol=context.symbol, frequency='1d', count=context.period, fields='close,high,low', df=True)

if context.mode == 1:
    context.history_data = history_n(symbol=context.symbol, frequency='1d', count=context.period-1, fields='close,high,low', df=True)

# print(context.history_Data)

def on_bar(context, bars):

bar = bars[0]
# data = context.history_data
# print(data.head())

# resent_data = context.data(symbol=context.symbol, frequency='60s', count=context.period, fields='close,high,low')
resent_data = context.history_data
print(resent_data)
评论: 2

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