private void OnWebSocketMessageReceived(object sender, WebSocketMessageEventArgs e) { // Assume the incoming string represents a JSON message. // Parse it, and access it via "dynamic" variable (no ["field"] and casts necessary). dynamic jobj = e.Message; if (jobj.type == "ticker") { string prod = jobj.product_id; string origin = GDAX; lock (_subMgr) { _subMgr.Set(SubscriptionManager.FormatPath(origin, String.Empty, prod, "BID"), jobj.best_bid); _subMgr.Set(SubscriptionManager.FormatPath(origin, String.Empty, prod, "ASK"), jobj.best_ask); _subMgr.Set(SubscriptionManager.FormatPath(origin, String.Empty, prod, "LAST_SIZE"), jobj.last_size); _subMgr.Set(SubscriptionManager.FormatPath(origin, String.Empty, prod, "LAST_PRICE"), jobj.price); _subMgr.Set(SubscriptionManager.FormatPath(origin, String.Empty, prod, "LAST_SIDE"), jobj.side); _subMgr.Set(SubscriptionManager.FormatPath(origin, String.Empty, prod, "high_24h"), jobj.high_24h); _subMgr.Set(SubscriptionManager.FormatPath(origin, String.Empty, prod, "low_24h"), jobj.low_24h); _subMgr.Set(SubscriptionManager.FormatPath(origin, String.Empty, prod, "open_24h"), jobj.open_24h); _subMgr.Set(SubscriptionManager.FormatPath(origin, String.Empty, prod, "volume_24h"), jobj.volume_24h); } } }
protected void FireMessageReceived(WebSocketMessageEventArgs e) { EventHandler <WebSocketMessageEventArgs> h = this.MessageReceived; if (h != null) { h.Invoke(this, e); } }