async public void InstantUpdate_OrderBook(string id) { Queue <string> buffer = AccessWebSocket._bufferPool[id]; OrderBookInfo snapShot = (OrderBookInfo)AccessWebSocket._snapShotPool[id]; Task tsk = new Task(() => { while (buffer.Count == 0) { ; } snapShot.Update(JsonConvert.DeserializeObject <PairInfo>(buffer.Dequeue())); }); await tsk; }
static void Main(string[] args) { string apiKey = ConfigurationManager.AppSettings["ApiKey"]; string secretKey = ConfigurationManager.AppSettings["SecretKey"]; OrderBookInfo BTC = new OrderBookInfo(); BitfinexMethod method = new BitfinexMethod("", ""); BTC = method.GetSnapShot_OrderBook("tBTCUSD", "tBTCUSD"); method.InstantUpdate_OrderBook("tBTCUSD"); //Main thread to update the info at a constant frequncy while (true) { Thread.Sleep(1000); Console.WriteLine("The current price of BTC is " + BTC.asks[0].price); } }
public OrderBookInfo GetSnapShot_OrderBook(string symbol, string id) { Dictionary <string, string> args = new Dictionary <string, string>(); args.Add("event", "subscribe"); args.Add("channel", "book"); args.Add("symbol", symbol); args.Add("prec", "P0"); args.Add("freq", "F0"); args.Add("len", "25"); string request = JsonConvert.SerializeObject(args); OrderBookInfo res = GetSnapShot <OrderBookInfo>(request, symbol); AccessWebSocket._snapShotPool[id] = res; return(res); }