Skip to content

Commit

Permalink
Add another local web socket test, but deactivated.
Browse files Browse the repository at this point in the history
  • Loading branch information
linuscu committed Nov 6, 2024
1 parent 6a5c9be commit 1b2abc1
Showing 1 changed file with 82 additions and 1 deletion.
83 changes: 82 additions & 1 deletion packages/network/tests/common/NetworkWebSocketTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "jsonxx/jsonxx.h"

#include <array>
#include <iostream>

using namespace l;

Expand Down Expand Up @@ -55,7 +56,7 @@ TEST(NetworkWebSocket, Setup) {
return 0;
}

TEST(NetworkWebSocket, Binance) {
TEST(NetworkWebSocket, BinanceKlines) {

return 0;

Expand Down Expand Up @@ -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");
Expand Down

0 comments on commit 1b2abc1

Please sign in to comment.