public void RunPriceLevelDelete(string pair, OrderBookEntry[] bids, OrderBookEntry[] asks) { if (OrderBooks.ContainsKey(pair)) { OrderBookDictionary dic = OrderBooks[pair]; foreach (OrderBookEntry bid in bids) { if (dic.Entries.ContainsKey(bid.id)) { OrderBookEntry entry = dic.Entries[bid.id]; dic.Entries.Remove(bid.id); } //else // throw new Exception(string.Format("Could not find price level for pair {0} with id {1}", pair, bid.id)); } foreach (OrderBookEntry ask in asks) { if (dic.Entries.ContainsKey(ask.id)) { OrderBookEntry entry = dic.Entries[ask.id]; dic.Entries.Remove(ask.id); } //else // throw new Exception(string.Format("Could not find price level for pair {0} with id {1}", pair, ask.id)); } } else { throw new Exception(string.Format("Unknown Error: Order Book not found in memory for pair {0}", pair)); } }
public void RunPriceLevelCreation(string pair, OrderBookEntry[] bids, OrderBookEntry[] asks) { OrderBookDictionary newDic = new OrderBookDictionary(); foreach (OrderBookEntry bid in bids.OrderByDescending(x => x.price).Take(5)) { newDic.Entries.Add(bid.id, bid); } foreach (OrderBookEntry ask in asks.OrderBy(x => x.price).Take(5)) { newDic.Entries.Add(ask.id, ask); } Console.WriteLine(); if (!OrderBooks.ContainsKey(pair)) { OrderBooks.Add(pair, newDic); } else { OrderBooks.Remove(pair); OrderBooks.Add(pair, newDic); } }
public void RunPriceLevelUpdate(string pair, OrderBookEntry[] bids, OrderBookEntry[] asks) { if (OrderBooks.ContainsKey(pair)) { OrderBookDictionary dic = OrderBooks[pair]; foreach (OrderBookEntry bid in bids) { if (dic.Entries.ContainsKey(bid.id)) { OrderBookEntry entry = dic.Entries[bid.id]; entry.size = bid.size; } //else // throw new Exception(string.Format("Could not find price level for pair {0} with id {1}", pair, bid.id)); } foreach (OrderBookEntry ask in asks) { if (dic.Entries.ContainsKey(ask.id)) { OrderBookEntry entry = dic.Entries[ask.id]; Console.WriteLine(string.Format("ASK UPDATE SIZE={0} PRICE={1}", ask.size.ToString("##.##"), entry.price.ToString("##.########"))); entry.size = ask.size; } //else // throw new Exception(string.Format("Could not find price level for pair {0} with id {1}", pair, ask.id)); } } else { throw new Exception(string.Format("Unknown Error: Order Book not found in memory for pair {0}", pair)); } }
public void RunPriceLevelNew(string pair, OrderBookEntry[] bids, OrderBookEntry[] asks) { if (OrderBooks.ContainsKey(pair)) { OrderBookDictionary dic = OrderBooks[pair]; foreach (OrderBookEntry bid in bids) { if (!dic.Entries.ContainsKey(bid.id)) { dic.Entries.Add(bid.id, bid); } else { throw new Exception(string.Format("Invalid new message for existing price level for pair {0} with id {1}", pair, bid.id)); } } foreach (OrderBookEntry ask in asks) { if (!dic.Entries.ContainsKey(ask.id)) { Console.WriteLine(string.Format("ASK NEW SIZE={0} PRICE={1}", ask.size.ToString("##.##"), ask.price.ToString("##.########"))); dic.Entries.Add(ask.id, ask); } else { throw new Exception(string.Format("Invalid new message for existing price level for pair {0} with id {1}", pair, ask.id)); } } } else { throw new Exception(string.Format("Unknown Error: Order Book not found in memory for pair {0}", pair)); } }