sasalgo local pos working
This commit is contained in:
1 parent
8569b02f5c
commit
7baaafbeeb
1 file changed
+41
-33
@@ -18,7 +18,6 @@
|
||||
#include "spark/orderman/orders/algo/IAlgoOrder.h"
|
||||
#include "spark/orderman/orders/algo/IAlgoServices.h"
|
||||
#include "spark/orderman/orders/algo/IBeforeLaunchAlgoServices.h"
|
||||
#include "spark/orderman/orders/queue_holder/QueueHolderOrder.h"
|
||||
#include "spark/utils/PBUtils.h"
|
||||
#include "spark/utils/bts_assert.h"
|
||||
#include <algorithm>
|
||||
@@ -341,7 +340,8 @@ class GridQuoteCoordinator {
|
||||
double position,
|
||||
double remaining_buy,
|
||||
double remaining_sell,
|
||||
double lot_sz) {
|
||||
double lot_sz,
|
||||
double mid_price) {
|
||||
std::unordered_map<Price, DesiredOrder> desired_map;
|
||||
for (const auto &d : desired)
|
||||
desired_map[d.price] = d;
|
||||
@@ -379,19 +379,22 @@ class GridQuoteCoordinator {
|
||||
for (const auto &d : desired) {
|
||||
if (matched_prices.contains(d.price))
|
||||
continue; // Already matched in step 1
|
||||
|
||||
double current_position_dollar = std::abs(position) * d.price.value();
|
||||
double order_value = d.qty.full_value_float() * d.price.value();
|
||||
|
||||
if ((current_position_dollar + order_value) > max_position_dollar) {
|
||||
double signed_qty = (d.side == api::SIDE_BUY)
|
||||
? d.qty.full_value_float()
|
||||
: -d.qty.full_value_float();
|
||||
double proposed_position = position + signed_qty;
|
||||
double proposed_exposure = std::abs(proposed_position) * mid_price;
|
||||
|
||||
if (proposed_exposure > max_position_dollar &&
|
||||
std::abs(proposed_position) > std::abs(position)) {
|
||||
LOG(OrderMan, Info,
|
||||
"Skipping order due to dollar position cap: side = {}, price = "
|
||||
"{}, qty = "
|
||||
"{}, "
|
||||
"current = {}, proposed = {}, cap = {}",
|
||||
std::string(d.side == api::SIDE_BUY ? "buy" : "sell"),
|
||||
d.price.value(), d.qty.full_value_float(),
|
||||
current_position_dollar, order_value, max_position_dollar);
|
||||
"Skipping order due to dollar position cap: side = {}, price = "
|
||||
"{}, qty = "
|
||||
"{}, "
|
||||
"current = {}, proposed = {}, cap = {}, mid_price= {}",
|
||||
std::string(d.side == api::SIDE_BUY ? "buy" : "sell"),
|
||||
d.price.value(), d.qty.full_value_float(),
|
||||
position, proposed_position, max_position_dollar, mid_price);
|
||||
continue;
|
||||
}
|
||||
bool has_remaining = (d.side == api::SIDE_BUY)
|
||||
@@ -536,9 +539,9 @@ void GridQuoteCoordinator::launch_missing_orders(
|
||||
"Skipping order due to dollar position cap: side = {}, price = "
|
||||
"{}, qty = "
|
||||
"{}, "
|
||||
"current = {}, proposed = {}, cap = {}",
|
||||
"current = {}, proposed = {}, cap = {}, pos = {}",
|
||||
side_str, d.price.value(), d.qty.full_value_float(),
|
||||
current_position_dollar, order_value, max_position_dollar);
|
||||
current_position_dollar, order_value, max_position_dollar, position);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -590,10 +593,12 @@ void GridQuoteCoordinator::update_quotes(
|
||||
"tick_size = {}, grid_num = {}, grid_interval = {}, position = {}",
|
||||
bid_price, ask_price, order_size, lot_size, tick_size, grid_num,
|
||||
grid_interval, position);
|
||||
|
||||
|
||||
auto book_ask = book.ask().at(0).price();
|
||||
auto book_bid = book.bid().at(0).price();
|
||||
grid_mgr_.update_bounds(
|
||||
bid_price, ask_price, book.bid().at(0).price(),
|
||||
book.ask().at(0).price());
|
||||
bid_price, ask_price,book_bid,
|
||||
book_ask);
|
||||
|
||||
auto desired = compute_desired_orders(
|
||||
bid_price, ask_price, order_size, lot_size, tick_size, grid_num,
|
||||
@@ -604,7 +609,7 @@ void GridQuoteCoordinator::update_quotes(
|
||||
// cancel_outdated_orders(desired);
|
||||
|
||||
// launch_missing_orders(desired, position, rem_b, rem_s, lot_sz);
|
||||
sync_orders(desired, position, rem_b, rem_s, lot_sz);
|
||||
sync_orders(desired, position, rem_b, rem_s, lot_sz, (book_ask+book_bid)/2);
|
||||
|
||||
LOG(OrderMan, Info, "Quote update completed.");
|
||||
}
|
||||
@@ -823,8 +828,10 @@ void SprayAndSkewAlgo::on_child_change(
|
||||
case ChildStatus::COMPLETED:
|
||||
if (prev_child_state.side == api::SIDE_BUY) {
|
||||
me->state->remaining_buy -= state.total_fills.full_value_float();
|
||||
me->state->position+=state.total_fills.full_value_float();
|
||||
} else {
|
||||
me->state->remaining_sell -= state.total_fills.full_value_float();
|
||||
me->state->position-=state.total_fills.full_value_float();
|
||||
}
|
||||
|
||||
LOG(OrderMan, Info,
|
||||
@@ -839,12 +846,13 @@ void SprayAndSkewAlgo::on_child_change(
|
||||
case ChildStatus::CANCELED:
|
||||
LOG(OrderMan, Info, "Child CANCELED: order_key: {} side: {}", ord_key,
|
||||
static_cast<int>(prev_child_state.side));
|
||||
if (prev_child_state.side == api::SIDE_BUY) {
|
||||
me->state->remaining_buy -= state.total_fills.full_value_float();
|
||||
} else {
|
||||
me->state->remaining_sell -= state.total_fills.full_value_float();
|
||||
}
|
||||
break;
|
||||
if (prev_child_state.side == api::SIDE_BUY) {
|
||||
me->state->remaining_buy -= state.total_fills.full_value_float();
|
||||
me->state->position+=state.total_fills.full_value_float();
|
||||
} else {
|
||||
me->state->remaining_sell -= state.total_fills.full_value_float();
|
||||
me->state->position-=state.total_fills.full_value_float();
|
||||
} break;
|
||||
|
||||
default:
|
||||
LOG(OrderMan, Warn, "Unhandled child status: {} for order_key: {}",
|
||||
@@ -987,13 +995,13 @@ void SprayAndSkewAlgo::on_book(SecurityKey key, Book const &book) {
|
||||
book.n_levels());
|
||||
}
|
||||
|
||||
void SprayAndSkewAlgo::on_position(PositionUpdate const &pu) {
|
||||
if (pu.security_id == me->params->security_key.value())
|
||||
me->state->position = pu.long_quantity.full_value_float() -
|
||||
pu.short_quantity.full_value_float();
|
||||
LOG(OrderMan, Info, "sec_id {}, Updated position: long={}, short={}, net={}",
|
||||
pu.security_id, pu.long_quantity.value(), pu.short_quantity.value(),
|
||||
me->state->position);
|
||||
void SprayAndSkewAlgo::on_position(PositionUpdate const &) {
|
||||
// if (pu.security_id == me->params->security_key.value())
|
||||
// me->state->position = pu.long_quantity.full_value_float() -
|
||||
// pu.short_quantity.full_value_float();
|
||||
// LOG(OrderMan, Info, "sec_id {}, Updated position: long={}, short={}, net={}",
|
||||
// pu.security_id, pu.long_quantity.value(), pu.short_quantity.value(),
|
||||
// me->state->position);
|
||||
}
|
||||
|
||||
void SprayAndSkewAlgo::_terminate_algo(
|
||||
|
||||
Reference in new issue
Block a user