public override void Connect() { _isPortfolioSubscribed = false; _loginFailed = false; _securitiesCreator = new FTXSecurityCreator(); _portfoliosCreator = new FTXPortfolioCreator(); _marketDepthCreator = new FTXMarketDepthCreator(); _tradesCreator = new FTXTradesCreator(); _orderCreator = new FTXOrderCreator(); _candlesCreator = new FTXCandlesCreator(); _client = new Client( ((ServerParameterString)ServerParameters[0]).Value, ((ServerParameterPassword)ServerParameters[1]).Value); _cancelTokenSource = new CancellationTokenSource(); _ftxRestApi = new FtxRestApi(_client); StartMessageReader(); _wsSource = new WsSource(WebSocketEndpointUrl); _wsSource.MessageEvent += WsSourceMessageEvent; _wsSource.Start(); }
public override void Dispose() { try { if (_wsSource != null) { if (_isPortfolioSubscribed) { var fillsRequest = FtxWebSockerRequestGenerator.GetUnsubscribeRequest("fills"); _wsSource.SendMessage(fillsRequest); var ordersRequest = FtxWebSockerRequestGenerator.GetUnsubscribeRequest("orders"); _wsSource.SendMessage(ordersRequest); _isPortfolioSubscribed = false; _loginFailed = false; } if (_subscribedSecurities.Any()) { foreach (var security in _subscribedSecurities) { var unsubscribeMarket = FtxWebSockerRequestGenerator.GetUnsubscribeRequest("market", security); _wsSource.SendMessage(unsubscribeMarket); var unsubscribeOrderbook = FtxWebSockerRequestGenerator.GetUnsubscribeRequest("orderbook", security); _wsSource.SendMessage(unsubscribeOrderbook); } _subscribedSecurities.Clear(); } _wsSource.Dispose(); _wsSource.MessageEvent -= WsSourceMessageEvent; _wsSource = null; _securitiesCreator = null; _portfoliosCreator = null; _marketDepthCreator = null; _tradesCreator = null; _orderCreator = null; _candlesCreator = null; _client = null; _ftxRestApi = null; _myOrders.Clear(); _securityMarketDepths.Clear(); } if (_cancelTokenSource != null && !_cancelTokenSource.IsCancellationRequested) { _cancelTokenSource.Cancel(); } } catch (Exception e) { SendLogMessage("FTX dispose error: " + e, LogMessageType.Error); } }