95 lines
3.5 KiB
C++
95 lines
3.5 KiB
C++
#include "OkxExecutionAdapter.h"
|
|
#include "OnixS/FIXEngine/FIX/Engine.h"
|
|
#include "lib/config/protos/marex_fix_cfg.pb.h"
|
|
#include "lib/domain_model/Security.pb.h"
|
|
#include "lib/logging/logging.h"
|
|
#include "lib/orderman/CancelOrderMsg.h"
|
|
#include "lib/orderman/CancelReplaceOrderMsg.h"
|
|
#include "lib/orderman/CreateOrderMsg.h"
|
|
#include "lib/orderman/gateways/OnixFIXListener.h"
|
|
#include "lib/orderman/gateways/TrafixOrderStateHandler.h"
|
|
#include "lib/orderman/orderman_utils/orderman_common.h"
|
|
#include "lib/utils/bts_assert.h"
|
|
#include "lib/utils/helper_macros.h"
|
|
#include <OnixS/FIXEngine/FIX/Exception.h>
|
|
#include <OnixS/FIXEngine/FIX/FIX42.h>
|
|
#include <OnixS/FIXEngine/FIX/Message.h>
|
|
#include <OnixS/FIXEngine/FIX/Numeric.h>
|
|
#include <OnixS/FIXEngine/FIX/ProtocolVersion.h>
|
|
#include <cassert>
|
|
#include <chrono>
|
|
#include <exception>
|
|
#include <memory>
|
|
#include <quickfix/FixFields.h>
|
|
#include <ratio>
|
|
#include <string>
|
|
#include <unistd.h>
|
|
|
|
namespace bts::orderman {
|
|
|
|
OkxExecutionAdapter::OkxExecutionAdapter(md::SecurityOracle){}//listener() {}
|
|
OkxExecutionAdapter::~OkxExecutionAdapter() {}
|
|
inline void handleOkException(
|
|
const std::string &context, const std::string &error) {
|
|
bts_assert_msgf(false, "{} Exception: {}", context, error);
|
|
}
|
|
void OkxExecutionAdapter::start() {
|
|
int attempt = 0;
|
|
|
|
while (true) {
|
|
try {
|
|
LOG(OrderMan, Warn, "OkxExecutionAdapter::start Attempting login (Attempt: {})", attempt + 1);
|
|
LOG(OrderMan, Warn, "OkxExecutionAdapter::start Login successful");
|
|
break; // Exit loop on success
|
|
} catch (const std::exception &ex) {
|
|
const std::string err = ex.what();
|
|
LOG(OrderMan, Error, "OkxExecutionAdapter::start Login failed: {}. Retrying in {} seconds.", err, 10);
|
|
|
|
// if (maxRetries > 0 && ++attempt >= maxRetries) {
|
|
// LOG(OrderMan, Error, "OkxExecutionAdapter::start Exceeded max retries ({}). Aborting.", maxRetries);
|
|
// handleOkException("OkxExecutionAdapter::start", err);
|
|
// break; // Exit if retries are exhausted
|
|
// }
|
|
// std::this_thread::sleep_for(std::chrono::seconds(std::max(60,retryInterval)));
|
|
}
|
|
}
|
|
}
|
|
|
|
void OkxExecutionAdapter::modify_order(
|
|
const CancelReplaceOrderMsg &msg) { //confirm will have everything
|
|
try {
|
|
LOG(OrderMan, Warn, "OkxExecutionAdapter::modify_order modifying order{}",
|
|
msg);
|
|
} catch (const std::exception &ex) {
|
|
const std::string err = ex.what();
|
|
handleOkException("Modify order", err);
|
|
}
|
|
}
|
|
|
|
void OkxExecutionAdapter::launch_new_order(const CreateOrderMsg &msg) {
|
|
LOG(OrderMan, Warn, "launch order {}", msg);
|
|
try {
|
|
LOG(OrderMan, Warn, "OkxExecutionAdapter::launch_new_order creating order");
|
|
}
|
|
// Shut down all reactors if they exist.
|
|
catch (const std::exception &ex) {
|
|
const std::string err = ex.what();
|
|
handleOkException("Launch order", err);
|
|
}
|
|
}
|
|
void OkxExecutionAdapter::register_callback([[maybe_unused]]const OnExecutionReport &cb) {
|
|
LOG(OrderMan, Warn, "OkxExecutionAdapter::register_callback callback registered");
|
|
// listener.setCallback(cb);
|
|
}
|
|
void OkxExecutionAdapter::cancel_order(const CancelOrderMsg &msg) {
|
|
LOG(OrderMan, Warn, "cancel order {}", msg);
|
|
try {
|
|
LOG(OrderMan, Warn, "order cancel sent");
|
|
}
|
|
// Shut down all reactors if they exist.
|
|
catch (const std::exception &ex) {
|
|
const std::string err = ex.what();
|
|
handleOkException("Cacnel order", err);
|
|
}
|
|
}
|
|
} // namespace bts::orderman
|