自动读取通达信预警并下单----个人量化

前几天有朋友说习惯用通达信的预警函数生成交易信号,

有没有办法用量化软件自动读取这种交易信号并下单呢?

我们采用的思路是 生成通达信的预警信号的TXT文件,间隔固定时间用软件检查TXT文件,如果信号触发,完成下单

先上代码

def run_tdx_yj_trader_func(self):
        '''
        运行通达信预警信号交易函数
        '''
        with open(encoding='utf-8') as f:
            com=f.read()
        path=text['通达信预警保存路径']
        columns=text['通达信预警列名称']
        buy_con=text['买入预警条件']
        sell_con=text['卖出预警条件']
        buy_df=pd.read_excel(r'买入股票\买入股票.xlsx',dtype='object')
        buy_df=buy_df[buy_df['交易状态']=='未买']
        try:
            del buy_df['Unnamed: 0']
        except:
            pass
        sell_df=pd.read_excel(r'卖出股票\卖出股票.xlsx',dtype='object')
        sell_df=sell_df[sell_df['交易状态']=='未卖']
        try:
            del sell_df['Unnamed: 0']
        except:
            pass
        with open(r'{}'.format(path),'r+') as f:
            com=f.readlines()
        result_list=[]
        for i in com:
            result_list.append(i.strip().split())
        tdx_df=pd.DataFrame(result_list)
        if tdx_df.shape[0]>0:
            tdx_df.columns=columns
            def select_buy_sell(x):
                if buy_con in x:
                    return '未买'
                elif sell_con in x:
                    return '未卖'
                else:
                    return '未知交易状态'
            tdx_df['交易状态']=tdx_df['买卖条件'].apply(select_buy_sell)
            tdx_df_buy=tdx_df[tdx_df['交易状态']=='未买']
            tdx_df_sell=tdx_df[tdx_df['交易状态']=='未卖']
            try:
                if len(buy_df.columns.tolist()) !=len(tdx_df_buy.columns.tolist()):
                    buy_df=pd.DataFrame()
                else:
                    buy_df=buy_df
                buy_df=pd.concat([buy_df,tdx_df_buy],ignore_index=True)
                buy_df=buy_df.drop_duplicates(subset=['证券代码'], keep='last')
                buy_df.to_excel(r'买入股票\买入股票.xlsx')
            except:
                if len(buy_df.columns.tolist()) !=len(tdx_df_buy.columns.tolist()):
                    buy_df=pd.DataFrame()
                else:
                    buy_df=buy_df
                buy_df=pd.concat([buy_df,tdx_df_buy],ignore_index=True)
                buy_df=buy_df.drop_duplicates(subset=['证券代码'], keep='last')
                buy_df.to_excel(r'买入股票\买入股票.xlsx')
            try:
                if len(sell_df.columns.tolist()) !=len(tdx_df_sell.columns.tolist()):
                    sell_df=pd.DataFrame()
                else:
                    sell_df=sell_df
                sell_df=pd.concat([sell_df,tdx_df_sell],ignore_index=True)
                sell_df=sell_df.drop_duplicates(subset=['证券代码'], keep='last')
                sell_df.to_excel(r'卖出股票\卖出股票.xlsx')
            except:
                if len(sell_df.columns.tolist()) !=len(tdx_df_sell.columns.tolist()):
                    sell_df=pd.DataFrame()
                else:
                    sell_df=sell_df
                sell_df=pd.concat([sell_df,tdx_df_sell],ignore_index=True)
                sell_df=sell_df.drop_duplicates(subset=['证券代码'], keep='last')
                sell_df.to_excel(r'卖出股票\卖出股票.xlsx')
            print(buy_df,sell_df)
        else:
            print('通达信没有预警数据')

支持股票,etf,可转债交易,同时支持同花顺,qmt下单,通达信预警为例提供使用教程,

我们简单讲一下源代码

用open read模块,需要设置TXT文件保存的位置,我们研究一下TXT文件中每一列的内容,区分买/卖信号

(下图是8月份测试时候生成的信号)

添加图片注释,不超过 140 字(可选)

为了检验程序是否在每一个设定的时间间隔都正常运行,一开始我们选择把每一次检查TXT文件的结果都记录下

来,包括没有新的信号未下单(print('通达信没有警告数据'))、有新的信号下单成功(并生成交易记录)

下面图片中有一些常用的函数,如果有问题欢迎交流咨询

添加图片注释,不超过 140 字(可选)

通达信的预警信号可选指标众多,下面也简单说一下如何在通达信中设置预警信号。

点击右下角铃铛,再点击设置(或者点击右上角一排按钮最左边的菜单页)

添加图片注释,不超过 140 字(可选)

添加图片注释,不超过 140 字(可选)

或者点击右上角一排按钮最左边的菜单页

添加图片注释,不超过 140 字(可选)

选择好预警触发条件后,可以设置股票池子(添加自选股很方便)

添加图片注释,不超过 140 字(可选)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值