public async Task PingPong()
        {
            var url = BitmexValues.ApiWebsocketUrl;

            using (var communicator = new BitmexWebsocketCommunicator(url))
            {
                PongResponse received      = null;
                var          receivedEvent = new ManualResetEvent(false);

                using (var client = new BitmexWebsocketClient(communicator))
                {
                    client.Streams.PongStream.Subscribe(pong =>
                    {
                        received = pong;
                        receivedEvent.Set();
                    });

                    await communicator.Start();

                    await client.Send(new PingRequest());

                    receivedEvent.WaitOne(TimeSpan.FromSeconds(30));

                    Assert.NotNull(received);
                }
            }
        }
示例#2
0
        public async Task PingPong()
        {
            var url = BitfinexValues.ApiWebsocketUrl;

            using (var communicator = new BitfinexWebsocketCommunicator(url))
            {
                PongResponse received      = null;
                var          receivedEvent = new ManualResetEvent(false);

                using (var client = new BitfinexWebsocketClient(communicator))
                {
                    client.Streams.PongStream.Subscribe(pong =>
                    {
                        received = pong;
                        receivedEvent.Set();
                    });

                    await communicator.Start();

                    client.Send(new PingRequest()
                    {
                        Cid = 123456
                    });

                    receivedEvent.WaitOne(TimeSpan.FromSeconds(30));

                    Assert.NotNull(received);
                    Assert.Equal(123456, received.Cid);
                    Assert.True(DateTime.UtcNow.Subtract(received.Ts).TotalSeconds < 15);
                }
            }
        }
示例#3
0
        private bool HandleRawMessage(string msg)
        {
            // ********************
            // ADD RAW HANDLERS BELOW
            // ********************

            return
                (PongResponse.TryHandle(msg, Streams.PongSubject));
        }
        /// <summary>
        /// Handles raw messages sent by bitmex.
        /// </summary>
        /// <param name="msg">The MSG.</param>
        /// <param name="streams">The streams.</param>
        /// <returns></returns>
        public static bool HandleRawMessage(string msg, BitmexClientStreams streams)
        {
            // ********************
            // ADD RAW HANDLERS BELOW
            // ********************

            return
                (PongResponse.TryHandle(msg, streams.PongSubject));
        }
        private bool HandleObjectMessage(string msg)
        {
            var gmessage = GenesysMessage.Parse(msg);

            return
                (PongResponse.TryHandle(gmessage, Streams.PongSubject) ||
                 HeartbeatResponse.TryHandle(gmessage, Streams.HeartbeatsSubject) ||
                 SocketClosingResponse.TryHandle(gmessage, Streams.SocketClosingSubject) ||
                 SubscriptionResponse.TryHandle(gmessage, Streams.SubscriptionsSubject, _subscriptions));
        }
示例#6
0
        public StatusType Wakeup(ref SIFHeaderType SIFHeader, WakeupType Wakeup1)
        {
            WakeupRequest inValue = new WakeupRequest();

            inValue.SIFHeader = SIFHeader;
            inValue.Wakeup    = Wakeup1;
            PongResponse retVal = ((IptFlowControl)(this)).Wakeup(inValue);

            SIFHeader = retVal.SIFHeader;
            return(retVal.Status);
        }
示例#7
0
        public StatusType Sleep(ref SIFHeaderType SIFHeader, SleepType Sleep1)
        {
            SleepRequest inValue = new SleepRequest();

            inValue.SIFHeader = SIFHeader;
            inValue.Sleep     = Sleep1;
            PongResponse retVal = ((IptFlowControl)(this)).Sleep(inValue);

            SIFHeader = retVal.SIFHeader;
            return(retVal.Status);
        }
示例#8
0
        public StatusType Ping(ref SIFHeaderType SIFHeader, PingType Ping1)
        {
            PingRequest inValue = new PingRequest();

            inValue.SIFHeader = SIFHeader;
            inValue.Ping      = Ping1;
            PongResponse retVal = ((IptFlowControl)(this)).Ping(inValue);

            SIFHeader = retVal.SIFHeader;
            return(retVal.Status);
        }
