Slick Trader 0.11.0
Multi-broker algorithmic trading engine with plugin strategies and a live web dashboard
Loading...
Searching...
No Matches
position_event.hpp
Go to the documentation of this file.
1#pragma once
2
5#include <cstring>
6#include <string_view>
7#include <type_traits>
8
9namespace slick::trader {
10
11constexpr size_t MAX_STRATEGY_ID_LENGTH = 64;
12
13#pragma pack(push, 1)
14
15// Position update event (published to position_update_queue)
16struct PositionUpdateEvent : public Event {
18 qty_t quantity; // Current position
19 price_t avg_price; // Average entry price
20 price_t realized_pnl; // Realized PnL
22
30
31 void set_strategy_id(std::string_view id) {
32 size_t len = std::min(id.size(), MAX_STRATEGY_ID_LENGTH - 1);
33 std::memcpy(strategy_id, id.data(), len);
34 strategy_id[len] = '\0';
35 }
36};
37
38// PnL snapshot event (published to pnl_update_queue)
39struct PnLUpdateEvent : public Event {
44
51
52 void set_strategy_id(std::string_view id) {
53 size_t len = std::min(id.size(), MAX_STRATEGY_ID_LENGTH - 1);
54 std::memcpy(strategy_id, id.data(), len);
55 strategy_id[len] = '\0';
56 }
57};
58
59#pragma pack(pop)
60
61static_assert(std::is_trivially_copyable_v<PositionUpdateEvent>);
62static_assert(std::is_trivially_copyable_v<PnLUpdateEvent>);
63
64} // namespace slick::trader
constexpr size_t MAX_STRATEGY_ID_LENGTH
int64_t qty_t
Definition types.hpp:17
int64_t price_t
Definition types.hpp:16
Event(EventType t=EventType::TRADE)
Definition event.hpp:63
void set_strategy_id(std::string_view id)
char strategy_id[MAX_STRATEGY_ID_LENGTH]
char strategy_id[MAX_STRATEGY_ID_LENGTH]
void set_strategy_id(std::string_view id)