示例#1
0
 public void SetTrdCallback(FTSPI_Trd callback)
 {
     lock (this)
     {
         trdCallback = callback;
     }
 }
示例#2
0
        protected override void OnPush(ProtoHeader protoHeader, byte[] data)
        {
            ProtoID   protoID     = (ProtoID)protoHeader.nProtoID;
            uint      serialNo    = protoHeader.nSerialNo;
            FTSPI_Trd trdCallback = null;

            lock (trdCallbackLock)
            {
                trdCallback = this.trdCallback;
            }

            if (trdCallback == null)
            {
                return;
            }

            switch (protoID)
            {
            case ProtoID.TrdUpdateOrder:    //订单状态变动通知(推送)
            {
                Futu.OpenApi.Pb.TrdUpdateOrder.Response rsp;
                try
                {
                    rsp = Futu.OpenApi.Pb.TrdUpdateOrder.Response.ParseFrom(data);
                }
                catch (InvalidProtocolBufferException)
                {
                    rsp = Futu.OpenApi.Pb.TrdUpdateOrder.Response.CreateBuilder().SetRetType((int)Common.RetType.RetType_Invalid).Build();
                }
                trdCallback.OnReply_UpdateOrder(this, serialNo, rsp);
            }
            break;

            case ProtoID.TrdUpdateOrderFill:    //成交通知(推送)
            {
                Futu.OpenApi.Pb.TrdUpdateOrderFill.Response rsp;
                try
                {
                    rsp = Futu.OpenApi.Pb.TrdUpdateOrderFill.Response.ParseFrom(data);
                }
                catch (InvalidProtocolBufferException)
                {
                    rsp = Futu.OpenApi.Pb.TrdUpdateOrderFill.Response.CreateBuilder().SetRetType((int)Common.RetType.RetType_Invalid).Build();
                }
                trdCallback.OnReply_UpdateOrderFill(this, serialNo, rsp);
            }
            break;
            }
        }