示例#9
0
 private void OnPong(PongResponse pong)
 {
     if (_sentPingPackets.TryDequeue(out var ping))
     {
         //if data is not empty then it was 'probe' packet so we should check if server responded with same data
         if (!string.IsNullOrEmpty(ping.Data))
         {
             if (ping.Data != pong.Data)
             {
                 Logger.LogWarning($"Invalid PONG packet received on probe packet. PING: {ping.Data} PONG: {pong.Data}");
                 Events.ProbeErrorSubject.OnNext(new ProbeErrorEvent(ping.Data, pong.Data));
             }
         }
     }
     else
     {
         Logger.LogWarning($"No corresponding PING packet found for PONG: {pong}");
     }
 }
 private bool HandleObjectMessage(string msg)
 {
     // ********************
     // ADD OBJECT HANDLERS BELOW
     // ********************
     //var response = FtxJsonSerializer.Deserialize<JObject>(msg);
     return
         (SubscribedResponse.TryHandle(msg, Streams.SubscribedSubject) ||
          ErrorResponse.TryHandle(msg, Streams.ErrorSubject) ||
          PongResponse.TryHandle(msg, Streams.PongSubject) ||
          TickerResponse.TryHandle(msg, Streams.TickerSubject) ||
          OrderBookUpdateResponse.TryHandle(msg, Streams.OrderBookUpdateSubject, "update") ||
          OrderBookSnapshotResponse.TryHandle(msg, Streams.OrderBookSnapshotSubject, "partial") ||
          // MarketsUpdateResponse.TryHandle(msg, Streams.MarketsUpdateSubject, "update") ||
          // MarketsSnapshotResponse.TryHandle(msg, Streams.MarketsSnapshotSubject, "partial") ||
          MarketsResponse.TryHandle(msg, Streams.MarketsSubject) ||
          TradeResponse.TryHandle(msg, Streams.TradesSubject) ||
          OrdersResponse.TryHandle(msg, Streams.OrdersSubject) ||
          FillsResponse.TryHandle(msg, Streams.FillsSubject));
 }
        public async Task PingPong()
        {
            Log.Logger = new LoggerConfiguration()
                         .MinimumLevel.Verbose()
                         .WriteTo.File(logPath, rollingInterval: RollingInterval.Day)
                         .WriteTo.ColoredConsole(LogEventLevel.Verbose)
                         .CreateLogger();

            var url = BitfinexValues.ApiWebsocketUrl;

            using (var communicator = new BitfinexWebsocketCommunicator(url))
            {
                PongResponse received      = null;
                var          receivedEvent = new ManualResetEvent(false);

                using (var client = new BitfinexWebsocketClient(communicator))
                {
                    client.Streams.PongStream.Subscribe(pong =>
                    {
                        received = pong;
                        receivedEvent.Set();
                    });

                    await communicator.Start();

                    await client.Send(new PingRequest()
                    {
                        Cid = 123456
                    });

                    receivedEvent.WaitOne(TimeSpan.FromSeconds(30));

                    Assert.NotNull(received);
                    Assert.Equal(123456, received.Cid);
                    Assert.True(DateTime.UtcNow.Subtract(received.Ts).TotalSeconds < 15);
                }
            }
        }
        public void OnObjectMessage(string msg)
        {
            var parsed = BitfinexSerialization.Deserialize <MessageBase>(msg);

            switch (parsed.Event)
            {
            case MessageType.Pong:
                PongResponse.Handle(msg, _streams.PongSubject);
                break;

            case MessageType.Error:
                ErrorResponse.Handle(msg, _streams.ErrorSubject);
                break;

            case MessageType.Info:
                InfoResponse.Handle(msg, _streams.InfoSubject);
                break;

            case MessageType.Auth:
                AuthenticationResponse.Handle(msg, _streams.AuthenticationSubject);
                break;

            case MessageType.Conf:
                ConfigurationResponse.Handle(msg, _streams.ConfigurationSubject);
                break;

            case MessageType.Subscribed:
                OnSubscription(BitfinexSerialization.Deserialize <SubscribedResponse>(msg));
                break;

            case MessageType.Unsubscribed:
                UnsubscribedResponse.Handle(msg, _streams.UnsubscriptionSubject);
                break;
                //default:
                //    Log.Warning($"Missing handler for public stream, data: '{msg}'");
                //    break;
            }
        }
        private void HandlePong(PongResponse pong)
        {
            var current = DateTime.UtcNow;

            ComputePing(current, _pingRequest);
        }
