Coder Social home page Coder Social logo

pyctp's People

Contributors

yuwangying avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

pyctp's Issues

当期货账户无策略时,点击删除,后台报错

期货账户无策略,鼠标右击删除,后台报错。

log:

Traceback (most recent call last):
File "C:\Users\yuanpengfei\Desktop\PyCTP-PyCTP_Dev\PyCTP_Client\PyCTP_ClientCore\QAccountWidget.py", line 711, in slot_action_del_strategy
print(">>> QAccountWidget.slot_action_del_strategy() i_strategy.get_user_id()=", i_strategy.get_user_id(), "i_strategy.get_strategy_id()=", i_strategy.get_strategy_id(), "self.__clicked_status['user_id']=", self.__clicked_status['user_id'], "self.__clicked_status['strategy_id']=", self.__clicked_status['strategy_id'])
AttributeError: 'QAccountWidget' object has no attribute '_QAccountWidget__clicked_status'

issue2
issue21

小蜜蜂客户端期货账户开关未开,服务端便可以发单

小蜜蜂账户策略总开关与TS端策略状态不一致。

测试步骤:
1:打开小蜜蜂客户端,设置某个期货账户策略参数,开启总开关,期货账户策略总开关,然后TS端开始发单,快期可以看到有报单;
2:小蜜蜂不做任何操作直接退出(账户策略总开关已经是打开状态),然后退出TS端,快期终端手动平仓,清空持仓;
3:重启TS端,发现启动后上次账户立马开启发单;
4:打开小蜜蜂客户端,发现账户下策略总开关显示还是未开启状态,其实已经打开。

新开报单小蜜蜂不显示

盘中交易,快期已经有报单,但是小蜜蜂不显示新开的报单。
退出小蜜蜂重启小蜜蜂之后又显示了。

建议修改开始策略开关文字

总账户和单账户下的开始策略文字使人困惑,容易引发误操作。
建议总账户下改名:交易员开关
期货账户改名:账户开关

小蜜蜂初始化报错User.py中commodity_id未定义先使用

如题,User.py代码中get_commission方法:

    def get_commission(self, instrument_id, exchange_id):

        # 获取品种代码,例如cu、zn
        if exchange_id in ['SHFE', 'CFFEX', 'DZCE']:
            commodity_id = instrument_id[:2]
        elif exchange_id in ['DCE']:
            commodity_id = instrument_id[:1]
        if commodity_id not in self.__dict_commission:
            ...

假如前两种判断都不成立,第三种逻辑判断,commodity_id属于直接使用变量,那么启动过程将会报错。

UnboundLocalError: local variable 'commodity_id' referenced before assignment

我修改如下,将变量变为self变量,然后bug不存在,系统正常启动:

    def get_commission(self, instrument_id, exchange_id):

        # 获取品种代码,例如cu、zn
        if exchange_id in ['SHFE', 'CFFEX', 'DZCE']:
            self.commodity_id = instrument_id[:2]
        elif exchange_id in ['DCE']:
            self.commodity_id = instrument_id[:1]
        if self.commodity_id not in self.__dict_commission:

server crash,客户端无任何提示

server socket crash, 客户端应当提示用户网络连接故障。
当客户端遇到如下socket异常:
SocketManager.RecvN() [WinError 10053] 你的主机中的软件中止了一个已建立的连接。
客户端理应弹窗提示。

获取CTP trade记录类型错误

b'063802' 连接交易前置 0
b'063802' 登陆交易账号 0
b'063802' 交易日 20161228
b'063802' 投资者代码 063802
Exception in thread Thread-1:
Traceback (most recent call last):
File "D:\Python34\lib\threading.py", line 920, in _bootstrap_inner
self.run()
File "D:\Python34\lib\threading.py", line 868, in run
self._target(*self._args, **self._kwargs)
File "C:\Users\yuanpengfei\Desktop\PyCTP-PyCTP_Dev\PyCTP_Client\PyCTP_ClientCore\CTPManager.py", line 75, in start_init
self.create_user(i)
File "C:\Users\yuanpengfei\Desktop\PyCTP-PyCTP_Dev\PyCTP_Client\PyCTP_ClientCore\CTPManager.py", line 115, in create_user
obj_user = User(dict_arguments, ctp_manager=self)
File "C:\Users\yuanpengfei\Desktop\PyCTP-PyCTP_Dev\PyCTP_Client\PyCTP_ClientCore\User.py", line 84, in init
self.QryTrade() # 获取user的Trade记录
File "C:\Users\yuanpengfei\Desktop\PyCTP-PyCTP_Dev\PyCTP_Client\PyCTP_ClientCore\User.py", line 284, in QryTrade
print(">>> User.QryTrade() self.__listQryTrade=", self.__listQryTrade, type(self.__listQryTrade), len(self.__listQryTrade))
TypeError: object of type 'int' has no len()

