コード例 #1
0
ファイル: Live.cs プロジェクト: mpvyard/ServiceNimbus
        public async Task SubscribeTicker()
        {
            if (!_subscriptions.ContainsKey(SUBJ_TICKER))
            {
                await _wampChannelOpenTask;
                var   subscriber = new TickSubscriber();
                subscriber.OnTickerUpdate += (s, e) =>
                {
                    _tickers[e.Symbol] = e;
                    OnTickerUpdate?.Invoke(this, e);
                };
                var obj = await _wampChannel.RealmProxy.Services.RegisterSubscriber(subscriber);

                _subscriptions[SUBJ_TICKER] = obj;
            }
        }
コード例 #2
0
        private void _webSocket_MessageReceived(object sender, MessageReceivedEventArgs e)
        {
            var message = JsonConvert.DeserializeObject <JArray>(e.Message);

            if (message.Count == 0 || message[0].Type != JTokenType.Integer)
            {
                return;
            }

            var msgCode = message[0].Value <int>();

            switch (msgCode)
            {
            case MessageHelper.Heartbeat:

                break;

            case MessageHelper.AccountNotifications:

                break;

            case MessageHelper.TickerData:
                if (message.Count > 2)
                {
                    for (int i = 2; i < message.Count; i++)
                    {
                        if (message[i].Type != JTokenType.Array && message[i].HasValues)
                        {
                            continue;
                        }

                        var tick = TickData.TickDataFromMessage(message[i].Values());

                        if (tick != null)
                        {
                            OnTickerUpdate?.Invoke(this, tick.ToQuote());
                        }
                    }
                }
                break;

            default:
                //MessageHelper.ExchangeVolume24Hours:

                break;
            }
        }
コード例 #3
0
        public void OnMessage(string currencyPair, decimal last, decimal lowestAsk, decimal highestBid, decimal percentChange,
                              decimal baseVolume, decimal quoteVolume, byte isFrozen, decimal dayHigh, decimal dayLow)
        {
            var quote = new Quote
            {
                Symbol        = CurrencyPair.Parse(currencyPair),
                Last          = last,
                Ask           = lowestAsk,
                Bid           = highestBid,
                PercentChange = percentChange,
                BaseVolume    = baseVolume,
                Volume        = quoteVolume,
                IsFrozenValue = isFrozen
            };

            OnTickerUpdate?.Invoke(this, quote);
        }
