public void Construction() { TradeImpl t = new TradeImpl("TST",10,100,DateTime.Now); Assert.That(t.isValid,t.ToString()); Assert.That(t.isFilled,t.ToString()); //midnight check t.xdate = 20081205; t.xtime = 0; Assert.That(t.isValid); t.xtime = 0; t.xdate = 0; Assert.That(!t.isValid); }
private void TradeHandler(object sender, TradeArgs e) { itemTrade itrade = e.ItemTrade; // Order o = new OrderImpl(iorder.msecsym, iorder.IsBuyOrder(), iorder.mqty, Convert.ToDecimal(iorder.mprice), Convert.ToDecimal(iorder.mstopprice), "", iorder.mc_date, iorder.mc_date, iorder.morderid); Trade trade = new TradeImpl(); trade.symbol = itrade.msecsym; itemOrder lorder =socketOrderServer.sitemOrder.FindItem(itrade.morderid); if (lorder== null) return; trade.side = lorder.IsBuyOrder(); trade.xprice = Convert.ToDecimal(itrade.mprice); trade.xsize = itrade.mqty; DateTime mdate = ComFucs.GetDate(itrade.mm_date); trade.Account = ""; trade.xdate = mdate.Day + mdate.Month * 100 + mdate.Year * 10000; trade.xtime = mdate.Second + mdate.Minute * 100 + mdate.Hour * 10000; tl.newFill(trade); v(trade.symbol+" received fill ack for: " + trade.ToString()); }
void dofillupdate(ref structSTITradeUpdate t) { Trade f = new TradeImpl(); f.symbol = t.bstrSymbol; f.Account = t.bstrAccount; long id = 0; if (long.TryParse(t.bstrClOrderId, out id)) f.id = id; else f.id = t.nOrderRecordId; f.xprice = (decimal)t.fExecPrice; f.xsize = t.nQuantity; long now = Convert.ToInt64(t.bstrUpdateTime); int xsec = (int)(now % 100); long rem = (now - xsec) / 100; f.side = t.bstrSide == "B"; f.xtime = ((int)(rem % 10000)) * 100 + xsec; f.xdate = (int)((now - f.xtime) / 1000000); f.ex = t.bstrDestination; pt.Adjust(f); tl.newFill(f); if (VerboseDebugging) debug("new trade sent: " + f.ToString() + " " + f.id); }
void MessageCache_CacheEvent(int action, int row) { switch (action) { case 1: //CN_Submit break; case 4: //CN_Insert { try { int i = row; int err = 0; object cv = null; string orderReferenceNumber = String.Empty; Order o = new OrderImpl(); _messageCache.VBGetCell(row, "SYMBOL", ref cv, ref err); if (!(cv == null)) { o.symbol = cv.ToString(); } _messageCache.VBGetCell(row, "SIDE", ref cv, ref err); if (!(cv == null)) { v("order side: "+cv.ToString()); if (cv.ToString() == "BUY") { o.side = true; } else if (cv.ToString() == "SELL") { o.side = false; } else if (cv.ToString().Contains("SHORT")) { o.side = false; } } _messageCache.VBGetCell(row, "QUANTITY", ref cv, ref err); if (!(cv == null)) { o.size = int.Parse(cv.ToString()); } _messageCache.VBGetCell(row, "PRICE", ref cv, ref err); if (!(cv == null)) { o.price = decimal.Parse(cv.ToString()); } _messageCache.VBGetCell(row, "STOPPRICE", ref cv, ref err); if (!(cv == null)) { o.stopp = decimal.Parse(cv.ToString()); } _messageCache.VBGetCell(row, "ACCOUNT", ref cv, ref err); if (!(cv == null)) { o.Account = cv.ToString(); } _messageCache.VBGetCell(row, "BRSEQ", ref cv, ref err); if (!(cv == null)) { orderReferenceNumber = cv.ToString(); } _messageCache.VBGetCell(row, "Status", ref cv, ref err); if (!(cv == null)) { if (cv.ToString() == "Open") { o.id = row; long now = Util.ToTLDate(DateTime.Now); int xsec = (int)(now % 100); long rem = (now - xsec) / 100; o.time = ((int)(rem % 10000)) * 100 + xsec; o.date = (int)((rem - o.time) / 10000); o.size = o.side ? o.UnsignedSize : o.UnsignedSize * -1; OrderIdDict.Add(orderReferenceNumber, (long)row); if (_onotified.Contains((int)row)) return; _onotified.Add(o.id); tl.newOrder(o); v("order ack received and sent: " + o.ToString()); } else if (cv.ToString() == "Canceled") { long id = OrderIdDict[orderReferenceNumber]; tl.newCancel(id); v("order cancel ack received and sent: " + id); } else if (cv.ToString() == "Complete") { Trade f = new TradeImpl(); _messageCache.VBGetCell(row, "SYMBOL", ref cv, ref err); if (!(cv == null)) { f.symbol = cv.ToString(); } _messageCache.VBGetCell(row, "ACCOUNT", ref cv, ref err); if (!(cv == null)) { f.Account = cv.ToString(); } _messageCache.VBGetCell(row, "BRSEQ", ref cv, ref err); if (!(cv == null)) { long id = 0; if (OrderIdDict.TryGetValue(cv.ToString(), out id)) f.id = id; else f.id = _idt.AssignId; f.id = id; } _messageCache.VBGetCell(row, "EXECPRICE", ref cv, ref err); if (!(cv == null)) { f.xprice = decimal.Parse(cv.ToString()); } _messageCache.VBGetCell(row, "EXECQUANTITY", ref cv, ref err); if (!(cv == null)) { f.xsize = int.Parse(cv.ToString()); } _messageCache.VBGetCell(row, "EXCHANGE", ref cv, ref err); if (!(cv == null)) { f.ex = cv.ToString(); } _messageCache.VBGetCell(row, "SIDE", ref cv, ref err); if (!(cv == null)) { if (cv.ToString() == "BUY") { f.side = true; } else if (cv.ToString() == "SELL") { f.side = false; } else if (cv.ToString().Contains("SHORT")) { f.side = false; } else v("invalid fill side: " + cv.ToString()); } long now = Util.ToTLDate(DateTime.Now); int xsec = (int)(now % 100); long rem = (now - xsec) / 100; f.xtime = ((int)(rem % 10000)) * 100 + xsec; f.xdate = (int)((now - f.xtime) / 1000000); Object objErr = null; _positionCache.VBRediCache.AddWatch(2, string.Empty, f.Account, ref objErr); if (f.isValid) { pt.Adjust(f); tl.newFill(f); v("fill ack received and sent: " + f.ToString()); } else debug("ignoring invalid fill: " + f.ToString()); } } } catch (Exception ex) { debug(ex.Message+ex.StackTrace); } } break; case 5: //CN_Update { try { int i = row; int err = 0; object cv = null; string orderStatus = null; _messageCache.VBGetCell(row, "Status", ref cv, ref err); if (!(cv == null)) { orderStatus = cv.ToString(); } if (orderStatus == "Complete") { Trade f = new TradeImpl(); _messageCache.VBGetCell(row, "SYMBOL", ref cv, ref err); if (!(cv == null)) { f.symbol = cv.ToString(); } _messageCache.VBGetCell(row, "ACCOUNT", ref cv, ref err); if (!(cv == null)) { f.Account = cv.ToString(); } _messageCache.VBGetCell(row, "BRSEQ", ref cv, ref err); if (!(cv == null)) { long id = 0; if (OrderIdDict.TryGetValue(cv.ToString(), out id)) f.id = id; else f.id = _idt.AssignId; f.id = id; } _messageCache.VBGetCell(row, "EXECPRICE", ref cv, ref err); if (!(cv == null)) { f.xprice = decimal.Parse(cv.ToString()); } _messageCache.VBGetCell(row, "EXECQUANTITY", ref cv, ref err); if (!(cv == null)) { f.xsize = int.Parse(cv.ToString()); } _messageCache.VBGetCell(row, "EXCHANGE", ref cv, ref err); if (!(cv == null)) { f.ex = cv.ToString(); } _messageCache.VBGetCell(row, "SIDE", ref cv, ref err); if (!(cv == null)) { if (cv.ToString() == "BUY") { f.side = true; } else if (cv.ToString() == "SELL") { f.side = false; } } long now = Util.ToTLDate(DateTime.Now); int xsec = (int)(now % 100); long rem = (now - xsec) / 100; f.xtime = ((int)(rem % 10000)) * 100 + xsec; f.xdate = (int)((now - f.xtime) / 1000000); Object objErr = null; _positionCache.VBRediCache.AddWatch(2, string.Empty, f.Account, ref objErr); if (f.isValid) { pt.Adjust(f); tl.newFill(f); v("fill ack received and sent: " + f.ToString()); } else debug("ignoring invalid fill: " + f.ToString()); } if (orderStatus == "Partial") { } } catch (Exception exc) { debug(exc.Message); } } break; case 8: //CN_Remove break; } }
void m_Session_OnExecutionMessage(object sender, BWExecution executionMsg) { foreach (KeyValuePair<long,int> ordID in _bwOrdIds) if ( ordID.Value == executionMsg.OrderID) { Trade t = new TradeImpl(executionMsg.Symbol, (decimal)executionMsg.Price, executionMsg.Size); t.side = (executionMsg.Side == ORDER_SIDE.SIDE_COVER) || (executionMsg.Side == ORDER_SIDE.SIDE_BUY); t.xtime = TradeLink.Common.Util.DT2FT(executionMsg.ExecutionTime); t.xdate = TradeLink.Common.Util.ToTLDate(executionMsg.ExecutionTime); t.Account = executionMsg.UserID.ToString(); t.id = ordID.Key; t.ex = executionMsg.MarketMaker; tl.newFill(t); v(t.symbol + " sent fill notification for: " + t.ToString()); } }
TradeImpl ToTradeLinkFill(MbtOpenOrder pOrd, MbtOrderHistory pHist) { //debug(String.Format("pOrd\n{0}\n\npHist\n{1}", Util.DumpObjectProperties(pOrd), Util.DumpObjectProperties(pHist))); debug(String.Format("pOrd: {0}", DisplayOrder(pOrd))); //TODO:Add hstory to this debug TradeImpl f = new TradeImpl(); f.symbol = pOrd.Symbol; f.Account = pOrd.Account.Account; //f.xprice = (pOrd.Price > 0) ? (decimal)pOrd.Price : (decimal)pOrd.StopLimit; //f.xprice = Math.Abs((decimal)pOrd.Price); f.xprice = (decimal)pHist.Price; //f.xsize = pHist.Event == "Executed" ? pHist.Quantity : pHist.SharesFilled; f.xsize = pHist.Quantity; f.side = (pOrd.BuySell == MBConst.VALUE_BUY); f.xtime = Util.DT2FT(pOrd.UTCDateTime); f.xdate = Util.ToTLDate(pOrd.UTCDateTime); long tlid = 0; if (broker2tl.TryGetValue(pOrd.OrderNumber, out tlid)) f.id = tlid; else debug(String.Format("WARNING: No order matching fill for pOrd.OrderNumber {0}", pOrd.OrderNumber)); //debug(String.Format("New fill {1}\n is valid:{0}\ndump:{2}", f.isValid, f.ToString(), Util.DumpObjectProperties(f))); debug(String.Format("New fill {1} is valid? {0}", f.isValid, f.ToString())); return f; }
void dofillupdate(ref structSTITradeUpdate t) { Trade f = new TradeImpl(); string ssym = t.bstrSymbol; if (UseSubscribedSymbolForNotify) { int idx = getlongsymbolidx(ssym); // check for error if ((idx < 0) || (idx >= syms.Length)) { debug(ssym + " fill ack error identifying symbol idx: " + idx + " symbols: " + string.Join(",", syms)); f.symbol = ssym; } else f.symbol = syms[idx]; } else f.symbol = ssym; f.Account = t.bstrAccount; long id = 0; if (long.TryParse(t.bstrClOrderId, out id)) f.id = id; else f.id = t.nOrderRecordId; f.xprice = (decimal)t.fExecPrice; f.xsize = t.nQuantity; long now = Convert.ToInt64(t.bstrUpdateTime); int xsec = (int)(now % 100); long rem = (now - xsec) / 100; f.side = t.bstrSide == "B"; f.xtime = ((int)(rem % 10000)) * 100 + xsec; f.xdate = (int)((now - f.xtime) / 1000000); f.ex = t.bstrDestination; pt.Adjust(f); if (RegSHOShorts) sho.GotFill(f); tl.newFill(f); if (VerboseDebugging) debug("new trade sent: " + f.ToString() +" pos: "+pt[f.symbol,f.Account]); }
public void Defaults() { TradeImpl t = new TradeImpl(); Assert.That(!t.isValid, t.ToString()); Assert.That(!t.isFilled, t.ToString()); }