22 #ifndef STRATEGIES_MARKET_MAKER_HPP
23 #define STRATEGIES_MARKET_MAKER_HPP
25 #include "data_feed/receiver.hpp"
26 #include "order_entry/client.hpp"
27 #include "maths/probability.hpp"
28 #include "maths/exponential_moving_average.hpp"
29 #include <nlohmann/json.hpp>
50 asio::steady_timer timer;
56 std::atomic<bool> is_running;
65 double decision_boundary;
71 inline void start_strategy() {
72 timer.expires_after(std::chrono::milliseconds(sleep_time));
73 timer.async_wait([
this](
const std::error_code& error) {
75 std::cout <<
"MarketMaker::start_strategy - " << error << std::endl;
93 OrderEntry::Side::Sell
101 }
else if (trade_side.
get_average() < -decision_boundary) {
106 OrderEntry::Side::Buy
112 OrderEntry::Side::Sell
125 asio::io_context& feed_context,
126 asio::io_context& context,
127 nlohmann::json options
131 asio::ip::make_address(options[
"data_feed"][
"listen"].get<std::string>()),
132 asio::ip::make_address(options[
"data_feed"][
"group"].get<std::string>()),
133 options[
"data_feed"][
"port"].get<uint16_t>(),
138 options[
"order_entry"][
"host"].get<std::string>(),
139 std::to_string(options[
"order_entry"][
"port"].get<uint16_t>())
142 sleep_time(options[
"strategy"][
"sleep_time"].get<uint32_t>()),
143 P_act(options[
"strategy"][
"P_act"].get<double>()),
145 minimum_size(options[
"strategy"][
"minimum_size"].get<
OrderEntry::Quantity>()),
146 maximum_size(options[
"strategy"][
"maximum_size"].get<
OrderEntry::Quantity>()),
147 hedge_size(options[
"strategy"][
"hedge_size"].get<
OrderEntry::Quantity>()),
148 decision_boundary(options[
"strategy"][
"decision_boundary"].get<double>()),
149 trade_side(options[
"strategy"][
"weight"].get<double>(), options[
"strategy"][
"average"].get<double>()) {
163 std::cerr <<
"received start of session when already running" << std::endl;
180 if (not is_running) {
181 std::cerr <<
"received end of session when not running" << std::endl;
222 #endif // STRATEGIES_MARKET_MAKER_HPP
void process(T observation)
Calculate the next average based on observation .
Definition: exponential_moving_average.hpp:92
Logic for sending/receiving application messages in a financial market.
Definition: authorizer.hpp:26
T uniform_real(T min, T max)
Sample a number from a real-valued uniform distribution.
Definition: probability.hpp:61
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::Clear &message)
Handle a clear book message.
Definition: market_maker.hpp:194
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
bool has_active_order() const
Return true if the client has an active order.
Definition: client.hpp:267
void send(Args &&...args)
Write a message asynchronously (non-blocking).
Definition: client.hpp:299
Price last_best_sell() const
Return the last best sell price.
Definition: limit_order_book.hpp:262
The market maker strategy logic.
Definition: market_maker.hpp:41
void did_receive(DataFeedReceiver *receiver, const DataFeed::Messages::EndOfSession &message)
Handle an end of session message.
Definition: market_maker.hpp:179
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
void reset(T observation=0)
Reset the average to initial state with observation .
Definition: exponential_moving_average.hpp:71
A message that indicates the end of a trading session.
Definition: messages.hpp:506
A message that indicates to clear all orders in the order book.
Definition: messages.hpp:213
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
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::DeleteOrder &message)
Handle a delete order message.
Definition: market_maker.hpp:208
void did_receive(DataFeedReceiver *receiver, const DataFeed::Messages::AddOrder &message)
Handle an add order message.
Definition: market_maker.hpp:201
const Side side
the side of the market order
Definition: messages.hpp:397
Price last_best_buy() const
Return the last best buy price.
Definition: limit_order_book.hpp:268
A client for interacting with the direct market access server.
Definition: client.hpp:42
A request to cancel all active orders in the book.
Definition: messages.hpp:917
Username make_username(std::string username)
Make a username from the given input string.
Definition: messages.hpp:46
void did_receive(DataFeedReceiver *receiver, const DataFeed::Messages::Trade &message)
Handle a trade message.
Definition: market_maker.hpp:215
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: market_maker.hpp:161
T get_average() const
Return the current value of the exponential moving average .
Definition: exponential_moving_average.hpp:101
constexpr double side_to_double(Side side)
Convert an order side character to a double.
Definition: messages.hpp:60
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
MarketMaker(asio::io_context &feed_context, asio::io_context &context, nlohmann::json options)
Initialize the strategy.
Definition: market_maker.hpp:124