void TickForm::on_pushButtonSendOrder_clicked() { QString symbol = ui->lineEditSymbol->text(); QString exchange = ui->lineEditExchange->text(); double price = ui->doubleSpinBoxPrice->value(); int volume = ui->spinBoxVolume->value(); BfDirection direction = (BfDirection)(ui->comboBoxDirection->currentIndex() + 1); BfOffset offset = (BfOffset)(ui->comboBoxOffset->currentIndex() + 1); BfPriceType priceType = (BfPriceType)(ui->comboBoxPriceType->currentIndex() + 1); BfSendOrderReq req; req.set_symbol(symbol.toStdString()); req.set_exchange(exchange.toStdString()); req.set_price(price); req.set_volume(volume); req.set_direction(direction); req.set_offset(offset); req.set_pricetype(priceType); QMetaObject::invokeMethod(g_sm->ctpMgr(), "sendOrder", Qt::QueuedConnection, Q_ARG(BfSendOrderReq, req)); }
// 如果不是上期所,平今仓可用close或closeToday,平昨仓可用close或closeYesterday= // 如果是上期所,平今仓只可用closeToday,平昨仓可用close或closeYesterday= // 那成交回报的流水回来的时侯: // CloseYesterday=> insert =>CloseYesterday // CloseToday=> insert =>CloseToday // 也存在:closeToday =>close或closeYesterday =>close的情况= // 参考:http://www.cnblogs.com/xiaouisme/p/4654750.html void PositionForm::on_pushButtonCloseAll_clicked() { for (auto pos : positions_) { // 没有持仓的pass if (pos.position() == 0) { continue; } QString symbol = pos.symbol().c_str(); QString exchange = pos.exchange().c_str(); if (exchange.length() == 0) { void* contract = g_sm->gatewayMgr()->getContract(symbol); exchange = CtpUtils::getExchangeFromContract(contract); } // 没有订阅的pass if (!symbols_my_.contains(symbol)) { BfInfo(symbol + " not subscrible,please close byhand"); continue; } // 取不到tick的pass,比如晚上if不开盘= void* tick = g_sm->gatewayMgr()->getLatestTick(symbol); if (!tick) { BfInfo(symbol + " has no tick,please close byhand"); continue; } BfTickData bfTick; CtpUtils::translateTick(tick, nullptr, &bfTick); // 平昨= if (pos.ydposition() > 0) { // 限价单= BfOffset offset = OFFSET_CLOSE; BfPriceType priceType = PRICETYPE_LIMITPRICE; //TODO(hege):这里要判断是否超过了contract->maxLimit //TODO(hege):这里要判断昨持仓和今持仓,先平昨再平今= int volume = pos.ydposition(); //空单-->最高价+多+平= //多单-->最低价+空+平= double price = bfTick.upperlimit(); BfDirection direction = DIRECTION_LONG; if (pos.direction() == DIRECTION_NET || pos.direction() == DIRECTION_LONG) { direction = DIRECTION_SHORT; price = bfTick.lowerlimit(); } BfSendOrderReq req; req.set_symbol(symbol.toStdString()); req.set_exchange(exchange.toStdString()); req.set_price(price); req.set_volume(volume); req.set_direction(direction); req.set_offset(offset); req.set_pricetype(priceType); QMetaObject::invokeMethod(g_sm->gatewayMgr(), "sendOrder", Qt::QueuedConnection, Q_ARG(BfSendOrderReq, req)); } // 平今= if (pos.position() - pos.ydposition() > 0) { // 限价单= BfOffset offset = OFFSET_CLOSETODAY; BfPriceType priceType = PRICETYPE_LIMITPRICE; //TODO(hege):这里要判断是否超过了contract->maxLimit int volume = pos.position() - pos.ydposition(); //空单-->最高价+多+平= //多单-->最低价+空+平= double price = bfTick.upperlimit(); BfDirection direction = DIRECTION_LONG; if (pos.direction() == DIRECTION_NET || pos.direction() == DIRECTION_LONG) { direction = DIRECTION_SHORT; price = bfTick.lowerlimit(); } BfSendOrderReq req; req.set_symbol(symbol.toStdString()); req.set_exchange(exchange.toStdString()); req.set_price(price); req.set_volume(volume); req.set_direction(direction); req.set_offset(offset); req.set_pricetype(priceType); QMetaObject::invokeMethod(g_sm->gatewayMgr(), "sendOrder", Qt::QueuedConnection, Q_ARG(BfSendOrderReq, req)); } } }