Slick Trader
0.11.0
Multi-broker algorithmic trading engine with plugin strategies and a live web dashboard
Loading...
Searching...
No Matches
order_entry.cpp
Go to the documentation of this file.
1
#include <
slick-trader/brokers/common/order_entry.hpp
>
2
#include <slick/logger.hpp>
3
4
namespace
slick::trader
{
5
6
const
char
*
post_only_problem
(
PostOnlyPolicy
policy,
const
SharedTopOfBook
* top,
Side
side,
OrderType
type,
7
TimeInForce
tif,
price_t
price,
bool
& warned, std::string_view who) {
8
if
(!
rests
(type, tif)) {
9
return
nullptr
;
10
}
11
switch
(policy) {
12
case
PostOnlyPolicy::REJECT
:
13
return
"this exchange takes no post-only orders (post_only_policy is \"reject\")"
;
14
case
PostOnlyPolicy::ACCEPT
:
15
if
(!warned) {
16
warned =
true
;
17
LOG_WARN(
"{}: \"post_only_policy\" is \"accept\" - post-only orders are sent as ordinary orders and can "
18
"take liquidity"
,
19
who);
20
}
21
return
nullptr
;
22
case
PostOnlyPolicy::NATIVE
:
23
return
nullptr
;
// the exchange itself will not match it on entry
24
case
PostOnlyPolicy::REJECT_IF_CROSSING
:
25
break
;
26
}
27
if
(!top) {
28
return
"post-only cannot be checked: the instrument has no market data"
;
29
}
30
// The one side the order could trade against, as the market data worker last built it.
31
const
price_t
opposite = (side ==
Side::BUY
? top->
ask
: top->
bid
).load(std::memory_order_acquire);
32
if
(opposite ==
SharedTopOfBook::UNKNOWN
) {
33
return
"post-only cannot be checked: the book is not in sequence"
;
34
}
35
if
(opposite ==
SharedTopOfBook::EMPTY
) {
36
return
nullptr
;
// nothing to trade against
37
}
38
return
(side ==
Side::BUY
? price >= opposite : price <= opposite) ?
"post-only order would cross the book"
39
:
nullptr
;
40
}
41
42
}
// namespace slick::trader
slick::trader
Definition
coinbase_broker.hpp:11
slick::trader::Side
Side
Definition
order_types.hpp:8
slick::trader::BUY
@ BUY
Definition
order_types.hpp:9
slick::trader::TimeInForce
TimeInForce
Definition
order_types.hpp:22
slick::trader::price_t
int64_t price_t
Definition
types.hpp:16
slick::trader::post_only_problem
const char * post_only_problem(PostOnlyPolicy policy, const SharedTopOfBook *top, Side side, OrderType type, TimeInForce tif, price_t price, bool &warned, std::string_view who)
Definition
order_entry.cpp:6
slick::trader::OrderType
OrderType
Definition
order_types.hpp:14
slick::trader::rests
bool rests(OrderType type, TimeInForce tif) noexcept
Definition
order_entry.hpp:59
slick::trader::PostOnlyPolicy
PostOnlyPolicy
Definition
order_entry.hpp:25
slick::trader::PostOnlyPolicy::ACCEPT
@ ACCEPT
Definition
order_entry.hpp:31
slick::trader::PostOnlyPolicy::REJECT_IF_CROSSING
@ REJECT_IF_CROSSING
Definition
order_entry.hpp:30
slick::trader::PostOnlyPolicy::REJECT
@ REJECT
Definition
order_entry.hpp:32
slick::trader::PostOnlyPolicy::NATIVE
@ NATIVE
Definition
order_entry.hpp:33
order_entry.hpp
slick::trader::SharedTopOfBook
Definition
shared_top_of_book.hpp:19
slick::trader::SharedTopOfBook::ask
std::atomic< price_t > ask
Definition
shared_top_of_book.hpp:26
slick::trader::SharedTopOfBook::EMPTY
static constexpr price_t EMPTY
Definition
shared_top_of_book.hpp:23
slick::trader::SharedTopOfBook::bid
std::atomic< price_t > bid
Definition
shared_top_of_book.hpp:25
slick::trader::SharedTopOfBook::UNKNOWN
static constexpr price_t UNKNOWN
Definition
shared_top_of_book.hpp:21
brokers
common
order_entry.cpp
Generated by
1.15.0