18 #ifndef STRATEGIES_MARKET_ARBITRAGE_HPP
19 #define STRATEGIES_MARKET_ARBITRAGE_HPP
21 #include "data_feed/receiver.hpp"
22 #include "order_entry/client.hpp"
23 #include "maths/probability.hpp"
24 #include <nlohmann/json.hpp>
49 asio::steady_timer timer;
55 std::atomic<bool> is_running;
63 inline void start_strategy() {
64 timer.expires_after(std::chrono::milliseconds(sleep_time));
65 timer.async_wait([
this](
const std::error_code& error) {
67 std::cout <<
"MarketArbitrage::start_strategy - " << error << std::endl;
82 OrderEntry::Messages::ORDER_PRICE_MARKET,
87 OrderEntry::Messages::ORDER_PRICE_MARKET,
89 OrderEntry::Side::Sell
96 OrderEntry::Messages::ORDER_PRICE_MARKET,
101 OrderEntry::Messages::ORDER_PRICE_MARKET,
103 OrderEntry::Side::Sell
117 asio::io_context& feedA_context,
118 asio::io_context& feedB_context,
119 asio::io_context& context,
120 nlohmann::json options
124 asio::ip::make_address(options[
"data_feed"][
"A"][
"listen"].get<std::string>()),
125 asio::ip::make_address(options[
"data_feed"][
"A"][
"group"].get<std::string>()),
126 options[
"data_feed"][
"A"][
"port"].get<uint16_t>(),
131 asio::ip::make_address(options[
"data_feed"][
"B"][
"listen"].get<std::string>()),
132 asio::ip::make_address(options[
"data_feed"][
"B"][
"group"].get<std::string>()),
133 options[
"data_feed"][
"B"][
"port"].get<uint16_t>(),
138 options[
"order_entry"][
"A"][
"host"].get<std::string>(),
139 std::to_string(options[
"order_entry"][
"A"][
"port"].get<uint16_t>())
143 options[
"order_entry"][
"B"][
"host"].get<std::string>(),
144 std::to_string(options[
"order_entry"][
"B"][
"port"].get<uint16_t>())
147 sleep_time(options[
"strategy"][
"sleep_time"].get<uint32_t>()),
148 P_act(options[
"strategy"][
"P_act"].get<double>()),
150 size(options[
"strategy"][
"size"].get<
OrderEntry::Quantity>()),
151 spread(options[
"strategy"][
"spread"].get<
DataFeed::Quantity>()) {
169 std::cerr <<
"received start of session when already running" << std::endl;
187 if (not is_running) {
188 std::cerr <<
"received end of session when not running" << std::endl;
230 #endif // STRATEGIES_MARKET_ARBITRAGE_HPP
Logic for sending/receiving application messages in a financial market.
Definition: authorizer.hpp:26
void did_receive(DataFeedReceiver *receiver, const DataFeed::Messages::DeleteOrder &message)
Handle a delete order message.
Definition: market_arbitrage.hpp:218
A request that indicates a client is attempting to create a new session.
Definition: messages.hpp:248
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
A message that indicates a limit order was added to the book.
Definition: messages.hpp:332
MarketArbitrage(asio::io_context &feedA_context, asio::io_context &feedB_context, asio::io_context &context, nlohmann::json options)
Initialize the strategy.
Definition: market_arbitrage.hpp:116
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
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
void did_receive(DataFeedReceiver *receiver, const DataFeed::Messages::Trade &message)
Handle a trade message.
Definition: market_arbitrage.hpp:225
void did_receive(DataFeedReceiver *receiver, const DataFeed::Messages::Clear &message)
Handle a clear book message.
Definition: market_arbitrage.hpp:204
The market arbitrage strategy logic.
Definition: market_arbitrage.hpp:36
Logic for sending and receiving messages on a financial data feed.
Definition: heartbeat.hpp:28
uint32_t Quantity
A type for order quantities.
Definition: messages.hpp:100
bool is_session_active() const
Return whether the trading session is active.
Definition: receiver.hpp:220
void did_receive(DataFeedReceiver *receiver, const DataFeed::Messages::AddOrder &message)
Handle an add order message.
Definition: market_arbitrage.hpp:211
A client for interacting with the direct market access server.
Definition: client.hpp:42
void did_receive(DataFeedReceiver *receiver, const DataFeed::Messages::StartOfSession &message)
Handle a start of session message.
Definition: market_arbitrage.hpp:167
bool does_cross(const LimitOrderBook &other, Quantity spread=0) const
Check if this book crosses another book.
Definition: limit_order_book.hpp:360
void did_receive(DataFeedReceiver *receiver, const DataFeed::Messages::EndOfSession &message)
Handle an end of session message.
Definition: market_arbitrage.hpp:186
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
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