Profile Picture

Market Data Service using Websocket

Posted By lampalork 9 Months Ago
Message
Posted Tuesday January 23 2018
Hi All,
I'm trying to build a market data plugin that would consume realtime data from a webservice (https://streamer.cryptocompare.com/). For this, i'm using the .net package Quobject.SocketIoClientDotNet. I got a proof of concept (successfull connection and streaming data) in a console project but for some reasons it does not work at all when i try to integrate this into a rightedge plugin i stops working (i never get a "callback" on connection or on "market data event received"; i have checked this with logs). I have built dummy market data plugin with random data using standard c# callback and timer and it works perfectly. i can't figure out what is going on between rightedge and this rightedge plugin.
Anyone would have a lead?

Note1. i have pasted below the proof of concept code to listen to this websocket
Note2. i have attached the source code of the embryonic plugin i intend to build. see method ConnectToCryptoCompareStream() in CryptoComparePlugin.cs

Thanks and regards
Bertrand

==============
using Newtonsoft.Json.Linq;
using Quobject.SocketIoClientDotNet.Client;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WebSocketSharp;
using System.Linq;

var socket = IO.Socket("https://streamer.cryptocompare.com/");

    socket.On(Socket.EVENT_CONNECT, () =>
    {
      // socket.emit('SubAdd', { subs: ['0~Poloniex~BTC~USD'] } );
      //socket.Emit("hi");

      var jarr = new JArray();
      jarr.Add("0~Bitstamp~BTC~USD");
      var jobj = new JObject();
      jobj.Add("subs", jarr);

      socket.Emit("SubAdd", jobj);

    });

    socket.On("m", (data) =>
    {
      string[] arr = ((string)data).Split('~');
      //Console.WriteLine(String.Join(",", arr));

      if (arr.Length > 0)
      {
       try
       {
        // '{SubscriptionId}~{ExchangeName}~{CurrencySymbol}~{CurrencySymbol}~{Flag}~{TradeId}~{TimeStamp}~{Quantity}~{Price}~{Total}'
        double price = Convert.ToDouble(arr[8]);
        string exchange = arr[1];
        string direction = arr[4] == "1" ? "Buy" : "Sell";
        string timestamp = arr[6];
        Console.WriteLine(String.Format("{0}: {1} - {2} - {3}", exchange, price, direction, timestamp));
       }
       catch { }

      }

    });

Attachments
CryptoComparePlugin.zip (54 views, 1.00 MB)


Similar Topics


Reading This Topic


2005-2018 © RightEdge Systems