Exemplo n.º 1
0
        public IEnumerable <string> Validate()
        {
            if (Host.IsEmpty())
            {
                yield return("Host not configured.");
            }
            if (Port <= 0)
            {
                yield return($"Port {Port} is invalid.");
            }
            if (ClientId.IsEmpty())
            {
                yield return("Host not configured.");
            }

            if (ClientStatusTopic.IsEmpty())
            {
                yield return("ClientStatusTopic is invalid.");
            }
        }
Exemplo n.º 2
0
        /// <inheritdoc />
        protected override bool OnSendInMessage(Message message)
        {
            switch (message.Type)
            {
            case MessageTypes.Reset:
            {
                _lastMyTradeId        = 0;
                _lastTimeBalanceCheck = null;

                if (_httpClient != null)
                {
                    try
                    {
                        _httpClient.Dispose();
                    }
                    catch (Exception ex)
                    {
                        SendOutError(ex);
                    }

                    _httpClient = null;
                }

                if (_pusherClient != null)
                {
                    try
                    {
                        UnsubscribePusherClient();
                        _pusherClient.Disconnect();
                    }
                    catch (Exception ex)
                    {
                        SendOutError(ex);
                    }

                    _pusherClient = null;
                }

                SendOutMessage(new ResetMessage());

                break;
            }

            case MessageTypes.Connect:
            {
                if (this.IsTransactional())
                {
                    if (!AuthV2 && ClientId.IsEmpty())
                    {
                        throw new InvalidOperationException(LocalizedStrings.Str3835);
                    }

                    if (Key.IsEmpty())
                    {
                        throw new InvalidOperationException(LocalizedStrings.Str3689);
                    }

                    if (Secret.IsEmpty())
                    {
                        throw new InvalidOperationException(LocalizedStrings.Str3690);
                    }
                }

#if !IGNORE_LICENSE
                var msg = "Crypto".ValidateLicense(component: GetType());
                if (!msg.IsEmpty())
                {
                    msg = nameof(BitStamp).ValidateLicense(component: GetType());

                    if (!msg.IsEmpty())
                    {
                        throw new InvalidOperationException(msg);
                    }
                }
#endif

                if (_httpClient != null)
                {
                    throw new InvalidOperationException(LocalizedStrings.Str1619);
                }

                if (_pusherClient != null)
                {
                    throw new InvalidOperationException(LocalizedStrings.Str1619);
                }

                _httpClient = new HttpClient(ClientId, Key, Secret, AuthV2)
                {
                    Parent = this
                };

                _pusherClient = new PusherClient {
                    Parent = this
                };
                SubscribePusherClient();
                _pusherClient.Connect();

                break;
            }

            case MessageTypes.Disconnect:
            {
                if (_httpClient == null)
                {
                    throw new InvalidOperationException(LocalizedStrings.Str1856);
                }

                if (_pusherClient == null)
                {
                    throw new InvalidOperationException(LocalizedStrings.Str1856);
                }

                _httpClient.Dispose();
                _httpClient = null;

                _pusherClient.Disconnect();

                break;
            }

            case MessageTypes.PortfolioLookup:
            {
                ProcessPortfolioLookup((PortfolioLookupMessage)message);
                break;
            }

            case MessageTypes.OrderStatus:
            {
                ProcessOrderStatus((OrderStatusMessage)message);
                break;
            }

            case MessageTypes.OrderRegister:
            {
                ProcessOrderRegister((OrderRegisterMessage)message);
                break;
            }

            case MessageTypes.OrderCancel:
            {
                ProcessOrderCancel((OrderCancelMessage)message);
                break;
            }

            case MessageTypes.OrderGroupCancel:
            {
                ProcessOrderGroupCancel((OrderGroupCancelMessage)message);
                break;
            }

            case MessageTypes.Time:
            {
                if (_orderInfo.Count > 0)
                {
                    ProcessOrderStatus(null);
                    ProcessPortfolioLookup(null);
                }

                if (BalanceCheckInterval > TimeSpan.Zero &&
                    (_lastTimeBalanceCheck == null || (CurrentTime - _lastTimeBalanceCheck) > BalanceCheckInterval))
                {
                    ProcessPortfolioLookup(null);
                }

                _pusherClient?.ProcessPing();

                //ProcessLevel1();
                break;
            }

            case MessageTypes.SecurityLookup:
            {
                ProcessSecurityLookup((SecurityLookupMessage)message);
                break;
            }

            case MessageTypes.MarketData:
            {
                ProcessMarketData((MarketDataMessage)message);
                break;
            }

            default:
                return(false);
            }

            return(true);
        }