コード例 #4
0
        public async Task <CallResult <UpdateSubscription> > SubscribeAsync <TParams>(HitBtcSocketSubscribeBaseRequest <TParams> subscribeRequest)
        {
            var dataHandler = new Action <string>(data =>
            {
                var token  = JToken.Parse(data);
                var method = (string)token["method"];

                HitBtcSocketEvent responseType;

                if (!mappedResponses.TryGetValue(method, out responseType))
                {
                    log.Write(LogVerbosity.Warning, $"Unknown response method [{method}] update catched at data {data}");
                    return;
                }

                switch (responseType)
                {
                case HitBtcSocketEvent.OrderBookUpdated:
                    {
                        var result = Deserialize <HitBtcSocketOrderBookEvent>(token, false);
                        if (result.Success)
                        {
                            OnOrderBookUpdate?.Invoke(result.Data);
                        }
                        else
                        {
                            log.Write(LogVerbosity.Warning, "Couldn't deserialize data received from  stream: " + result.Error);
                        }
                        break;
                    }

                case HitBtcSocketEvent.OrderbookFullSnapshot:
                    {
                        var result = Deserialize <HitBtcSocketOrderBookEvent>(token, false);
                        if (result.Success)
                        {
                            OnOrderBookSnapshot?.Invoke(result.Data);
                        }
                        else
                        {
                            log.Write(LogVerbosity.Warning, "Couldn't deserialize data received from  stream: " + result.Error);
                        }
                        break;
                    }

                case HitBtcSocketEvent.TradesSnapshot:
                    {
                        var result = Deserialize <HitBtcSocketTradesEvent>(token, false);
                        if (result.Success)
                        {
                            OnTradesSnapshot?.Invoke(result.Data);
                        }
                        else
                        {
                            log.Write(LogVerbosity.Warning, "Couldn't deserialize data received from  stream: " + result.Error);
                        }
                        break;
                    }

                case HitBtcSocketEvent.TradesUpdated:
                    {
                        var result = Deserialize <HitBtcSocketTradesEvent>(token, false);
                        if (result.Success)
                        {
                            OnTradesUpdate?.Invoke(result.Data);
                        }
                        else
                        {
                            log.Write(LogVerbosity.Warning, "Couldn't deserialize data received from  stream: " + result.Error);
                        }
                        break;
                    }

                case HitBtcSocketEvent.TickerUpdated:
                    {
                        var result = Deserialize <HitBtcSocketTickerEvent>(token, false);
                        if (result.Success)
                        {
                            OnTickerUpdate?.Invoke(result.Data);
                        }
                        else
                        {
                            log.Write(LogVerbosity.Warning, "Couldn't deserialize data received from  stream: " + result.Error);
                        }
                        break;
                    }

                case HitBtcSocketEvent.CandlesSnapshot:
                    {
                        var result = Deserialize <HitBtcSocketCandlesEvent>(token, false);
                        if (result.Success)
                        {
                            OnCandlesSnapshot?.Invoke(result.Data);
                        }
                        else
                        {
                            log.Write(LogVerbosity.Warning, "Couldn't deserialize data received from  stream: " + result.Error);
                        }
                        break;
                    }

                case HitBtcSocketEvent.CandlesUpdated:
                    {
                        var result = Deserialize <HitBtcSocketCandlesEvent>(token, false);
                        if (result.Success)
                        {
                            OnCandlesUpdate?.Invoke(result.Data);
                        }
                        else
                        {
                            log.Write(LogVerbosity.Warning, "Couldn't deserialize data received from  stream: " + result.Error);
                        }
                        break;
                    }

                case HitBtcSocketEvent.ActiveOrdersSnapshot:
                    {
                        var result = Deserialize <HitBtcSocketActiveOrdersReportEvent>(token, false);
                        if (result.Success)
                        {
                            OnActiveOrdersSnapshot?.Invoke(result.Data);
                        }
                        else
                        {
                            log.Write(LogVerbosity.Warning, "Couldn't deserialize data received from  stream: " + result.Error);
                        }
                        break;
                    }

                case HitBtcSocketEvent.OrderUpdated:
                    {
                        var result = Deserialize <HitBtcSocketOrderReportEvent>(token, false);
                        if (result.Success)
                        {
                            OnOrderUpdate?.Invoke(result.Data);
                        }
                        else
                        {
                            log.Write(LogVerbosity.Warning, "Couldn't deserialize data received from  stream: " + result.Error);
                        }
                        break;
                    }

                case HitBtcSocketEvent.MarginOrdersSnapshot:
                    {
                        var result = Deserialize <HitBtcSocketMarginActiveOrdersReportEvent>(token, false);
                        if (result.Success)
                        {
                            OnMarginActiveOrdersSnapshot?.Invoke(result.Data);
                        }
                        else
                        {
                            log.Write(LogVerbosity.Warning, "Couldn't deserialize data received from  stream: " + result.Error);
                        }
                        break;
                    }

                case HitBtcSocketEvent.MarginOrderUpdated:
                    {
                        var result = Deserialize <HitBtcSocketMarginOrderReportEvent>(token, false);
                        if (result.Success)
                        {
                            OnMarginOrderUpdate?.Invoke(result.Data);
                        }
                        else
                        {
                            log.Write(LogVerbosity.Warning, "Couldn't deserialize data received from  stream: " + result.Error);
                        }
                        break;
                    }

                case HitBtcSocketEvent.MarginAccountsSnapshot:
                    {
                        var result = Deserialize <HitBtcSocketMarginAccountsEvent>(token, false);
                        if (result.Success)
                        {
                            OnMarginAccountsSnapshot?.Invoke(result.Data);
                        }
                        else
                        {
                            log.Write(LogVerbosity.Warning, "Couldn't deserialize data received from  stream: " + result.Error);
                        }
                        break;
                    }

                case HitBtcSocketEvent.MarginAccountUpdated:
                    {
                        var result = Deserialize <HitBtcSocketMarginAccountReportEvent>(token, false);
                        if (result.Success)
                        {
                            OnMarginAccountUpdate?.Invoke(result.Data);
                        }
                        else
                        {
                            log.Write(LogVerbosity.Warning, "Couldn't deserialize data received from  stream: " + result.Error);
                        }
                        break;
                    }

                case HitBtcSocketEvent.TransactionUpdated:
                    {
                        var result = Deserialize <HitBtcSocketAccountTransactionEvent>(token, false);
                        if (result.Success)
                        {
                            OnAccountTransactionUpdate?.Invoke(result.Data);
                        }
                        else
                        {
                            log.Write(LogVerbosity.Warning, "Couldn't deserialize data received from  stream: " + result.Error);
                        }
                        break;
                    }

                default:
                    log.Write(LogVerbosity.Warning, $"Catched unknown method update: {data}");
                    break;
                }
            });

            return(await Subscribe(BaseAddress + subscribeRequest.EndpointSuffix, subscribeRequest, null, subscribeRequest.EndpointSuffix != MarketDataUrlSuffix, dataHandler));
        }