示例#3
0
        protected override void OnReply(ReqReplyType replyType, ProtoHeader protoHeader, byte[] data)
        {
            ProtoID   protoID     = (ProtoID)protoHeader.nProtoID;
            uint      serialNo    = protoHeader.nSerialNo;
            FTSPI_Trd trdCallback = null;

            lock (trdCallbackLock)
            {
                trdCallback = this.trdCallback;
            }

            if (trdCallback == null)
            {
                return;
            }

            switch (protoID)
            {
            case ProtoID.TrdGetAccList:    //获取交易账户列表
            {
                Futu.OpenApi.Pb.TrdGetAccList.Response rsp;
                if (replyType == ReqReplyType.SvrReply)
                {
                    try
                    {
                        rsp = Futu.OpenApi.Pb.TrdGetAccList.Response.ParseFrom(data);
                    }
                    catch (InvalidProtocolBufferException)
                    {
                        rsp = Futu.OpenApi.Pb.TrdGetAccList.Response.CreateBuilder().SetRetType((int)Common.RetType.RetType_Invalid).Build();
                    }
                }
                else
                {
                    rsp = Futu.OpenApi.Pb.TrdGetAccList.Response.CreateBuilder().SetRetType((int)replyType).Build();
                }

                trdCallback.OnReply_GetAccList(this, serialNo, rsp);
            }
            break;

            case ProtoID.TrdUnlockTrade:    //解锁
            {
                Futu.OpenApi.Pb.TrdUnlockTrade.Response rsp;
                if (replyType == ReqReplyType.SvrReply)
                {
                    try
                    {
                        rsp = Futu.OpenApi.Pb.TrdUnlockTrade.Response.ParseFrom(data);
                    }
                    catch (InvalidProtocolBufferException)
                    {
                        rsp = Futu.OpenApi.Pb.TrdUnlockTrade.Response.CreateBuilder().SetRetType((int)Common.RetType.RetType_Invalid).Build();
                    }
                }
                else
                {
                    rsp = Futu.OpenApi.Pb.TrdUnlockTrade.Response.CreateBuilder().SetRetType((int)replyType).Build();
                }

                trdCallback.OnReply_UnlockTrade(this, serialNo, rsp);
            }
            break;

            case ProtoID.TrdSubAccPush:    //订阅接收推送数据的交易账户
            {
                Futu.OpenApi.Pb.TrdSubAccPush.Response rsp;
                if (replyType == ReqReplyType.SvrReply)
                {
                    try
                    {
                        rsp = Futu.OpenApi.Pb.TrdSubAccPush.Response.ParseFrom(data);
                    }
                    catch (InvalidProtocolBufferException)
                    {
                        rsp = Futu.OpenApi.Pb.TrdSubAccPush.Response.CreateBuilder().SetRetType((int)Common.RetType.RetType_Invalid).Build();
                    }
                }
                else
                {
                    rsp = Futu.OpenApi.Pb.TrdSubAccPush.Response.CreateBuilder().SetRetType((int)replyType).Build();
                }

                trdCallback.OnReply_SubAccPush(this, serialNo, rsp);
            }
            break;

            case ProtoID.TrdGetFunds:    //获取账户资金
            {
                Futu.OpenApi.Pb.TrdGetFunds.Response rsp;
                if (replyType == ReqReplyType.SvrReply)
                {
                    try
                    {
                        rsp = Futu.OpenApi.Pb.TrdGetFunds.Response.ParseFrom(data);
                    }
                    catch (InvalidProtocolBufferException)
                    {
                        rsp = Futu.OpenApi.Pb.TrdGetFunds.Response.CreateBuilder().SetRetType((int)Common.RetType.RetType_Invalid).Build();
                    }
                }
                else
                {
                    rsp = Futu.OpenApi.Pb.TrdGetFunds.Response.CreateBuilder().SetRetType((int)replyType).Build();
                }

                trdCallback.OnReply_GetFunds(this, serialNo, rsp);
            }
            break;

            case ProtoID.TrdGetPositionList:    //获取账户持仓
            {
                Futu.OpenApi.Pb.TrdGetPositionList.Response rsp;
                if (replyType == ReqReplyType.SvrReply)
                {
                    try
                    {
                        rsp = Futu.OpenApi.Pb.TrdGetPositionList.Response.ParseFrom(data);
                    }
                    catch (InvalidProtocolBufferException)
                    {
                        rsp = Futu.OpenApi.Pb.TrdGetPositionList.Response.CreateBuilder().SetRetType((int)Common.RetType.RetType_Invalid).Build();
                    }
                }
                else
                {
                    rsp = Futu.OpenApi.Pb.TrdGetPositionList.Response.CreateBuilder().SetRetType((int)replyType).Build();
                }

                trdCallback.OnReply_GetPositionList(this, serialNo, rsp);
            }
            break;

            case ProtoID.TrdGetMaxTrdQtys:    //获取最大交易数量
            {
                Futu.OpenApi.Pb.TrdGetMaxTrdQtys.Response rsp;
                if (replyType == ReqReplyType.SvrReply)
                {
                    try
                    {
                        rsp = Futu.OpenApi.Pb.TrdGetMaxTrdQtys.Response.ParseFrom(data);
                    }
                    catch (InvalidProtocolBufferException)
                    {
                        rsp = Futu.OpenApi.Pb.TrdGetMaxTrdQtys.Response.CreateBuilder().SetRetType((int)Common.RetType.RetType_Invalid).Build();
                    }
                }
                else
                {
                    rsp = Futu.OpenApi.Pb.TrdGetMaxTrdQtys.Response.CreateBuilder().SetRetType((int)replyType).Build();
                }

                trdCallback.OnReply_GetMaxTrdQtys(this, serialNo, rsp);
            }
            break;

            case ProtoID.TrdGetOrderList:    //获取当日订单列表
            {
                Futu.OpenApi.Pb.TrdGetOrderList.Response rsp;
                if (replyType == ReqReplyType.SvrReply)
                {
                    try
                    {
                        rsp = Futu.OpenApi.Pb.TrdGetOrderList.Response.ParseFrom(data);
                    }
                    catch (InvalidProtocolBufferException)
                    {
                        rsp = Futu.OpenApi.Pb.TrdGetOrderList.Response.CreateBuilder().SetRetType((int)Common.RetType.RetType_Invalid).Build();
                    }
                }
                else
                {
                    rsp = Futu.OpenApi.Pb.TrdGetOrderList.Response.CreateBuilder().SetRetType((int)replyType).Build();
                }

                trdCallback.OnReply_GetOrderList(this, serialNo, rsp);
            }
            break;

            case ProtoID.TrdPlaceOrder:    //下单
            {
                Futu.OpenApi.Pb.TrdPlaceOrder.Response rsp;
                if (replyType == ReqReplyType.SvrReply)
                {
                    try
                    {
                        rsp = Futu.OpenApi.Pb.TrdPlaceOrder.Response.ParseFrom(data);
                    }
                    catch (InvalidProtocolBufferException)
                    {
                        rsp = Futu.OpenApi.Pb.TrdPlaceOrder.Response.CreateBuilder().SetRetType((int)Common.RetType.RetType_Invalid).Build();
                    }
                }
                else
                {
                    rsp = Futu.OpenApi.Pb.TrdPlaceOrder.Response.CreateBuilder().SetRetType((int)replyType).Build();
                }

                trdCallback.OnReply_PlaceOrder(this, serialNo, rsp);
            }
            break;

            case ProtoID.TrdModifyOrder:    //修改订单
            {
                Futu.OpenApi.Pb.TrdModifyOrder.Response rsp;
                if (replyType == ReqReplyType.SvrReply)
                {
                    try
                    {
                        rsp = Futu.OpenApi.Pb.TrdModifyOrder.Response.ParseFrom(data);
                    }
                    catch (InvalidProtocolBufferException)
                    {
                        rsp = Futu.OpenApi.Pb.TrdModifyOrder.Response.CreateBuilder().SetRetType((int)Common.RetType.RetType_Invalid).Build();
                    }
                }
                else
                {
                    rsp = Futu.OpenApi.Pb.TrdModifyOrder.Response.CreateBuilder().SetRetType((int)replyType).Build();
                }

                trdCallback.OnReply_ModifyOrder(this, serialNo, rsp);
            }
            break;

            case ProtoID.TrdGetOrderFillList:    //获取当日成交列表
            {
                Futu.OpenApi.Pb.TrdGetOrderFillList.Response rsp;
                if (replyType == ReqReplyType.SvrReply)
                {
                    try
                    {
                        rsp = Futu.OpenApi.Pb.TrdGetOrderFillList.Response.ParseFrom(data);
                    }
                    catch (InvalidProtocolBufferException)
                    {
                        rsp = Futu.OpenApi.Pb.TrdGetOrderFillList.Response.CreateBuilder().SetRetType((int)Common.RetType.RetType_Invalid).Build();
                    }
                }
                else
                {
                    rsp = Futu.OpenApi.Pb.TrdGetOrderFillList.Response.CreateBuilder().SetRetType((int)replyType).Build();
                }

                trdCallback.OnReply_GetOrderFillList(this, serialNo, rsp);
            }
            break;

            case ProtoID.TrdGetHistoryOrderList:    //获取历史订单列表
            {
                Futu.OpenApi.Pb.TrdGetHistoryOrderList.Response rsp;
                if (replyType == ReqReplyType.SvrReply)
                {
                    try
                    {
                        rsp = Futu.OpenApi.Pb.TrdGetHistoryOrderList.Response.ParseFrom(data);
                    }
                    catch (InvalidProtocolBufferException)
                    {
                        rsp = Futu.OpenApi.Pb.TrdGetHistoryOrderList.Response.CreateBuilder().SetRetType((int)Common.RetType.RetType_Invalid).Build();
                    }
                }
                else
                {
                    rsp = Futu.OpenApi.Pb.TrdGetHistoryOrderList.Response.CreateBuilder().SetRetType((int)replyType).Build();
                }

                trdCallback.OnReply_GetHistoryOrderList(this, serialNo, rsp);
            }
            break;

            case ProtoID.TrdGetHistoryOrderFillList:    //获取历史成交列表
            {
                Futu.OpenApi.Pb.TrdGetHistoryOrderFillList.Response rsp;
                if (replyType == ReqReplyType.SvrReply)
                {
                    try
                    {
                        rsp = Futu.OpenApi.Pb.TrdGetHistoryOrderFillList.Response.ParseFrom(data);
                    }
                    catch (InvalidProtocolBufferException)
                    {
                        rsp = Futu.OpenApi.Pb.TrdGetHistoryOrderFillList.Response.CreateBuilder().SetRetType((int)Common.RetType.RetType_Invalid).Build();
                    }
                }
                else
                {
                    rsp = Futu.OpenApi.Pb.TrdGetHistoryOrderFillList.Response.CreateBuilder().SetRetType((int)replyType).Build();
                }

                trdCallback.OnReply_GetHistoryOrderFillList(this, serialNo, rsp);
            }
            break;
            }
        }