【量化交易】QMT自动交易逆回购

#encoding:gbk
import pandas as pd
import time
from datetime import datetime


accID = '00000001'
asset_name = '204001.SH'  # 上交所1天逆回购


def init(ContextInfo):
    global accID, asset_name
    ContextInfo.set_account(accID)
    ContextInfo.run_time("process_condition_order","1nDay","2022-12-01 15:03:00") #'3nSecond' '1nDay'
    print('已启动')

def process_condition_order(ContextInfo):
    # 查可用资金
    available_funds = get_trade_detail_data(accID, 'stock', 'account')[0].m_dAvailable
    volume = int(available_funds/1000)*10
    print('可用余额:',available_funds)
    print('可交易逆回购数量:',volume)
    
    if volume >= 1000:
        # 查逆回购价格
        result=ContextInfo.get_market_data(['quoter'],stock_code=[asset_name],start_time='',end_time='',skip_paused=True,period='tick',dividend_type='none')
        buy5_price = result['bidPrice'][-1]
        last_price = result['lastPrice']
        print('buy5_price',buy5_price)
        
        #下单方向、下单方式、账号、标的代码、价格类型、下单价格、下单数量、策略名称、是否立即促发下单、委托id、ContextInfo
        passorder(24,1101,accID,asset_name,11,buy5_price,volume, '', 2, '', ContextInfo)
    else:
        print('可用资金不足,不交易')
    
def order_callback(ContextInfo, orderInfo): 
    print(f'>>> order_callback: {orderInfo.m_nRef}')

def deal_callback(ContextInfo, dealInfo): 
    print(f'>>> deal_callback: {dealInfo.m_nRef}')

def stop(ContextInfo):
    print( 'strategy is stop !')

你可能感兴趣的:(量化交易研究,QMT,python,量化交易,qmt,量化研究,逆回购自动交易)