Profile Picture

Market Data Service using Websocket

Posted By lampalork Last Year
Posted Tuesday January 23 2018
Hi All,
I'm trying to build a market data plugin that would consume realtime data from a webservice ( 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

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("");

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

      var jarr = new JArray();
      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)
        // '{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 (88 views, 1.00 MB)
Posted Monday December 17 2018
You are welcome to share even more interesting guides about trading. What about my contribution, I can do the same but with guide about live real money casino if you are interested of course. 

Similar Topics

Reading This Topic

2005-2019 © RightEdge Systems