掘金社区

subscribe函数订阅了,很多股票,怎么让订阅的股池中的,每个股票都都执行on_bra下面的代码Pinned highlighted

门捷 发表在策略研究 2021-04-22 18:47:21

策略研究
443
4
0

def init(context):
context.gc = ['SZSE.000725', 'SZSE.300676', 'SZSE.002340', 'SZSE.000725', 'SZSE.000100', 'SZSE.600703']
context.zq = '60s'
context.kx = 500
subscribe(symbols=context.gc, frequency=context.zq, count=context.kx)

def on_bar(context, bars):
data = context.data(symbol=context.gc, frequency=context.zq, count=context.kx, fields='close')
print(data)

评论: 4
  • 0_1619144525858_6aea53cb-b7c5-4fbe-b766-3fc24f0d08f1-image.png
    你的symbol直接传了列表,建议修改
    `def init(context):
    context.gc = ['SZSE.000725', 'SZSE.300676', 'SZSE.002340', 'SZSE.000725', 'SZSE.000100', 'SZSE.600703']
    context.zq = '60s'
    context.kx = 500
    subscribe(symbols=context.gc, frequency=context.zq, count=context.kx)

    def on_bar(context, bars):
    for symbol in context.gc:
    data = context.data(symbol=symbol, frequency=context.zq, count=context.kx, fields='close')
    print(data)`

    2021-04-23 10:23:16
  • @charkong 搞定 谢谢

    2021-04-25 12:43:32
  • @charkong 为什么我这样做的时候,context.gc下面有几个股票代码,我的算法就会运行几遍呀

    2021-05-19 16:58:27
  • @tqww 因为for循环

    2021-05-20 09:00:02

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