-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtrade_execution.h
52 lines (38 loc) · 1.64 KB
/
trade_execution.h
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
49
50
#ifndef TRADE_EXECUTION_H
#define TRADE_EXECUTION_H
#include "websocket_handler.h"
#include <nlohmann/json.hpp>
#include <string>
#include <functional>
#include <map>
#include <atomic>
// Forward declaration to avoid circular dependency
class WebSocketHandler;
using json = nlohmann::json;
class TradeExecution {
public:
explicit TradeExecution(WebSocketHandler& websocket); // Constructor requiring WebSocketHandler reference
~TradeExecution(); // Destructor for cleanup
// Order Management Functions
json authenticate(const std::string& client_id, const std::string& client_secret);
json getInstruments(const std::string& currency, const std::string& kind, bool expired);
json placeBuyOrder(const std::string& instrument_name, double amount, double price);
json cancelOrder(const std::string& order_id);
json modifyOrder(const std::string& order_id, double new_price, double new_amount);
json getOrderBook(const std::string& instrument_name);
json getPositions();
// Market Data Handling
void handleMarketData(const json& data);
void onMarketDataReceived(const json& market_data);
// Subscriber Management
void addMarketDataSubscriber(const std::string& symbol, std::function<void(const json&)> callback);
private:
WebSocketHandler& websocket_;
// Map to store subscribers and their callback functions
std::map<std::string, std::function<void(const json&)>> market_data_subscribers_;
// Atomic counter for generating unique JSON-RPC IDs
static std::atomic<int> request_id;
// Helper function to generate the next request ID
int getNextRequestId();
};
#endif // TRADE_EXECUTION_H