Advertisement
den4ik2003

Untitled

Dec 13th, 2024
19
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.42 KB | None | 0 0
  1. #include <algo/market_making/mexc_spot/refund.hpp>
  2.  
  3. using namespace mira;
  4. using namespace mira::marketmaking;
  5.  
  6. RefundMarketMakerManager::RefundMarketMakerManager(
  7. std::shared_ptr<SharedState> shared_state,
  8. const std::vector<const ticker_t*>& symbols,
  9. const field_t& params
  10. ) : shared_state_(shared_state)
  11. {
  12. for (size_t i = 0; i < symbols.size(); ++i) {
  13. refunds_[symbols[i]] = RefundFond {
  14. .quote_refund_fond = (params.v()[i].count("quote_refund_fond") ? params.v()[i].at("quote_refund_fond").f() : 0),
  15. .base_refund_fond = (params.v()[i].count("base_refund_fond") ? params.v()[i].at("base_refund_fond").f() : 0),
  16. };
  17. }
  18. }
  19.  
  20. void RefundMarketMakerManager::shift_grid(order_limit_grid_event& grid, double shift_value, e_side side) {
  21. if (shift_value <= 0) {
  22. return;
  23. }
  24. if (side == e_side::BUY) {
  25. for (auto& level : grid.bids) {
  26. level.price -= (shift_value + grid.symbol->price_step.to_double());
  27. }
  28. }
  29. if (side == e_side::SELL) {
  30. for (auto& level : grid.asks) {
  31. level.price += (shift_value + grid.symbol->price_step.to_double());
  32. }
  33. }
  34. }
  35.  
  36. void RefundMarketMakerManager::organic_orders_correction(std::vector<order_event>& orders) {
  37. double min_bid = 1'000'000'000.;
  38. double max_ask = 0;
  39. for (const auto& order : orders) {
  40. auto book = shared_state_->get_data_getter(order.symbol).get_best_book(); // organic
  41. auto grid = order.get<order_limit_grid_event>();
  42. if (grid.asks[0].price <= book.bid_price) {
  43. if (refunds_[order.symbol].base_refund_fond > 5) {
  44. max_ask = std::max(max_ask, book.bid_price);
  45. }
  46. }
  47. if (grid.bids[0].price >= book.ask_price) {
  48. if (refunds_[order.symbol].quote_refund_fond > 5) {
  49. min_bid = std::min(min_bid, book.ask_price);
  50. }
  51. }
  52. } // OK
  53.  
  54. for (auto& order : orders) {
  55. auto book = shared_state_->get_data_getter(order.symbol).get_best_book();
  56. auto grid = order.get<order_limit_grid_event>();
  57.  
  58. if (grid.asks[0].price <= book.bid_price) {
  59. if (refunds_[order.symbol].base_refund_fond > 5) {
  60. shift_grid(grid, min_bid - grid.asks[0].price, e_side::SELL);
  61.  
  62. extended_limit_request_t refund_req; // а где здесь что не post-only???
  63. refund_req.price = book.bid_price;
  64. refund_req.quantity = std::min(refunds_[order.symbol].base_refund_fond / book.bid_price, book.bid_quantity);
  65. grid.asks.push_back(refund_req);
  66.  
  67. } else {
  68. shift_grid(grid, book.bid_price - grid.asks[0].price, e_side::SELL);
  69. }
  70. } else {
  71. shift_grid(grid, min_bid - grid.asks[0].price, e_side::SELL);
  72. }
  73.  
  74. if (grid.bids[0].price >= book.ask_price) {
  75. if (refunds_[order.symbol].quote_refund_fond > 5) {
  76. shift_grid(grid, grid.bids[0].price - max_ask, e_side::BUY);
  77.  
  78. extended_limit_request_t refund_req; // а где здесь что не post-only???
  79. refund_req.price = book.ask_price;
  80. refund_req.quantity = std::min(refunds_[order.symbol].quote_refund_fond / book.ask_price, book.ask_quantity);
  81. grid.asks.push_back(refund_req);
  82. } else {
  83. shift_grid(grid, grid.bids[0].price - book.ask_price, e_side::BUY);
  84. }
  85. } else {
  86. shift_grid(grid, grid.bids[0].price - max_ask, e_side::BUY);
  87. }
  88.  
  89. order.set(grid);
  90.  
  91. }
  92. }
  93.  
  94. std::vector<order_event> RefundMarketMakerManager::collaborative_orders_correction(const std::vector<order_event>& orders) {
  95. double min_bid = orders.back().get<order_limit_grid_event>().bids[0].price;
  96. double max_ask = orders.back().get<order_limit_grid_event>().asks[0].price;
  97. for (const auto& order : orders) {
  98. auto data_getter = shared_state_->get_data_getter(order.symbol);
  99. if (refunds_[order.symbol].quote_refund_fond >= 5) {
  100. min_bid = std::min(min_bid, order.get<order_limit_grid_event>().bids[0].price);
  101. }
  102. if (refunds_[order.symbol].base_refund_fond >= 5) {
  103. max_ask = std::min(max_ask, order.get<order_limit_grid_event>().asks[0].price);
  104. }
  105. }
  106. for (const auto& order : orders) {
  107.  
  108. }
  109.  
  110. }
  111.  
  112.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement