Files
spark/src/lib/orderman/ccapi/CCAPIOrderState.h
T

74 lines
2.5 KiB
C++

#pragma once
#include "CCAPIOrderCallbackMsgs.h"
#include "lib/api/services/OrderService.pb.h"
#include "lib/domain/OrderStatus.h"
#include "lib/domain_model/Security.h"
#include "lib/domain_model/Security.pb.h"
#include "lib/domain_model/SecurityKey.h"
#include "lib/orderman/orderman_utils/orderman_common.h"
#include "lib/os/os.h"
#include <bits/stdint-uintn.h>
#include <boost/container/small_vector.hpp>
#include <functional>
namespace bts::orderman {
typedef std::string CCAPIOrderKey;
// this is the data returned from the Mux callback to the gateway
struct CCAPIOrderState {
struct CCAPITradeRecord {};
struct CCAPISpreadLegFill {};
const api::Security &security;
const OrderKey order_key;
const std::string cc_create_corr_id;
const bts::api::Side side;
CCAPIOrderKey cc_order_key = "";
bts::api::orderman::OrderStatus status =
bts::api::orderman::OrderStatus::ORDER_STATUS_PENDING_WORKING;
double order_px =
os::nan(); // copied only when qty > 0 (might not ne needed anymore)
double order_qty = 0;
double total_fills = 0;
double avg_filled_price = 0;
double last_filled_qty = 0;
double last_filled_price = 0;
// these are not the accumulated trades but trades that happened bw last
// callback and now
boost::container::small_vector<CCAPITradeMsg, 2> cb_trades = {};
// leg fills corresponding to the above trades (optional) (lifecycle is the
// same as above
boost::container::small_vector<CCAPISpreadLegFill, 4> cb_leg_trades = {};
size_t n_cbs = 0;
size_t n_outgoing_mods = 0;
CCAPIOrderState(
const api::Security &security,
OrderKey order_key,
const std::string &cc_create_corr_id,
bts::api::Side side,
double order_px,
double order_qty)
: security(security), order_key(order_key),
cc_create_corr_id(cc_create_corr_id), side(side), order_px(order_px),
order_qty(order_qty) {}
};
inline std::ostream &operator<<(std::ostream &out, CCAPIOrderState const &s) {
out << "sec_key: " << s.security.id() << " order_key: " << s.order_key
<< " cc_create_corr_id: " << s.cc_create_corr_id
<< " side: " << securities::side_name(s.side)
<< " cc_order_key: " << s.cc_order_key
<< " status: " << api::orderman::OrderStatus_Name(s.status)
<< " order_px: " << s.order_px << " order_qty: " << s.order_qty
<< " total_fills: " << s.total_fills
<< " avg_filled_price: " << s.avg_filled_price
<< " n_trades: " << s.cb_trades.size();
return out;
}
} // namespace bts::orderman