diff --git a/packages/network/tests/common/NetworkWebSocketTest.cpp b/packages/network/tests/common/NetworkWebSocketTest.cpp index b276384..707b78e 100644 --- a/packages/network/tests/common/NetworkWebSocketTest.cpp +++ b/packages/network/tests/common/NetworkWebSocketTest.cpp @@ -7,6 +7,7 @@ #include "jsonxx/jsonxx.h" #include +#include using namespace l; @@ -55,7 +56,7 @@ TEST(NetworkWebSocket, Setup) { return 0; } -TEST(NetworkWebSocket, Binance) { +TEST(NetworkWebSocket, BinanceKlines) { return 0; @@ -116,6 +117,86 @@ TEST(NetworkWebSocket, Binance) { } while (readCount-- >= 0); + std::this_thread::sleep_for(std::chrono::milliseconds(1000)); + + networkInterfaceWS->Disconnect("binance"); + + networkInterfaceWS->Shutdown(); + networkManager->ClearJobs(); + networkManager->Shutdown(); + + TEST_FALSE(failed, ""); + + return 0; +} + +TEST(NetworkWebSocket, BinanceUIKlines) { + + return 0; + + auto networkManager = l::network::CreateNetworkManager(1, false); + auto networkInterfaceWS = l::network::CreateNetworkInterfaceWS(networkManager); + + bool failed = false; + auto websocketHandler = [&]( + bool success, + std::string_view queryArguments, + l::network::WebSocket& ws) { + failed = !success; + LOG(LogInfo) << "Success: " << success; + + return success ? l::concurrency::RunnableResult::SUCCESS : l::concurrency::RunnableResult::FAILURE; + }; + + // wss://testnet.binance.vision/ws-api/v3 + networkInterfaceWS->CreateInterface("Binance", "wss", "testnet.binance.vision"); + //networkInterfaceWS->CreateInterface("Binance", "wss", "stream.binance.com", 443); + networkInterfaceWS->CreateWebSocket("Binance", "binance", "ws-api/v3", websocketHandler); + networkInterfaceWS->Connect("Binance", "binance"); + + char buffer[1024]; + int32_t write = 0; + int64_t time = l::string::get_unix_epoch() - 60 * 15; + time *= 1000; + + std::string requestKlines; + requestKlines += "{\n"; + requestKlines += "\"id\" : 3,\n"; + requestKlines += "\"method\": \"uiKlines\",\n"; + requestKlines += "\"params\" : {"; + + requestKlines += "\"symbol\" : \"BTCUSDT\","; + requestKlines += "\"interval\" : \"5m\","; + requestKlines += "\"startTime\" : " + std::to_string(time) + ", "; + requestKlines += "\"limit\" : \"500\""; + + requestKlines += "}\n"; + requestKlines += "}\n"; + + + int32_t read = 0; + int32_t readCount = 3; + do { + std::this_thread::sleep_for(std::chrono::milliseconds(1000)); + read = networkInterfaceWS->Read("Binance", "binance", &buffer[0], 1024); + if (read > 0) { + LOG(LogInfo) << std::string_view(buffer, read); + } + } while (readCount-- >= 0); + + networkInterfaceWS->Write("Binance", "binance", requestKlines.data(), requestKlines.size()); + + + readCount = 60; + do { + std::this_thread::sleep_for(std::chrono::milliseconds(1000)); + read = networkInterfaceWS->Read("Binance", "binance", &buffer[0], 1024); + if (read > 0) { + LOG(LogInfo) << std::string_view(buffer, read); + } + } while (readCount-- >= 0); + + std::this_thread::sleep_for(std::chrono::milliseconds(1000)); networkInterfaceWS->Disconnect("binance");