QMT量化交易模型模型使用教程

源代码分享看主页或si我

今天我把最新版的综合交易框架里面的qmt独立出来方便大家开发,使用简单,和easytrader一样的调用,复制的处理全部封装了,我们把程序当作第三方库使用

QMT量化交易模型模型使用教程

大概的内容

QMT量化交易模型模型使用教程

第二部复制python路径,打开文件夹路径

QMT量化交易模型模型使用教程

进入lib

QMT量化交易模型模型使用教程

找到文件夹site-packages,放在文件夹内部

QMT量化交易模型模型使用教程

放在文件夹内部就完成了

QMT量化交易模型模型使用教程

使用的教程和easytrader差不多

#可转债数据from qmt_trader.bond_cov_data_qmt import bond_cov_data_qmt#etf数据from qmt_trader.etf_fund_data_qmt import etf_fund_data_qmt#qmt数据from qmt_trader.qmt_data import qmt_data#股票数据from qmt_trader.stock_data_qmt import stock_data_qmt#交易框架from qmt_trader.qmt_trader_ths import qmt_trader_ths#通达信数据from qmt_trader.tdx_data import tdx_data#统一接口数据from qmt_trader.unification_data_qmt import unification_data_qmt#qmt数据unification_data=unification_data_qmt()#qmt交易模型trader=qmt_trader_ths(path= r'D:/国金QMT交易端模拟/userdata_mini',                  session_id = 123456,account='55009640',account_type='STOCK',                  is_slippage=True,slippage=0.01)#连接qmttrader.connect()#获取持股hold_stock=trader.position()print(hold_stock)#获取账户account=trader.balance()print(account)#买入#获取数据stock='600031'stock=trader.adjust_stock(stock=stock)spot_data=unification_data.get_spot_data(stock=stock)print(spot_data)price=spot_data['最新价']trader.buy(security=stock,price=price,amount=1000)#卖出trader.sell(security=stock,price=price,amount=1000)#撤单trader.cancel_order_stock(order_id='12')#开发的通过代码撤单trader.cancel_order_stock_async_by_code(cancel_type='all',stock=stock)

运行效果获取持股

QMT量化交易模型模型使用教程

QMT量化交易模型模型使用教程

下单的结果

QMT量化交易模型模型使用教程

QMT量化交易模型模型使用教程

自己开发的通过股票代码来撤单

def cancel_order_stock_async_by_code(self,cancel_type='all',stock='600031.SH',num='all'):
        '''
        通过证券代码来撤单
        类型cancel_type=all/buy/sell/one
        在有多个单时候选择怎么样撤单num=0/all
        '''
        # 使用订单编号撤单
        entrusts=self.today_entrusts()
        if entrusts.shape[0]>0:
            stock=self.adjust_stock(stock=stock)
            stock_list=entrusts['证券代码'].tolist()
            if stock in stock_list:
                if cancel_type=='all':
                    order_id_list=entrusts['订单编号'].tolist()
                    for order_id in order_id_list:
                        self.cancel_order_stock_async(order_id=order_id)
                elif cancel_type=='buy':
                    entrusts_buy=entrusts[entrusts['委托类型']==xtconstant.STOCK_BUY]
                    order_id_list=entrusts_buy['订单编号'].tolist()
                    for order_id in order_id_list:
                        self.cancel_order_stock_async(order_id=order_id)
                elif cancel_type=='sell':
                    entrusts_sell=entrusts[entrusts['委托类型']==xtconstant.STOCK_SELL]
                    order_id_list=entrusts_sell['订单编号'].tolist()
                    for order_id in order_id_list:
                        self.cancel_order_stock_async(order_id=order_id)
                else:
                    entrusts_on=entrusts[entrusts['证券代码']==stock]
                    if num=='all':
                        order_id_list=entrusts_on['订单编号'].tolist()
                        for order_id in order_id_list:
                            self.cancel_order_stock_async(order_id=order_id)
                    else:
                        order_id_list=entrusts_on['订单编号'].tolist()
                        self.cancel_order_stock_async(order_id=order_id_list[num])

发布者:股市刺客,转载请注明出处:https://www.95sca.cn/archives/68809
站内所有文章皆来自网络转载或读者投稿,请勿用于商业用途。如有侵权、不妥之处,请联系站长并出示版权证明以便删除。敬请谅解!

(0)
股市刺客的头像股市刺客
上一篇 2024 年 7 月 9 日 上午10:32
下一篇 2024 年 7 月 9 日

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注