示例#14
0
        protected override void GetText()
        {
            try
            {
                PongResponse pingResponse = _pdfBoxServiceClient.Ping(new PingRequest {
                    Message = GROUPNAME
                });

                //SaleFinderDb.DeleteLeaflets(GROUPNAME);

                foreach (var leaflet in _leaflets)
                {
                    string       fullFileName = Path.Combine(_tempFolder, leaflet.DownloadedFileName);
                    LeafletModel leafletModel = new LeafletModel
                    {
                        FileName  = leaflet.DownloadedFileName,
                        GroupName = GROUPNAME,
                        Hash      = leaflet.MD5,
                        Status    = LeafletModelStatus.Processed,
                        Pages     = new List <LeafletPageModel>()
                    };
                    bool saleDateFound = false;
                    var  response      = _pdfBoxServiceClient.PdfPagesCount(new Messages.PDFInfoMessage {
                        FileName = fullFileName
                    });
                    for (int i = 0; i < response.PagesCount; i++)
                    {
                        byte[] fileContent = File.ReadAllBytes(leaflet.DownloadedFileName);

                        var exportMessage = _pdfBoxServiceClient.ImportExport(new PDFExportRequest
                        {
                            PDFInputMessage = new PDFInputMessage
                            {
                                FileName = fullFileName,
                                Pagenr   = i
                            }
                        });

                        LeafletPageModel leafletPageModel = new LeafletPageModel
                        {
                            PageNumber = i + 1,
                            Text       = exportMessage.PDFOutputMessage.Text
                        };

                        if (!saleDateFound)
                        {
                            Regex rgx = new Regex(@"\d{2}.\d{2}.\d{4}");
                            Match mat = rgx.Match(leafletPageModel.Text);
                            if (mat.Success)
                            {
                            }
                        }
                        //string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(leaflet.DownloadedFileName);
                        //string textFileName = $"{fileNameWithoutExtension}_{i}.txt";

                        //File.WriteAllText(textFileName, exportMessage.PDFOutputMessage.Text);
                        leafletModel.Pages.Add(leafletPageModel);
                    }
                    SaleFinderDb.AddLeaflet(leafletModel);
                }
            }
            catch (RpcException e)
            {
            }
        }
示例#15
0
 protected virtual void OnPongResponse(PongResponse response)
 {
     PongResponseReceived?.Invoke(this, new ResponseEventArgs <PongResponse>(response));
 }
 internal void Raise(PongResponse response)
 {
     _pongSubject.OnNext(response);
 }
示例#17
0
        private void HandlePongB(PongResponse pong)
        {
            var current = DateTime.UtcNow;

            ComputePing(current, _pingRequestB, MTAccount.B);
        }
