Exemplo n.º 1
0
def test_MMTradeProto():
    req_data = trade_pb2.MMTradeProto(
        Header = trade_pb2.TradeMessageHead(
            FunCode = 0,
            RequestID = 0,
            AccountID = 100101, # 与下面的AccountID是什么关系?
            ),
        OrderID = order_id,                     # 单号   int64
        OrderType = 0101020101,          # 单据类型 int64 做市/买/市价/建仓/保证金
        OperateID = 4,                   # 操作员ID int64
        AccountID = 5,                   # 资金账户ID int64
        GoodID = 7,                      # 商品ID int32
        Qty = 1.0,                       # 数量 double
        Price = 1.0,                     # 价格 double
        BuyOrSell = 0,                   # 买卖方向 int32
        )
    """CloseDetails = 11, # 平仓明细 repeated MMCloseDetail
    #optional   int64 OrderID = 1,                # (被平)单号
    #optional  double Qty = 2,                    # 平仓数量
    #optional  double UserMargin = 3,             # 释放占用保证金
    #optional  double ReleaseHoldAmount = 4,      # 释放持仓金额
    #optional  double CloseCharge = 5,            # 平仓手续费
    #optional  double WarehouseCharge = 6,        # 仓单服务费
    #optional  double ClosePL = 7,                # 平仓盈亏"""
    req_data.CloseDetails.add(Qty=10.0)
    req_data.CloseDetails.add(Qty=10.0, UserMargin=10.0)
    s = req_data.SerializeToString()
    data2 = trade_pb2.MMTradeProto()
    data2.ParseFromString(s)
    protobuf.assert_equal(req_data, data2)
Exemplo n.º 2
0
 def expect2(self, queue, exp_funcode, exp_session_id, exp_protobuf_data, timeout=1.0):
     assert_in(queue, self.queue_set)
     funcode, session_id, protobuf_data = self.get(queue, timeout)
     print 'expect2() protobuf_data(%s)='%type(protobuf_data)
     print protobuf_data
     eq_(exp_funcode, funcode)
     assert_is_instance(protobuf_data, type(exp_protobuf_data))
     if exp_session_id:
         eq_(exp_session_id, session_id)
     protobuf.assert_equal(exp_protobuf_data, protobuf_data)
     return protobuf_data
Exemplo n.º 3
0
def test_MMOrderReq():# 做市委托单请求 0 3 201 -> funcode=196809
    t = time.time()
    header = common_pb2.MessageHead(
        FunCode = 196809,                       # 功能号
	    RequestID = request_id_generator.gen(), # 客户端的流水ID
	    AccountId = 3,                          # 账号ID
	    AccessId = 0,                           # 二级分配给客户端的接入ID
	    ClientTime = int(t*1000)                #消息发起时间 时间戳 毫秒
        )
    data = TkernelTas1_pb2.MMOrderReq(
        Header = header,
	    OrderHead = TkernelTas1_pb2.OrderHead( # OrderHead 委托消息头
	        Header = header, # MessageHead
	        #int32 RetCode = 2, # int32 返回码
	        OrderID = order_generator.gen(t), #optional int64 OrderID = 3, # int64 委托单号
	        ClientSerialNo = '1', #optional string = 4, # string 客户端流水号
	        ClientOrderTime = gen_client_order_time(t), #optional string 5, # string 客户端委托时间
	        ClientFlag = 'PC Client',#optional string 6, # string 终端标示, 手机,PC端等
	        AccountID = 7, #optional int32  # int32 交易账号
	        #AccountStatus = 8,#optional int32  # int32 账户状态
	        GoodsID = 9, #optional int32 # int32 商品ID
	        #optional int32 ValidType = 10, # int32 校验类型
	        #optional string ValidTime = 11, # string 有效期限
	        OperateType = 1, #optional int32 # int32 操作类型: 委托, 强平,代客
	        #OperatorID = 1, #optional int32 # int32 操作员账号ID
	        AccountType = 1, #optional int32 # int32 账户类型
	        OrderSrc = 15, #optional int32 # int32 单据来源:交易端,管理端,风控
	        #optional string AttachParam = 16, # string 附加参数(JSON字符串,协议待定,用于临时新增字段定)	        )
	        ),
	    MemberID = 3, #optional int32 # int32 所属会员
        OrderPrice = 10.0, #optional double # double 委托价格
	    OrderQty = 5, #optional double # double 委托数量
	    BuyOrSell = 0, #optional int32 # int32 买卖方向
	    OpenType = 0, #optional int32 # int32 下单类型:建仓,平仓,
	    AllowTradeSub = 8, #optional double # double 允许成交偏差范围
	    #optional int32 SpecialAccount = 9, # int32 特别会员账号ID
	    #optional double BuyOrSellPtSub = 10, # double 买卖点差
	    #optional double SpPrice = 11, # double 止盈价格
	    #optional double SlPrice = 12, # double 止损价格
	    #optional int32 MarketID = 13, # int32 市场ID
	    #optional string StartTime = 14, # string 开始时间
	    #optional string EndTime = 15, # string 结束时间
	    #optional int32 ReOpenFlag = 16, # int32 反手建仓标记
        )
    s = data.SerializeToString()
    data2 = TkernelTas1_pb2.MMOrderReq()
    data2.ParseFromString(s)
    protobuf.assert_equal(data, data2)
 def expect2(self,
             queue,
             exp_funcode,
             exp_session_id,
             exp_protobuf_data,
             timeout=1.0):
     assert_in(queue, self.queue_set)
     funcode, session_id, protobuf_data = self.get(queue, timeout)
     print 'expect2() protobuf_data(%s)=' % type(protobuf_data)
     print protobuf_data
     eq_(exp_funcode, funcode)
     assert_is_instance(protobuf_data, type(exp_protobuf_data))
     if exp_session_id:
         eq_(exp_session_id, session_id)
     protobuf.assert_equal(exp_protobuf_data, protobuf_data)
     return protobuf_data
Exemplo n.º 5
0
 def expect2(self, exp_data, timeout):
     funcode, data = self.recv_queue.get(True, timeout)
     assert_is_instance(data, type(exp_data))
     protobuf.assert_equal(exp_data, data)
Exemplo n.º 6
0
def test_OrderDealedNtf():
    data = TkernelTas1_pb2.OrderDealedNtf()
    data.CloseInfos.add(ClosedOrderID=1)
    data2 = TkernelTas1_pb2.OrderDealedNtf()
    data2.CloseInfos.add(ClosedOrderID=1, TradeCharge=1.0)
    protobuf.assert_equal(data, data2)