fix: Reject orders w/ invalid TimeInForce at binance
Do this internally (before sending them to the exchange)
This commit is contained in:
1 parent
24f0eef2eb
commit
5b9fc54ea6
3 files changed
+35
-1
No files matched your search
@@ -1,4 +1,5 @@
|
||||
#include "execution_gateway.h"
|
||||
#include "binance_execution/enums/time_in_force.h"
|
||||
#include "binance_execution/rest_api_result.h"
|
||||
#include "binance_execution/spots/messages/modify_order_request.h"
|
||||
#include "binance_execution/spots/messages/order_record.h"
|
||||
@@ -127,6 +128,20 @@ static void validate(bts::api::Side side, string &error) {
|
||||
}
|
||||
}
|
||||
|
||||
static void validate(bts::api::orderman::TimeInForce bts_tif, string &error) {
|
||||
const auto tif = convert_time_in_force(bts_tif);
|
||||
switch (tif.value) {
|
||||
case TimeInForce::GTC:
|
||||
case TimeInForce::IOC:
|
||||
case TimeInForce::FOK:
|
||||
break;
|
||||
default:
|
||||
append_error(
|
||||
error, fmt::format("invalid TimeInForce '{}'.", bts_tif).c_str());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Store exch order id in EMNativeOrder (until then, it'll always be 0).
|
||||
// We can ignore this for now and use "orig client id" in cancel/replace requests.
|
||||
static constexpr const bool VALIDATE_EXCH_ORDER_ID = false;
|
||||
@@ -137,6 +152,7 @@ static bool validate(const CreateOrderMsg &m, string &error) {
|
||||
validate(m.key, error);
|
||||
validate(m.quantity, error);
|
||||
validate(m.side, error);
|
||||
validate(m.time_in_force, error);
|
||||
return error.size() == orig_sz;
|
||||
}
|
||||
|
||||
|
||||
@@ -142,6 +142,8 @@ inline bts::api::orderman::TimeInForce convert_time_in_force(TimeInForce tif) {
|
||||
switch (tif.value) {
|
||||
case TimeInForce::GTC:
|
||||
return bts::api::orderman::TIME_IN_FORCE_GTC;
|
||||
case TimeInForce::GTD:
|
||||
return bts::api::orderman::TIME_IN_FORCE_DAY;
|
||||
case TimeInForce::IOC:
|
||||
case TimeInForce::FOK:
|
||||
return bts::api::orderman::TIME_IN_FORCE_IOC;
|
||||
@@ -202,8 +204,9 @@ inline OrderType convert_order_type(bts::api::orderman::NativeOrderType tif) {
|
||||
inline TimeInForce convert_time_in_force(bts::api::orderman::TimeInForce tif) {
|
||||
switch (tif) {
|
||||
case bts::api::orderman::TIME_IN_FORCE_GTC:
|
||||
case bts::api::orderman::TIME_IN_FORCE_DAY:
|
||||
return TimeInForce::GTC;
|
||||
case bts::api::orderman::TIME_IN_FORCE_DAY:
|
||||
return TimeInForce::GTD;
|
||||
case bts::api::orderman::TIME_IN_FORCE_IOC:
|
||||
return TimeInForce::IOC;
|
||||
case bts::api::orderman::TIME_IN_FORCE_UNDEFINED:
|
||||
|
||||
@@ -126,6 +126,20 @@ static void validate(bts::api::Side side, string &error) {
|
||||
}
|
||||
}
|
||||
|
||||
static void validate(bts::api::orderman::TimeInForce bts_tif, string &error) {
|
||||
const auto tif = convert_time_in_force(bts_tif);
|
||||
switch (tif.value) {
|
||||
case TimeInForce::GTC:
|
||||
case TimeInForce::IOC:
|
||||
case TimeInForce::FOK:
|
||||
break;
|
||||
default:
|
||||
append_error(
|
||||
error, fmt::format("invalid TimeInForce '{}'.", bts_tif).c_str());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Store exch order id in EMNativeOrder (until then, it'll always be 0).
|
||||
// We can ignore this for now and use "orig client id" in cancel/replace requests.
|
||||
static constexpr const bool VALIDATE_EXCH_ORDER_ID = false;
|
||||
@@ -136,6 +150,7 @@ static bool validate(const CreateOrderMsg &m, string &error) {
|
||||
validate(m.key, error);
|
||||
validate(m.quantity, error);
|
||||
validate(m.side, error);
|
||||
validate(m.time_in_force, error);
|
||||
return error.size() == orig_sz;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user