diff --git a/src/server/sparkd/fill_models/Comparers.h b/src/server/sparkd/fill_models/Comparers.h new file mode 100644 index 000000000..8857d8fb5 --- /dev/null +++ b/src/server/sparkd/fill_models/Comparers.h @@ -0,0 +1,53 @@ +#pragma once + +#include "lib/utils/TimeStamp.h" +#include "server/sparkd/fill_models/ExchangeOrderSnapshot.h" +#include "server/sparkd/fill_models/OrderStatus.h" + +namespace bts { +namespace md { +struct PriceCmp { + bool operator()(const IntPrice &lhs, const IntPrice &rhs) { + return lhs.price() > rhs.price(); + } +}; +struct TransactionTimeCmp { + // bool operator()(const OrderStatus& lhs, const OrderStatus& rhs) { + // return lhs.transaction_time > rhs.transaction_time; + // } + // bool cmp(const std::pair& + // , const bts::utils::TimeStamp& ) + //{ + // return true; + //} + bool comp_member(bts::utils::TimeStamp, bts::utils::TimeStamp) { + return true; + } + bool operator()(const bts::utils::TimeStamp &lhs, + const bts::utils::TimeStamp &rhs) { + return lhs.to_uint64() > rhs.to_uint64(); + } + + bool operator()(const ExchangeOrderSnapshot &lhs, + const ExchangeOrderSnapshot &rhs) { + return lhs.transaction_time.to_uint64() > + rhs.transaction_time.to_uint64(); + } + bool operator()(const OrderStatus &lhs, const OrderStatus &rhs) { + return lhs.transaction_time > rhs.transaction_time; + } + + bool operator()(const google::protobuf::Timestamp &lhs, + const google::protobuf::Timestamp &rhs) { + + if (lhs.seconds() > rhs.seconds()) { + return true; + } else if (lhs.seconds() < rhs.seconds()) { + return false; + } else { + return lhs.nanos() > rhs.nanos(); + } + } +}; +} // namespace md +} // namespace bts \ No newline at end of file diff --git a/src/server/sparkd/fill_models/ExchangeOrderSnapshot.h b/src/server/sparkd/fill_models/ExchangeOrderSnapshot.h new file mode 100644 index 000000000..b008dec43 --- /dev/null +++ b/src/server/sparkd/fill_models/ExchangeOrderSnapshot.h @@ -0,0 +1,20 @@ +#pragma once + +#include "lib/md/MBOProcessor.h" +#include "lib/utils/TimeStamp.h" + +namespace bts { +namespace md { + +struct ExchangeOrderSnapshot { + SnapshotOrder *state; + bts::utils::TimeStamp transaction_time; + uint64_t priority; + bool is_bid; + + ExchangeOrderSnapshot() {} + ExchangeOrderSnapshot(SnapshotOrder *state, TimeStamp transaction_time) + : state(state), transaction_time(transaction_time) {} +}; +} // namespace md +} // namespace bts \ No newline at end of file diff --git a/src/server/sparkd/fill_models/FIFOFillModel.cpp b/src/server/sparkd/fill_models/FIFOFillModel.cpp new file mode 100644 index 000000000..bd37ea45b --- /dev/null +++ b/src/server/sparkd/fill_models/FIFOFillModel.cpp @@ -0,0 +1,125 @@ +#include "lib/config/config.h" +//#include "lib/config/protos/toggles.pb.h" +//#include "lib/utils/ConcurrentPool.h" +//#include "lib/utils/WaitFreeQueue.h" +//#include "lib/utils/thread_manager.h" + +#include +#include +#include +#include +#include +#include + +#ifndef _WIN32 +//#include +//#include +#endif +//#include +//#include +#include "FIFOFillModel.h" + +namespace bts { +namespace md { +// btree::btree_map; +// btree::btree_map< +void FIFOFillModel::on_mbo(const MBOUpdate &order) { + auto result = _exchange_orders.find(order.id); + if (result == _exchange_orders.end()) { + std::map history; + history.insert(std::pair(order.timestamp, order)); + _exchange_orders[order.id] = history; + } else { + result->second.insert( + std::pair(order.timestamp, order)); + } +} + +void FIFOFillModel::on_order(const OrderStatus &order) { + auto result = _orders.find(order.id); + if (result != _orders.end()) { + _remove_order(result->second); + } + if (!order.is_active) + return; + auto orders_by_price = _get_orders_by_price(order.is_bid); + auto price_node = orders_by_price.find(order.price); + if (price_node != orders_by_price.end()) { + price_node->second.orders.insert(order); + } else { + OrdersOfPrice op(order.price); + op.orders.insert(order); + orders_by_price.insert( + std::pair(order.price, op)); + } +} +void FIFOFillModel::on_trade(TimeStamp transaction_time, IntPrice price, + co2::AggressorSide aggressor_side, + std::vector trades) { + switch (aggressor_side) { + case co2::AggressorSide::AGGRESSOR_SIDE_BUY: + break; + default: + break; + } + if (aggressor_side == co2::AggressorSide::AGGRESSOR_SIDE_BUY) { + std::vector::iterator tit = trades.begin(); // lol + if (tit == trades.end()) + return; + auto bts_it = _bts_asks.begin(); + if (bts_it == _bts_asks.end() || bts_it->first.price() > price.price()) + return; + //auto orders_at_price_it = bts_it->second.orders.begin(); + for (; tit != trades.end(); ++tit) { + auto exch_order_hist = _exchange_orders.find(tit->order_id); + if (exch_order_hist == _exchange_orders.end()) { + continue; + } + auto match = exch_order_hist->second.lower_bound(transaction_time); + while (match->second.timestamp >= transaction_time && + match != exch_order_hist->second.begin()) + match--; + if (match->second.timestamp > transaction_time) + continue; + //auto exch_order_time = match->second.timestamp; + // for (; orders_at_price_it != orders_at_price_it-> && orders_at_price_it->transaction_time < exch_order_time; orders_at_price_it++) { + + // } + //if (bts_it->second.tim + } + } +} + +void FIFOFillModel::_order_data_for_side( + bool, std::multiset &, + std::multiset &) { + // if (is_bid) { + + //} + // IntPrice p; + // orders.find(p); + // opposite_side_orders.find(p); +} + +void FIFOFillModel::_flush_crosses() {} + +void FIFOFillModel::_remove_order(const OrderStatus &order) { + auto orders_by_price = _get_orders_by_price(order.is_bid); + auto price_node = orders_by_price.find(order.price); + if (price_node != orders_by_price.end()) { + price_node->second.orders.erase(order); + if (price_node->second.orders.empty()) + orders_by_price.erase(order.price); + } +} + +std::map +FIFOFillModel::_get_orders_by_price(bool is_bid) { + if (is_bid) + return _bts_bids; + return _bts_asks; +} + +// void on_orders_filled(const std::vector& orders); +} // namespace md +} // namespace bts \ No newline at end of file diff --git a/src/server/sparkd/fill_models/FIFOFillModel.h b/src/server/sparkd/fill_models/FIFOFillModel.h new file mode 100644 index 000000000..4617572fa --- /dev/null +++ b/src/server/sparkd/fill_models/FIFOFillModel.h @@ -0,0 +1,103 @@ +#pragma once +#include +#include "server/sparkd/fill_models/IFillModel.h" +#include "server/sparkd/fill_models/Comparers.h" +#include "lib/md/ExchangeOrderKey.h" +#include "lib/md/MBOProcessor.h" +#include "lib/md/IntPrice.h" +#include +#include +#include +#include "server/sparkd/exchange_sim/book/OrderMatcher.h" +#ifndef _WIN32 +#include +#endif + +//typedef std::tuple OrderPricePriority; +//typedef std::tuple OrderPricePriority; + +//using OrdersByPrice std::map, bts::md::PriceCmp>; + +namespace bts { +namespace md { +struct MBOUpdateCmp { + MBOUpdateCmp() {} + MBOUpdateCmp(bool ascending) : ascending(ascending) {} + + bool operator()(MBOUpdate const &, MBOUpdate const &) const { + if (ascending) { + return true; + } + return false; + } + + bool ascending; +}; + +struct OrdersOfPrice { + OrdersOfPrice() {} + OrdersOfPrice(IntPrice price) : price(price), orders() { } + OrdersOfPrice(const OrdersOfPrice& other) : price(other.price), orders(other.orders) { + } + IntPrice price; + std::multiset orders; +}; + +struct PriceCmp { + PriceCmp() {} + + bool operator()(const OrderStatus &lhs, const OrderStatus &rhs) { + double diff = lhs.price.price() - rhs.price.price(); + if (diff > std::numeric_limits::epsilon()) + return true; + if (diff < -std::numeric_limits::epsilon()) + return false; + return lhs.id.value() > rhs.id.value(); + } + + bool operator()(const IntPrice& lhs, const IntPrice& rhs) { + double diff = lhs.price() - rhs.price(); + if (diff > std::numeric_limits::epsilon()) + return true; + if (diff < -std::numeric_limits::epsilon()) + return false; + return false; + } + + bool operator()(const OrdersOfPrice& lhs, const OrdersOfPrice& rhs) { + double diff = lhs.price.price() - rhs.price.price(); + if (diff > std::numeric_limits::epsilon()) + return true; + if (diff < -std::numeric_limits::epsilon()) + return false; + return false; + } +}; + +struct OrderSideData { + std::map, PriceCmp> bts_orders; +}; + +struct FIFOFillModel : public IFillModel { + void on_order(const OrderStatus &order) override; + void on_mbo(const MBOUpdate &update) override; + void on_trade(bts::utils::TimeStamp transaction_time, IntPrice price, co2::AggressorSide aggressor_side, std::vector real_trades) override; + private: + //btree::btree_set dirty; + //btree::btree_map working_orders; + //std::multiset _bids, _asks; + + std::map _bts_bids, _bts_asks; + std::unordered_map> _exchange_orders; + //std::unordered_map> _exchange_orders; + std::unordered_map _orders; + + //void check_crosses(); + //void on_orders_filled(const std::vector& orders); + void _order_data_for_side(bool is_bid, std::multiset& orders, std::multiset& opposite_side_orders); + void _remove_order(const OrderStatus& order); + void _flush_crosses(); + std::map _get_orders_by_price(bool is_bid); +}; +} // namespace md +} // namespace bts \ No newline at end of file diff --git a/src/server/sparkd/fill_models/FillData.h b/src/server/sparkd/fill_models/FillData.h new file mode 100644 index 000000000..ba3ba76e3 --- /dev/null +++ b/src/server/sparkd/fill_models/FillData.h @@ -0,0 +1,36 @@ +#pragma once + +#include + +namespace bts { +namespace md { +struct FillData { + private: + std::vector> fills; + + public: + uint32_t qty; + uint32_t filled_qty; + ExchangeOrderKey id; + + double avg_price; + + FillData() {} + FillData(uint64_t qty, uint64_t filled_qty) + : qty(qty), filled_qty(filled_qty) {} + + uint32_t working_qty() { return qty > filled_qty ? qty - filled_qty : 0; } + bool is_filled() { return filled_qty >= working_qty; } + uint32_t add_partial_fill(IntPrice price, uint32_t qty) { + if (working_qty() < qty) { + qty = working_qty(); + } + if (qty > 0) { + filled_qty += qty; + fills.push_back(std::make_pair(price, qty)); + } + return qty; + } +}; +} // namespace md +} // namespace bts \ No newline at end of file diff --git a/src/server/sparkd/fill_models/FillOp.cpp b/src/server/sparkd/fill_models/FillOp.cpp new file mode 100644 index 000000000..e69de29bb diff --git a/src/server/sparkd/fill_models/FillOp.h b/src/server/sparkd/fill_models/FillOp.h new file mode 100644 index 000000000..12851a68a --- /dev/null +++ b/src/server/sparkd/fill_models/FillOp.h @@ -0,0 +1,67 @@ +//#pragma once +// +//#include "lib/md/ExchangeOrderKey.h" +//#include "lib/md/IntPrice.h" +//#include "lib/utils/TimeStamp.h" +//#include +// +//namespace bts { +//namespace md { +// +//struct WorkingOrdersOfPrice { +// IntPrice price; +// std::map orders; +//}; +//using WorkingBook = std::map; +//using WorkingBookIter = std::map::iterator; +//using WorkingOrderIter = +// std::map::iterator; +//struct FillOp { +// bool is_done() { return _price_level == _book_end; } +// +// void fill_against(const ExchangeOrderSnapshot &exch_order, +// uint32_t fill_qty) { +// if (_curr_fill.is_filled()) { +// // todo: assert (curr_fill should be immediately reset when it is +// // 'filled') +// } +// if (!_ensure_working()) +// return; +// // requirements to 'steal' fill from the exchange order: +// // 1) transaction time 'at or before' that of the exch order. +// // 2) price 'better than or equal to' that of the exchange order +// // (i.e., >= for bids, <= for asks). +// while (_ensure_working()) { +// uint32_t remaining_qty = _curr_order().working_qty(); +// } +// } +// +// private: +// WorkingBookIter _price_level, _book_end; +// WorkingOrderIter _order, _order_end; +// FillData _curr_fill; +// // std::vector> _fills; +// std::unordered_map _fills; +// bool _done; +// +// const OrderStatus &_curr_order() { return _order->second; } +// +// // advance enumeration until _order +// // points to a working order. +// bool _ensure_working() { +// while (true) { +// while (_order != _order_end) { +// if (_order->second.is_working()) +// return true; +// _order++; +// } +// if (++_price_level == _book_end) { +// break; +// } +// _order = _price_level->second.orders.begin(); +// } +// return false; +// } +//}; +//} // namespace md +//} // namespace bts diff --git a/src/server/sparkd/fill_models/IFillModel.h b/src/server/sparkd/fill_models/IFillModel.h new file mode 100644 index 000000000..116806c38 --- /dev/null +++ b/src/server/sparkd/fill_models/IFillModel.h @@ -0,0 +1,35 @@ +#pragma once + +#include +#include "server/sparkd/fill_models/OrderStatus.h" +#include "TradeDetail.h" +#include "lib/md/IntPrice.h" +#include "lib/md/protos/Co2.pb.h" +//#include "lib/domain_model/Security.pb.h" +#include "lib/md/MBOProcessor.h" +#include +#include "lib/utils/PBUtils.h" +#include "lib/utils/TimeStamp.h" +//#include "lib/api/services/OrderService.pb.h" +//#include "lib/orderman/orders/Order.h" +//#include "server/sparkd/exchange_sim/book/Order.h" + +//using bts::ex_sim::Order = OrderStatus; +//using Side = bts::api::Side; + + +namespace bts { +namespace md { + using Timestamp = bts::utils::TimeStamp; + using TimeStamp = bts::utils::TimeStamp; + struct PriceCmp; + struct TransactionTimeCmp; + + class IFillModel { + public: + virtual void on_order(const OrderStatus& ) { } + virtual void on_mbo(const MBOUpdate& ){ } + virtual void on_trade(bts::utils::TimeStamp , IntPrice , co2::AggressorSide, std::vector) {} + }; +} // namespace md +} // namespace bts \ No newline at end of file diff --git a/src/server/sparkd/fill_models/MBOBook.cpp b/src/server/sparkd/fill_models/MBOBook.cpp new file mode 100644 index 000000000..08856204e --- /dev/null +++ b/src/server/sparkd/fill_models/MBOBook.cpp @@ -0,0 +1,170 @@ +#include "server/sparkd/fill_models/MBOBook.h" + +namespace bts { +namespace md { + // FillOp + + bool FillOp::is_done() { return _price_level == _book_end; } + + void FillOp::fill_against(const ExchangeOrderSnapshot &exch_order, + uint32_t fill_qty) { + while (fill_qty > 0 && _ensure_working(exch_order)) { + if (_curr_fill == nullptr) { + // todo: assert (the purpose of _ensure_working is to prepare + // curr_fill for manipulation) + } + if (_curr_fill->is_filled()) { + // todo: assert (curr_fill should be immediately reset when it is + // 'filled') + } + if (_curr_fill->filled_qty == 0) { + } + fill_qty -= _curr_fill.add_partial_fill(_curr_order().price, fill_qty); + } + } + + const OrderStatus& FillOp::_curr_order() { return _order->second; } + + // requirements to 'steal' fill from the exchange order: + // 1) transaction time 'at or before' that of the exch order. + // 2) price 'better than or equal to' that of the exchange order + // (i.e., >= for bids, <= for asks). + bool FillOp::_can_steal_fill(const ExchangeOrderSnapshot &exch_order, + const OrderStatus &order) { + return order.transaction_time.to_uint64() <= exch_order.transaction_time.to_uint64() && + (exch_order.is_bid ? + order.price.price() >= exch_order.state->price.price() : + order.price.price() <= exch_order.state->price.price()); + } + + bool FillOp::_ensure_working(const ExchangeOrderSnapshot& exch_order) { + if (_curr_fill != nullptr && _curr_fill->working_qty() > 0) + return true; + // God forbid, something terrible happens and ++_price_level never reaches _book_end + // limit the num of loops to an arbitrary large number + int num_loops = 0; + while (true) { + if (++num_loops > 16384) { + // todo: log a warning/error (something bad must have happened) + break; + } + while (_order != _order_end) { + if (_order->second.is_working() && _can_steal_fill(exch_order, _order->second)) { + auto p = _fills.insert_or_assign(_order->second.id, FillData(_order->second.size, _order->second.filled_quantity)); + if (p.second) { + // todo: maybe assert (order should not already have a corresponding fill item) + } + _curr_fill = &(p.first->second); + return true; + } + _order++; + } + if (++_price_level == _book_end) { + break; + } + _order = _price_level->second.orders.begin(); + } + return false; + } + + + +// uint32_t MBOBook::_assign_fills(const OrderStatus& target_order, uint32_t +// filled_qty, OrderAtPriceIter order_it, OrderAtPriceIter order_end, +// PriceNodeIter price_node_it, PriceNodeIter price_node_end) { if (order_it == +// order_end) { if (price_node_it == price_node_end) return filled_qty; +// +//} +// int32_t working_qty = target_order.working_quantity(); +// while (filled_qty < working_qty) { +// if (order_it == order_end) { +// if (++price_node_it == price_node_end) +// break; +// price_node_it->second.orders.begin(); +//} +//} +// return filled_qty; +//} +void MBOBook::assign_fills( + TimeStamp transaction_time, + std::map::iterator working_orders_it, + std::map::iterator working_orders_end, + std::vector> &fills_out, + std::vector trades) { + if (working_orders_it == working_orders_it) + return; + FillData curr_fill; + for (auto tit = trades.begin(); tit != trades.end(); tit++) { + auto exch_order_it = _cache.find(tit->order_id); + if (exch_order_it != _cache.end()) { + SnapshotOrder state; + TimeStamp exch_order_transaction_time; + if (exch_order_it->second.try_match_order( + transaction_time, *state, *exch_order_transaction_time)) { + if (exch_order_transaction_time.to_uint64() > + working_orders_it->first) { + uint32_t wkg_qty = working_orders_it->second.working_quantity(); + } + } + } + } +} +void MBOBook::_assign_fills(const OrderStatus &target_order, + const std::vector &trades, + std::vector> &fills) { + +} +void MBOBook::_assign_fills( + TimeStamp transaction_time, WorkingBookIter worders_it, + WorkingBookIter worders_end, + std::vector> &fills_out, + std::vector::iterator trades_it, + std::vector::iterator trades_end) { + if (trades_it == trades_end || worders_it == worders_end) + return; + FillData fill_data; + worders_it->second.orders.begin(); + do { + FillData curr_fill; + ExchangeOrderSnapshot exch_order; + if (_find_exchange_order(transaction_time, trades_it->order_id, + exch_order)) { + } + trades_it++; + } while (trades_it != trades_end); +} +bool MBOBook::_find_exchange_order(TimeStamp transaction_time, + ExchangeOrderKey order_id, + ExchangeOrderSnapshot &result) { + auto order_hist = _cache.find(order_id); + if (order_hist == _cache.end()) { + return false; + } + auto state_it = order_hist->second.lower_bound(transaction_time); + if (state_it == order_hist->second.begin()) + return false; + auto priority = --state_it->second.priority; + while (state_it != order_hist->second.begin() && + --state_it->second.priority == priority) + ; + result = state_it->second; + return true; +} +bool MBOBook::_find_working_order( + TimeStamp transaction_time, IntPrice price, bool is_bid, + std::map::iterator &it) { + auto working_orders = is_bid ? _working_bids : _working_asks; + auto price_level_it = working_orders.begin(); + if (price_level_it == working_orders.end()) + return false; + + it = working_orders.lower_bound(transaction_time); + if (it == working_orders.begin()) + return false; + it--; + return true; +} +// void MBOBook::_assign_fills(const OrderStatus& target_order, +} // namespace md +} // namespace bts +} // namespace bts \ No newline at end of file diff --git a/src/server/sparkd/fill_models/MBOBook.h b/src/server/sparkd/fill_models/MBOBook.h new file mode 100644 index 000000000..3ca9f0fc4 --- /dev/null +++ b/src/server/sparkd/fill_models/MBOBook.h @@ -0,0 +1,123 @@ +#pragma once + +#include "lib/md/ExchangeOrderKey.h" +#include "lib/md/IntPrice.h" +#include "lib/md/MBOProcessor.h" +#include "server/sparkd/fill_models/Comparers.h" +#include "server/sparkd/fill_models/ExchangeOrderSnapshot.h" +#include "server/sparkd/fill_models/FillData.h" +#include "server/sparkd/fill_models/OrderStatus.h" +#include "server/sparkd/fill_models/TradeDetail.h" +#include +#include +#include +#include + +namespace bts { +namespace md { +using TimeStamp = bts::utils::TimeStamp; + +using OrderAtPriceIter = + std::map::iterator; +// std::multiset::iterator; +using MarketOrderHistory = + std::map; + +using WorkingOrderIter = + std::map::iterator; + +struct MarketOrdersOfPrice { + IntPrice price; + std::map orders; + + MarketOrdersOfPrice() {} + MarketOrdersOfPrice(IntPrice price) : price(price), orders() {} + MarketOrdersOfPrice(const OrdersOfPrice &other) + : price(other.price), orders(other.orders) {} + + bool try_match_order(TimeStamp transaction_time, SnapshotOrder &result, + TimeStamp &result_transaction_time) { + auto it = orders.lower_bound(transaction_time); + if (it == orders.begin()) { + return false; + } + do { + it--; + } while (it->first.to_uint64() > transaction_time); + result_transaction_time = it->first; + result = it->second; + return true; + } +}; + +struct WorkingOrdersOfPrice { + IntPrice price; + std::map orders; +}; + +using PriceNodes = std::map; +using PriceNodeIter = std::map::iterator; +using WorkingBook = std::map; +using WorkingBookIter = std::map::iterator; +using WorkingOrderIter = + std::map::iterator; + +struct FillOp { + bool is_done(); + void fill_against(const ExchangeOrderSnapshot &exch_order, uint32_t fill_qty); + + FillOp(WorkingBookIter price_level, WorkingBookIter price_level_end, + WorkingOrderIter order, WorkingOrderIter order_end) + : price_level(price_level), price_level_end(price_level_end), + order(order), order_end(order_end) { + + } + + private: + WorkingBookIter _price_level, _book_end; + WorkingOrderIter _order, _order_end; + FillData* _curr_fill; + // curr_fill is added to the map in anticipation of being the order to get filled. + // if the + ExchangeOrderKey _curr_fill_id; + // std::vector> _fills; + std::unordered_map _fills; + + const OrderStatus &_curr_order(); + // advance enumeration until _order + // points to a working order. + bool _ensure_working(const ExchangeOrderSnapshot& exch_order); + bool _can_steal_fill(const ExchangeOrderSnapshot &exch_order, + const OrderStatus &order); +}; + +struct MBOBook { + void on_mbo_update(MBOUpdate); + void + assign_fills(TimeStamp transaction_time, + std::vector> &fills_out, + std::vector trades); + bool try_get_history(); + + private: + std::unordered_map _cache; + std::map _working_bids, _working_asks; + // std::map + void + _assign_fills(TimeStamp transaction_time, WorkingBookIter working_orders_it, + WorkingBookIter working_orders_end, + std::vector> &fills_out, + std::vector::iterator trades_it, + std::vector::iterator trades_end); + bool _find_exchange_order(TimeStamp transaction_time, + ExchangeOrderKey order_id, + ExchangeOrderSnapshot &result); + // bool _find_working_orders(IntPrice price, std::map::iterator &it); + // std::vector>& fills); uint32_t + // _assign_fills(const OrderStatus &target_order, uint32_t filled_qty); +}; +} // namespace md +} // namespace bts \ No newline at end of file diff --git a/src/server/sparkd/fill_models/OrderStatus.h b/src/server/sparkd/fill_models/OrderStatus.h new file mode 100644 index 000000000..7d397d6b4 --- /dev/null +++ b/src/server/sparkd/fill_models/OrderStatus.h @@ -0,0 +1,30 @@ +#pragma once + +#include "lib/md/IntPrice.h" +#include "lib/md/ExchangeOrderKey.h" +#include +#include "lib/utils/PBUtils.h" +#include "lib/utils/TimeStamp.h" + +namespace bts { +namespace md { + +struct OrderStatus { + ExchangeOrderKey id; + bts::utils::TimeStamp transaction_time; + IntPrice price; + int32_t size; + int32_t filled_quantity; + bool is_active, is_bid; + + OrderStatus() + : id(0), price(IntPrice(0, 0)), size(0), + filled_quantity(0), is_active(false), is_bid(false) {} + + int32_t working_quantity() { return size - filled_quantity; } + bool is_filled() { return filled_quantity >= size; } + bool is_working() { return size >= filled_quantity; } +}; + +} // namespace md +} // namespace bts \ No newline at end of file diff --git a/src/server/sparkd/fill_models/TradeDetail.h b/src/server/sparkd/fill_models/TradeDetail.h new file mode 100644 index 000000000..0ed2cfd80 --- /dev/null +++ b/src/server/sparkd/fill_models/TradeDetail.h @@ -0,0 +1,19 @@ +#pragma once +#include "lib/md/ExchangeOrderKey.h" + +namespace bts { +namespace md { + +enum class AggressorSide { + Buy, Sell, None +}; + +struct TradeDetail { + const ExchangeOrderKey& order_id; + const uint32_t& last_qty; + + TradeDetail(ExchangeOrderKey order_id, uint32_t last_qty) + : order_id(order_id), last_qty(last_qty) { } +}; +} // namespace md +} // namespace bts \ No newline at end of file