-
Notifications
You must be signed in to change notification settings - Fork 3
/
robinhoodtrader.h
118 lines (102 loc) · 2.75 KB
/
robinhoodtrader.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#pragma once
#include <curl/curl.h>
#include <string>
#include <nlohmann/json.hpp>
using json = nlohmann::json;
enum Trigger {IMMEDIATE, STOP};
enum OrderType {MARKET, LIMIT};
enum TimeInForce {GFD, GTC };
enum Side {BUY, SELL };
class RobinhoodTrader {
private:
CURL* curl;
struct curl_slist *headers;
public:
RobinhoodTrader();
int login(const std::string& username, const std::string& password, const std::string& qr_code);
std::unique_ptr<json> submit_curl_request( const std::string &url);
static std::size_t write_callback(const char* in, std::size_t size, std::size_t num, std::string* out) {
const std::size_t totalBytes(size * num);
out->append(in, totalBytes);
return totalBytes;
}
json quote_data(const std::string &stock);
float ask_price(const std::string &stock);
float bid_price(const std::string &stock);
int ask_size(const std::string &stock);
int bid_size(const std::string &stock);
json positions();
json positions_nonzero();
json get_account();
json get_orders(const std::string& symbol);
int submit_buy_order( const std::string &symbol,
Side side,
int quantity,
float price,
OrderType order_type,
TimeInForce time_in_force,
Trigger trigger,
float stop_price,
const std::string &instrument_URL
);
int place_limit_buy_order(
const std::string &symbol,
int quantity,
float price,
TimeInForce time_in_force,
const std::string &instrument_URL =""
);
int place_market_buy_order(
const std::string &symbol,
int quantity,
TimeInForce time_in_force,
const std::string &instrument_URL =""
);
int place_stop_loss_buy_order(
const std::string& symbol,
int quantity,
TimeInForce time_in_force,
float stop_price,
const std::string& instrument_URL = ""
);
int place_stop_limit_buy_order(
const std::string& symbol,
int quantity,
float price,
TimeInForce time_in_force,
float stop_price,
const std::string& instrument_URL =""
);
int submit_sell_order(
const std::string& symbol,
Side side,
int quantity,
float price,
OrderType order_type,
TimeInForce time_in_force,
Trigger trigger,
float stop_price,
const std::string& instrument_URL =""
);
int place_market_sell_order(
const std::string& symbol,
int quantity,
TimeInForce time_in_force,
const std::string& instrument_URL =""
);
int place_limit_sell_order(
const std::string& symbol,
int quantity,
float price,
TimeInForce time_in_force,
const std::string& instrument_URL =""
);
int place_stop_loss_sell_order(
const std::string& symbol,
int quantity,
TimeInForce time_in_force,
float stop_price,
const std::string& instrument_URL =""
);
int cancel_order(const std::string &orderId);
};