コード例 #1
0
ファイル: QryTransferBank.cpp プロジェクト: kayv/ctp_examples
    ///请求查询转帐银行响应
    virtual void OnRspQryTransferBank(
        CThostFtdcTransferBankField * pTransferBank,
        CThostFtdcRspInfoField * pRspInfo,
        int nRequestID,
        bool bIsLast
    ) {
        //printf("OnRspQryTransferBank():被执行...\n");

        // 进程返回结果检查
        if ( (pRspInfo) && (pRspInfo->ErrorID != 0) )  {
            // typedef int TThostFtdcErrorIDType;
            // typedef char TThostFtdcErrorMsgType[81];
            char ErrorMsg[243];
            gbk2utf8(pRspInfo->ErrorMsg,ErrorMsg,sizeof(ErrorMsg));
            printf("OnRspQryTransferBank():出错:ErrorId=%d,ErrorMsg=%s\n",pRspInfo->ErrorID,ErrorMsg);
        }

        // 如果有返回结果读取返回信息
        if ( pTransferBank != NULL ) {
            // 读取返回信息,并做编码转化
            ///银行代码 TThostFtdcBankIDType char[4]
            char BankID[12];
            gbk2utf8(pTransferBank->BankID,BankID,sizeof(BankID));
            ///银行分中心代码 TThostFtdcBankBrchIDType char[5]
            char BankBrchID[15];
            gbk2utf8(pTransferBank->BankBrchID,BankBrchID,sizeof(BankBrchID));
            ///银行名称 TThostFtdcBankNameType char[101]
            char BankName[303];
            gbk2utf8(pTransferBank->BankName,BankName,sizeof(BankName));
            ///是否活跃 TThostFtdcBoolType int
            int IsActive = pTransferBank->IsActive;


			printf("BankID=%s,",BankID); // 银行代码
			printf("BankBrchID=%s,",BankBrchID); //银行分中心代码
			printf("BankName=%s,",BankName); // 银行名称
			printf("IsActive=%d\n",IsActive); //是否活跃

        }

        // 如果响应函数已经返回最后一条信息
        if(bIsLast) {
            // 通知主过程,响应函数将结束
            sem_post(&sem);
        }
    }
コード例 #2
0
ファイル: OrderInsert.cpp プロジェクト: kayv/ctp_examples
    /////报单通知
    virtual void OnRtnOrder(
        CThostFtdcOrderField * pOrder
    ) {
        printf("OnRtnOrder():被执行...\n");
        // 如果有返回结果读取返回信息
        if ( pOrder != NULL ) {
            // 读取返回信息,并做编码转化
            ///经纪公司代码 TThostFtdcBrokerIDType char[11]
            char BrokerID[33];
            gbk2utf8(pOrder->BrokerID,BrokerID,sizeof(BrokerID));
            ///投资者代码 TThostFtdcInvestorIDType char[13]
            char InvestorID[39];
            gbk2utf8(pOrder->InvestorID,InvestorID,sizeof(InvestorID));
            ///合约代码 TThostFtdcInstrumentIDType char[31]
            char InstrumentID[93];
            gbk2utf8(pOrder->InstrumentID,InstrumentID,sizeof(InstrumentID));
            ///报单引用 TThostFtdcOrderRefType char[13]
            char OrderRef[39];
            gbk2utf8(pOrder->OrderRef,OrderRef,sizeof(OrderRef));
            ///用户代码 TThostFtdcUserIDType char[16]
            char UserID[48];
            gbk2utf8(pOrder->UserID,UserID,sizeof(UserID));
            ///报单价格条件 TThostFtdcOrderPriceTypeType char
            //// THOST_FTDC_OPT_AnyPrice '1' 任意价
            //// THOST_FTDC_OPT_LimitPrice '2' 限价
            //// THOST_FTDC_OPT_BestPrice '3' 最优价
            //// THOST_FTDC_OPT_LastPrice '4' 最新价
            //// THOST_FTDC_OPT_LastPricePlusOneTicks '5' 最新价浮动上浮1个ticks
            //// THOST_FTDC_OPT_LastPricePlusTwoTicks '6' 最新价浮动上浮2个ticks
            //// THOST_FTDC_OPT_LastPricePlusThreeTicks '7' 最新价浮动上浮3个ticks
            //// THOST_FTDC_OPT_AskPrice1 '8' 卖一价
            //// THOST_FTDC_OPT_AskPrice1PlusOneTicks '9' 卖一价浮动上浮1个ticks
            //// THOST_FTDC_OPT_AskPrice1PlusTwoTicks 'A' 卖一价浮动上浮2个ticks
            //// THOST_FTDC_OPT_AskPrice1PlusThreeTicks 'B' 卖一价浮动上浮3个ticks
            //// THOST_FTDC_OPT_BidPrice1 'C' 买一价
            //// THOST_FTDC_OPT_BidPrice1PlusOneTicks 'D' 买一价浮动上浮1个ticks
            //// THOST_FTDC_OPT_BidPrice1PlusTwoTicks 'E' 买一价浮动上浮2个ticks
            //// THOST_FTDC_OPT_BidPrice1PlusThreeTicks 'F' 买一价浮动上浮3个ticks
            char OrderPriceType = pOrder->OrderPriceType;
            ///买卖方向 TThostFtdcDirectionType char
            //// THOST_FTDC_D_Buy '0' 买
            //// THOST_FTDC_D_Sell '1' 卖
            char Direction = pOrder->Direction;
            ///组合开平标志 TThostFtdcCombOffsetFlagType char[5]
            //// THOST_FTDC_OF_Open '0' 开仓
            //// THOST_FTDC_OF_Close '1' 平仓
            //// THOST_FTDC_OF_ForceClose '2' 强平
            //// THOST_FTDC_OF_CloseToday '3' 平今
            //// THOST_FTDC_OF_CloseYesterday '4' 平昨
            //// THOST_FTDC_OF_ForceOff '5' 强减
            //// THOST_FTDC_OF_LocalForceClose '6' 本地强平
            char CombOffsetFlag[15];
            gbk2utf8(pOrder->CombOffsetFlag,CombOffsetFlag,sizeof(CombOffsetFlag));
            ///组合投机套保标志 TThostFtdcCombHedgeFlagType char[5]
            //// THOST_FTDC_HF_Speculation '1' 投机
            //// THOST_FTDC_HF_Arbitrage '2' 套利
            //// THOST_FTDC_HF_Hedge '3' 套保
            char CombHedgeFlag[15];
            gbk2utf8(pOrder->CombHedgeFlag,CombHedgeFlag,sizeof(CombHedgeFlag));
            ///价格 TThostFtdcPriceType double
            double LimitPrice = pOrder->LimitPrice;
            ///数量 TThostFtdcVolumeType int
            int VolumeTotalOriginal = pOrder->VolumeTotalOriginal;
            ///有效期类型 TThostFtdcTimeConditionType char
            //// THOST_FTDC_TC_IOC '1' 立即完成,否则撤销
            //// THOST_FTDC_TC_GFS '2' 本节有效
            //// THOST_FTDC_TC_GFD '3' 当日有效
            //// THOST_FTDC_TC_GTD '4' 指定日期前有效
            //// THOST_FTDC_TC_GTC '5' 撤销前有效
            //// THOST_FTDC_TC_GFA '6' 集合竞价有效
            char TimeCondition = pOrder->TimeCondition;
            ///GTD日期 TThostFtdcDateType char[9]
            char GTDDate[27];
            gbk2utf8(pOrder->GTDDate,GTDDate,sizeof(GTDDate));
            ///成交量类型 TThostFtdcVolumeConditionType char
            //// THOST_FTDC_VC_AV '1' 任何数量
            //// THOST_FTDC_VC_MV '2' 最小数量
            //// THOST_FTDC_VC_CV '3' 全部数量
            char VolumeCondition = pOrder->VolumeCondition;
            ///最小成交量 TThostFtdcVolumeType int
            int MinVolume = pOrder->MinVolume;
            ///触发条件 TThostFtdcContingentConditionType char
            //// THOST_FTDC_CC_Immediately '1' 立即
            //// THOST_FTDC_CC_Touch '2' 止损
            //// THOST_FTDC_CC_TouchProfit '3' 止赢
            //// THOST_FTDC_CC_ParkedOrder '4' 预埋单
            //// THOST_FTDC_CC_LastPriceGreaterThanStopPrice '5' 最新价大于条件价
            //// THOST_FTDC_CC_LastPriceGreaterEqualStopPrice '6' 最新价大于等于条件价
            //// THOST_FTDC_CC_LastPriceLesserThanStopPrice '7' 最新价小于条件价
            //// THOST_FTDC_CC_LastPriceLesserEqualStopPrice '8' 最新价小于等于条件价
            //// THOST_FTDC_CC_AskPriceGreaterThanStopPrice '9' 卖一价大于条件价
            //// THOST_FTDC_CC_AskPriceGreaterEqualStopPrice 'A' 卖一价大于等于条件价
            //// THOST_FTDC_CC_AskPriceLesserThanStopPrice 'B' 卖一价小于条件价
            //// THOST_FTDC_CC_AskPriceLesserEqualStopPrice 'C' 卖一价小于等于条件价
            //// THOST_FTDC_CC_BidPriceGreaterThanStopPrice 'D' 买一价大于条件价
            //// THOST_FTDC_CC_BidPriceGreaterEqualStopPrice 'E' 买一价大于等于条件价
            //// THOST_FTDC_CC_BidPriceLesserThanStopPrice 'F' 买一价小于条件价
            //// THOST_FTDC_CC_BidPriceLesserEqualStopPrice 'H' 买一价小于等于条件价
            char ContingentCondition = pOrder->ContingentCondition;
            ///止损价 TThostFtdcPriceType double
            double StopPrice = pOrder->StopPrice;
            ///强平原因 TThostFtdcForceCloseReasonType char
            //// THOST_FTDC_FCC_NotForceClose '0' 非强平
            //// THOST_FTDC_FCC_LackDeposit '1' 资金不足
            //// THOST_FTDC_FCC_ClientOverPositionLimit '2' 客户超仓
            //// THOST_FTDC_FCC_MemberOverPositionLimit '3' 会员超仓
            //// THOST_FTDC_FCC_NotMultiple '4' 持仓非整数倍
            //// THOST_FTDC_FCC_Violation '5' 违规
            //// THOST_FTDC_FCC_Other '6' 其它
            //// THOST_FTDC_FCC_PersonDeliv '7' 自然人临近交割
            char ForceCloseReason = pOrder->ForceCloseReason;
            ///自动挂起标志 TThostFtdcBoolType int
            int IsAutoSuspend = pOrder->IsAutoSuspend;
            ///业务单元 TThostFtdcBusinessUnitType char[21]
            char BusinessUnit[63];
            gbk2utf8(pOrder->BusinessUnit,BusinessUnit,sizeof(BusinessUnit));
            ///请求编号 TThostFtdcRequestIDType int
            int RequestID = pOrder->RequestID;
            ///本地报单编号 TThostFtdcOrderLocalIDType char[13]
            char OrderLocalID[39];
            gbk2utf8(pOrder->OrderLocalID,OrderLocalID,sizeof(OrderLocalID));
            ///交易所代码 TThostFtdcExchangeIDType char[9]
            char ExchangeID[27];
            gbk2utf8(pOrder->ExchangeID,ExchangeID,sizeof(ExchangeID));
            ///会员代码 TThostFtdcParticipantIDType char[11]
            char ParticipantID[33];
            gbk2utf8(pOrder->ParticipantID,ParticipantID,sizeof(ParticipantID));
            ///客户代码 TThostFtdcClientIDType char[11]
            char ClientID[33];
            gbk2utf8(pOrder->ClientID,ClientID,sizeof(ClientID));
            ///合约在交易所的代码 TThostFtdcExchangeInstIDType char[31]
            char ExchangeInstID[93];
            gbk2utf8(pOrder->ExchangeInstID,ExchangeInstID,sizeof(ExchangeInstID));
            ///交易所交易员代码 TThostFtdcTraderIDType char[21]
            char TraderID[63];
            gbk2utf8(pOrder->TraderID,TraderID,sizeof(TraderID));
            ///安装编号 TThostFtdcInstallIDType int
            int InstallID = pOrder->InstallID;
            ///报单提交状态 TThostFtdcOrderSubmitStatusType char
            //// THOST_FTDC_OSS_InsertSubmitted '0' 已经提交
            //// THOST_FTDC_OSS_CancelSubmitted '1' 撤单已经提交
            //// THOST_FTDC_OSS_ModifySubmitted '2' 修改已经提交
            //// THOST_FTDC_OSS_Accepted '3' 已经接受
            //// THOST_FTDC_OSS_InsertRejected '4' 报单已经被拒绝
            //// THOST_FTDC_OSS_CancelRejected '5' 撤单已经被拒绝
            //// THOST_FTDC_OSS_ModifyRejected '6' 改单已经被拒绝
            char OrderSubmitStatus = pOrder->OrderSubmitStatus;
            ///报单提示序号 TThostFtdcSequenceNoType int
            int NotifySequence = pOrder->NotifySequence;
            ///交易日 TThostFtdcDateType char[9]
            char TradingDay[27];
            gbk2utf8(pOrder->TradingDay,TradingDay,sizeof(TradingDay));
            ///结算编号 TThostFtdcSettlementIDType int
            int SettlementID = pOrder->SettlementID;
            ///报单编号 TThostFtdcOrderSysIDType char[21]
            char OrderSysID[63];
            gbk2utf8(pOrder->OrderSysID,OrderSysID,sizeof(OrderSysID));
            ///报单来源 TThostFtdcOrderSourceType char
            //// THOST_FTDC_OSRC_Participant '0' 来自参与者
            //// THOST_FTDC_OSRC_Administrator '1' 来自管理员
            char OrderSource = pOrder->OrderSource;
            ///报单状态 TThostFtdcOrderStatusType char
            //// THOST_FTDC_OST_AllTraded '0' 全部成交
            //// THOST_FTDC_OST_PartTradedQueueing '1' 部分成交还在队列中
            //// THOST_FTDC_OST_PartTradedNotQueueing '2' 部分成交不在队列中
            //// THOST_FTDC_OST_NoTradeQueueing '3' 未成交还在队列中
            //// THOST_FTDC_OST_NoTradeNotQueueing '4' 未成交不在队列中
            //// THOST_FTDC_OST_Canceled '5' 撤单
            //// THOST_FTDC_OST_Unknown 'a' 未知
            //// THOST_FTDC_OST_NotTouched 'b' 尚未触发
            //// THOST_FTDC_OST_Touched 'c' 已触发
            char OrderStatus = pOrder->OrderStatus;
            ///报单类型 TThostFtdcOrderTypeType char
            //// THOST_FTDC_ORDT_Normal '0' 正常
            //// THOST_FTDC_ORDT_DeriveFromQuote '1' 报价衍生
            //// THOST_FTDC_ORDT_DeriveFromCombination '2' 组合衍生
            //// THOST_FTDC_ORDT_Combination '3' 组合报单
            //// THOST_FTDC_ORDT_ConditionalOrder '4' 条件单
            //// THOST_FTDC_ORDT_Swap '5' 互换单
            char OrderType = pOrder->OrderType;
            ///今成交数量 TThostFtdcVolumeType int
            int VolumeTraded = pOrder->VolumeTraded;
            ///剩余数量 TThostFtdcVolumeType int
            int VolumeTotal = pOrder->VolumeTotal;
            ///报单日期 TThostFtdcDateType char[9]
            char InsertDate[27];
            gbk2utf8(pOrder->InsertDate,InsertDate,sizeof(InsertDate));
            ///委托时间 TThostFtdcTimeType char[9]
            char InsertTime[27];
            gbk2utf8(pOrder->InsertTime,InsertTime,sizeof(InsertTime));
            ///激活时间 TThostFtdcTimeType char[9]
            char ActiveTime[27];
            gbk2utf8(pOrder->ActiveTime,ActiveTime,sizeof(ActiveTime));
            ///挂起时间 TThostFtdcTimeType char[9]
            char SuspendTime[27];
            gbk2utf8(pOrder->SuspendTime,SuspendTime,sizeof(SuspendTime));
            ///最后修改时间 TThostFtdcTimeType char[9]
            char UpdateTime[27];
            gbk2utf8(pOrder->UpdateTime,UpdateTime,sizeof(UpdateTime));
            ///撤销时间 TThostFtdcTimeType char[9]
            char CancelTime[27];
            gbk2utf8(pOrder->CancelTime,CancelTime,sizeof(CancelTime));
            ///最后修改交易所交易员代码 TThostFtdcTraderIDType char[21]
            char ActiveTraderID[63];
            gbk2utf8(pOrder->ActiveTraderID,ActiveTraderID,sizeof(ActiveTraderID));
            ///结算会员编号 TThostFtdcParticipantIDType char[11]
            char ClearingPartID[33];
            gbk2utf8(pOrder->ClearingPartID,ClearingPartID,sizeof(ClearingPartID));
            ///序号 TThostFtdcSequenceNoType int
            int SequenceNo = pOrder->SequenceNo;
            ///前置编号 TThostFtdcFrontIDType int
            int FrontID = pOrder->FrontID;
            ///会话编号 TThostFtdcSessionIDType int
            int SessionID = pOrder->SessionID;
            ///用户端产品信息 TThostFtdcProductInfoType char[11]
            char UserProductInfo[33];
            gbk2utf8(pOrder->UserProductInfo,UserProductInfo,sizeof(UserProductInfo));
            ///状态信息 TThostFtdcErrorMsgType char[81]
            char StatusMsg[243];
            gbk2utf8(pOrder->StatusMsg,StatusMsg,sizeof(StatusMsg));
            ///用户强评标志 TThostFtdcBoolType int
            int UserForceClose = pOrder->UserForceClose;
            ///操作用户代码 TThostFtdcUserIDType char[16]
            char ActiveUserID[48];
            gbk2utf8(pOrder->ActiveUserID,ActiveUserID,sizeof(ActiveUserID));
            ///经纪公司报单编号 TThostFtdcSequenceNoType int
            int BrokerOrderSeq = pOrder->BrokerOrderSeq;
            ///相关报单 TThostFtdcOrderSysIDType char[21]
            char RelativeOrderSysID[63];
            gbk2utf8(pOrder->RelativeOrderSysID,RelativeOrderSysID,sizeof(RelativeOrderSysID));
            ///郑商所成交数量 TThostFtdcVolumeType int
            int ZCETotalTradedVolume = pOrder->ZCETotalTradedVolume;
            ///互换单标志 TThostFtdcBoolType int
            int IsSwapOrder = pOrder->IsSwapOrder;

        }

    }
