Slick Sim 0.10.1
Exchange simulator that shadows real venues for risk-free strategy testing
Loading...
Searching...
No Matches
hyperliquid_rest_order_gateway.hpp
Go to the documentation of this file.
1#pragma once
2
4#include <nlohmann/json.hpp>
5#include <string>
6#include <unordered_map>
7#include <memory>
8#include <hyperliquid/info.hpp>
9
10struct us_listen_socket_t;
11using json = nlohmann::json;
12
13namespace hyperliquid { class Info; }
14
16
18 std::string body_buffer;
19 std::string user_id;
20};
21
23 // std::thread thread_;
24 // us_listen_socket_t* listen_socket_ = nullptr;
25 // uWS::Loop* loop_ = nullptr;
26 uint32_t port_ = 4003;
27 std::string base_url_;
28 std::string default_wallet_;
29
30 // asset index -> coin name (e.g. 3 -> "ETH")
31 // std::unordered_map<int, std::string> asset_to_coin_;
32 // coin name -> asset index
33 // std::unordered_map<std::string, int> coin_to_asset_;
34 hyperliquid::Info info_;
35
36public:
38 slick::queue<Request>& request_queue,
39 slick::queue<OrderResponse>& response_queue);
40 ~HyperliquidRestOrderGateway() override = default;
41
42 std::string_view type() const noexcept override { return "REST"; }
43
44 // void start() override;
45 // void stop() override {
46 // if (listen_socket_ && loop_) {
47 // // Closing the listen socket must happen on the loop's own thread;
48 // // doing it cross-thread races with the loop's poll handles.
49 // loop_->defer([this]() {
50 // if (listen_socket_) {
51 // us_listen_socket_close(0, listen_socket_);
52 // listen_socket_ = nullptr;
53 // }
54 // });
55 // }
56 // if (thread_.joinable()) thread_.join();
57 // }
58
59private:
60 // void load_meta();
61 std::string extract_wallet(const json& body, uWS::HttpRequest* req);
62 std::string coin_for_asset(int asset_index) const;
63 void setup_routes(uWS::App& app) override;
64
65 void handle_exchange(uWS::HttpResponse<false>* res, uWS::HttpRequest* req);
66 void handle_info(uWS::HttpResponse<false>* res, uWS::HttpRequest* req);
67
68 void process_order_action(uWS::HttpResponse<false>* res,
69 const json& action, const std::string& user_id);
70 void process_cancel_action(uWS::HttpResponse<false>* res,
71 const json& action, const std::string& user_id);
72 void process_cancel_by_cloid_action(uWS::HttpResponse<false>* res,
73 const json& action, const std::string& user_id);
74 void process_batch_modify_action(uWS::HttpResponse<false>* res,
75 const json& action, const std::string& user_id);
76};
77
78} // end namespace slick::sim::order_gateway::hyperliquid_hl
HyperliquidRestOrderGateway(const json &config, slick::queue< Request > &request_queue, slick::queue< OrderResponse > &response_queue)
RestWsOrderGateway(Venue venue, slick::queue< Request > &request_queue, slick::queue< OrderResponse > &response_queue, uint32_t port)
nlohmann::json json
Definition order.hpp:16