예제 #1
0
        //------------------------------------------------------------------------------------------------
        // construction
        //------------------------------------------------------------------------------------------------

        public DeribitJsonRpcService
        (
            IDeribitService deribit,
            IDeribitWebSocketService wsservice,
            DeribitConfig config
        )
        {
            // dependencies
            this.deribit       = deribit;
            this.deribitconfig = config;
            this.wsservice     = wsservice;
            // logger
            this.logger = Serilog.Log.ForContext <DeribitJsonRpcService>();
            // message formatter
            JsonMessageFormatter messageformatter = new JsonMessageFormatter()
            {
                Encoding        = Encoding.UTF8,
                ProtocolVersion = new Version(2, 0),
            };

            // web socket connection
            this.wsservice.ReconnectionHappened += this.Wsservice_ReconnectionHappened;
            // check connection loop
            {
                this.CheckConnectionLoopTimer = new System.Timers.Timer()
                {
                    Interval = TimeSpan.FromSeconds(this.CheckConnectionLoopPeriodSecs).TotalMilliseconds,
                    Enabled  = false,
                };
                this.CheckConnectionLoopTimer.Elapsed += (sender, e) =>
                {
                    lock (this.CheckConnectionLoopSyncLock)
                    {
                        this.CheckConnection(default).Wait();
예제 #2
0
        //------------------------------------------------------------------------------------------------
        // construction
        //------------------------------------------------------------------------------------------------

        public DeribitJsonRpcService
        (
            IDeribitService deribit,
            IDeribitWebSocketService wsservice,
            DeribitConfig config
        )
        {
            // dependencies
            this.deribit       = deribit;
            this.deribitconfig = config;
            this.wsservice     = wsservice;
            // logger
            this.logger = Serilog.Log.ForContext <DeribitJsonRpcService>();
            // message formatter
            JsonMessageFormatter messageformatter = new JsonMessageFormatter()
            {
                Encoding        = Encoding.UTF8,
                ProtocolVersion = new Version(2, 0),
            };
            // attach json rpc to websocket
            WebSocketMessageHandler wsmh = new WebSocketMessageHandler(wsservice.ClientWebSocket);

            this.JsonRpc = new StreamJsonRpc.JsonRpc(wsmh);
            // build proxy // https://github.com/microsoft/vs-streamjsonrpc/blob/master/doc/dynamicproxy.md
            this.RpcProxy = this.JsonRpc.Attach <IDeribitJsonRpcProxy>(new JsonRpcProxyOptions
            {
                ServerRequiresNamedArguments = true,
            });
            // tracing
            if (config.EnableJsonRpcTracing)
            {
                var listener = new global::SerilogTraceListener.SerilogTraceListener();
                this.JsonRpc.TraceSource.Listeners.Add(listener);
                this.JsonRpc.TraceSource.Switch.Level = System.Diagnostics.SourceLevels.Information;
                this.logger.Verbose("JsonRpc tracing enabled");
            }
        }