コード例 #3
0
ファイル: OrderInsert.cpp プロジェクト: kayv/ctp_examples
    ///报单录入请求响应
    virtual void OnRspOrderInsert(
        CThostFtdcInputOrderField * pInputOrder,
        CThostFtdcRspInfoField * pRspInfo,
        int nRequestID,
        bool bIsLast
    ) {
        printf("OnRspOrderInsert():被执行...\n");

        // 进程返回结果检查
        if ( (pRspInfo) && (pRspInfo->ErrorID != 0) )  {
            // typedef int TThostFtdcErrorIDType;
            // typedef char TThostFtdcErrorMsgType[81];
            char ErrorMsg[243];
            gbk2utf8(pRspInfo->ErrorMsg,ErrorMsg,sizeof(ErrorMsg));
            printf("OnRspOrderInsert():出错:ErrorId=%d,ErrorMsg=%s\n",pRspInfo->ErrorID,ErrorMsg);
        }

        // 如果有返回结果读取返回信息
        if ( pInputOrder != NULL ) {
            // 读取返回信息,并做编码转化
            ///经纪公司代码 TThostFtdcBrokerIDType char[11]
            char BrokerID[33];
            gbk2utf8(pInputOrder->BrokerID,BrokerID,sizeof(BrokerID));
            ///投资者代码 TThostFtdcInvestorIDType char[13]
            char InvestorID[39];
            gbk2utf8(pInputOrder->InvestorID,InvestorID,sizeof(InvestorID));
            ///合约代码 TThostFtdcInstrumentIDType char[31]
            char InstrumentID[93];
            gbk2utf8(pInputOrder->InstrumentID,InstrumentID,sizeof(InstrumentID));
            ///报单引用 TThostFtdcOrderRefType char[13]
            char OrderRef[39];
            gbk2utf8(pInputOrder->OrderRef,OrderRef,sizeof(OrderRef));
            ///用户代码 TThostFtdcUserIDType char[16]
            char UserID[48];
            gbk2utf8(pInputOrder->UserID,UserID,sizeof(UserID));
            ///报单价格条件 TThostFtdcOrderPriceTypeType char
            //// THOST_FTDC_OPT_AnyPrice '1' 任意价
            //// THOST_FTDC_OPT_LimitPrice '2' 限价
            //// THOST_FTDC_OPT_BestPrice '3' 最优价
            //// THOST_FTDC_OPT_LastPrice '4' 最新价
            //// THOST_FTDC_OPT_LastPricePlusOneTicks '5' 最新价浮动上浮1个ticks
            //// THOST_FTDC_OPT_LastPricePlusTwoTicks '6' 最新价浮动上浮2个ticks
            //// THOST_FTDC_OPT_LastPricePlusThreeTicks '7' 最新价浮动上浮3个ticks
            //// THOST_FTDC_OPT_AskPrice1 '8' 卖一价
            //// THOST_FTDC_OPT_AskPrice1PlusOneTicks '9' 卖一价浮动上浮1个ticks
            //// THOST_FTDC_OPT_AskPrice1PlusTwoTicks 'A' 卖一价浮动上浮2个ticks
            //// THOST_FTDC_OPT_AskPrice1PlusThreeTicks 'B' 卖一价浮动上浮3个ticks
            //// THOST_FTDC_OPT_BidPrice1 'C' 买一价
            //// THOST_FTDC_OPT_BidPrice1PlusOneTicks 'D' 买一价浮动上浮1个ticks
            //// THOST_FTDC_OPT_BidPrice1PlusTwoTicks 'E' 买一价浮动上浮2个ticks
            //// THOST_FTDC_OPT_BidPrice1PlusThreeTicks 'F' 买一价浮动上浮3个ticks
            char OrderPriceType = pInputOrder->OrderPriceType;
            ///买卖方向 TThostFtdcDirectionType char
            //// THOST_FTDC_D_Buy '0' 买
            //// THOST_FTDC_D_Sell '1' 卖
            char Direction = pInputOrder->Direction;
            ///组合开平标志 TThostFtdcCombOffsetFlagType char[5]
            //// THOST_FTDC_OF_Open '0' 开仓
            //// THOST_FTDC_OF_Close '1' 平仓
            //// THOST_FTDC_OF_ForceClose '2' 强平
            //// THOST_FTDC_OF_CloseToday '3' 平今
            //// THOST_FTDC_OF_CloseYesterday '4' 平昨
            //// THOST_FTDC_OF_ForceOff '5' 强减
            //// THOST_FTDC_OF_LocalForceClose '6' 本地强平
            char CombOffsetFlag[15];
            gbk2utf8(pInputOrder->CombOffsetFlag,CombOffsetFlag,sizeof(CombOffsetFlag));
            ///组合投机套保标志 TThostFtdcCombHedgeFlagType char[5]
            //// THOST_FTDC_HF_Speculation '1' 投机
            //// THOST_FTDC_HF_Arbitrage '2' 套利
            //// THOST_FTDC_HF_Hedge '3' 套保
            char CombHedgeFlag[15];
            gbk2utf8(pInputOrder->CombHedgeFlag,CombHedgeFlag,sizeof(CombHedgeFlag));
            ///价格 TThostFtdcPriceType double
            double LimitPrice = pInputOrder->LimitPrice;
            ///数量 TThostFtdcVolumeType int
            int VolumeTotalOriginal = pInputOrder->VolumeTotalOriginal;
            ///有效期类型 TThostFtdcTimeConditionType char
            //// THOST_FTDC_TC_IOC '1' 立即完成,否则撤销
            //// THOST_FTDC_TC_GFS '2' 本节有效
            //// THOST_FTDC_TC_GFD '3' 当日有效
            //// THOST_FTDC_TC_GTD '4' 指定日期前有效
            //// THOST_FTDC_TC_GTC '5' 撤销前有效
            //// THOST_FTDC_TC_GFA '6' 集合竞价有效
            char TimeCondition = pInputOrder->TimeCondition;
            ///GTD日期 TThostFtdcDateType char[9]
            char GTDDate[27];
            gbk2utf8(pInputOrder->GTDDate,GTDDate,sizeof(GTDDate));
            ///成交量类型 TThostFtdcVolumeConditionType char
            //// THOST_FTDC_VC_AV '1' 任何数量
            //// THOST_FTDC_VC_MV '2' 最小数量
            //// THOST_FTDC_VC_CV '3' 全部数量
            char VolumeCondition = pInputOrder->VolumeCondition;
            ///最小成交量 TThostFtdcVolumeType int
            int MinVolume = pInputOrder->MinVolume;
            ///触发条件 TThostFtdcContingentConditionType char
            //// THOST_FTDC_CC_Immediately '1' 立即
            //// THOST_FTDC_CC_Touch '2' 止损
            //// THOST_FTDC_CC_TouchProfit '3' 止赢
            //// THOST_FTDC_CC_ParkedOrder '4' 预埋单
            //// THOST_FTDC_CC_LastPriceGreaterThanStopPrice '5' 最新价大于条件价
            //// THOST_FTDC_CC_LastPriceGreaterEqualStopPrice '6' 最新价大于等于条件价
            //// THOST_FTDC_CC_LastPriceLesserThanStopPrice '7' 最新价小于条件价
            //// THOST_FTDC_CC_LastPriceLesserEqualStopPrice '8' 最新价小于等于条件价
            //// THOST_FTDC_CC_AskPriceGreaterThanStopPrice '9' 卖一价大于条件价
            //// THOST_FTDC_CC_AskPriceGreaterEqualStopPrice 'A' 卖一价大于等于条件价
            //// THOST_FTDC_CC_AskPriceLesserThanStopPrice 'B' 卖一价小于条件价
            //// THOST_FTDC_CC_AskPriceLesserEqualStopPrice 'C' 卖一价小于等于条件价
            //// THOST_FTDC_CC_BidPriceGreaterThanStopPrice 'D' 买一价大于条件价
            //// THOST_FTDC_CC_BidPriceGreaterEqualStopPrice 'E' 买一价大于等于条件价
            //// THOST_FTDC_CC_BidPriceLesserThanStopPrice 'F' 买一价小于条件价
            //// THOST_FTDC_CC_BidPriceLesserEqualStopPrice 'H' 买一价小于等于条件价
            char ContingentCondition = pInputOrder->ContingentCondition;
            ///止损价 TThostFtdcPriceType double
            double StopPrice = pInputOrder->StopPrice;
            ///强平原因 TThostFtdcForceCloseReasonType char
            //// THOST_FTDC_FCC_NotForceClose '0' 非强平
            //// THOST_FTDC_FCC_LackDeposit '1' 资金不足
            //// THOST_FTDC_FCC_ClientOverPositionLimit '2' 客户超仓
            //// THOST_FTDC_FCC_MemberOverPositionLimit '3' 会员超仓
            //// THOST_FTDC_FCC_NotMultiple '4' 持仓非整数倍
            //// THOST_FTDC_FCC_Violation '5' 违规
            //// THOST_FTDC_FCC_Other '6' 其它
            //// THOST_FTDC_FCC_PersonDeliv '7' 自然人临近交割
            char ForceCloseReason = pInputOrder->ForceCloseReason;
            ///自动挂起标志 TThostFtdcBoolType int
            int IsAutoSuspend = pInputOrder->IsAutoSuspend;
            ///业务单元 TThostFtdcBusinessUnitType char[21]
            char BusinessUnit[63];
            gbk2utf8(pInputOrder->BusinessUnit,BusinessUnit,sizeof(BusinessUnit));
            ///请求编号 TThostFtdcRequestIDType int
            int RequestID = pInputOrder->RequestID;
            ///用户强评标志 TThostFtdcBoolType int
            int UserForceClose = pInputOrder->UserForceClose;
            ///互换单标志 TThostFtdcBoolType int
            int IsSwapOrder = pInputOrder->IsSwapOrder;

        }

        // 如果响应函数已经返回最后一条信息
        if(bIsLast) {
            // 通知主过程,响应函数将结束
            sem_post(&sem);
        }
    }
