-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_api_structure.cpp
More file actions
152 lines (139 loc) · 4.27 KB
/
test_api_structure.cpp
File metadata and controls
152 lines (139 loc) · 4.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/*
Test program for the new binance-cpp API structure
Verifies both modern and legacy API interfaces work correctly
*/
#include <json/json.h>
#include <iostream>
#include "binance_api.h"
int main()
{
std::cout << "=== Testing New binance-cpp API Structure ===" << std::endl;
// Test 1: Modern API initialization
std::cout << "\n1. Testing Modern API initialization..." << std::endl;
try
{
binance_cpp::core::BinanceAPI::Init();
std::cout << "✅ Modern API initialization successful" << std::endl;
}
catch (const std::exception& e)
{
std::cout << "❌ Modern API initialization failed: " << e.what()
<< std::endl;
}
// Test 2: API Server Time
std::cout << "\n2. Testing API Server Time..." << std::endl;
try
{
Json::Value result;
binance_cpp::financial_trading::spot_trading::general_endpoints::
ServerTime::GetServerTime(result);
if (!result.empty())
{
std::cout << "✅ API server time: " << result["serverTime"].asUInt64()
<< std::endl;
}
else
{
std::cout << "⚠️ API server time returned empty result" << std::endl;
}
}
catch (const std::exception& e)
{
std::cout << "❌ API server time failed: " << e.what() << std::endl;
}
// Test 3: Test Connectivity
std::cout << "\n3. Testing API - Test Connectivity..." << std::endl;
try
{
Json::Value result;
binance_cpp::financial_trading::spot_trading::general_endpoints::
TestConnectivity::Ping(result);
std::cout << "✅ Modern API connectivity test successful" << std::endl;
}
catch (const std::exception& e)
{
std::cout << "❌ Modern API connectivity test failed: " << e.what()
<< std::endl;
}
// Test 6: Modern API - Get Exchange Info
std::cout << "\n6. Testing Modern API - Exchange Information..." << std::endl;
try
{
Json::Value result;
binance_cpp::financial_trading::spot_trading::general_endpoints::
ExchangeInformation::GetExchangeInfo(result);
if (!result.empty())
{
std::cout << "✅ Modern API exchange info received (symbols count: "
<< result["symbols"].size() << ")" << std::endl;
}
else
{
std::cout << "⚠️ Modern API exchange info returned empty result"
<< std::endl;
}
}
catch (const std::exception& e)
{
std::cout << "❌ Modern API exchange info failed: " << e.what()
<< std::endl;
}
// Test 7: Modern API - Get Price (BTC)
std::cout << "\n7. Testing Modern API - Get BTC Price..." << std::endl;
try
{
double price = binance_cpp::financial_trading::spot_trading::
market_data_endpoints::CurrentPrices::GetPrice("BTCUSDT");
if (price > 0)
{
std::cout << "✅ Modern API BTC price: $" << price << std::endl;
}
else
{
std::cout << "⚠️ Modern API BTC price returned 0" << std::endl;
}
}
catch (const std::exception& e)
{
std::cout << "❌ Modern API BTC price failed: " << e.what() << std::endl;
}
// Test 4: Get Price (BTC)
std::cout << "\n4. Testing API - Get BTC Price..." << std::endl;
try
{
double price = binance_cpp::financial_trading::spot_trading::
market_data_endpoints::CurrentPrices::GetPrice("BTCUSDT");
if (price > 0)
{
std::cout << "✅ API BTC price: $" << price << std::endl;
}
else
{
std::cout << "⚠️ API BTC price returned 0" << std::endl;
}
}
catch (const std::exception& e)
{
std::cout << "❌ Legacy API BTC price failed: " << e.what() << std::endl;
}
// Cleanup
std::cout << "\n9. Cleanup..." << std::endl;
try
{
binance_cpp::core::BinanceAPI::Cleanup();
std::cout << "✅ Cleanup successful" << std::endl;
}
catch (const std::exception& e)
{
std::cout << "❌ Cleanup failed: " << e.what() << std::endl;
}
std::cout << "\n=== Test Complete ===" << std::endl;
std::cout << "\n📋 Summary:" << std::endl;
std::cout << "• New categorized API structure implemented" << std::endl;
std::cout << "• Legacy API compatibility maintained" << std::endl;
std::cout << "• Google C++ Style Guide naming conventions applied"
<< std::endl;
std::cout << "• Binance API documentation category structure followed"
<< std::endl;
return 0;
}