public OpenBookReturn(TransaqOpenBook tq, int position, int type) { if (tq.Sell > 0 || tq.Sell == -1) { this.Side = BidAsk.Ask; this.Size = tq.Sell; } if (tq.Buy > 0 || tq.Buy == -1) { this.Side = BidAsk.Bid; this.Size = tq.Buy; } switch (type) { case 1: this.Action = OrderBookAction.Delete; break; case 2: this.Action = OrderBookAction.Insert; break; case 3: this.Action = OrderBookAction.Update; break; default: this.Action = OrderBookAction.Undefined; break; } this.Price = tq.Price; this.Position = position; }
private OpenBookReturn Delete(ref TransaqOpenBook tob, ref List <OpenBookData> openBookData) { bool flag = true; if (openBookData.Count == 0) { return(new OpenBookReturn(tob, -1, 0)); } if (openBookData.Count > 0 && flag) { for (int index = 0; index < openBookData.Count; ++index) { if (openBookData[index].Price == tob.Price) { openBookData.RemoveAt(index); return(new OpenBookReturn(tob, index, 1)); } } flag = false; } if (openBookData.Count > 0 && !flag) { return(new OpenBookReturn(tob, -1, 0)); } else { return(new OpenBookReturn(tob, -1, 0)); } }
public OpenBookReturn UpdateOpenBook(TransaqOpenBook tob) { if (tob.Sell == -1) return this.Delete(ref tob, ref this.openBookAsk); if (tob.Buy == -1) return this.Delete(ref tob, ref this.openBookBid); if (tob.Sell > 0) return this.UpdateOrInsert(ref tob, ref this.openBookAsk, "ASK"); if (tob.Buy > 0) return this.UpdateOrInsert(ref tob, ref this.openBookBid, "DESC"); else return new OpenBookReturn(tob, -1, 0); }
private OpenBookReturn Delete(ref TransaqOpenBook tob, ref List<OpenBookData> openBookData) { bool flag = true; if (openBookData.Count == 0) return new OpenBookReturn(tob, -1, 0); if (openBookData.Count > 0 && flag) { for (int index = 0; index < openBookData.Count; ++index) { if (openBookData[index].Price == tob.Price) { openBookData.RemoveAt(index); return new OpenBookReturn(tob, index, 1); } } flag = false; } if (openBookData.Count > 0 && !flag) return new OpenBookReturn(tob, -1, 0); else return new OpenBookReturn(tob, -1, 0); }
public OpenBookReturn UpdateOpenBook(TransaqOpenBook tob) { if (tob.Sell == -1) { return(this.Delete(ref tob, ref this.openBookAsk)); } if (tob.Buy == -1) { return(this.Delete(ref tob, ref this.openBookBid)); } if (tob.Sell > 0) { return(this.UpdateOrInsert(ref tob, ref this.openBookAsk, "ASK")); } if (tob.Buy > 0) { return(this.UpdateOrInsert(ref tob, ref this.openBookBid, "DESC")); } else { return(new OpenBookReturn(tob, -1, 0)); } }
private OpenBookReturn UpdateOrInsert(ref TransaqOpenBook tob, ref List<OpenBookData> openBookData, string sortType) { for (int index = 0; index < openBookData.Count; ++index) { if (openBookData[index].Price == tob.Price) { openBookData.RemoveAt(index); openBookData.Insert(index, new OpenBookData(tob.Price, tob.Buy == 0 ? tob.Sell : tob.Buy)); return new OpenBookReturn(tob, index, 3); } } if (openBookData.Count == 0) { openBookData.Insert(0, new OpenBookData(tob.Price, tob.Buy == 0 ? tob.Sell : tob.Buy)); return new OpenBookReturn(tob, 0, 2); } else { if (openBookData.Count > 0 && sortType == "ASK") { if (tob.Price < Enumerable.First<OpenBookData>((IEnumerable<OpenBookData>) openBookData).Price) { openBookData.Insert(0, new OpenBookData(tob.Price, tob.Buy == 0 ? tob.Sell : tob.Buy)); return new OpenBookReturn(tob, 0, 2); } else if (tob.Price > Enumerable.Last<OpenBookData>((IEnumerable<OpenBookData>) openBookData).Price) { openBookData.Add(new OpenBookData(tob.Price, tob.Buy == 0 ? tob.Sell : tob.Buy)); return new OpenBookReturn(tob, openBookData.Count - 1, 2); } else { for (int index = 0; index < openBookData.Count - 1; ++index) { if (openBookData[index].Price < tob.Price && tob.Price < openBookData[index + 1].Price) { openBookData.Insert(index + 1, new OpenBookData(tob.Price, tob.Buy == 0 ? tob.Sell : tob.Buy)); return new OpenBookReturn(tob, index + 1, 2); } } } } if (openBookData.Count > 0 && sortType == "DESC") { if (tob.Price > Enumerable.First<OpenBookData>((IEnumerable<OpenBookData>) openBookData).Price) { openBookData.Insert(0, new OpenBookData(tob.Price, tob.Buy == 0 ? tob.Sell : tob.Buy)); return new OpenBookReturn(tob, 0, 2); } else if (tob.Price < Enumerable.Last<OpenBookData>((IEnumerable<OpenBookData>) openBookData).Price) { openBookData.Add(new OpenBookData(tob.Price, tob.Buy == 0 ? tob.Sell : tob.Buy)); return new OpenBookReturn(tob, openBookData.Count - 1, 2); } else { for (int index = 0; index < openBookData.Count - 1; ++index) { if (openBookData[index].Price > tob.Price && tob.Price > openBookData[index + 1].Price) { openBookData.Insert(index + 1, new OpenBookData(tob.Price, tob.Buy == 0 ? tob.Sell : tob.Buy)); return new OpenBookReturn(tob, index + 1, 2); } } } } return new OpenBookReturn(tob, -1, 0); } }
private void AddQuote(string data) { TransaqOpenBook tob = new TransaqOpenBook(data); if (this.selectedSecurity == SecuritySelector.seccode) { OpenBookReturn openBookReturn = this.openBookBySecId[tob.SecId].UpdateOpenBook(tob); if (!this.instrumentBySymbol.ContainsKey(tob.SecCode)) return; this.EmitNewOrderBookUpdate(this.instrumentBySymbol[tob.SecCode], Clock.Now, openBookReturn.Side, openBookReturn.Action, openBookReturn.Price, openBookReturn.Size, openBookReturn.Position); } else { if (this.selectedSecurity != SecuritySelector.seccode_board) return; OpenBookReturn openBookReturn = this.openBookBySCB[tob.SecCodeBoard].UpdateOpenBook(tob); if (!this.instrumentBySymbol.ContainsKey(tob.SecCodeBoard)) return; this.EmitNewOrderBookUpdate(this.instrumentBySymbol[tob.SecCodeBoard], Clock.Now, openBookReturn.Side, openBookReturn.Action, openBookReturn.Price, openBookReturn.Size, openBookReturn.Position); } }
private OpenBookReturn UpdateOrInsert(ref TransaqOpenBook tob, ref List <OpenBookData> openBookData, string sortType) { for (int index = 0; index < openBookData.Count; ++index) { if (openBookData[index].Price == tob.Price) { openBookData.RemoveAt(index); openBookData.Insert(index, new OpenBookData(tob.Price, tob.Buy == 0 ? tob.Sell : tob.Buy)); return(new OpenBookReturn(tob, index, 3)); } } if (openBookData.Count == 0) { openBookData.Insert(0, new OpenBookData(tob.Price, tob.Buy == 0 ? tob.Sell : tob.Buy)); return(new OpenBookReturn(tob, 0, 2)); } else { if (openBookData.Count > 0 && sortType == "ASK") { if (tob.Price < Enumerable.First <OpenBookData>((IEnumerable <OpenBookData>)openBookData).Price) { openBookData.Insert(0, new OpenBookData(tob.Price, tob.Buy == 0 ? tob.Sell : tob.Buy)); return(new OpenBookReturn(tob, 0, 2)); } else if (tob.Price > Enumerable.Last <OpenBookData>((IEnumerable <OpenBookData>)openBookData).Price) { openBookData.Add(new OpenBookData(tob.Price, tob.Buy == 0 ? tob.Sell : tob.Buy)); return(new OpenBookReturn(tob, openBookData.Count - 1, 2)); } else { for (int index = 0; index < openBookData.Count - 1; ++index) { if (openBookData[index].Price < tob.Price && tob.Price < openBookData[index + 1].Price) { openBookData.Insert(index + 1, new OpenBookData(tob.Price, tob.Buy == 0 ? tob.Sell : tob.Buy)); return(new OpenBookReturn(tob, index + 1, 2)); } } } } if (openBookData.Count > 0 && sortType == "DESC") { if (tob.Price > Enumerable.First <OpenBookData>((IEnumerable <OpenBookData>)openBookData).Price) { openBookData.Insert(0, new OpenBookData(tob.Price, tob.Buy == 0 ? tob.Sell : tob.Buy)); return(new OpenBookReturn(tob, 0, 2)); } else if (tob.Price < Enumerable.Last <OpenBookData>((IEnumerable <OpenBookData>)openBookData).Price) { openBookData.Add(new OpenBookData(tob.Price, tob.Buy == 0 ? tob.Sell : tob.Buy)); return(new OpenBookReturn(tob, openBookData.Count - 1, 2)); } else { for (int index = 0; index < openBookData.Count - 1; ++index) { if (openBookData[index].Price > tob.Price && tob.Price > openBookData[index + 1].Price) { openBookData.Insert(index + 1, new OpenBookData(tob.Price, tob.Buy == 0 ? tob.Sell : tob.Buy)); return(new OpenBookReturn(tob, index + 1, 2)); } } } } return(new OpenBookReturn(tob, -1, 0)); } }