Add: config for sim trading

This commit is contained in:
Mohammad Arham committed 2025-02-13 22:06:23 +00:00
1 parent 914ac597cd
commit bdf5b980fc
4 files changed
+14 -9

No files matched your search

@@ -11,5 +11,6 @@ OkxExeCfg {
ws_ping_interval_seconds : 25
ws_reconnect_interval_seconds : 5
ws_reconnect_max_count : 5
simulated_trading : true
}
}
+1
View File
@@ -12,5 +12,6 @@ message OkxExeCfg {
uint32 ws_ping_interval_seconds = 9;
uint32 ws_reconnect_interval_seconds = 10;
uint32 ws_reconnect_max_count = 11;
bool simulated_trading = 12;
}
@@ -59,6 +59,7 @@ struct OkxExecutionAdapter::PImpl {
const std::string passphrase = config::get<config::OkxExeCfg>().passphrase();
const std::string url =
config::get<config::OkxExeCfg>().ws_url() + "/ws/v5/private";
const bool simulated_trading = config::get<config::OkxExeCfg>().simulated_trading();
const core::TimeSpan connect_timeout = core::TimeSpan::from_seconds(0);
const core::TimeSpan pong_timeout = core::TimeSpan::from_seconds(
config::get<config::OkxExeCfg>().ws_ping_interval_seconds());
@@ -372,7 +373,7 @@ void OkxExecutionAdapter::modify_order(
msg.create_fields.quantity.full_value());
auto headers = OkxUtils::createHeaders(
me_->api_key, me_->passphrase, me_->secret_key, "POST", REQUEST_PATH,
body);
me_->simulated_trading,body);
// Generate and log the curl command
std::string curlCommand = OkxUtils::generateCurlCommand(
config::get<config::OkxExeCfg>().rest_url() + REQUEST_PATH, headers,
@@ -397,8 +398,8 @@ void OkxExecutionAdapter::modify_order(
// er.exec_type = api::orderman::ExecType::EXEC_TYPE_PENDING_REPLACE;
// er.order_status = api::orderman::NATIVE_ORDER_STATUS_PENDING_REPLACE;
} else {
LOG(md, Info, "Http get failed {},,,{}", res.errors, res.body);
// er.exec_type = api::orderman::ExecType::EXEC_TYPE_REJECTED;
LOG(md, Info, "Http get failed code: {}, errors: {}, body: {}", res.code, res.errors, res.body);
// er.exec_type = api::orderman::ExecType::EXEC_TYPE_REJECTED;
// er.order_status = api::orderman::NATIVE_ORDER_STATUS_REJECTED;
// er.msg = ex_msg + " " + top_msg;
}
@@ -431,7 +432,7 @@ void OkxExecutionAdapter::launch_new_order(const CreateOrderMsg &msg) {
http::HttpResponse res;
auto headers = OkxUtils::createHeaders(
me_->api_key, me_->passphrase, me_->secret_key, "POST", REQUEST_PATH,
body);
me_->simulated_trading,body);
// Generate and log the curl command
std::string curlCommand = OkxUtils::generateCurlCommand(
config::get<config::OkxExeCfg>().rest_url() + REQUEST_PATH, headers,
@@ -462,7 +463,7 @@ void OkxExecutionAdapter::launch_new_order(const CreateOrderMsg &msg) {
er.exec_type = api::orderman::ExecType::EXEC_TYPE_PENDING_NEW;
er.order_status = api::orderman::NATIVE_ORDER_STATUS_PENDING_NEW;
} else {
LOG(md, Info, "Http get failed {},,,{}", res.errors, res.body);
LOG(md, Info, "Http get failed code: {}, errors: {}, body: {}", res.code, res.errors, res.body);
er.exec_type = api::orderman::ExecType::EXEC_TYPE_REJECTED;
er.order_status = api::orderman::NATIVE_ORDER_STATUS_REJECTED;
er.msg = ex_msg + " " + top_msg;
@@ -493,7 +494,7 @@ void OkxExecutionAdapter::cancel_order(const CancelOrderMsg &msg) {
body_template, msg.security->okx().security_desc(), msg.key);
auto headers = OkxUtils::createHeaders(
me_->api_key, me_->passphrase, me_->secret_key, "POST", REQUEST_PATH,
body);
me_->simulated_trading,body);
// Generate and log the curl command
std::string curlCommand = OkxUtils::generateCurlCommand(
config::get<config::OkxExeCfg>().rest_url() + REQUEST_PATH, headers,
@@ -518,7 +519,7 @@ void OkxExecutionAdapter::cancel_order(const CancelOrderMsg &msg) {
// er.exec_type = api::orderman::ExecType::EXEC_TYPE_PENDING_CANCEL;
// er.order_status = api::orderman::NATIVE_ORDER_STATUS_PENDING_CANCEL;
} else {
LOG(md, Info, "Http get failed {},,,{}", res.errors, res.body);
LOG(md, Info, "Http get failed code: {}, errors: {}, body: {}", res.code, res.errors, res.body);
// er.exec_type = api::orderman::ExecType::EXEC_TYPE_REJECTED;
// er.order_status = api::orderman::NATIVE_ORDER_STATUS_REJECTED;
// er.msg = ex_msg + " " + top_msg;
+4 -2
View File
@@ -168,22 +168,24 @@ class OkxUtils {
const std::string &secretKey,
const std::string &method,
const std::string &requestPath,
const bool simulated_trading,
const std::string &body = "") {
auto ts = bts::core::TimeStamp::now();
std::string timestamp = getUTCTimestamp(ts);
std::string prehash = timestamp + method + requestPath + body;
auto signature = getSign(prehash, secretKey);
LOG(OrderMan, bts::Info, "prehash '{}' , key '{}'", prehash, signature);
// Prepare headers
std::unordered_map<std::string, std::string> headers = {
{"accept", "application/json"},
{"Content-Type", "application/json"},
{"x-simulated-trading", "1"},
{"OK-ACCESS-KEY", apiKey},
{"OK-ACCESS-SIGN", signature},
{"OK-ACCESS-TIMESTAMP", timestamp},
{"OK-ACCESS-PASSPHRASE", passphrase}};
if (simulated_trading){
headers.insert({"x-simulated-trading", "1"});
}
return headers;
}