コード例 #4
0
ファイル: OrderInsert.cpp プロジェクト: kayv/ctp_examples
    /////成交通知
    virtual void OnRtnTrade(
        CThostFtdcTradeField * pTrade
    ) {
        printf("OnRtnTrade():被执行...\n");
        // 如果有返回结果读取返回信息
        if ( pTrade != NULL ) {
            // 读取返回信息,并做编码转化
            ///经纪公司代码 TThostFtdcBrokerIDType char[11]
            char BrokerID[33];
            gbk2utf8(pTrade->BrokerID,BrokerID,sizeof(BrokerID));
            ///投资者代码 TThostFtdcInvestorIDType char[13]
            char InvestorID[39];
            gbk2utf8(pTrade->InvestorID,InvestorID,sizeof(InvestorID));
            ///合约代码 TThostFtdcInstrumentIDType char[31]
            char InstrumentID[93];
            gbk2utf8(pTrade->InstrumentID,InstrumentID,sizeof(InstrumentID));
            ///报单引用 TThostFtdcOrderRefType char[13]
            char OrderRef[39];
            gbk2utf8(pTrade->OrderRef,OrderRef,sizeof(OrderRef));
            ///用户代码 TThostFtdcUserIDType char[16]
            char UserID[48];
            gbk2utf8(pTrade->UserID,UserID,sizeof(UserID));
            ///交易所代码 TThostFtdcExchangeIDType char[9]
            char ExchangeID[27];
            gbk2utf8(pTrade->ExchangeID,ExchangeID,sizeof(ExchangeID));
            ///成交编号 TThostFtdcTradeIDType char[21]
            char TradeID[63];
            gbk2utf8(pTrade->TradeID,TradeID,sizeof(TradeID));
            ///买卖方向 TThostFtdcDirectionType char
            //// THOST_FTDC_D_Buy '0' 买
            //// THOST_FTDC_D_Sell '1' 卖
            char Direction = pTrade->Direction;
            ///报单编号 TThostFtdcOrderSysIDType char[21]
            char OrderSysID[63];
            gbk2utf8(pTrade->OrderSysID,OrderSysID,sizeof(OrderSysID));
            ///会员代码 TThostFtdcParticipantIDType char[11]
            char ParticipantID[33];
            gbk2utf8(pTrade->ParticipantID,ParticipantID,sizeof(ParticipantID));
            ///客户代码 TThostFtdcClientIDType char[11]
            char ClientID[33];
            gbk2utf8(pTrade->ClientID,ClientID,sizeof(ClientID));
            ///交易角色 TThostFtdcTradingRoleType char
            //// THOST_FTDC_ER_Broker '1' 代理
            //// THOST_FTDC_ER_Host '2' 自营
            //// THOST_FTDC_ER_Maker '3' 做市商
            char TradingRole = pTrade->TradingRole;
            ///合约在交易所的代码 TThostFtdcExchangeInstIDType char[31]
            char ExchangeInstID[93];
            gbk2utf8(pTrade->ExchangeInstID,ExchangeInstID,sizeof(ExchangeInstID));
            ///开平标志 TThostFtdcOffsetFlagType char
            //// THOST_FTDC_OF_Open '0' 开仓
            //// THOST_FTDC_OF_Close '1' 平仓
            //// THOST_FTDC_OF_ForceClose '2' 强平
            //// THOST_FTDC_OF_CloseToday '3' 平今
            //// THOST_FTDC_OF_CloseYesterday '4' 平昨
            //// THOST_FTDC_OF_ForceOff '5' 强减
            //// THOST_FTDC_OF_LocalForceClose '6' 本地强平
            char OffsetFlag = pTrade->OffsetFlag;
            ///投机套保标志 TThostFtdcHedgeFlagType char
            //// THOST_FTDC_HF_Speculation '1' 投机
            //// THOST_FTDC_HF_Arbitrage '2' 套利
            //// THOST_FTDC_HF_Hedge '3' 套保
            char HedgeFlag = pTrade->HedgeFlag;
            ///价格 TThostFtdcPriceType double
            double Price = pTrade->Price;
            ///数量 TThostFtdcVolumeType int
            int Volume = pTrade->Volume;
            ///成交时期 TThostFtdcDateType char[9]
            char TradeDate[27];
            gbk2utf8(pTrade->TradeDate,TradeDate,sizeof(TradeDate));
            ///成交时间 TThostFtdcTimeType char[9]
            char TradeTime[27];
            gbk2utf8(pTrade->TradeTime,TradeTime,sizeof(TradeTime));
            ///成交类型 TThostFtdcTradeTypeType char
            //// THOST_FTDC_TRDT_SplitCombination '#' 组合持仓拆分为单一持仓,初始化不应包含该类型的持仓
            //// THOST_FTDC_TRDT_Common '0' 普通成交
            //// THOST_FTDC_TRDT_OptionsExecution '1' 期权执行
            //// THOST_FTDC_TRDT_OTC '2' OTC成交
            //// THOST_FTDC_TRDT_EFPDerived '3' 期转现衍生成交
            //// THOST_FTDC_TRDT_CombinationDerived '4' 组合衍生成交
            char TradeType = pTrade->TradeType;
            ///成交价来源 TThostFtdcPriceSourceType char
            //// THOST_FTDC_PSRC_LastPrice '0' 前成交价
            //// THOST_FTDC_PSRC_Buy '1' 买委托价
            //// THOST_FTDC_PSRC_Sell '2' 卖委托价
            char PriceSource = pTrade->PriceSource;
            ///交易所交易员代码 TThostFtdcTraderIDType char[21]
            char TraderID[63];
            gbk2utf8(pTrade->TraderID,TraderID,sizeof(TraderID));
            ///本地报单编号 TThostFtdcOrderLocalIDType char[13]
            char OrderLocalID[39];
            gbk2utf8(pTrade->OrderLocalID,OrderLocalID,sizeof(OrderLocalID));
            ///结算会员编号 TThostFtdcParticipantIDType char[11]
            char ClearingPartID[33];
            gbk2utf8(pTrade->ClearingPartID,ClearingPartID,sizeof(ClearingPartID));
            ///业务单元 TThostFtdcBusinessUnitType char[21]
            char BusinessUnit[63];
            gbk2utf8(pTrade->BusinessUnit,BusinessUnit,sizeof(BusinessUnit));
            ///序号 TThostFtdcSequenceNoType int
            int SequenceNo = pTrade->SequenceNo;
            ///交易日 TThostFtdcDateType char[9]
            char TradingDay[27];
            gbk2utf8(pTrade->TradingDay,TradingDay,sizeof(TradingDay));
            ///结算编号 TThostFtdcSettlementIDType int
            int SettlementID = pTrade->SettlementID;
            ///经纪公司报单编号 TThostFtdcSequenceNoType int
            int BrokerOrderSeq = pTrade->BrokerOrderSeq;
            ///成交来源 TThostFtdcTradeSourceType char
            //// THOST_FTDC_TSRC_NORMAL '0' 来自交易所普通回报
            //// THOST_FTDC_TSRC_QUERY '1' 来自查询
            char TradeSource = pTrade->TradeSource;

        }

    }
コード例 #5
0
ファイル: vjudge_hduoj.cpp プロジェクト: gwq5210/learn_curl
int get_status_hduoj(void)
{
	int status, i, j;
	regmatch_t pmatch[5];
	const int nmatch = 5;
	regex_t reg;
	const char *pattern = "<td height=22px>([0-9]*)</td>"
		"<td>[: 0-9-]*</td>"
		"<td><font color=[ a-zA-Z]*>([^/]*)</font></td>"
		"<td><a[ 0-9a-zA-Z\\./\\?\\\"=]*>[0-9]*</a></td>"
		"<td>([0-9]*)MS</td>"
		"<td>([0-9]*)K</td>"
		;
	char url[BUFSIZE];
	sprintf(url, "http://acm.hdu.edu.cn/status.php?first=&pid=%d&user=%s"
			"&lang=0&status=0", solution->problem_info.origin_id,
			vjudge_user);
	if (DEBUG) {
		write_log("perform url is %s.\n", url);
	}

	// 设置提交地址
	curl_easy_setopt(curl, CURLOPT_URL, url);

	char filename[BUFSIZE];
	sprintf(filename, "%dstatus.txt", solution->solution_id);

	time_t begin_time = time(NULL);
	int rid = 0;
	int usedtime = 0;
	int memory = 0;
	char result[BUFSIZE];
	char err[BUFSIZE];
	char match_str[BUFSIZE];
	int ret = regcomp(&reg, pattern, REG_EXTENDED);
	if (ret) {
		regerror(ret, &reg, err, BUFSIZE);
		write_log("compile regex error: %s.\n", err);
		return OJ_JE;
	}
	char *html = (char *)malloc(BUFSIZE * BUFSIZE);
	if (html == NULL) {
		write_log("alloc get_status_hduoj html buf memory error.\n");
		regfree(&reg);
		return OJ_JE;
	}
	while (1) {
		if (time(NULL) - begin_time > vj_max_wait_time) {
			write_log("judge time out.\n");
			free(html);
			return OJ_JE;
		}
		perform_curl(filename);

		load_file(filename, html);
		gbk2utf8(html, strlen(html));
		// modified form bnuoj
		if (strstr(html, "Connect(0) to MySQL Server failed.") != NULL
			|| strstr(html, "<b>One or more following ERROR(s) occurred.") != NULL
			|| strstr(html, "<h2>The requested URL could not be retrieved</h2>") != NULL
			|| strstr(html, "<H1 style=\"COLOR: #1A5CC8\" align=center>Sign In Your Account</H1>") != NULL
			|| strstr(html, "PHP: Maximum execution time of") != NULL
			|| strstr(html, "<DIV>Exercise Is Closed Now!</DIV>") != NULL) {
			write_log("get_status_hduoj remote server error.\n");
			write_log("get solution %d status error.\n", solution->solution_id);
			free(html);
			regfree(&reg);
			return OJ_JE;
		} else {
			status = regexec(&reg, html, nmatch, pmatch, 0);
			if (status == REG_NOMATCH) {
				write_log("no match regex: %s.\n", pattern);
				write_log("get solution %d status error.\n", solution->solution_id);
				free(html);
				regfree(&reg);
				return OJ_JE;
			} else if (status == 0) {
				char buf[BUFSIZE];
				for (i = 0; i < nmatch; ++i) {
					int cnt = 0;
					for (j = pmatch[i].rm_so; j < pmatch[i].rm_eo; ++j) {
						buf[cnt++] = html[j];
					}
					buf[cnt] = '\0';
					switch (i) {
						case 0: strcpy(match_str, buf); break;
						case 1: rid = atoi(buf); break;
						case 2: strcpy(result, buf); break;
						case 3: usedtime = atoi(buf); break;
						case 4: memory = atoi(buf); break;
					}
				}
				write_log("match_str = %s\n", match_str);
				write_log("rid = %d\n", rid);
				write_log("usedtime = %d\n", usedtime);
				write_log("memory = %d\n", memory);
				write_log("result = %s\n", result);
				if (is_final_result(result)) {
					solution->remote_rid = rid;
					solution->time = usedtime;
					solution->memory = memory;
					int ret = convert_result(result);
					if (ret == OJ_RE) {
						strcpy(solution->runtimeinfo, result);
					}
					write_log("get solution %d status over"
							": %d.\n", solution->solution_id, ret);
					free(html);
					regfree(&reg);
					return ret;
				}
			}
		}
	}

	free(html);
	regfree(&reg);

	return OJ_JE;
}
コード例 #6
0
ファイル: vjudge_hduoj.cpp プロジェクト: gwq5210/learn_curl
int get_ceinfo_hduoj(void)
{
	int status, i;
	regmatch_t pmatch[2];
	const int nmatch = 2;
	regex_t reg;
	const char *pattern = "<pre>(.*)</pre>";
	char url[BUFSIZE];
	sprintf(url, "http://acm.hdu.edu.cn/viewerror.php?rid=%d",
			solution->remote_rid);

	if (DEBUG) {
		write_log("perform url is %s.\n", url);
	}
	// 设置提交地址
	curl_easy_setopt(curl, CURLOPT_URL, url);

	char err[BUFSIZE];
	int ret = regcomp(&reg, pattern, REG_EXTENDED);
	if (ret) {
		regerror(ret, &reg, err, BUFSIZE);
		write_log("compile regex error: %s.\n", err);
		return -1;
	}
	char *html = (char *)malloc(BUFSIZE * BUFSIZE);
	if (html == NULL) {
		write_log("alloc get_ceinfo_hduoj html buf memory error.\n");
		regfree(&reg);
		return -1;
	}
	perform_curl(cefname);
	load_file(cefname, html);
	gbk2utf8(html, strlen(html));
	// modified form bnuoj
	if (strstr(html, "Connect(0) to MySQL Server failed.") != NULL
			|| strstr(html, "<b>One or more following ERROR(s) occurred.") != NULL
			|| strstr(html, "<h2>The requested URL could not be retrieved</h2>") != NULL
			|| strstr(html, "<H1 style=\"COLOR: #1A5CC8\" align=center>Sign In Your Account</H1>") != NULL
			|| strstr(html, "PHP: Maximum execution time of") != NULL
			|| strstr(html, "<DIV>Exercise Is Closed Now!</DIV>") != NULL) {
		write_log("get_ceinfo_hduoj remote server error.\n");
		write_log("get solution %d compile error info error.\n", solution->solution_id);
		free(html);
		regfree(&reg);
		return -1;
	} else {
		status = regexec(&reg, html, nmatch, pmatch, 0);
		if (status == REG_NOMATCH) {
			write_log("get_ceinfo_hduoj regex no match.\n", solution->solution_id);
			write_log("get solution %d compile error info error.\n", solution->solution_id);
			regfree(&reg);
			free(html);
			return -1;
		} else if (status == 0) {
			int cnt = 0;
			for (i = pmatch[1].rm_so; i < pmatch[1].rm_eo; ++i) {
				solution->compileinfo[cnt++] = html[i];
			}
			solution->compileinfo[cnt] = '\0';
			write_log("match_str = %s\n", solution->compileinfo);
			save_file(cefname, solution->compileinfo);
		}
	}
	write_log("get compile error info: %s.\n", solution->compileinfo);
	free(html);
	regfree(&reg);
	return 0;
}
コード例 #7
0
    ///查询最大报单数量响应
    virtual void OnRspQueryMaxOrderVolume(
        CThostFtdcQueryMaxOrderVolumeField * pQueryMaxOrderVolume,
        CThostFtdcRspInfoField * pRspInfo,
        int nRequestID,
        bool bIsLast
    ) {
        printf("OnRspQueryMaxOrderVolume():被执行...\n");

        // 进程返回结果检查
        if ( (pRspInfo) && (pRspInfo->ErrorID != 0) )  {
            // typedef int TThostFtdcErrorIDType;
            // typedef char TThostFtdcErrorMsgType[81];
            char ErrorMsg[243];
            gbk2utf8(pRspInfo->ErrorMsg,ErrorMsg,sizeof(ErrorMsg));
            printf("OnRspQueryMaxOrderVolume():出错:ErrorId=%d,ErrorMsg=%s\n",pRspInfo->ErrorID,ErrorMsg);
        }

        // 如果有返回结果读取返回信息
        if ( pQueryMaxOrderVolume != NULL ) {
			printf("pQueryMaxOrderVolume != NULL\n");
            // 读取返回信息,并做编码转化
            ///经纪公司代码 TThostFtdcBrokerIDType char[11]
            char BrokerID[33];
            gbk2utf8(pQueryMaxOrderVolume->BrokerID,BrokerID,sizeof(BrokerID));
            ///投资者代码 TThostFtdcInvestorIDType char[13]
            char InvestorID[39];
            gbk2utf8(pQueryMaxOrderVolume->InvestorID,InvestorID,sizeof(InvestorID));
            ///合约代码 TThostFtdcInstrumentIDType char[31]
            char InstrumentID[93];
            gbk2utf8(pQueryMaxOrderVolume->InstrumentID,InstrumentID,sizeof(InstrumentID));
            ///买卖方向 TThostFtdcDirectionType char
            //// THOST_FTDC_D_Buy '0' 买
            //// THOST_FTDC_D_Sell '1' 卖
            char Direction = pQueryMaxOrderVolume->Direction;
            ///开平标志 TThostFtdcOffsetFlagType char
            //// THOST_FTDC_OF_Open '0' 开仓
            //// THOST_FTDC_OF_Close '1' 平仓
            //// THOST_FTDC_OF_ForceClose '2' 强平
            //// THOST_FTDC_OF_CloseToday '3' 平今
            //// THOST_FTDC_OF_CloseYesterday '4' 平昨
            //// THOST_FTDC_OF_ForceOff '5' 强减
            //// THOST_FTDC_OF_LocalForceClose '6' 本地强平
            char OffsetFlag = pQueryMaxOrderVolume->OffsetFlag;
            ///投机套保标志 TThostFtdcHedgeFlagType char
            //// THOST_FTDC_HF_Speculation '1' 投机
            //// THOST_FTDC_HF_Arbitrage '2' 套利
            //// THOST_FTDC_HF_Hedge '3' 套保
            char HedgeFlag = pQueryMaxOrderVolume->HedgeFlag;
            ///最大允许报单数量 TThostFtdcVolumeType int
            int MaxVolume = pQueryMaxOrderVolume->MaxVolume;

			printf("BrokerID=%s,InvestorID=%s,InstrumentID=%s,Direction=%c,OffsetFlag=%c,HedgeFlag=%c,MaxVolume=%d\n",
					BrokerID,InvestorID,InstrumentID,Direction,OffsetFlag,HedgeFlag,MaxVolume);

        }

        // 如果响应函数已经返回最后一条信息
        if(bIsLast) {
            // 通知主过程,响应函数将结束
            sem_post(&sem);
        }
    }
コード例 #8
0
ファイル: QryInstrument.cpp プロジェクト: kayv/ctp_examples
    ///请求查询合约响应
    virtual void OnRspQryInstrument(
        CThostFtdcInstrumentField * pInstrument,
        CThostFtdcRspInfoField * pRspInfo,
        int nRequestID,
        bool bIsLast
    ) {
        printf("OnRspQryInstrument():被执行...\n");

        // 进程返回结果检查
        if ( (pRspInfo) && (pRspInfo->ErrorID != 0) )  {
            // typedef int TThostFtdcErrorIDType;
            // typedef char TThostFtdcErrorMsgType[81];
            char ErrorMsg[243];
            gbk2utf8(pRspInfo->ErrorMsg,ErrorMsg,sizeof(ErrorMsg));
            printf("OnRspQryInstrument():出错:ErrorId=%d,ErrorMsg=%s\n",pRspInfo->ErrorID,ErrorMsg);
        }

        // 如果有返回结果读取返回信息
        if ( pInstrument != NULL ) {
            // 读取返回信息,并做编码转化
            ///合约代码 TThostFtdcInstrumentIDType char[31]
            char InstrumentID[93];
            gbk2utf8(pInstrument->InstrumentID,InstrumentID,sizeof(InstrumentID));
            ///交易所代码 TThostFtdcExchangeIDType char[9]
            char ExchangeID[27];
            gbk2utf8(pInstrument->ExchangeID,ExchangeID,sizeof(ExchangeID));
            ///合约名称 TThostFtdcInstrumentNameType char[21]
            char InstrumentName[63];
            gbk2utf8(pInstrument->InstrumentName,InstrumentName,sizeof(InstrumentName));
            ///合约在交易所的代码 TThostFtdcExchangeInstIDType char[31]
            char ExchangeInstID[93];
            gbk2utf8(pInstrument->ExchangeInstID,ExchangeInstID,sizeof(ExchangeInstID));
            ///产品代码 TThostFtdcInstrumentIDType char[31]
            char ProductID[93];
            gbk2utf8(pInstrument->ProductID,ProductID,sizeof(ProductID));
            ///产品类型 TThostFtdcProductClassType char
            //// THOST_FTDC_PC_Futures '1' 期货
            //// THOST_FTDC_PC_Options '2' 期权
            //// THOST_FTDC_PC_Combination '3' 组合
            //// THOST_FTDC_PC_Spot '4' 即期
            //// THOST_FTDC_PC_EFP '5' 期转现
            char ProductClass = pInstrument->ProductClass;
            ///交割年份 TThostFtdcYearType int
            int DeliveryYear = pInstrument->DeliveryYear;
            ///交割月 TThostFtdcMonthType int
            int DeliveryMonth = pInstrument->DeliveryMonth;
            ///市价单最大下单量 TThostFtdcVolumeType int
            int MaxMarketOrderVolume = pInstrument->MaxMarketOrderVolume;
            ///市价单最小下单量 TThostFtdcVolumeType int
            int MinMarketOrderVolume = pInstrument->MinMarketOrderVolume;
            ///限价单最大下单量 TThostFtdcVolumeType int
            int MaxLimitOrderVolume = pInstrument->MaxLimitOrderVolume;
            ///限价单最小下单量 TThostFtdcVolumeType int
            int MinLimitOrderVolume = pInstrument->MinLimitOrderVolume;
            ///合约数量乘数 TThostFtdcVolumeMultipleType int
            int VolumeMultiple = pInstrument->VolumeMultiple;
            ///最小变动价位 TThostFtdcPriceType double
            double PriceTick = pInstrument->PriceTick;
            ///创建日 TThostFtdcDateType char[9]
            char CreateDate[27];
            gbk2utf8(pInstrument->CreateDate,CreateDate,sizeof(CreateDate));
            ///上市日 TThostFtdcDateType char[9]
            char OpenDate[27];
            gbk2utf8(pInstrument->OpenDate,OpenDate,sizeof(OpenDate));
            ///到期日 TThostFtdcDateType char[9]
            char ExpireDate[27];
            gbk2utf8(pInstrument->ExpireDate,ExpireDate,sizeof(ExpireDate));
            ///开始交割日 TThostFtdcDateType char[9]
            char StartDelivDate[27];
            gbk2utf8(pInstrument->StartDelivDate,StartDelivDate,sizeof(StartDelivDate));
            ///结束交割日 TThostFtdcDateType char[9]
            char EndDelivDate[27];
            gbk2utf8(pInstrument->EndDelivDate,EndDelivDate,sizeof(EndDelivDate));
            ///合约生命周期状态 TThostFtdcInstLifePhaseType char
            //// THOST_FTDC_IP_NotStart '0' 未上市
            //// THOST_FTDC_IP_Started '1' 上市
            //// THOST_FTDC_IP_Pause '2' 停牌
            //// THOST_FTDC_IP_Expired '3' 到期
            char InstLifePhase = pInstrument->InstLifePhase;
            ///当前是否交易 TThostFtdcBoolType int
            int IsTrading = pInstrument->IsTrading;
            ///持仓类型 TThostFtdcPositionTypeType char
            //// THOST_FTDC_PT_Net '1' 净持仓
            //// THOST_FTDC_PT_Gross '2' 综合持仓
            char PositionType = pInstrument->PositionType;
            ///持仓日期类型 TThostFtdcPositionDateTypeType char
            //// THOST_FTDC_PDT_UseHistory '1' 使用历史持仓
            //// THOST_FTDC_PDT_NoUseHistory '2' 不使用历史持仓
            char PositionDateType = pInstrument->PositionDateType;
            ///多头保证金率 TThostFtdcRatioType double
            double LongMarginRatio = pInstrument->LongMarginRatio;
            ///空头保证金率 TThostFtdcRatioType double
            double ShortMarginRatio = pInstrument->ShortMarginRatio;
            ///是否使用大额单边保证金算法 TThostFtdcMaxMarginSideAlgorithmType char
            //// THOST_FTDC_MMSA_NO '0' 不使用大额单边保证金算法
            //// THOST_FTDC_MMSA_YES '1' 使用大额单边保证金算法
            char MaxMarginSideAlgorithm = pInstrument->MaxMarginSideAlgorithm;

			printf("InstrumentID=%s,ExchangeID=%s,InstrumentName=%s\n",InstrumentID,ExchangeID,InstrumentName);

        }

        // 如果响应函数已经返回最后一条信息
        if(bIsLast) {
            // 通知主过程,响应函数将结束
            sem_post(&sem);
        }
    }
コード例 #9
0
    ///请求查询资金账户响应
    virtual void OnRspQryTradingAccount(
        CThostFtdcTradingAccountField * pTradingAccount,
        CThostFtdcRspInfoField * pRspInfo,
        int nRequestID,
        bool bIsLast
    ) {
        printf("OnRspQryTradingAccount():被执行...\n");

        // 进程返回结果检查
        if ( (pRspInfo) && (pRspInfo->ErrorID != 0) )  {
            // typedef int TThostFtdcErrorIDType;
            // typedef char TThostFtdcErrorMsgType[81];
            char ErrorMsg[243];
            gbk2utf8(pRspInfo->ErrorMsg,ErrorMsg,sizeof(ErrorMsg));
            printf("OnRspQryTradingAccount():出错:ErrorId=%d,ErrorMsg=%s\n",pRspInfo->ErrorID,ErrorMsg);
        }

        // 如果有返回结果读取返回信息
        if ( pTradingAccount != NULL ) {
            // 读取返回信息,并做编码转化
            ///经纪公司代码 TThostFtdcBrokerIDType char[11]
            char BrokerID[33];
            gbk2utf8(pTradingAccount->BrokerID,BrokerID,sizeof(BrokerID));
            ///投资者帐号 TThostFtdcAccountIDType char[13]
            char AccountID[39];
            gbk2utf8(pTradingAccount->AccountID,AccountID,sizeof(AccountID));
            printf("len(pTradingAccount->AccountID)=%d\n",(int)strlen(pTradingAccount->AccountID));
            printf("len(AccountID)=%d\n",(int)strlen(AccountID));
            ///上次质押金额 TThostFtdcMoneyType double
            double PreMortgage = pTradingAccount->PreMortgage;
            ///上次信用额度 TThostFtdcMoneyType double
            double PreCredit = pTradingAccount->PreCredit;
            ///上次存款额 TThostFtdcMoneyType double
            double PreDeposit = pTradingAccount->PreDeposit;
            ///上次结算准备金 TThostFtdcMoneyType double
            double PreBalance = pTradingAccount->PreBalance;
            ///上次占用的保证金 TThostFtdcMoneyType double
            double PreMargin = pTradingAccount->PreMargin;
            ///利息基数 TThostFtdcMoneyType double
            double InterestBase = pTradingAccount->InterestBase;
            ///利息收入 TThostFtdcMoneyType double
            double Interest = pTradingAccount->Interest;
            ///入金金额 TThostFtdcMoneyType double
            double Deposit = pTradingAccount->Deposit;
            ///出金金额 TThostFtdcMoneyType double
            double Withdraw = pTradingAccount->Withdraw;
            ///冻结的保证金 TThostFtdcMoneyType double
            double FrozenMargin = pTradingAccount->FrozenMargin;
            ///冻结的资金 TThostFtdcMoneyType double
            double FrozenCash = pTradingAccount->FrozenCash;
            ///冻结的手续费 TThostFtdcMoneyType double
            double FrozenCommission = pTradingAccount->FrozenCommission;
            ///当前保证金总额 TThostFtdcMoneyType double
            double CurrMargin = pTradingAccount->CurrMargin;
            ///资金差额 TThostFtdcMoneyType double
            double CashIn = pTradingAccount->CashIn;
            ///手续费 TThostFtdcMoneyType double
            double Commission = pTradingAccount->Commission;
            ///平仓盈亏 TThostFtdcMoneyType double
            double CloseProfit = pTradingAccount->CloseProfit;
            ///持仓盈亏 TThostFtdcMoneyType double
            double PositionProfit = pTradingAccount->PositionProfit;
            ///期货结算准备金 TThostFtdcMoneyType double
            double Balance = pTradingAccount->Balance;
            ///可用资金 TThostFtdcMoneyType double
            double Available = pTradingAccount->Available;
            ///可取资金 TThostFtdcMoneyType double
            double WithdrawQuota = pTradingAccount->WithdrawQuota;
            ///基本准备金 TThostFtdcMoneyType double
            double Reserve = pTradingAccount->Reserve;
            ///交易日 TThostFtdcDateType char[9]
            char TradingDay[27];
            gbk2utf8(pTradingAccount->TradingDay,TradingDay,sizeof(TradingDay));
            ///结算编号 TThostFtdcSettlementIDType int
            int SettlementID = pTradingAccount->SettlementID;
            ///信用额度 TThostFtdcMoneyType double
            double Credit = pTradingAccount->Credit;
            ///质押金额 TThostFtdcMoneyType double
            double Mortgage = pTradingAccount->Mortgage;
            ///交易所保证金 TThostFtdcMoneyType double
            double ExchangeMargin = pTradingAccount->ExchangeMargin;
            ///投资者交割保证金 TThostFtdcMoneyType double
            double DeliveryMargin = pTradingAccount->DeliveryMargin;
            ///交易所交割保证金 TThostFtdcMoneyType double
            double ExchangeDeliveryMargin = pTradingAccount->ExchangeDeliveryMargin;
            ///保底期货结算准备金 TThostFtdcMoneyType double
            double ReserveBalance = pTradingAccount->ReserveBalance;
            ///币种代码 TThostFtdcCurrencyIDType char[4]
            char CurrencyID[12];
            gbk2utf8(pTradingAccount->CurrencyID,CurrencyID,sizeof(pTradingAccount->CurrencyID));
            ///上次货币质入金额 TThostFtdcMoneyType double
            double PreFundMortgageIn = pTradingAccount->PreFundMortgageIn;
            ///上次货币质出金额 TThostFtdcMoneyType double
            double PreFundMortgageOut = pTradingAccount->PreFundMortgageOut;
            ///货币质入金额 TThostFtdcMoneyType double
            double FundMortgageIn = pTradingAccount->FundMortgageIn;
            ///货币质出金额 TThostFtdcMoneyType double
            double FundMortgageOut = pTradingAccount->FundMortgageOut;
            ///货币质押余额 TThostFtdcMoneyType double
            double FundMortgageAvailable = pTradingAccount->FundMortgageAvailable;
            ///可质押货币金额 TThostFtdcMoneyType double
            double MortgageableFund = pTradingAccount->MortgageableFund;
            ///特殊产品占用保证金 TThostFtdcMoneyType double
            double SpecProductMargin = pTradingAccount->SpecProductMargin;
            ///特殊产品冻结保证金 TThostFtdcMoneyType double
            double SpecProductFrozenMargin = pTradingAccount->SpecProductFrozenMargin;
            ///特殊产品手续费 TThostFtdcMoneyType double
            double SpecProductCommission = pTradingAccount->SpecProductCommission;
            ///特殊产品冻结手续费 TThostFtdcMoneyType double
            double SpecProductFrozenCommission = pTradingAccount->SpecProductFrozenCommission;
            ///特殊产品持仓盈亏 TThostFtdcMoneyType double
            double SpecProductPositionProfit = pTradingAccount->SpecProductPositionProfit;
            ///特殊产品平仓盈亏 TThostFtdcMoneyType double
            double SpecProductCloseProfit = pTradingAccount->SpecProductCloseProfit;
            ///根据持仓盈亏算法计算的特殊产品持仓盈亏 TThostFtdcMoneyType double
            double SpecProductPositionProfitByAlg = pTradingAccount->SpecProductPositionProfitByAlg;
            ///特殊产品交易所保证金 TThostFtdcMoneyType double
            double SpecProductExchangeMargin = pTradingAccount->SpecProductExchangeMargin;

            // 打印出关键信息
            printf("经纪公司代码=%s,投资者帐号=%s,币种代码=%s,可用金额=%.2f\n",BrokerID,AccountID,CurrencyID,Available);

        }

        // 如果响应函数已经返回最后一条信息
        if(bIsLast) {
            // 通知主过程,响应函数将结束
            sem_post(&sem);
        }
    }
