/// <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)); }
static async Task Main(string[] args) { var configuration = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json", true, true) .AddEnvironmentVariables() .Build(); var logger = new LoggerConfiguration() .MinimumLevel.Verbose() .WriteTo.RollingFile("logs/kraken-websockets.log") .WriteTo.Console(restrictedToMinimumLevel: Serilog.Events.LogEventLevel.Information) .CreateLogger(); _ = new LoggerFactory() .AddKrakenWebSockets() .AddSerilog(logger); var krakenApi = new KrakenApi() .ConfigureAuthentication( configuration.GetValue <string>("API_URL"), configuration.GetValue <string>("API_KEY"), configuration.GetValue <string>("API_SECRET")) .ConfigureWebsocket(configuration.GetValue <string>("WS_ENDPOINT")); token = await krakenApi.AuthenticationClient.GetWebsocketToken(); using (var client = krakenApi.BuildClient()) { await Task.Run(() => RunKraken(client, token)); do { Console.WriteLine("Press [ESC] to exit."); }while (Console.ReadKey().Key != ConsoleKey.Escape); } }