请教一下,如何使用MindgoHqGenerator

用户头像猿游梦
2024-10-10 发布

06cd543cc3a9a92f3018be07f6dadb03.png

from tick_trade_api import MindgoHqGenerator
import pandas as pd

#初始化账户
def init(context):
    context.s1 = "300033.SZ"
    subscribe([context.s1])
    set_holding_stocks({'300033.SZ': 1000})
    reg_signal('big', get_big)

# 开盘前运行函数
def before_trading(context):
    print('before_trading')

# 收盘后运行函数
def after_trading(context):
    print('after_trading')

# 信号定义函数
def get_big(data):
    return data['current'] > data['open']

# 设置买卖条件,每个交易频率(tick)调用一次
def handle_tick(context, tick):
    # 获取时间
    time = tick.datetime.strftime('%H%M')
  
    for bar in MindgoHqGenerator(['600000.SZ'], is_standard=False):
        print(bar.all_values())
        print('\n')
        print('通过属性获取主动买入特大单量:%s' % bar.BIGBUYCOUNT1)
        print('通过属性获取主动买入特大单量:%s' % bar['BIGBUYCOUNT1'])
        break

    # 获取信号
    big_single = get_signal(tick.order_book_id, "big")

    if (big_single) and (time == '0930'):
        order_shares(tick.order_book_id, 100)

    if (not big_single) and (time == '0930'):
        order_shares(tick.order_book_id, -100)
  

1e56a12b34e714acac59dbd56671e164.png

评论

需要帮助?

试试AI小助手吧