Skip to content

Commit 726320d

Browse files
committed
ops rest testnet
1 parent c46f959 commit 726320d

File tree

2 files changed

+68
-42
lines changed

2 files changed

+68
-42
lines changed

include/Exchange_Client.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -876,15 +876,11 @@ class OpsClient : public Client<OpsClient>
876876
Json::Value v_exchange_info();
877877
Json::Value v_get_ticker(const Params* params_ptr = nullptr);
878878

879-
Json::Value get_spot_index_price(const Params* params_ptr);
880-
Json::Value get_mark_price(const Params* params_ptr = nullptr);
881879
Json::Value v_order_book(const Params* params_ptr);
882880
Json::Value v_klines(const Params* params_ptr);
883881
Json::Value v_public_trades_recent(const Params* params_ptr);
884882
Json::Value v_public_trades_historical(const Params* params_ptr);
885883

886-
887-
888884
// ------------------- crtp global end
889885

890886
// Trading endpoints
@@ -943,6 +939,10 @@ class OpsClient : public Client<OpsClient>
943939

944940
public:
945941
friend Client;
942+
943+
Json::Value get_spot_index_price(const Params* params_ptr);
944+
Json::Value get_mark_price(const Params* params_ptr = nullptr);
945+
946946
bool _testnet_mode;
947947

948948
void set_testnet_mode(const bool status);

src/Binance_Client.cpp

Lines changed: 64 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -7348,7 +7348,7 @@ Json::Value FuturesClientCoin::v_funding_rate_history(const Params* params_ptr)
73487348
A constructor - called directly by the user
73497349
Public client
73507350
*/
7351-
OpsClient::OpsClient() : Client(*this)
7351+
OpsClient::OpsClient() : Client(*this), _testnet_mode{ 0 }
73527352
{};
73537353

73547354
/**
@@ -7358,7 +7358,7 @@ OpsClient::OpsClient() : Client(*this)
73587358
@param secret - API secret
73597359
*/
73607360
OpsClient::OpsClient(const std::string key, const std::string secret)
7361-
: Client(*this, key, secret)
7361+
: Client(*this, key, secret), _testnet_mode{ 0 }
73627362
{}
73637363

73647364
/**
@@ -7390,8 +7390,8 @@ void OpsClient::v_init_ws_session()
73907390
*/
73917391
void OpsClient::set_testnet_mode(const bool status)
73927392
{
7393-
if (status) this->_ws_client->set_host_port(_WS_BASE_FUTURES_USDT_TESTNET, _WS_PORT_FUTURES);
7394-
else this->_ws_client->set_host_port(_WS_BASE_FUTURES_USDT, _WS_PORT_FUTURES);
7393+
if (status) this->_ws_client->set_host_port(_WS_BASE_OPS_TESTNET, _WS_PORT_OPS);
7394+
else this->_ws_client->set_host_port(_WS_BASE_OPS, _WS_PORT_OPS);
73957395
this->_testnet_mode = status;
73967396
}
73977397

