Slick Trader 0.11.0
Multi-broker algorithmic trading engine with plugin strategies and a live web dashboard
Loading...
Searching...
No Matches
fee_structure.hpp
Go to the documentation of this file.
1#pragma once
2
4#include <cmath>
5
6namespace slick::trader {
7
8enum class FeeType : uint8_t {
9 PERCENTAGE, // fee = |notional| * rate (e.g. Coinbase: rate = 0.006)
10 FIXED_AMOUNT, // fee = rate per fill (flat amount in quote currency)
11 PER_UNIT // fee = |quantity| * rate (e.g. futures exchange + clearing fees per contract)
12};
13
18
19// Fallback fee computation used when fill event carries no fee (non-Coinbase brokers)
20inline price_t compute_fee(price_t fill_price, qty_t fill_qty, const FeeStructure& fee) {
21 if (fee.rate <= 0.0) return 0;
22 if (fee.type == FeeType::PERCENTAGE) {
23 double notional = std::abs(from_price_t(fill_price) * from_qty_t(fill_qty));
24 return to_price_t(notional * fee.rate);
25 }
26 if (fee.type == FeeType::PER_UNIT) {
27 return to_price_t(std::abs(from_qty_t(fill_qty)) * fee.rate);
28 }
29 return to_price_t(fee.rate); // FIXED_AMOUNT: flat fee per fill
30}
31
32} // namespace slick::trader
double from_price_t(price_t value)
Definition types.hpp:36
price_t to_price_t(double value)
Definition types.hpp:24
price_t compute_fee(price_t fill_price, qty_t fill_qty, const FeeStructure &fee)
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