Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <algo/market_making/mexc_spot/refund.hpp>
- using namespace mira;
- using namespace mira::marketmaking;
- RefundMarketMakerManager::RefundMarketMakerManager(
- std::shared_ptr<SharedState> shared_state,
- const std::vector<const ticker_t*>& symbols,
- const field_t& params
- ) : shared_state_(shared_state)
- {
- for (size_t i = 0; i < symbols.size(); ++i) {
- refunds_[symbols[i]] = RefundFond {
- .quote_refund_fond = (params.v()[i].count("quote_refund_fond") ? params.v()[i].at("quote_refund_fond").f() : 0),
- .base_refund_fond = (params.v()[i].count("base_refund_fond") ? params.v()[i].at("base_refund_fond").f() : 0),
- };
- }
- }
- void RefundMarketMakerManager::shift_grid(order_limit_grid_event& grid, double shift_value, e_side side) {
- if (shift_value <= 0) {
- return;
- }
- if (side == e_side::BUY) {
- for (auto& level : grid.bids) {
- level.price -= (shift_value + grid.symbol->price_step.to_double());
- }
- }
- if (side == e_side::SELL) {
- for (auto& level : grid.asks) {
- level.price += (shift_value + grid.symbol->price_step.to_double());
- }
- }
- }
- void RefundMarketMakerManager::organic_orders_correction(std::vector<order_event>& orders) {
- double min_bid = 1'000'000'000.;
- double max_ask = 0;
- for (const auto& order : orders) {
- auto book = shared_state_->get_data_getter(order.symbol).get_best_book(); // organic
- auto grid = order.get<order_limit_grid_event>();
- if (grid.asks[0].price <= book.bid_price) {
- if (refunds_[order.symbol].base_refund_fond > 5) {
- max_ask = std::max(max_ask, book.bid_price);
- }
- }
- if (grid.bids[0].price >= book.ask_price) {
- if (refunds_[order.symbol].quote_refund_fond > 5) {
- min_bid = std::min(min_bid, book.ask_price);
- }
- }
- } // OK
- for (auto& order : orders) {
- auto book = shared_state_->get_data_getter(order.symbol).get_best_book();
- auto grid = order.get<order_limit_grid_event>();
- if (grid.asks[0].price <= book.bid_price) {
- if (refunds_[order.symbol].base_refund_fond > 5) {
- shift_grid(grid, min_bid - grid.asks[0].price, e_side::SELL);
- extended_limit_request_t refund_req; // а где здесь что не post-only???
- refund_req.price = book.bid_price;
- refund_req.quantity = std::min(refunds_[order.symbol].base_refund_fond / book.bid_price, book.bid_quantity);
- grid.asks.push_back(refund_req);
- } else {
- shift_grid(grid, book.bid_price - grid.asks[0].price, e_side::SELL);
- }
- } else {
- shift_grid(grid, min_bid - grid.asks[0].price, e_side::SELL);
- }
- if (grid.bids[0].price >= book.ask_price) {
- if (refunds_[order.symbol].quote_refund_fond > 5) {
- shift_grid(grid, grid.bids[0].price - max_ask, e_side::BUY);
- extended_limit_request_t refund_req; // а где здесь что не post-only???
- refund_req.price = book.ask_price;
- refund_req.quantity = std::min(refunds_[order.symbol].quote_refund_fond / book.ask_price, book.ask_quantity);
- grid.asks.push_back(refund_req);
- } else {
- shift_grid(grid, grid.bids[0].price - book.ask_price, e_side::BUY);
- }
- } else {
- shift_grid(grid, grid.bids[0].price - max_ask, e_side::BUY);
- }
- order.set(grid);
- }
- }
- std::vector<order_event> RefundMarketMakerManager::collaborative_orders_correction(const std::vector<order_event>& orders) {
- double min_bid = orders.back().get<order_limit_grid_event>().bids[0].price;
- double max_ask = orders.back().get<order_limit_grid_event>().asks[0].price;
- for (const auto& order : orders) {
- auto data_getter = shared_state_->get_data_getter(order.symbol);
- if (refunds_[order.symbol].quote_refund_fond >= 5) {
- min_bid = std::min(min_bid, order.get<order_limit_grid_event>().bids[0].price);
- }
- if (refunds_[order.symbol].base_refund_fond >= 5) {
- max_ask = std::min(max_ask, order.get<order_limit_grid_event>().asks[0].price);
- }
- }
- for (const auto& order : orders) {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement