目前,已经成功实现了调用易达Api接口查询合约的行情,并下单买入卖出[1-7]。但是此时遇到个重要问题是无法查询当前的持仓和可用资金情况,因此接下来还需要实现一下查询相关的接口。
查询账户资金情况
YDApi不提供资金查询的功能,而扩展版的易达Api接口YDExtendedApi可以通过调用getExtendedAccount函数来查询账户资金情况。函数原型为:
virtual const YDExtendedAccount *getExtendedAccount(const YDAccount *pAccount=NULL);函数返回的是一个YDExtendedAccount结构体,结构体中包含账户信息:
设计一条指令qryfund,输入后便调用getExtendedAccount函数,并打印返回的YDExtendedAccount结构体中的数据:
void myYDListener::qryFund()
{
YDExtendedApi *ydExApi = static_cast<YDExtendedApi *>(m_ydApi);
if (ydExApi != nullptr)
{
const YDExtendedAccount *pAccount = ydExApi->getExtendedAccount();
cout << fixed;
cout << &#34;\t平仓盈亏:&#34; << pAccount->CloseProfit;
cout << &#34;\t权利金:&#34; << pAccount->CashIn;
cout << &#34;\t所有非期货品种的平仓盈亏:&#34; << pAccount->OtherCloseProfit;
cout << &#34;\t手续费:&#34; << pAccount->Commission;
cout << &#34;\t保证金:&#34; << pAccount->Margin;
cout << &#34;\t持仓盈亏:&#34; << pAccount->PositionProfit;
cout << &#34;\t资金余额:&#34; << pAccount->Balance;
cout << &#34;\t可用资金:&#34; << pAccount->Available;
cout << &#34;\t用户报单数:&#34; << pAccount->UsedOrderCount;
cout << &#34;\t期权执行保证金:&#34; << pAccount->ExecMargin;
cout << endl;
}
else
{
cout << &#34;\t易达基础版不支持资金查询;&#34;;
cout << &#34;需根据报单、成交情况和当前价格自行计算平仓盈亏、期权品种现金出入、手续费、持仓盈亏、已使用保证金、当前余额和可用金额&#34; << endl;
}
}编译运行程序,登录之后输入qryfund,查询账户信息,显示如下:
查询当前持仓
易达基础版Api不支持查询当前持仓的功能,只能通过YDApi::getPrePositionCount获取日初持仓。而扩展版Api提供了盘中实时查询当前持仓的功能,可以通过YDExtendedApi::findExtendedPositions来进行查询,函数原型为:
virtual unsigned findExtendedPositions(const YDExtendedPositionFilter *pFilter, unsigned count, const YDExtendedPosition *positions[]);第一个参数是过滤条件,易达柜台服务器会根据客户端程序设置好的过滤条件返回查询结果。第二个参数是一个无符号整数count,指返回的查询结果的总数,在结果总数多于count时,positions只会保存count个结果。第三个参数是一个YDExtendedPosition类的数组,长度为count,用来存放查询结果。
用来存放过滤条件的结构体是YDExtendedPositionFilter,其数据结构如下:
查询结果存储在一个数组里,数组里的每一项都是一个YDExtendedPosition结构体,YDExtendedPosition结构体中的成员变量如下表:
可以看到对于不同的交易所,YDExtendedPosition结构体中包含的信息略有不同,因此针对不同交易所,需要分别实现YDExtendedPosition结构体的展示,把想要的信息输出出来,由于郑商所只有易盛的柜台能托管在郑商所机房,易达柜台进不了郑商所机房,所以在实际使用时,在郑商所做高频低延迟量化交易只能使用易盛柜台。所以这里对于易达的接口,先忽略郑商所。
对于上期所和能源所,查询和展示函数如下:
void show_position_shfe_or_ine(const YDExtendedPosition *ppos)
{
cout << &#34;\t合约代码:&#34; << ppos->getInstrument()->InstrumentID;
cout << &#34;\t持仓方向:&#34;;
switch (ppos->PositionDirection)
{
case YD_PD_Long:
cout << &#34;多头&#34;;
break;
case YD_PD_Short:
cout << &#34;空头&#34;;
break;
default:
cerr << &#34;未知&#34;;
}
cout << &#34;\t持仓量:&#34; << ppos->Position;
cout << &#34;\t套保标志:&#34;;
switch (ppos->HedgeFlag)
{
case YD_HF_Speculation:
cout << &#34;投机&#34;;
break;
case YD_HF_Hedge:
cout << &#34;保值&#34;;
break;
default:
cerr << &#34;未知&#34;;
}
cout << &#34;\t持仓盈亏:&#34; << ppos->PositionProfit;
cout << &#34;\t平仓盈亏:&#34; << ppos->CloseProfit;
}
void myYDListener::qry_position_shfe_or_ine(YDExtendedApi *ydExApi)
{
const YDExtendedPositionFilter history_pos_filter{ YD_PSD_History, -1, -1, NULL, NULL, NULL };
const YDExtendedPosition *history_pos[MAX_POSITION_COUNT];
unsigned total_count = ydExApi->findExtendedPositions(&history_pos_filter, MAX_POSITION_COUNT, history_pos);
if (total_count > MAX_POSITION_COUNT)
cout << &#34;\t历史持仓记录总共有&#34; << total_count << &#34;条,返回的仅是部分持仓结果(100条),需增大MAX_POSITION_COUNT参数来获得全部历史持仓&#34; << endl;
unsigned n = min(total_count, MAX_POSITION_COUNT);
cout << &#34;\t【历史仓】&#34; << endl;
for (size_t i = 0; i != n; ++i)
{
show_position_shfe_or_ine(history_pos);
cout << &#34;\t-------------------------&#34; << endl;
}
const YDExtendedPositionFilter today_pos_filter{ YD_PSD_Today, -1, -1, NULL, NULL, NULL };
const YDExtendedPosition *today_pos[MAX_POSITION_COUNT];
total_count = ydExApi->findExtendedPositions(&today_pos_filter, MAX_POSITION_COUNT, today_pos);
if (total_count > MAX_POSITION_COUNT)
cout << &#34;\t今日持仓记录总共有&#34; << total_count << &#34;条,返回的仅是部分持仓结果(100条),需增大MAX_POSITION_COUNT参数来获得全部今日持仓&#34; << endl;
n = min(total_count, MAX_POSITION_COUNT);
cout << &#34;\t【今仓】&#34; << endl;
for (size_t i = 0; i != n; ++i)
{
show_position_shfe_or_ine(today_pos);
cout << endl;
}
}对于大商所,查询和展示函数如下:
void myYDListener::qry_position_dce(YDExtendedApi *ydExApi) // 与中金所的区别仅在于套保标志没有套利
{
const YDExtendedPositionFilter pos_filter{ YD_PSD_History, -1, -1, NULL, NULL, NULL };
const YDExtendedPosition *pos[MAX_POSITION_COUNT];
unsigned total_count = ydExApi->findExtendedPositions(&pos_filter, MAX_POSITION_COUNT, pos);
if (total_count > MAX_POSITION_COUNT)
cout << &#34;\t持仓记录总共有&#34; << total_count << &#34;条,返回的仅是部分持仓结果(100条),需增大MAX_POSITION_COUNT参数来获得全部持仓&#34; << endl;
unsigned n = min(total_count, MAX_POSITION_COUNT);
cout << &#34;\t【总持仓】&#34; << endl;
for (size_t i = 0; i != n; ++i)
{
cout << &#34;\t合约代码:&#34; << pos->getInstrument()->InstrumentID;
cout << &#34;\t持仓方向:&#34;;
switch (pos->PositionDirection)
{
case YD_PD_Long:
cout << &#34;多头&#34;;
break;
case YD_PD_Short:
cout << &#34;空头&#34;;
break;
default:
cerr << &#34;未知&#34;;
}
cout << &#34;\t持仓量(剩余昨仓):&#34; << pos->YDPositionForCommission;
cout << &#34;\t持仓量(总持仓):&#34; << pos->Position;
cout << &#34;\t套保标志:&#34;;
switch (pos->HedgeFlag)
{
case YD_HF_Speculation:
cout << &#34;投机&#34;;
break;
case YD_HF_Hedge:
cout << &#34;保值&#34;;
break;
default:
cerr << &#34;未知&#34;;
}
cout << &#34;\t持仓盈亏:&#34; << pos->PositionProfit;
cout << &#34;\t平仓盈亏:&#34; << pos->CloseProfit;
cout << endl;
}
}对于中金所,查询和展示函数如下:
void myYDListener::qry_position_cffex(YDExtendedApi *ydExApi)
{
const YDExtendedPositionFilter pos_filter{ YD_PSD_History, -1, -1, NULL, NULL, NULL, NULL };
const YDExtendedPosition *pos[MAX_POSITION_COUNT];
unsigned total_count = ydExApi->findExtendedPositions(&pos_filter, MAX_POSITION_COUNT, pos);
if (total_count > MAX_POSITION_COUNT)
cout << &#34;\t持仓记录总共有&#34; << total_count << &#34;条,返回的仅是部分持仓结果(100条),需增大MAX_POSITION_COUNT参数来获得全部持仓&#34; << endl;
unsigned n = min(total_count, MAX_POSITION_COUNT);
cout << &#34;\t【总持仓】&#34; << endl;
for (size_t i = 0; i != n; ++i)
{
cout << &#34;\t合约代码:&#34; << pos->getInstrument()->InstrumentID;
cout << &#34;\t持仓方向:&#34;;
switch (pos->PositionDirection)
{
case YD_PD_Long:
cout << &#34;多头&#34;;
break;
case YD_PD_Short:
cout << &#34;空头&#34;;
//cout << &#34;\tBaseMarginRate: &#34; << pos->getMarginRate()->BaseMarginRate;
//cout << &#34;\tLinearFactor: &#34; << pos->getMarginRate()->LinearFactor;
//cout << &#34;\tLowerBoundaryCoef: &#34; << pos->getMarginRate()->LowerBoundaryCoef;
/*if (pos->getInstrument()->OptionsType == YD_OT_CallOption)
cout << &#34;\t按金额计算保证金率:&#34; << pos->getMarginRate()->CallMarginRatioByMoney;
else if (pos->getInstrument()->OptionsType == YD_OT_PutOption)
cout << &#34;\t按金额计算保证金率:&#34; << pos->getMarginRate()->PutMarginRatioByMoney;
else
cerr << &#34;错误的期权类型&#34;;*/
break;
default:
cerr << &#34;未知&#34;;
}
cout << &#34;\t持仓量(剩余昨仓):&#34; << pos->YDPositionForCommission;
cout << &#34;\t持仓量(总持仓):&#34; << pos->Position;
cout << &#34;\t套保标志:&#34;;
switch (pos->HedgeFlag)
{
case YD_HF_Speculation:
cout << &#34;投机&#34;;
break;
case YD_HF_Arbitrage:
cout << &#34;套利&#34;;
break;
case YD_HF_Hedge:
cout << &#34;保值&#34;;
break;
default:
cerr << &#34;未知&#34;;
}
cout << &#34;\t持仓盈亏:&#34; << pos->PositionProfit;
cout << &#34;\t平仓盈亏:&#34; << pos->CloseProfit;
// cout << &#34;\t非期货品种的平仓盈亏(期权):&#34; << pos->OtherCloseProfit;
cout << &#34;\t保证金:&#34; << pos->Margin;
/*cout << &#34;\t按金额计算的开仓手续费率:&#34; << pos->getCommissionRate()->OpenRatioByMoney;
cout << &#34;\t按数量计算的开仓手续费率:&#34; << pos->getCommissionRate()->OpenRatioByVolume;
cout << &#34;\t按金额计算的平昨手续费率:&#34; << pos->getCommissionRate()->CloseRatioByMoney;
cout << &#34;\t按数量计算的平昨手续费率:&#34; << pos->getCommissionRate()->CloseRatioByVolume;
cout << &#34;\t按金额计算的平今手续费率:&#34; << pos->getCommissionRate()->CloseTodayRatioByMoney;
cout << &#34;\t按数量计算的平今手续费率:&#34; << pos->getCommissionRate()->CloseTodayRatioByVolume;
cout << &#34;\t按数量计算的报单手续费率:&#34; << pos->getCommissionRate()->OrderCommByVolume;
cout << &#34;\t按数量计算的撤单手续费率:&#34; << pos->getCommissionRate()->OrderActionCommByVolume;*/
cout << endl;
}
}在main函数中新增一条指令qryposition:
else if (*iter == &#34;qryposition&#34;)
plistener->qryPosition();输入qryposition之后就调用qryPosition函数,qryPosition函数根据配置文件中指定的交易所名字查询和展示账户当前持仓情况,其实现如下:
void myYDListener::qryPosition()
{
YDExtendedApi *ydExApi = static_cast<YDExtendedApi *>(m_ydApi);
if (ydExApi != nullptr)
{
if ((m_exchangeID == &#34;CFFEX&#34;) || (m_exchangeID == &#34;SSE&#34;) || (m_exchangeID == &#34;SZSE&#34;))
qry_position_cffex(ydExApi);
else if ((m_exchangeID == &#34;SHFE&#34;) || (m_exchangeID == &#34;INE&#34;))
qry_position_shfe_or_ine(ydExApi);
else if (m_exchangeID == &#34;DCE&#34;)
qry_position_dce(ydExApi);
else
cerr << &#34;交易所代码有误,无法查询其持仓情况&#34; << endl;
}
else
{
cout << &#34;\t易达基础版不支持即时持仓查询,只能获取日初持仓&#34; << endl;
cout << &#34;\t【日初持仓(静态数据)】&#34; << endl;
int n = m_ydApi->getPrePositionCount();
for (int i = 0; i != n; ++i)
{
const YDPrePosition *pos = m_ydApi->getPrePosition(i);
cout << &#34;\t合约代码:&#34; << pos->m_pInstrument->InstrumentID;
cout << &#34;\t持仓方向:&#34;;
switch (pos->PositionDirection)
{
case YD_PD_Long:
cout << &#34;多头&#34;;
break;
case YD_PD_Short:
cout << &#34;空头&#34;;
break;
default:
cerr << &#34;未知&#34;;
}
cout << &#34;\t套保标志:&#34;;
switch (pos->HedgeFlag)
{
case YD_HF_Speculation:
cout << &#34;投机&#34;;
break;
case YD_HF_Hedge:
cout << &#34;保值&#34;;
break;
default:
cerr << &#34;未知&#34;;
}
cout << &#34;\t昨持仓量:&#34; << pos->PrePosition;
cout << &#34;\t昨结算价:&#34; << pos->PreSettlementPrice;
cout << endl;
}
}
}编译运行程序,依次查询一下上期所、大商所和中金所的持仓:
上期所
大商所
中金所
查询报单
YDApi同样不提供报单查询功能,易达Api的扩展版YDExtendedApi提供了报单查询接口。可以调用findOrders函数批量的查询报单信息,函数原型为:
virtual unsigned findOrders(const YDOrderFilter *pFilter,unsigned count,const YDExtendedOrder *orders[]);第一个参数是过滤条件,获取满足条件的报单信息。第二个参数是无符号整数count,指一次查询最大的数量。第三个参数查询结果,保存在一个长度为count的YDExtendedOrder数组中。
YDOrderFilter的成员变量如下:
如果想查询全部报单信息,可以把八个成员变量依次设置为(-1,-1,-1,Null,Null,Null,Null,Null),然后指定一个count值,比如100,调用findOrders函数,得到的查询信息存储在YDExtendedOrder *orders[]之中,可以依次遍历orders数组打印报单信息,打印函数如下:
void showOrder(const YDExtendedOrder *pOrder)
{
cout << &#34;\tOrderSysID: &#34; << pOrder->OrderSysID;
cout << &#34;\t合约代码: &#34; << pOrder->m_pInstrument->InstrumentID;
cout << &#34;\t买卖方向:&#34;;
switch (pOrder->Direction)
{
case YD_D_Buy:
cout << &#34;买&#34;;
break;
case YD_D_Sell:
cout << &#34;卖&#34;;
break;
default:
cerr << &#34;错误&#34;;
}
cout << &#34;\t报单数量:&#34; << pOrder->OrderVolume;
cout << &#34;\t开平仓标志:&#34;;
switch (pOrder->OffsetFlag)
{
case YD_OF_Open:
cout << &#34;开仓&#34;;
break;
case YD_OF_Close:
cout << &#34;平仓&#34;;
break;
case YD_OF_CloseToday:
cout << &#34;平今仓&#34;;
break;
case YD_OF_CloseYesterday:
cout << &#34;平历史仓&#34;;
break;
case YD_OF_ForceClose:
cout << &#34;强平&#34;;
break;
default:
cout << &#34;错误&#34;;
}
cout << &#34;\t报单状态:&#34;;
switch (pOrder->OrderStatus)
{
case YD_OS_Queuing:
cout << &#34;交易所确认报单(部成或未成)&#34;;
break;
case YD_OS_Canceled:
cout << &#34;报单已被撤销&#34;;
break;
case YD_OS_AllTraded:
cout << &#34;全部成交&#34;;
break;
default:
cout << &#34;未知&#34;;
}
cout << &#34;\t报单已成交量:&#34; << pOrder->TradeVolume;
cout << endl;
}同时,YDExtendedApi也提供了通过OrderRef或OrderSysID查询报单信息的函数getOrder:
virtual const YDExtendedOrder *getOrder(int orderRef,const YDAccount *pAccount=NULL);
virtual const YDExtendedOrder *getOrder(int orderSysID,const YDExchange *pExchange)=0;只有通过checkAndInsertOrder和checkAndInsertMultiOrders发出的报单才可以通过这个方法查询到。
在main函数中新增一个qryorders指令用于查询全部报单,新增qryordersysid和qryorderref指令用于通过orderSysID和orderRef来查询报单信息:
else if (*iter == &#34;qryorders&#34;)
plistener->qryOrders();
else if (*iter == &#34;qryordersysid&#34;)
{
for (++iter; iter != cmdWords.end(); ++iter)
plistener->qryOrderSys(atoi(iter->c_str()));
}
else if (*iter == &#34;qryorderref&#34;)
{
for (++iter; iter != cmdWords.end(); ++iter)
plistener->qryOrderRef(atoi(iter->c_str()));
}三个函数的实现分别为:
void myYDListener::qryOrders()
{
cout << &#34;\t【报单查询】&#34; << endl;
YDExtendedApi *ydExApi = static_cast<YDExtendedApi *>(m_ydApi);
if (ydExApi != nullptr)
{
const YDOrderFilter of{ -1, -1, -1, NULL, NULL, NULL, NULL, NULL };
const YDExtendedOrder *orders[MAX_ORDER_COUNT];
unsigned total_count = ydExApi->findOrders(&of, MAX_ORDER_COUNT, orders);
if (total_count > MAX_ORDER_COUNT)
cout << &#34;\t报单总共有&#34; << total_count << &#34;条,返回的仅是部分报单(100条),需增大MAX_ORDER_COUNT参数来获得全部报单&#34; << endl;
unsigned n = min(total_count, MAX_ORDER_COUNT);
if (n == 0)
cout << &#34;\t没有报单&#34; << endl;
else
{
for (size_t i = 0; i != n; ++i)
showOrder(orders);
}
}
else
cout << &#34;\t易达基础版没有报单查询功能&#34; << endl;
}
void myYDListener::qryOrderSys(int orderSysID)
{
cout << &#34;\t【orderSysID报单查询】&#34; << endl;
YDExtendedApi *ydExApi = static_cast<YDExtendedApi *>(m_ydApi);
if (ydExApi != nullptr)
{
const YDExtendedOrder *pOrder = ydExApi->getOrder(orderSysID, m_pExchange);
if (pOrder == nullptr)
cerr << &#34;\tOrderSysID错误,查无此单&#34; << endl;
else
showOrder(pOrder);
}
else
cout << &#34;\t易达基础版没有报单查询功能&#34; << endl;
}
void myYDListener::qryOrderRef(int orderRef)
{
cout << &#34;\t【orderRef报单查询】&#34; << endl;
const YDAccount * pAccount = m_ydApi->getAccount(0);
YDExtendedApi *ydExApi = static_cast<YDExtendedApi *>(m_ydApi);
if (ydExApi != nullptr)
{
const YDExtendedOrder *pOrder = ydExApi->getOrder(orderRef, pAccount);
if (pOrder == nullptr)
cerr << &#34;\tOrderSysID错误,查无此单&#34; << endl;
else
showOrder(pOrder);
}
else
cout << &#34;\t易达基础版没有报单查询功能&#34; << endl;
}编译运行程序,测试报单查询功能:
查询成交信息
基础班易达Api接口不提供查询成交信息的功能,扩展版YDExtended提供了查询成交信息的功能函数findTrades,其函数原型为:
virtual unsigned findTrades(const YDTradeFilter *pFilter,unsigned count,const YDExtendedTrade *trades[]);传入的参数同样为三个:过滤条件、最大结果数、保存结果的数组。
过滤条件的成员变量如下:
如果查询全部成交信息可以把过滤条件设置为(-1,-1,Null,Null,Null,Null)。
在main函数中新增指令qrytrade:
else if (*iter == &#34;qrytrade&#34;)
plistener->qryTrade();qryTrade函数实现如下:
void myYDListener::qryTrade()
{
cout << &#34;\t【成交查询】&#34; << endl;
YDExtendedApi *ydExApi = static_cast<YDExtendedApi *>(m_ydApi);
if (ydExApi != nullptr)
{
const YDTradeFilter tf{ -1, -1, NULL, NULL, NULL, NULL };
const YDExtendedTrade *trades[MAX_TRADE_COUNT];
unsigned total_count = ydExApi->findTrades(&tf, MAX_TRADE_COUNT, trades);
if (total_count > MAX_TRADE_COUNT)
cout << &#34;\t成交记录总共有&#34; << total_count << &#34;条,返回的仅是部分成交结果(100条),需增大MAX_TRADE_COUNT参数来获得全部成交&#34; << endl;
unsigned n = min(total_count, MAX_TRADE_COUNT);
if (n == 0)
cout << &#34;\t无成交记录&#34; << endl;
else
{
for (size_t i = 0; i != n; ++i)
{
cout << &#34;\tOrderRef: &#34; << trades->OrderRef;
cout << &#34;\tOrderSysID: &#34; << trades->OrderSysID;
cout << &#34;\t合约代码:&#34; << trades->m_pInstrument->InstrumentID;
cout << &#34;\t买卖方向:&#34;;
switch (trades->Direction)
{
case YD_D_Buy:
cout << &#34;买&#34;;
break;
case YD_D_Sell:
cout << &#34;卖&#34;;
break;
default:
cerr << &#34;错误&#34;;
}
cout << &#34;\t开平仓标志:&#34;;
switch (trades->OffsetFlag)
{
case YD_OF_Open:
cout << &#34;开仓&#34;;
break;
case YD_OF_Close:
cout << &#34;平仓&#34;;
break;
case YD_OF_CloseToday:
cout << &#34;平今仓&#34;;
break;
case YD_OF_CloseYesterday:
cout << &#34;平历史仓&#34;;
break;
case YD_OF_ForceClose:
cout << &#34;强平&#34;;
break;
default:
cerr << &#34;错误&#34;;
}
cout << &#34;\t套保标志:&#34;;
switch (trades->HedgeFlag)
{
case YD_HF_Speculation:
cout << &#34;投机&#34;;
break;
case YD_HF_Arbitrage:
cout << &#34;套利&#34;;
break;
case YD_HF_Hedge:
cout << &#34;保值&#34;;
break;
default:
cerr << &#34;未知&#34;;
}
cout << &#34;\t成交价格:&#34; << trades->Price;
cout << &#34;\t成交数量:&#34; << trades->Volume;
cout << endl;
}
}
}
else
cout << &#34;\t易达基础版没有成交单查询功能&#34; << endl;
}编译运行程序:
以上便实现了通过YDExtendedApi对账户信息进行各种查询。
撤单:
向ydServer发送撤单请求可以通过调用YDApi::cancelOrder来实现,函数原型为:
virtual bool cancelOrder(YDCancelOrder *pCancelOrder,const YDExchange *pExchange, const YDAccount *pAccount=0)=0;如果网络不通则返回false,返回true则说明撤单请求成功到达了ydServer,正确的撤单请求的回报通过YDListener:notifyOrder回调返回,错误的撤单请求通过YDListener:notifyFailedCancelOrder返回。
对于普通报单,需要传入的信息显示在上表。
在main函数中新增一个cancel指令:
else if (*iter == &#34;cancel&#34;)
{
for (++iter; iter != cmdWords.end(); ++iter)
plistener->cancelOrder(atoi(iter->c_str()), YD_YOF_Normal);
}cancelOrder函数的实现如下:
void myYDListener::cancelOrder(int orderSysID, int orderFlag)
{
YDCancelOrder cancel_order;
memset(&cancel_order, 0, sizeof(cancel_order));
cancel_order.ConnectionSelectionType = YD_CS_Any;
cancel_order.YDOrderFlag = orderFlag;
cancel_order.OrderSysID = orderSysID;
if (m_ydApi->cancelOrder(&cancel_order, m_pExchange))
{
cout << &#34;\t【撤单发送成功】&#34; << endl;
cout << &#34;\t撤单OrderSysID: &#34; << cancel_order.OrderSysID << endl;
}
else
cout << &#34;\t网络断开,发送撤单请求失败&#34; << endl;
}回调函数YDListener:notifyOrder在报单部分已经实现过了,YDListener:notifyFailedCancelOrder需要实现一下:
void myYDListener::notifyFailedCancelOrder(const YDFailedCancelOrder *pFailedCancelOrder, const YDExchange *pExchange, const YDAccount *pAccount)
{
cout << &#34;\tnotifyFailedCancelOrder::易达柜台拒绝撤单请求&#34; << endl;
cout << &#34;\t撤单OrderSysID: &#34; << pFailedCancelOrder->OrderSysID;
cout << &#34;\t错误码:&#34; << pFailedCancelOrder->ErrorNo;
cout << endl;
}编译运行程序,验证撤单功能:
以上便是查询和撤单功能。
至此,易达期货Api大体完成,可以实现登录、退出登录、订阅行情、取消订阅、报单、撤单、查询等基础功能。
参考文献
[1] 易达期货交易系统探索(零) - 知乎 (zhihu.com)
[2] 易达期货交易系统探索(一) - 知乎 (zhihu.com)
[3] 易达期货交易系统探索(二) - 知乎 (zhihu.com)
[4] 易达期货交易系统探索(三) - 知乎 (zhihu.com)
[5] 易达期货交易系统探索(四) - 知乎 (zhihu.com)
[6] 易达期货交易系统探索(五) - 知乎 (zhihu.com)
[7] 客户端应用编程接口 – 易达交易系统 (hanlinit.com) |
|