Slick Trader 0.11.0
Multi-broker algorithmic trading engine with plugin strategies and a live web dashboard
Loading...
Searching...
No Matches
hyperliquid_order_connector.hpp
Go to the documentation of this file.
1#pragma once
2
4#include <slick/stream_buffer_multiplexer.hpp>
5#include <nlohmann/json.hpp>
6#include <atomic>
7#include <cstdint>
8#include <memory>
9#include <mutex>
10#include <string>
11#include <thread>
12#include <unordered_map>
13#include <unordered_set>
14
15namespace hyperliquid {
16class Info;
17class Exchange;
18}
19
20namespace slick::trader {
21
22using json = nlohmann::json;
23
24struct NewOrderEvent;
25struct ModifyOrderEvent;
26struct CancelOrderEvent;
27using producer_buffer = slick::stream_buffer_multiplexer::producer_buffer;
28
30public:
32 const json& config,
33 slick::stream_buffer_multiplexer &mux,
34 slick::queue<uint8_t>& control_queue,
35 slick::queue<uint8_t>& order_queue
36 );
38
39 void register_order_connector() override;
40
41 bool connect() override;
42 void disconnect() override;
43 bool is_connected() const override { return connected_.load(std::memory_order_relaxed); }
44
45 void start() override;
46 void stop() override;
47 bool is_running() const override { return running_.load(std::memory_order_relaxed); }
48
49private:
50 void run();
51 void process_order_requests();
52 void handle_new_order(const NewOrderEvent& req);
53 void handle_modify_order(const ModifyOrderEvent& req);
54 void handle_cancel_order(const CancelOrderEvent& req);
55
56 void publish_reject(const NewOrderEvent& req, const std::string& reason);
57 void on_user_fill(const nlohmann::json& fill);
58 void on_order_update(const nlohmann::json& update);
59
60 std::atomic_bool running_{false};
61 std::atomic_bool connected_{false};
62
63 bool enabled_{true};
64
65 std::shared_ptr<hyperliquid::Info> info_;
66 std::unique_ptr<hyperliquid::Exchange> exchange_;
67 std::thread worker_thread_;
68
69 std::string shm_name_;
70
71 std::shared_ptr<producer_buffer> event_buffer_;
72 slick::queue<uint8_t>& control_queue_;
73 slick::queue<uint8_t>& request_queue_;
74 uint64_t request_cursor_;
75
76 std::string api_url_{"https://api.hyperliquid.xyz"};
77 std::string private_key_;
78 std::string wallet_address_;
79
80 std::atomic<uint64_t> cloid_counter_{0};
81
82 mutable std::mutex order_map_mutex_;
83 std::unordered_map<std::string, std::string> cloid_to_client_id_; // cloid_raw → client_order_id
84 std::unordered_map<int64_t, std::string> oid_to_client_id_; // oid → client_order_id
85 std::unordered_map<int64_t, std::string> oid_to_instrument_; // oid → instrument
86 std::unordered_set<uint64_t> seen_fill_tids_; // dedup by trade id
87};
88
89} // namespace slick::trader
HyperliquidOrderConnector(const json &config, slick::stream_buffer_multiplexer &mux, slick::queue< uint8_t > &control_queue, slick::queue< uint8_t > &order_queue)
nlohmann::json json
slick::stream_buffer_multiplexer::producer_buffer producer_buffer