示例#18
0
        private void MessageReceived(object sender, BitmexSocketMessageEventArgs e)
        {
            if (PongResponse.TryParse(e.Message, OnPongResponse))
            {
                return;
            }

            var jsonElement = JsonDocument.Parse(e.Message).RootElement;

            if (jsonElement.TryGetProperty("table", out _))
            {
                if (TableResponse <AffiliateDto> .TryHandle(jsonElement, OnAffiliateResponse, SubscriptionType.affiliate))
                {
                    return;
                }
                if (TableResponse <AnnouncementDto> .TryHandle(jsonElement, OnAnnouncementResponse, SubscriptionType.announcement))
                {
                    return;
                }
                if (TableResponse <ChatDto> .TryHandle(jsonElement, OnChatResponse, SubscriptionType.chat))
                {
                    return;
                }
                if (TableResponse <ChatConnectedDto> .TryHandle(jsonElement, OnChatConnectedResponse, SubscriptionType.connected))
                {
                    return;
                }
                if (TableResponse <ExecutionDto> .TryHandle(jsonElement, OnExecutionResponse, SubscriptionType.execution))
                {
                    return;
                }
                if (TableResponse <FundingDto> .TryHandle(jsonElement, OnFundingResponse, SubscriptionType.funding))
                {
                    return;
                }
                if (TableResponse <InstrumentDto> .TryHandle(jsonElement, OnInstrumentResponse, SubscriptionType.instrument))
                {
                    return;
                }
                if (TableResponse <InsuranceDto> .TryHandle(jsonElement, OnInsuranceResponse, SubscriptionType.insurance))
                {
                    return;
                }
                if (TableResponse <LiquidationDto> .TryHandle(jsonElement, OnLiquidationResponse, SubscriptionType.liquidation))
                {
                    return;
                }
                if (TableResponse <MarginDto> .TryHandle(jsonElement, OnMarginResponse, SubscriptionType.margin))
                {
                    return;
                }
                if (TableResponse <OrderDto> .TryHandle(jsonElement, OnOrderResponse, SubscriptionType.order))
                {
                    return;
                }
                if (TableResponse <OrderBook10Dto> .TryHandle(jsonElement, OnOrderBook10Response, SubscriptionType.orderBook10))
                {
                    return;
                }
                if (TableResponse <OrderBookDto> .TryHandle(jsonElement, OnOrderBookL2Response, SubscriptionType.orderBookL2))
                {
                    return;
                }
                if (TableResponse <OrderBookDto> .TryHandle(jsonElement, OnOrderBookL225Response, SubscriptionType.orderBookL2_25))
                {
                    return;
                }
                if (TableResponse <PositionDto> .TryHandle(jsonElement, OnPositionResponse, SubscriptionType.position))
                {
                    return;
                }
                if (TableResponse <NotificationDto> .TryHandle(jsonElement, OnPrivateNotificationResponse, SubscriptionType.privateNotifications))
                {
                    return;
                }
                if (TableResponse <NotificationDto> .TryHandle(jsonElement, OnPublicNotificationResponse, SubscriptionType.publicNotifications))
                {
                    return;
                }
                if (TableResponse <QuoteDto> .TryHandle(jsonElement, OnQuoteResponse, SubscriptionType.quote))
                {
                    return;
                }
                if (TableResponse <QuoteDto> .TryHandle(jsonElement, OnQuote1DResponse, SubscriptionType.quoteBin1d))
                {
                    return;
                }
                if (TableResponse <QuoteDto> .TryHandle(jsonElement, OnQuote1HResponse, SubscriptionType.quoteBin1h))
                {
                    return;
                }
                if (TableResponse <QuoteDto> .TryHandle(jsonElement, OnQuote1MResponse, SubscriptionType.quoteBin1m))
                {
                    return;
                }
                if (TableResponse <QuoteDto> .TryHandle(jsonElement, OnQuote5MResponse, SubscriptionType.quoteBin5m))
                {
                    return;
                }
                if (TableResponse <SettlementDto> .TryHandle(jsonElement, OnSettlementResponse, SubscriptionType.settlement))
                {
                    return;
                }
                if (TableResponse <TradeDto> .TryHandle(jsonElement, OnTradeResponse, SubscriptionType.trade))
                {
                    return;
                }
                if (TableResponse <TradeDto> .TryHandle(jsonElement, OnTradeResponse, SubscriptionType.trade))
                {
                    return;
                }
                if (TableResponse <TradeBucketedDto> .TryHandle(jsonElement, OnTradeBucketed1DResponse, SubscriptionType.tradeBin1d))
                {
                    return;
                }
                if (TableResponse <TradeBucketedDto> .TryHandle(jsonElement, OnTradeBucketed1HResponse, SubscriptionType.tradeBin1h))
                {
                    return;
                }
                if (TableResponse <TradeBucketedDto> .TryHandle(jsonElement, OnTradeBucketed1MResponse, SubscriptionType.tradeBin1m))
                {
                    return;
                }
                if (TableResponse <TradeBucketedDto> .TryHandle(jsonElement, OnTradeBucketed5MResponse, SubscriptionType.tradeBin5m))
                {
                    return;
                }
                if (TableResponse <TransactionDto> .TryHandle(jsonElement, OnTransactionResponse, SubscriptionType.transact))
                {
                    return;
                }
                if (TableResponse <WalletDto> .TryHandle(jsonElement, OnWalletResponse, SubscriptionType.wallet))
                {
                    return;
                }
            }
            if (AuthenticationResponse.TryParse(jsonElement, OnAuthenticationResponse))
            {
                return;
            }
            if (CancelAllAfterResponse.TryHandle(jsonElement, OnCancelAllAfterResponse))
            {
                return;
            }
            //if (ErrorResponse.TryParse(jsonElement, OnErrorResponse)) return;
            if (SubscribeResponse.TryParse(jsonElement, OnSubscribeResponse))
            {
                return;
            }
            if (UnsubscribeResponse.TryParse(jsonElement, OnUnsubscribeResponse))
            {
                return;
            }
            if (WelcomeInfoResponse.TryParse(jsonElement, OnWelcomeInfoResponse))
            {
                return;
            }

            _logger.LogWarning($"Unknown type message.{e.Message}");
        }
示例#19
0
#pragma warning disable S1172 // Unused method parameters should be removed
        private Task <bool> HandleResponse(PongResponse pong)
#pragma warning restore S1172 // Unused method parameters should be removed
        {
            return(Task.FromResult(false));
        }
示例#20
0
 private void HandlePong(PongResponse pong)
 {
     ComputePing(_pingRequest);
 }
示例#21
0
 public IActionResult Get()
 {
     return(new OkObjectResult(PongResponse.Response()));
 }