@@ -7410,7 +7410,8 @@ bool OpsClient::get_testnet_mode()
74107410
*/
74117411
std::string OpsClient::v_get_listen_key()
74127412
{
7413-
std::string full_path = _BASE_REST_OPS + "/vapi/v1/userDataStream";
7413+
std::string full_path = !this->_testnet_mode ? _BASE_REST_OPS : _BASE_REST_OPS_TESTNET;
7414+
full_path += _BASE_REST_OPS + "/vapi/v1/userDataStream";
74147415
Json::Value response = (this->_rest_client)->_postreq(full_path);
74157416

74167417
return response["response"]["listenKey"].asString();
@@ -7423,7 +7424,8 @@ std::string OpsClient::v_get_listen_key()
74237424
*/
74247425
Json::Value OpsClient::v_ping_listen_key(const std::string& listen_key)
74257426
{
7426-
std::string full_path = _BASE_REST_OPS + "/vapi/v1/userDataStream" + "?listenKey=" + listen_key;
7427+
std::string full_path = !this->_testnet_mode ? _BASE_REST_OPS : _BASE_REST_OPS_TESTNET;
7428+
full_path += ("/vapi/v1/userDataStream?listenKey=" + listen_key);
74277429
Json::Value response = listen_key.empty() ? (this->_rest_client)->_putreq(full_path) : (this->_rest_client)->_postreq(full_path);
74287430

74297431
return response;
@@ -7436,7 +7438,8 @@ Json::Value OpsClient::v_ping_listen_key(const std::string& listen_key)
74367438
*/
74377439
Json::Value OpsClient::v_revoke_listen_key(const std::string& listen_key)
74387440
{
7439-
std::string full_path = _BASE_REST_OPS + "/vapi/v1/userDataStream" + "?listenKey=" + listen_key;
7441+
std::string full_path = !this->_testnet_mode ? _BASE_REST_OPS : _BASE_REST_OPS_TESTNET;
7442+
full_path += ("/vapi/v1/userDataStream?listenKey=" + listen_key);
74407443
Json::Value response = (this->_rest_client)->_postreq(full_path);
74417444

74427445
return response;
@@ -7451,7 +7454,8 @@ Json::Value OpsClient::v_revoke_listen_key(const std::string& listen_key)
74517454
*/
74527455
bool OpsClient::v_ping_client()
74537456
{
7454-
std::string full_path = _BASE_REST_OPS + "/vapi/v1/ping";
7457+
std::string full_path = !this->_testnet_mode ? _BASE_REST_OPS : _BASE_REST_OPS_TESTNET;
7458+
full_path += "/vapi/v1/ping";
74557459
Json::Value ping_response = (this->_rest_client)->_getreq(full_path)["response"];
74567460
return (ping_response != Json::nullValue);
74577461
}
@@ -7461,7 +7465,8 @@ bool OpsClient::v_ping_client()
74617465
*/
74627466
unsigned long long OpsClient::v_exchange_time()
74637467
{
7464-
std::string full_path = _BASE_REST_OPS + "/vapi/v1/time";
7468+
std::string full_path = !this->_testnet_mode ? _BASE_REST_OPS : _BASE_REST_OPS_TESTNET;
7469+
full_path += "/vapi/v1/time";
74657470
std::string ex_time = (this->_rest_client)->_getreq(full_path)["response"]["serverTime"].asString();
74667471

74677472
return std::atoll(ex_time.c_str());
@@ -7472,7 +7477,8 @@ unsigned long long OpsClient::v_exchange_time()
74727477
*/
74737478
Json::Value OpsClient::v_exchange_info()
74747479
{
7475-
std::string full_path = _BASE_REST_OPS + "/vapi/v1/exchangeInfo";
7480+
std::string full_path = !this->_testnet_mode ? _BASE_REST_OPS : _BASE_REST_OPS_TESTNET;
7481+
full_path += "/vapi/v1/exchangeInfo";
74767482
Json::Value response = (this->_rest_client)->_getreq(full_path);
74777483
return response;
74787484
}
@@ -7483,7 +7489,8 @@ Json::Value OpsClient::v_exchange_info()
74837489
Json::Value OpsClient::v_get_ticker(const Params* params_ptr)
74847490
{
74857491
std::string query = params_ptr ? this->_generate_query(params_ptr) : "";
7486-
std::string full_path = _BASE_REST_OPS + "/vapi/v1/ticker" + query;
7492+
std::string full_path = !this->_testnet_mode ? _BASE_REST_OPS : _BASE_REST_OPS_TESTNET;
7493+
full_path += "/vapi/v1/ticker" + query;
74877494
Json::Value response = (this->_rest_client)->_getreq(full_path);
74887495
return response;
74897496
}
@@ -7494,7 +7501,8 @@ Json::Value OpsClient::v_get_ticker(const Params* params_ptr)
74947501
Json::Value OpsClient::get_spot_index_price(const Params* params_ptr)
74957502
{
74967503
std::string query = params_ptr ? this->_generate_query(params_ptr) : "";
7497-
std::string full_path = _BASE_REST_OPS + "/vapi/v1/index" + query;
7504+
std::string full_path = !this->_testnet_mode ? _BASE_REST_OPS : _BASE_REST_OPS_TESTNET;
7505+
full_path += "/vapi/v1/index" + query;
74987506
Json::Value response = (this->_rest_client)->_getreq(full_path);
74997507
return response;
75007508
}
@@ -7505,7 +7513,8 @@ Json::Value OpsClient::get_spot_index_price(const Params* params_ptr)
75057513
Json::Value OpsClient::get_mark_price(const Params* params_ptr)
75067514
{
75077515
std::string query = params_ptr ? this->_generate_query(params_ptr) : "";
7508-
std::string full_path = _BASE_REST_OPS + "/vapi/v1/mark" + query;
7516+
std::string full_path = !this->_testnet_mode ? _BASE_REST_OPS : _BASE_REST_OPS_TESTNET;
7517+
full_path += "/vapi/v1/mark" + query;
75097518
Json::Value response = (this->_rest_client)->_getreq(full_path);
75107519
return response;
75117520
}
@@ -7518,7 +7527,8 @@ Json::Value OpsClient::get_mark_price(const Params* params_ptr)
75187527
Json::Value OpsClient::v_order_book(const Params* params_ptr)
75197528
{
75207529
std::string query = params_ptr ? this->_generate_query(params_ptr) : "";
7521-
std::string full_path = _BASE_REST_OPS + "/vapi/v1/depth" + query;
7530+
std::string full_path = !this->_testnet_mode ? _BASE_REST_OPS : _BASE_REST_OPS_TESTNET;
7531+
full_path += "/vapi/v1/depth" + query;
75227532
Json::Value response = (this->_rest_client)->_getreq(full_path);
75237533
return response;
75247534
}
@@ -7529,7 +7539,8 @@ Json::Value OpsClient::v_order_book(const Params* params_ptr)
75297539
Json::Value OpsClient::v_klines(const Params* params_ptr)
75307540
{
75317541
std::string query = params_ptr ? this->_generate_query(params_ptr) : "";
7532-
std::string full_path = _BASE_REST_OPS + "/vapi/v1/klines" + query;
7542+
std::string full_path = !this->_testnet_mode ? _BASE_REST_OPS : _BASE_REST_OPS_TESTNET;
7543+
full_path += "/vapi/v1/klines" + query;
75337544
Json::Value response = (this->_rest_client)->_getreq(full_path);
75347545
return response;
75357546
}
@@ -7540,7 +7551,8 @@ Json::Value OpsClient::v_klines(const Params* params_ptr)
75407551
Json::Value OpsClient::v_public_trades_recent(const Params* params_ptr)
75417552
{
75427553
std::string query = params_ptr ? this->_generate_query(params_ptr) : "";
7543-
std::string full_path = _BASE_REST_OPS + "/vapi/v1/trades" + query;
7554+
std::string full_path = !this->_testnet_mode ? _BASE_REST_OPS : _BASE_REST_OPS_TESTNET;
7555+
full_path += "/vapi/v1/trades" + query;
75447556
Json::Value response = (this->_rest_client)->_getreq(full_path);
75457557
return response;
75467558
}
@@ -7551,7 +7563,8 @@ Json::Value OpsClient::v_public_trades_recent(const Params* params_ptr)
75517563
Json::Value OpsClient::v_public_trades_historical(const Params* params_ptr)
75527564
{
75537565
std::string query = params_ptr ? this->_generate_query(params_ptr) : "";
7554-
std::string full_path = _BASE_REST_OPS + "/vapi/v1/historicalTrades" + query;
7566+
std::string full_path = !this->_testnet_mode ? _BASE_REST_OPS : _BASE_REST_OPS_TESTNET;
7567+
full_path += "/vapi/v1/historicalTrades" + query;
75557568
Json::Value response = (this->_rest_client)->_getreq(full_path);
75567569
return response;
75577570
}
@@ -7562,7 +7575,8 @@ Json::Value OpsClient::v_public_trades_historical(const Params* params_ptr)
75627575
Json::Value OpsClient::funds_transfer(const Params* params_ptr)
75637576
{
75647577
std::string query = params_ptr ? this->_generate_query(params_ptr) : "";
7565-
std::string full_path = _BASE_REST_OPS + "/vapi/v1/transfer" + query;
7578+
std::string full_path = !this->_testnet_mode ? _BASE_REST_OPS : _BASE_REST_OPS_TESTNET;
7579+
full_path += "/vapi/v1/transfer" + query;
75667580
Json::Value response = (this->_rest_client)->_postreq(full_path);
75677581
return response;
75687582
}
@@ -7573,7 +7587,8 @@ Json::Value OpsClient::funds_transfer(const Params* params_ptr)
75737587
Json::Value OpsClient::holding_info(const Params* params_ptr)
75747588
{
75757589
std::string query = params_ptr ? this->_generate_query(params_ptr) : "";
7576-
std::string full_path = _BASE_REST_OPS + "/vapi/v1/position" + query;
7590+
std::string full_path = !this->_testnet_mode ? _BASE_REST_OPS : _BASE_REST_OPS_TESTNET;
7591+
full_path += "/vapi/v1/position" + query;
75777592
Json::Value response = (this->_rest_client)->_getreq(full_path);
75787593
return response;
75797594
}
@@ -7583,7 +7598,8 @@ Json::Value OpsClient::holding_info(const Params* params_ptr)
75837598
Json::Value OpsClient::account_funding_flow(const Params* params_ptr)
75847599
{
75857600
std::string query = params_ptr ? this->_generate_query(params_ptr) : "";
7586-
std::string full_path = _BASE_REST_OPS + "/vapi/v1/bill" + query;
7601+
std::string full_path = !this->_testnet_mode ? _BASE_REST_OPS : _BASE_REST_OPS_TESTNET;
7602+
full_path += "/vapi/v1/bill" + query;
75877603
Json::Value response = (this->_rest_client)->_postreq(full_path);
75887604
return response;
75897605
}
@@ -7593,7 +7609,8 @@ Json::Value OpsClient::account_funding_flow(const Params* params_ptr)
75937609
Json::Value OpsClient::batch_orders(const Params* params_ptr)
75947610
{
75957611
std::string query = params_ptr ? this->_generate_query(params_ptr) : "";
7596-
std::string full_path = _BASE_REST_OPS + "/vapi/v1/batchOrders" + query;
7612+
std::string full_path = !this->_testnet_mode ? _BASE_REST_OPS : _BASE_REST_OPS_TESTNET;
7613+
full_path += "/vapi/v1/batchOrders" + query;
75977614
Json::Value response = (this->_rest_client)->_postreq(full_path);
75987615
return response;
75997616
}
@@ -7603,7 +7620,8 @@ Json::Value OpsClient::batch_orders(const Params* params_ptr)
76037620
Json::Value OpsClient::cancel_batch_orders(const Params* params_ptr)
76047621
{
76057622
std::string query = params_ptr ? this->_generate_query(params_ptr) : "";
7606-
std::string full_path = _BASE_REST_OPS + "/vapi/v1/batchOrders" + query;
7623+
std::string full_path = !this->_testnet_mode ? _BASE_REST_OPS : _BASE_REST_OPS_TESTNET;
7624+
full_path += "/vapi/v1/batchOrders" + query;
76077625
Json::Value response = (this->_rest_client)->_deletereq(full_path);
76087626
return response;
76097627
}
@@ -7621,9 +7639,10 @@ Json::Value OpsClient::cancel_batch_orders(const Params* params_ptr)
76217639
*/
76227640
Json::Value OpsClient::v_account_info(const Params* params_ptr)
76237641
{
7624-
std::string full_path = _BASE_REST_OPS + "/vapi/v1/account";
76257642
std::string query = this->_generate_query(params_ptr, 1);
7626-
Json::Value response = (this->_rest_client)->_getreq(full_path + query);
7643+
std::string full_path = !this->_testnet_mode ? _BASE_REST_OPS : _BASE_REST_OPS_TESTNET;
7644+
full_path += "/vapi/v1/account" + query;
7645+
Json::Value response = (this->_rest_client)->_getreq(full_path);
76277646

76287647
return response;
76297648
}
@@ -7634,9 +7653,10 @@ Json::Value OpsClient::v_account_info(const Params* params_ptr)
76347653
*/
76357654
Json::Value OpsClient::v_test_new_order(const Params* params_ptr)
76367655
{
7637-
std::string full_path = _BASE_REST_OPS_TESTNET + "/vapi/v1/order";
76387656
std::string query = this->_generate_query(params_ptr, 1);
7639-
Json::Value response = (this->_rest_client)->_postreq(full_path + query);
7657+
std::string full_path = !this->_testnet_mode ? _BASE_REST_OPS : _BASE_REST_OPS_TESTNET;
7658+
full_path += "/vapi/v1/order" + query;
7659+
Json::Value response = (this->_rest_client)->_postreq(full_path);
76407660

76417661
return response;
76427662
}
@@ -7646,9 +7666,10 @@ Json::Value OpsClient::v_test_new_order(const Params* params_ptr)
76467666
*/
76477667
Json::Value OpsClient::v_new_order(const Params* params_ptr)
76487668
{
7649-
std::string full_path = _BASE_REST_OPS + "/vapi/v1/order";
76507669
std::string query = this->_generate_query(params_ptr, 1);
7651-
Json::Value response = (this->_rest_client)->_postreq(full_path + query);
7670+
std::string full_path = !this->_testnet_mode ? _BASE_REST_OPS : _BASE_REST_OPS_TESTNET;
7671+
full_path += "/vapi/v1/order" + query;
7672+
Json::Value response = (this->_rest_client)->_postreq(full_path);
76527673

76537674
return response;
76547675
}
@@ -7658,9 +7679,10 @@ Json::Value OpsClient::v_new_order(const Params* params_ptr)
76587679
*/
76597680
Json::Value OpsClient::v_cancel_order(const Params* params_ptr)
76607681
{
7661-
std::string full_path = _BASE_REST_OPS + "/vapi/v1/order";
76627682
std::string query = this->_generate_query(params_ptr, 1);
7663-
Json::Value response = (this->_rest_client)->_deletereq(full_path + query);
7683+
std::string full_path = !this->_testnet_mode ? _BASE_REST_OPS : _BASE_REST_OPS_TESTNET;
7684+
full_path += "/vapi/v1/order" + query;
7685+
Json::Value response = (this->_rest_client)->_deletereq(full_path);
76647686

76657687
return response;
76667688
}
@@ -7670,9 +7692,10 @@ Json::Value OpsClient::v_cancel_order(const Params* params_ptr)
76707692
*/
76717693
Json::Value OpsClient::v_cancel_all_orders(const Params* params_ptr)
76727694
{
7673-
std::string full_path = _BASE_REST_OPS + "/vapi/v1/allOpenOrders";
76747695
std::string query = this->_generate_query(params_ptr, 1);
7675-
Json::Value response = (this->_rest_client)->_deletereq(full_path + query);
7696+
std::string full_path = !this->_testnet_mode ? _BASE_REST_OPS : _BASE_REST_OPS_TESTNET;
7697+
full_path += "/vapi/v1/allOpenOrders" + query;
7698+
Json::Value response = (this->_rest_client)->_deletereq(full_path);
76767699

76777700
return response;
76787701
}
@@ -7682,9 +7705,10 @@ Json::Value OpsClient::v_cancel_all_orders(const Params* params_ptr)
76827705
*/
76837706
Json::Value OpsClient::v_query_order(const Params* params_ptr)
76847707
{
7685-
std::string full_path = _BASE_REST_OPS + " /vapi/v1/order";
76867708
std::string query = this->_generate_query(params_ptr, 1);
7687-
Json::Value response = (this->_rest_client)->_getreq(full_path + query);
7709+
std::string full_path = !this->_testnet_mode ? _BASE_REST_OPS : _BASE_REST_OPS_TESTNET;
7710+
full_path += " /vapi/v1/order" + query;
7711+
Json::Value response = (this->_rest_client)->_getreq(full_path);
76887712

76897713
return response;
76907714
}
@@ -7694,9 +7718,10 @@ Json::Value OpsClient::v_query_order(const Params* params_ptr)
76947718
*/
76957719
Json::Value OpsClient::v_open_orders(const Params* params_ptr)
76967720
{
7697-
std::string full_path = _BASE_REST_OPS + "/vapi/v1/openOrders";
76987721
std::string query = this->_generate_query(params_ptr, 1);
7699-
Json::Value response = (this->_rest_client)->_getreq(full_path + query);
7722+
std::string full_path = !this->_testnet_mode ? _BASE_REST_OPS : _BASE_REST_OPS_TESTNET;
7723+
full_path += "/vapi/v1/openOrders" + query;
7724+
Json::Value response = (this->_rest_client)->_getreq(full_path);
77007725

77017726
return response;
77027727
}
@@ -7706,9 +7731,10 @@ Json::Value OpsClient::v_open_orders(const Params* params_ptr)
77067731
*/
77077732
Json::Value OpsClient::v_all_orders(const Params* params_ptr)
77087733
{
7709-
std::string full_path = _BASE_REST_OPS + "/vapi/v1/historyOrders";
77107734
std::string query = this->_generate_query(params_ptr, 1);
7711-
Json::Value response = (this->_rest_client)->_getreq(full_path + query);
7735+
std::string full_path = !this->_testnet_mode ? _BASE_REST_OPS : _BASE_REST_OPS_TESTNET;
7736+
full_path += "/vapi/v1/historyOrders" + query;
7737+
Json::Value response = (this->_rest_client)->_getreq(full_path);
77127738

77137739
return response;
77147740
}

0 commit comments

Comments
 (0)