-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfetch_meta.cpp
More file actions
48 lines (41 loc) · 1.64 KB
/
fetch_meta.cpp
File metadata and controls
48 lines (41 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <hyperliquid/rest/InfoApi.h>
#include <hyperliquid/rest/RestListener.h>
#include <hyperliquid/rest/RestMessageParser.h>
#include <hyperliquid/rest/InfoEndpointListener.h>
#include <hyperliquid/types/InfoEndpointTypes.h>
#include <iostream>
#include <thread>
#include <chrono>
#include <atomic>
class MetaPrinter : public hyperliquid::RestListener, public hyperliquid::InfoEndpointListener {
public:
std::atomic<bool> done{false};
// hyperliquid::RestListener — raw message arrives here
void onMessage(const std::string& message, hyperliquid::InfoEndpointType type) override {
hyperliquid::RestMessageParser parser(*this);
parser.parse(message, type);
}
// hyperliquid::InfoEndpointListener — parsed response arrives here
void onMeta(const hyperliquid::MetaResponse& response) override {
std::cout << "Universe: " << response.universe.size() << " assets" << std::endl;
std::cout << std::endl;
for (const auto& asset : response.universe) {
std::cout << asset.name
<< " szDecimals=" << asset.szDecimals
<< " maxLeverage=" << asset.maxLeverage
<< std::endl;
}
done = true;
}
};
int main() {
MetaPrinter printer;
hyperliquid::InfoApi api(hyperliquid::Environment::Mainnet, printer);
std::cout << "Fetching meta from Hyperliquid... (dex=xyz)" << std::endl;
api.sendRequest(hyperliquid::InfoEndpointType::Meta, {{"dex", "xyz"}});
// Wait for the async response
while (!printer.done) {
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
return 0;
}