void TLServer_WM::SrvGotOrder(TLOrder order) { if (!order.isValid()) return; for (size_t i = 0; i<client.size(); i++) if (client[i]!="") TLSend(ORDERNOTIFY,order.Serialize(),client[i]); }
static void __stdcall Basics() { const CString sym = "LVS"; const double x = 10; const int s = 200; TLOrder o; CFIX_ASSERT(!o.isFilled()); CFIX_ASSERT(!o.isValid()); o.symbol = sym; o.size = s; CFIX_ASSERT(o.isMarket()); o.price = x; CFIX_ASSERT(o.isLimit()); o.stop = x; CFIX_ASSERT(o.isStop()); }
int TWS_TLWM::SendOrder(TLOrder o) { // check our order if (!o.isValid()) return GOTNULLORDER; if (o.symbol=="") return UNKNOWNSYM; // create broker-specific objects here Order* order(new Order); order->auxPrice = o.stop; order->lmtPrice = o.price; order->orderType = (o.stop!=0) ? "STP" : (o.price!=0 ? "LMT" : "MKT"); order->totalQuantity = (long)o.size; order->action = (o.side) ? "BUY" : "SELL"; order->account = o.account; order->tif = o.TIF; order->outsideRth = true; if (o.id!=0) // if ID is provided, keep it order->orderId = o.id; else // otherwise just get the next id order->orderId = getNextOrderId(o.account); order->transmit = true; Contract* contract(new Contract); contract->symbol = o.symbol; contract->localSymbol = o.localsymbol; if (o.exchange=="") o.exchange = "SMART"; contract->exchange = o.exchange; contract->secType = o.security; contract->currency = o.currency; // get the TWS session associated with our account EClient* client; if (o.account=="") // if no account specified, get default client = m_link[this->validlinkids[0]]; else // otherwise get the session our account is logged into client = GetOrderSink(o.account); // place our order if (client!=NULL) client->placeOrder(order->orderId,*contract,*order); delete order; delete contract; return OK; }
int TWS_TLServer::SendOrder(TLOrder o) { // check our order if (o.symbol=="") return UNKNOWN_SYMBOL; if (!o.isValid()) return INVALID_ORDERSIZE; // create broker-specific objects here Order* order(new Order); order->auxPrice = o.isTrail() ? o.trail : o.stop; order->lmtPrice = o.price; order->orderType = (o.isStop()) ? "STP" : (o.isLimit() ? "LMT" : (o.isTrail() ? "TRAIL" : "MKT")); order->totalQuantity = (long)o.size; order->action = (o.side) ? "BUY" : "SELL"; order->account = o.account; order->tif = o.TIF; order->outsideRth = true; order->orderId = newOrder(o.id,o.account); order->transmit = true; Contract* contract(new Contract); contract->symbol = o.symbol; contract->localSymbol = o.localsymbol!="" ? o.localsymbol : o.symbol; if (o.exchange=="") o.exchange = "SMART"; contract->exchange = o.exchange; contract->secType = o.security; contract->currency = o.currency; // get the TWS session associated with our account EClient* client; if (o.account=="") // if no account specified, get default client = m_link[this->validlinkids[0]]; else // otherwise get the session our account is logged into client = GetOrderSink(o.account); // place our order if (client!=NULL) client->placeOrder(order->orderId,*contract,*order); delete order; delete contract; return OK; }
UINT __cdecl DoOrderResend(LPVOID param) { // we need a queue object LS_TLWM* tl = (LS_TLWM*)param; // ensure it's present if (tl==NULL) { return OK; } while (tl->_go) { if (tl->_resends!=0) { // process every valid order in queue for (uint i = 0; i<tl->resend.size(); i++) { // get tradelink order TLOrder ord = tl->resend[i]; // skip if invalid if (!ord.isValid()) continue; // mark as invalid TLOrder blank; tl->resend[i] = blank; tl->_resends--; // resend it tl->SendOrder(ord); // notify CString tmp; tmp.Format("%s Resending order: %s",ord.symbol,ord.Serialize()); tl->D(tmp); // wait briefly Sleep(25); } } Sleep(100); } return OK; }