22 #ifndef STRATEGIES_MOMENTUM_HPP
23 #define STRATEGIES_MOMENTUM_HPP
25 #include "data_feed/receiver.hpp"
26 #include "order_entry/client.hpp"
27 #include "maths/probability.hpp"
28 #include "maths/rate_of_change.hpp"
29 #include <nlohmann/json.hpp>
51 asio::steady_timer timer;
57 std::atomic<bool> is_running;
64 double decision_boundary;
67 inline void start_strategy() {
68 timer.expires_after(std::chrono::milliseconds(sleep_time));
69 timer.async_wait([
this](
const std::error_code& error) {
71 std::cout <<
"Momentum::start_strategy - " << error << std::endl;
87 size = std::clamp(size, min_size, max_size);
91 OrderEntry::Messages::ORDER_PRICE_MARKET,
97 OrderEntry::Messages::ORDER_PRICE_MARKET,
99 OrderEntry::Side::Sell
111 asio::io_context& feed_context,
112 asio::io_context& context,
113 nlohmann::json options
117 asio::ip::make_address(options[
"data_feed"][
"listen"].get<std::string>()),
118 asio::ip::make_address(options[
"data_feed"][
"group"].get<std::string>()),
119 options[
"data_feed"][
"port"].get<uint16_t>(),
124 options[
"order_entry"][
"host"].get<std::string>(),
125 std::to_string(options[
"order_entry"][
"port"].get<uint16_t>())
128 sleep_time(options[
"strategy"][
"sleep_time"].get<uint32_t>()),
129 P_act(options[
"strategy"][
"P_act"].get<double>()),
131 roc(options[
"strategy"][
"history_size"].get<uint32_t>()),
132 max_size(options[
"strategy"][
"max_size"].get<
OrderEntry::Quantity>()),
133 decision_boundary(options[
"strategy"][
"decision_boundary"].get<double>()) {
139 client.
set_capital(options[
"order_entry"][
"capital"].get<OrderEntry::ClientCapital>());
140 client.
set_shares(options[
"order_entry"][
"shares"].get<OrderEntry::ClientShares>());
150 std::cerr <<
"received start of session when already running" << std::endl;
165 if (not is_running) {
166 std::cerr <<
"received end of session when not running" << std::endl;
205 #endif // STRATEGIES_MOMENTUM_HPP
Logic for sending/receiving application messages in a financial market.
Definition: authorizer.hpp:26
Price last_price() const
Return the current price of the asset using last prices.
Definition: limit_order_book.hpp:283
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
void set_shares(ClientShares shares_)
Set the client shares to a new value.
Definition: client.hpp:273
void did_receive(DataFeedReceiver *receiver, const DataFeed::Messages::DeleteOrder &message)
Handle a delete order message.
Definition: momentum.hpp:193
void did_receive(DataFeedReceiver *receiver, const DataFeed::Messages::Clear &message)
Handle a clear book message.
Definition: momentum.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
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::EndOfSession &message)
Handle an end of session message.
Definition: momentum.hpp:164
ClientCapital get_capital() const
Return the amount of capital the client currently has.
Definition: client.hpp:291
void did_receive(DataFeedReceiver *receiver, const DataFeed::Messages::AddOrder &message)
Handle an add order message.
Definition: momentum.hpp:186
A client for interacting with the direct market access server.
Definition: client.hpp:42
void set_capital(ClientCapital capital_)
Set the client capital to a new value.
Definition: client.hpp:285
void did_receive(DataFeedReceiver *receiver, const DataFeed::Messages::Trade &message)
Handle a trade message.
Definition: momentum.hpp:200
The momentum trader strategy logic.
Definition: momentum.hpp:42
Username make_username(std::string username)
Make a username from the given input string.
Definition: messages.hpp:46
void process(Observation observation)
Calculate the next RoC based on observation .
Definition: rate_of_change.hpp:99
uint32_t Quantity
A type for order quantities.
Definition: messages.hpp:133
Momentum(asio::io_context &feed_context, asio::io_context &context, nlohmann::json options)
Initialize the strategy.
Definition: momentum.hpp:110
RoC get_rate_of_change() const
Return the current rate of change (RoC).
Definition: rate_of_change.hpp:86
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
void did_receive(DataFeedReceiver *receiver, const DataFeed::Messages::StartOfSession &message)
Handle a start of session message.
Definition: momentum.hpp:148