コード例 #10
0
ファイル: unimo.c プロジェクト: tkpclark/cdopr_system
static sgip_read()
{
	//proclog("reading data...");
	
	int n=0;
	void *seq;
	int len,g;
	int cmd;
	int i;
	unsigned char buffer[PKG_LENGTH];
	//read header
	memset(buffer,0,20);
	//proclog("reading header...");

	n=read(readfd,buffer,20);
	if(n==0)
		exit(0);
	if(n!=20)
	{
		proclog("Read Header Error! return [%d]",n);
		exit(0);
	}
	//proclog_HEX(buffer,20);
	seq=(void*)malloc(12);
	len=ntohl(*((int *)buffer));
	cmd=ntohl(*((unsigned int *)(buffer+4)));
	
	*(int*)seq=ntohl(*((unsigned int *)(buffer+8)));
	*(int*)(seq+4)=ntohl(*((unsigned int *)(buffer+12)));
	*(int*)(seq+8)=ntohl(*((unsigned int *)(buffer+16)));
	
	proclog("HEADER:len[%d]cmd[0x%X]seq[%d][%d][%d]",len,cmd,*(int*)seq,*(int*)(seq+4),*(int*)(seq+8));


	///read body
	memset(buffer,0,PKG_LENGTH);
	//proclog("reading body...");
	if((n=read(readfd,buffer,len-20))!=(len-20))
	{
		proclog("Read Body Error! return [%d]",n);
		exit(0);
	}


	///////////////print binlog
	//proclog_HEX(buffer,len-20);
	////////////////////
	
	if(cmd==0x4)//deliver
	{
		sgip_resp(0x80000004,seq,29);
		char UserNumber[22]={0};
		char UserNumber_db[32];
		char SPNumber[22]={0};
		char MessageContent[256]={0};
		int MessageLength=0;
		char MessageContent_utf8[256]={0};
		memset(MessageContent_utf8,0,sizeof(MessageContent_utf8));
		unsigned char MessageCoding;
		unsigned char pid,udhi;
		char linkid[32];
		
		MessageLength=ntohl(*(unsigned int*)(buffer+45));
		strncpy(UserNumber,buffer,21);
		//proclog("UserNumber[%s]",UserNumber);
		strncpy(SPNumber,buffer+21,21);
		//proclog("SPNumber[%s]",SPNumber);
		pid=*(unsigned char *)(buffer+42);
		udhi=*(unsigned char *)(buffer+43);
		MessageCoding=*(unsigned char *)(buffer+44);
		memset(MessageContent,0,sizeof(MessageContent));
		memcpy(MessageContent,buffer+49,MessageLength);
		strcpy(linkid,buffer+49+MessageLength);
		//proclog("linkid[%s]",linkid);


		//convert to utf-8
		memset(MessageContent_utf8,0,sizeof(MessageContent_utf8));
		if (MessageCoding==8)
		{
			//convt(MessageContent,MessageContent_utf8,"ucs-2be","utf-8");
			ucs2_to_utf8(MessageContent,MessageContent_utf8);
		}
		else if(MessageCoding==15)
		{
			//convt(MessageContent,MessageContent_utf8,"gb2312","utf-8");
			gbk2utf8(MessageContent,MessageContent_utf8);
		}
		else
		{
			strcpy(MessageContent_utf8,MessageContent);
		}





/*
		//################# write to db#################
		memset(UserNumber_db,0,sizeof(UserNumber_db));
		if(strncmp(UserNumber,"86",2)==0)
			strcpy(UserNumber_db,UserNumber+2);
		else
			strcpy(UserNumber_db,UserNumber);
			*/
		proclog("MO:UserNumber[%s]SPNumber[%s]Messagelen[%d]Cont[%s]MessageCoding[%d]linkid[%s]pid[%d]udhi[%d]",UserNumber,SPNumber,MessageLength,MessageContent_utf8,MessageCoding,linkid,pid,udhi);

		char sql[512];
		sprintf(sql,"insert into wraith_message( motime, phone_number, mo_message, sp_number, linkid, gwid ) values (NOW(),'%s', '%s', '%s', '%s', '%s');",
				//UserNumber_db,
				UserNumber+2,
				MessageContent_utf8,
				SPNumber,
				linkid,
				gwid
				);
		proclog(sql);
		mysql_exec(&mysql,"set names utf8");
		mysql_exec(&mysql, sql);

		/*
		char cmd[128];
		sprintf(cmd,"./fakemt %s hello",UserNumber);
		proclog("%s\n",cmd);
		//system(cmd);
		*/
	}
	else if(cmd==0x5)//report
	{
		sgip_resp(0x80000005,seq,29);
		*(time_t*)(buffer+252)=time(0);
		char UserNumber[22]={0};
		strncpy(UserNumber,buffer+13,21);
		unsigned int seq;
		seq=ntohl(*((unsigned int *)(buffer+8)));
		unsigned char state,report_code;
		//state=*(int *)(buffer+34);
		state=*(unsigned char *)(buffer+34);
		report_code=*(unsigned char *)(buffer+35);
		proclog("REPORT: seq[%d]usernumber[%s]state[%d]errorcode[%d]",seq,UserNumber,state,report_code);
//		write_to_heapfile(heapstatdbfd,buffer,sizeof(buffer));
		char sql[512];
		//int report=report_code==0?1:2;
		int report=0;
		if(report_code==0||report_code==100)
		{
			report=1;
		}
		else
		{
			report=2;
		}
		sprintf(sql,"update wraith_message set report='%d', report_orig='%d', report_time=NOW() where id='%d'",report,report_code,seq);
		//proclog(sql);
		mysql_exec(&mysql, sql);

	}
	else if(cmd==0x1)//bind
	{
		sgip_resp(0x80000001,seq,29);
		//proclog("MESSAGE:got BIND command\n");
	}
	else if(cmd==0x2)//unbind
	{
		sgip_resp(0x80000002,seq,20);
		//proclog("MESSAGE:got UNBIND command!\n");
		exit(0);
	}
	else
	{
		proclog( "WARNING:Strange CMD:%x\n",cmd);
	}
	//proclog("returning...");
}
コード例 #11
0
    ///请求查询行情响应
    virtual void OnRspQryDepthMarketData(
        CThostFtdcDepthMarketDataField * pDepthMarketData,
        CThostFtdcRspInfoField * pRspInfo,
        int nRequestID,
        bool bIsLast
    ) {
        //printf("OnRspQryDepthMarketData():被执行...\n");

        // 进程返回结果检查
        if ( (pRspInfo) && (pRspInfo->ErrorID != 0) )  {
            // typedef int TThostFtdcErrorIDType;
            // typedef char TThostFtdcErrorMsgType[81];
            char ErrorMsg[243];
            gbk2utf8(pRspInfo->ErrorMsg,ErrorMsg,sizeof(ErrorMsg));
            printf("OnRspQryDepthMarketData():出错:ErrorId=%d,ErrorMsg=%s\n",pRspInfo->ErrorID,ErrorMsg);
        }

        // 如果有返回结果读取返回信息
        if ( pDepthMarketData != NULL ) {
            // 读取返回信息,并做编码转化
            ///交易日 TThostFtdcDateType char[9]
            char TradingDay[27];
            gbk2utf8(pDepthMarketData->TradingDay,TradingDay,sizeof(TradingDay));
            ///合约代码 TThostFtdcInstrumentIDType char[31]
            char InstrumentID[93];
            gbk2utf8(pDepthMarketData->InstrumentID,InstrumentID,sizeof(InstrumentID));
            ///交易所代码 TThostFtdcExchangeIDType char[9]
            char ExchangeID[27];
            gbk2utf8(pDepthMarketData->ExchangeID,ExchangeID,sizeof(ExchangeID));
            ///合约在交易所的代码 TThostFtdcExchangeInstIDType char[31]
            char ExchangeInstID[93];
            gbk2utf8(pDepthMarketData->ExchangeInstID,ExchangeInstID,sizeof(ExchangeInstID));
            ///最新价 TThostFtdcPriceType double
            double LastPrice = pDepthMarketData->LastPrice;
            ///上次结算价 TThostFtdcPriceType double
            double PreSettlementPrice = pDepthMarketData->PreSettlementPrice;
            ///昨收盘 TThostFtdcPriceType double
            double PreClosePrice = pDepthMarketData->PreClosePrice;
            ///昨持仓量 TThostFtdcLargeVolumeType double
            double PreOpenInterest = pDepthMarketData->PreOpenInterest;
            ///今开盘 TThostFtdcPriceType double
            double OpenPrice = pDepthMarketData->OpenPrice;
            ///最高价 TThostFtdcPriceType double
            double HighestPrice = pDepthMarketData->HighestPrice;
            ///最低价 TThostFtdcPriceType double
            double LowestPrice = pDepthMarketData->LowestPrice;
            ///数量 TThostFtdcVolumeType int
            int Volume = pDepthMarketData->Volume;
            ///成交金额 TThostFtdcMoneyType double
            double Turnover = pDepthMarketData->Turnover;
            ///持仓量 TThostFtdcLargeVolumeType double
            double OpenInterest = pDepthMarketData->OpenInterest;
            ///今收盘 TThostFtdcPriceType double
            double ClosePrice = pDepthMarketData->ClosePrice;
            ///本次结算价 TThostFtdcPriceType double
            double SettlementPrice = pDepthMarketData->SettlementPrice;
            ///涨停板价 TThostFtdcPriceType double
            double UpperLimitPrice = pDepthMarketData->UpperLimitPrice;
            ///跌停板价 TThostFtdcPriceType double
            double LowerLimitPrice = pDepthMarketData->LowerLimitPrice;
            ///昨虚实度 TThostFtdcRatioType double
            double PreDelta = pDepthMarketData->PreDelta;
            ///今虚实度 TThostFtdcRatioType double
            double CurrDelta = pDepthMarketData->CurrDelta;
            ///最后修改时间 TThostFtdcTimeType char[9]
            char UpdateTime[27];
            gbk2utf8(pDepthMarketData->UpdateTime,UpdateTime,sizeof(UpdateTime));
            ///最后修改毫秒 TThostFtdcMillisecType int
            int UpdateMillisec = pDepthMarketData->UpdateMillisec;
            ///申买价一 TThostFtdcPriceType double
            double BidPrice1 = pDepthMarketData->BidPrice1;
            ///申买量一 TThostFtdcVolumeType int
            int BidVolume1 = pDepthMarketData->BidVolume1;
            ///申卖价一 TThostFtdcPriceType double
            double AskPrice1 = pDepthMarketData->AskPrice1;
            ///申卖量一 TThostFtdcVolumeType int
            int AskVolume1 = pDepthMarketData->AskVolume1;
            ///申买价二 TThostFtdcPriceType double
            double BidPrice2 = pDepthMarketData->BidPrice2;
            ///申买量二 TThostFtdcVolumeType int
            int BidVolume2 = pDepthMarketData->BidVolume2;
            ///申卖价二 TThostFtdcPriceType double
            double AskPrice2 = pDepthMarketData->AskPrice2;
            ///申卖量二 TThostFtdcVolumeType int
            int AskVolume2 = pDepthMarketData->AskVolume2;
            ///申买价三 TThostFtdcPriceType double
            double BidPrice3 = pDepthMarketData->BidPrice3;
            ///申买量三 TThostFtdcVolumeType int
            int BidVolume3 = pDepthMarketData->BidVolume3;
            ///申卖价三 TThostFtdcPriceType double
            double AskPrice3 = pDepthMarketData->AskPrice3;
            ///申卖量三 TThostFtdcVolumeType int
            int AskVolume3 = pDepthMarketData->AskVolume3;
            ///申买价四 TThostFtdcPriceType double
            double BidPrice4 = pDepthMarketData->BidPrice4;
            ///申买量四 TThostFtdcVolumeType int
            int BidVolume4 = pDepthMarketData->BidVolume4;
            ///申卖价四 TThostFtdcPriceType double
            double AskPrice4 = pDepthMarketData->AskPrice4;
            ///申卖量四 TThostFtdcVolumeType int
            int AskVolume4 = pDepthMarketData->AskVolume4;
            ///申买价五 TThostFtdcPriceType double
            double BidPrice5 = pDepthMarketData->BidPrice5;
            ///申买量五 TThostFtdcVolumeType int
            int BidVolume5 = pDepthMarketData->BidVolume5;
            ///申卖价五 TThostFtdcPriceType double
            double AskPrice5 = pDepthMarketData->AskPrice5;
            ///申卖量五 TThostFtdcVolumeType int
            int AskVolume5 = pDepthMarketData->AskVolume5;
            ///当日均价 TThostFtdcPriceType double
            double AveragePrice = pDepthMarketData->AveragePrice;
            ///业务日期 TThostFtdcDateType char[9]
            char ActionDay[27];
            gbk2utf8(pDepthMarketData->ActionDay,ActionDay,sizeof(ActionDay));

			printf("TradingDay=%s,",TradingDay);    // 交易日
            printf("InstrumentID=%s,",InstrumentID);  // 合约代码
            printf("LastPrice=%f\n",LastPrice);  // 最新价

        }

        // 如果响应函数已经返回最后一条信息
        if(bIsLast) {
            // 通知主过程,响应函数将结束
            sem_post(&sem);
        }
    }