/// <summary> /// connect to API /// подсоединиться к апи /// </summary> public async void Connect() { if (_clientRest == null) { _clientRest = new KrakenClient( ((ServerParameterString)ServerParameters[0]).Value, ((ServerParameterPassword)ServerParameters[1]).Value); _clientRest.Connected += _client_Connected; _clientRest.UpdatePairs += _client_UpdatePairs; _clientRest.Disconnected += _client_Disconnected; _clientRest.NewPortfolioEvent += _client_NewPortfolioSpot; _clientRest.UpdateMarketDepth += _client_UpdateMarketDepth; _clientRest.NewTradesEvent += _client_NewTradesEvent; _clientRest.MyTradeEvent += _client_MyTradeEvent; _clientRest.MyOrderEvent += _client_MyOrderEvent; _clientRest.LogMessageEvent += SendLogMessage; } KrakenApi.LogMessageEvent += SendLogMessage; KrakenApi.TradeUpdateEvent += KrakenApi_TradeUpdateEvent; KrakenApi.MarketDepthUpdateEvent += KrakenApi_MarketDepthUpdateEvent; KrakenApi.MyTradeUpdateEvent += KrakenApi_MyTradeUpdateEvent; KrakenApi.OrdersUpdateEvent += KrakenApi_OrdersUpdateEvent; _clientRest.Connect(); _clientSocketPublicData = new KrakenApi(); _clientSocketPublicData.ConfigureAuthentication( "https://api.kraken.com", ((ServerParameterString)ServerParameters[0]).Value, ((ServerParameterPassword)ServerParameters[1]).Value); //_clientSocket.ConfigureWebsocket(("wss://ws-auth.kraken.com")); _clientSocketPublicData.ConfigureWebsocket(("wss://ws.kraken.com")); AuthToken token = await _clientSocketPublicData.AuthenticationClient.GetWebsocketToken(); var client = _clientSocketPublicData.BuildClient(); await Task.Run(() => KrakenApi.RunKraken(client, token)); _clientSocketPrivateData = new KrakenApi(); _clientSocketPrivateData.ConfigureAuthentication( "https://api.kraken.com", ((ServerParameterString)ServerParameters[0]).Value, ((ServerParameterPassword)ServerParameters[1]).Value); _clientSocketPrivateData.ConfigureWebsocket(("wss://ws-auth.kraken.com")); token = await _clientSocketPrivateData.AuthenticationClient.GetWebsocketToken(); client = _clientSocketPrivateData.BuildClient(); await Task.Run(() => KrakenApi.RunKraken(client, token)); }
/// <summary> /// release API /// освободить апи /// </summary> public void Dispose() { if (_clientRest != null) { _clientRest.Dispose(); _clientRest.Connected -= _client_Connected; _clientRest.UpdatePairs -= _client_UpdatePairs; _clientRest.Disconnected -= _client_Disconnected; _clientRest.NewPortfolioEvent -= _client_NewPortfolioSpot; _clientRest.UpdateMarketDepth -= _client_UpdateMarketDepth; _clientRest.NewTradesEvent -= _client_NewTradesEvent; _clientRest.MyTradeEvent -= _client_MyTradeEvent; _clientRest.MyOrderEvent -= _client_MyOrderEvent; _clientRest.LogMessageEvent -= SendLogMessage; } _clientRest = null; ServerStatus = ServerConnectStatus.Disconnect; }