Slick Trader 0.11.0
Multi-broker algorithmic trading engine with plugin strategies and a live web dashboard
Loading...
Searching...
No Matches
position.hpp
Go to the documentation of this file.
1#pragma once
2
4#include <string>
5#include <string_view>
6#include <cstdint>
7
8namespace slick::trader {
9
10// Position for a single instrument
11struct Position {
12 std::string instrument;
13 qty_t quantity{0}; // Current position size (positive = long, negative = short)
14 price_t avg_price{0}; // Average entry price
15 price_t realized_pnl{0}; // Gross realized PnL from closed trades
16 price_t realized_fees{0}; // Fees on closed trades (entry fees of closed lots + their exit fees)
17 price_t open_fees{0}; // Entry fees paid for currently held lots (not yet realized)
18 double multiplier{1.0}; // Contract multiplier: currency value of a one-unit price move per unit held (ES: 50)
19 uint64_t last_update_time{0}; // Last update timestamp
20
21 Position() = default;
22 Position(std::string_view inst) : instrument(std::string(inst)) {}
23
24 bool is_flat() const { return quantity == 0; }
25 bool is_long() const { return quantity > 0; }
26 bool is_short() const { return quantity < 0; }
27
28 // Calculate unrealized PnL given current market price
29 double get_unrealized_pnl(price_t mark_price) const {
30 if (is_flat()) return 0.0;
32 }
33
34 double get_total_pnl(price_t mark_price) const {
35 return from_price_t(realized_pnl) + get_unrealized_pnl(mark_price);
36 }
37};
38
39} // namespace slick::trader
double from_price_t(price_t value)
Definition types.hpp:36
int64_t qty_t
Definition types.hpp:17
int64_t price_t
Definition types.hpp:16
double from_qty_t(qty_t value)
Definition types.hpp:40
double get_total_pnl(price_t mark_price) const
Definition position.hpp:34
double get_unrealized_pnl(price_t mark_price) const
Definition position.hpp:29
Position(std::string_view inst)
Definition position.hpp:22
bool is_short() const
Definition position.hpp:26