22 #ifndef STRATEGIES_ICEBERG_TRADER_HPP
23 #define STRATEGIES_ICEBERG_TRADER_HPP
25 #include "data_feed/receiver.hpp"
26 #include "order_entry/client.hpp"
27 #include "maths/probability.hpp"
28 #include <nlohmann/json.hpp>
49 asio::steady_timer timer;
55 std::atomic<bool> is_running;
69 inline void sell_order() {
71 if (volume == 0)
return;
72 auto order_size = std::min(size, iceberg_size);
75 OrderEntry::Messages::ORDER_PRICE_MARKET,
77 OrderEntry::Side::Sell
85 inline void buy_order() {
87 if (volume == 0)
return;
88 auto order_size = std::min(size, iceberg_size);
91 OrderEntry::Messages::ORDER_PRICE_MARKET,
101 inline void start_strategy() {
102 timer.expires_after(std::chrono::milliseconds(sleep_time));
103 timer.async_wait([
this](
const std::error_code& error) {
105 std::cout <<
"IcebergLiquidityConsumer::start_strategy - " << error << std::endl;
117 case OrderEntry::Side::Sell: { sell_order();
break; }
118 case OrderEntry::Side::Buy: { buy_order();
break; }
130 asio::io_context& feed_context,
131 asio::io_context& context,
132 nlohmann::json options
136 asio::ip::make_address(options[
"data_feed"][
"listen"].get<std::string>()),
137 asio::ip::make_address(options[
"data_feed"][
"group"].get<std::string>()),
138 options[
"data_feed"][
"port"].get<uint16_t>(),
143 options[
"order_entry"][
"host"].get<std::string>(),
144 std::to_string(options[
"order_entry"][
"port"].get<uint16_t>())
147 sleep_time(options[
"strategy"][
"sleep_time"].get<uint32_t>()),
148 P_act(options[
"strategy"][
"P_act"].get<double>()),
150 minimum_size(options[
"strategy"][
"minimum_size"].get<double>()),
151 maximum_size(options[
"strategy"][
"maximum_size"].get<double>()),
152 iceberg_size(options[
"strategy"][
"iceberg_size"].get<double>()) {
166 std::cerr <<
"received start of session when already running" << std::endl;
186 if (not is_running) {
187 std::cerr <<
"received end of session when not running" << std::endl;
227 #endif // STRATEGIES_ICEBERG_TRADER_HPP
A request that indicates a client is attempting to create a new session.
Definition: messages.hpp:248
void did_receive(DataFeedReceiver *receiver, const DataFeed::Messages::Trade &message)
Handle a trade message.
Definition: iceberg_liquidity_consumer.hpp:222
Password make_password(std::string password)
Make a password from the given input string.
Definition: messages.hpp:62
A message that indicates a market order matches with a limit order.
Definition: messages.hpp:387
void send(Args &&...args)
Write a message asynchronously (non-blocking).
Definition: client.hpp:299
void did_receive(DataFeedReceiver *receiver, const DataFeed::Messages::DeleteOrder &message)
Handle a delete order message.
Definition: iceberg_liquidity_consumer.hpp:215
A message that indicates a limit order was added to the book.
Definition: messages.hpp:332
A request to place a new limit / market order in the book.
Definition: messages.hpp:502
const LOB::LimitOrderBook & get_book()
Return the limit order book for this receiver.
Definition: receiver.hpp:214
Volume volume_sell_best() const
Return the volume at the best sell price.
Definition: limit_order_book.hpp:300
A message that indicates the end of a trading session.
Definition: messages.hpp:506
The iceberg trader strategy logic.
Definition: iceberg_liquidity_consumer.hpp:40
A message that indicates to clear all orders in the order book.
Definition: messages.hpp:213
IcebergLiquidityConsumer(asio::io_context &feed_context, asio::io_context &context, nlohmann::json options)
Initialize the strategy.
Definition: iceberg_liquidity_consumer.hpp:129
Volume volume_buy_best() const
Return the volume at the best sell price.
Definition: limit_order_book.hpp:318
bool boolean()
Return the result of a coin toss.
Definition: probability.hpp:105
A message that indicates the start of a trading session.
Definition: messages.hpp:460
void did_receive(DataFeedReceiver *receiver, const DataFeed::Messages::Clear &message)
Handle a clear book message.
Definition: iceberg_liquidity_consumer.hpp:201
T uniform_int(T min, T max)
Sample a number from an integer-valued uniform distribution.
Definition: probability.hpp:49
void did_receive(DataFeedReceiver *receiver, const DataFeed::Messages::EndOfSession &message)
Handle an end of session message.
Definition: iceberg_liquidity_consumer.hpp:185
A client for interacting with the direct market access server.
Definition: client.hpp:42
Username make_username(std::string username)
Make a username from the given input string.
Definition: messages.hpp:46
uint32_t Quantity
A type for order quantities.
Definition: messages.hpp:133
void did_receive(DataFeedReceiver *receiver, const DataFeed::Messages::StartOfSession &message)
Handle a start of session message.
Definition: iceberg_liquidity_consumer.hpp:164
void did_receive(DataFeedReceiver *receiver, const DataFeed::Messages::AddOrder &message)
Handle an add order message.
Definition: iceberg_liquidity_consumer.hpp:208
Side
The side of an order.
Definition: messages.hpp:71
Direct market access trading strategies.
Definition: iceberg_liquidity_consumer.hpp:33
A message that indicates a limit order was added to the book.
Definition: messages.hpp:259