小蜜蜂部署问题

小蜜蜂在某些windows系统上一运行就报错,现象为黑窗口一闪而过。

该问题如下所示:
qq 20170511125253

经过分析是缺少某些动态链接库导致。

小蜜蜂新建策略后启动报错KeyError: 'ProfitPosition'

测试环境:TS端从来没操作过包含cu1707,cu1709两个合约相关的策略
现象:启动TS端,小蜜蜂新建策略,合约id为:cu1707, cu1709,关闭小蜜蜂,重新启动,发现报错。

报错日志:

Strategy.statistics_for_trade() user_id = 091921 strategy_id = 01 既不属于A也不属于B合约的trade
Strategy.OnRtnTrade() user_id = 091921 strategy_id = 01 时间过滤,跳过持仓量统计
Exception in thread Thread-4:
Traceback (most recent call last):
  File "D:\Python34\lib\threading.py", line 920, in _bootstrap_inner
    self.run()
  File "D:\Python34\lib\threading.py", line 868, in run
    self._target(*self._args, **self._kwargs)
  File "D:\CTP\PyCTP\PyCTP_Client\PyCTP_ClientCore\User.py", line 908, in timer_queue_put
    'DataMain': self.get_table_widget_data()  # 进程通信:发送策略信息
  File "D:\CTP\PyCTP\PyCTP_Client\PyCTP_ClientCore\User.py", line 772, in get_table_widget_data
    strategy_statistics = self.__dict_strategy[strategy_id].get_statistics()
  File "D:\CTP\PyCTP\PyCTP_Client\PyCTP_ClientCore\Strategy.py", line 1916, in get_statistics
    'profit_position': self.count_profit_position(),  # 持仓盈亏
  File "D:\CTP\PyCTP\PyCTP_Client\PyCTP_ClientCore\Strategy.py", line 1890, in count_profit_position
    self.__profit_position += trade['ProfitPosition']
KeyError: 'ProfitPosition'

Strategy.OnRtnTrade() user_id = 091921 strategy_id = 01 时间过滤,跳过持仓量统计
Strategy.statistics_for_trade() user_id = 091921 strategy_id = 01 既不属于A也不属于B合约的trade

log日志:
bee_start_error.txt

[优化]创建期货账户多进程方式代码结构

示例代码是一个主进程,两个期货账户进程.

在主进程里通过multiprocessing.Process创建两个账户进程,每个进程进行轮询即可,轮询可以采用Queue方式进行读取,有消息就处理

# -*- coding: utf-8 -*-
"""
Created on Tue Jan 12 00:31:14 2016
"""

import sys
import time
import os
import threading
import chardet
import pandas as pd
from pandas import Series, DataFrame
import FunctionLog
from Trade import PyCTP_Trader
from Market import PyCTP_Market
import Utils
import uuid
import multiprocessing

#多进程函数
def my_function(x):
    # time.sleep(1)
    # print('My Unique Id: {0}'.format(uuid.uuid1()))
    print(">>> process name = ", multiprocessing.current_process())
    print("x = ", x)
    if x == 0:
        BrokerID = b'9999'
        UserID = b'058176'  # 063802
        Password = b'669822'  # 123456
        ExchangeID = b'SHFE'
        listInstrumentID = [b'cu1706', b'cu1709']
        InstrumentID = b'cu1701'
        trader = PyCTP_Trader.CreateFtdcTraderApi(b'tmp/_tmp_t_')  # Trade实例
        market = PyCTP_Market.CreateFtdcMdApi(b'tmp/_tmp_m_')  # Market实例
        print('连接交易前置', Utils.code_transform(trader.Connect(b'tcp://180.168.146.187:10000')))
        print('连接行情前置', Utils.code_transform(market.Connect(b'tcp://180.168.146.187:10010')))
        print('交易账号登陆', Utils.code_transform(trader.Login(BrokerID, UserID, Password)))
        print('交易账号登陆', Utils.code_transform(market.Login(BrokerID, UserID, Password)))
        print('交易日', Utils.code_transform(trader.GetTradingDay()))
        print('设置投资者代码', Utils.code_transform(trader.setInvestorID(UserID)))
        time.sleep(1)
        print('查询账户信息\n', Utils.code_transform(trader.QryInvestor()))
        while True:
            # print('查询账户信息')
            print("In process ", multiprocessing.current_process(), '查询账户信息', Utils.code_transform(trader.QryInvestor()))
            print("\n")
            time.sleep(2)

    elif x == 1:
        BrokerID = b'9999'
        UserID = b'063802'  # 063802
        Password = b'123456'  # 123456
        ExchangeID = b'SHFE'
        listInstrumentID = [b'cu1706', b'cu1709']
        InstrumentID = b'cu1701'
        trader = PyCTP_Trader.CreateFtdcTraderApi(b'tmp/_tmp_t_')  # Trade实例
        market = PyCTP_Market.CreateFtdcMdApi(b'tmp/_tmp_m_')  # Market实例
        print('连接交易前置', Utils.code_transform(trader.Connect(b'tcp://180.168.146.187:10000')))
        print('连接行情前置', Utils.code_transform(market.Connect(b'tcp://180.168.146.187:10010')))
        print('交易账号登陆', Utils.code_transform(trader.Login(BrokerID, UserID, Password)))
        print('交易账号登陆', Utils.code_transform(market.Login(BrokerID, UserID, Password)))
        print('交易日', Utils.code_transform(trader.GetTradingDay()))
        print('设置投资者代码', Utils.code_transform(trader.setInvestorID(UserID)))
        time.sleep(1)
        while True:
            # print('查询账户信息')
            print("In process ", multiprocessing.current_process(), '查询账户信息', Utils.code_transform(trader.QryInvestor()))
            print("\n")
            time.sleep(2)


def __main__():
    print("\n\n>>> In process ", multiprocessing.current_process())
    for x in range(2):
        process = multiprocessing.Process(target=my_function, args=(x,))
        process.daemon = True
        process.start()
        # process.join()

    BrokerID = b'9999'
    UserID = b'063802'  # 063802
    Password = b'123456'  # 123456
    ExchangeID = b'SHFE'
    listInstrumentID = [b'cu1706', b'cu1709']
    InstrumentID = b'cu1701'
    trader = PyCTP_Trader.CreateFtdcTraderApi(b'tmp/_tmp_t_')  # Trade实例
    market = PyCTP_Market.CreateFtdcMdApi(b'tmp/_tmp_m_')  # Market实例
    print('连接交易前置', Utils.code_transform(trader.Connect(b'tcp://180.168.146.187:10000')))
    print('连接行情前置', Utils.code_transform(market.Connect(b'tcp://180.168.146.187:10011')))
    print('交易账号登陆', Utils.code_transform(trader.Login(BrokerID, UserID, Password)))
    print('交易账号登陆', Utils.code_transform(market.Login(BrokerID, UserID, Password)))
    print('交易日', Utils.code_transform(trader.GetTradingDay()))
    print('设置投资者代码', Utils.code_transform(trader.setInvestorID(UserID)))

    # 调试OrderInsert
    while True:
        print(">>> In process ", multiprocessing.current_process())
        time.sleep(2)

    time.sleep(2.0)
    print('退订行情:', market.UnSubMarketData(listInstrumentID))
    print('交易账号登出', trader.Logout())
    print('行情账号登出', market.Logout())


if __name__ == '__main__':
    __main__()

没有止损

价差止损设置为1,价差偏离2个跳,程序没有止损,快期没有报单

删除策略id后,添加同一策略id,界面无响应

测试步骤:
1:添加策略id:"06",
2:删除策略id“06”,
3:添加策略id:"06"
结果:
界面无响应,Python后台提示重复创建id
期望结果:
可以添加进去,如果遇到重复添加,应该消息框提示.

添加新策略报错

鼠标右击添加新策略,发现报错。
log:
Traceback (most recent call last):
File "C:\Users\yuanpengfei\Desktop\PyCTP-PyCTP_Dev\PyCTP_Client\PyCTP_ClientCore\QNewStrategy.py", line 123, in on_pushButton_ok_clicked
'order_algorithm': self.__socket_manager.get_list_algorithm_info()[0]['name'], # 下单算法
IndexError: list index out of range

issue3
issue31

设置持仓错误

中金所品种跨期套利的策略有持仓,将策略设置持仓为非零,TS正常接收和处理了修改持仓指令,TS发给小蜜蜂的设置持仓回报消息的值也是正确的,小蜜蜂界面和内核将设置持仓的各个持仓值全部为0.

校正持仓数据后,列表持仓明细未更新

测试步骤:
1::手工在策略参数表中设置持仓,设置A总卖,B总买,A总买,B总卖...均为0,点击发送持仓;
2:检查服务端数据库,发现已经修改,但是客户端策略列表界面未更新。

期望:
策略列表应该实时更新最新数据。

qq 20170109111158

非上期所的手续费计算

非上期所的平今平昨标志注意:
通过小蜜蜂套利系统发单,平今和平仓标志分别为3、4,如果是通过快期平仓或平今,标志都是1.
小蜜蜂需要处理平仓标志为1、3、4的所有情况。

小蜜蜂布局policy有问题

小蜜蜂布局,size policy设置存在问题。

  • 参数面板不该被遮挡
  • 期货账户tabbar不该被遮挡
  • 其他空间size policy都要检查下,符合布局需求

qq 20170414230648

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.