robinhood-api 0.1.2 → 0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/robinhood.rb +18 -32
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 62a6dc3419346454e7b5a4a62f938e7ca68170d4
|
4
|
+
data.tar.gz: 77f67aa1c30b2ea275fe37f31bc4f2b4d34180f1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: db1173fd2cd51d4849dd4e9980240682b273a13fc201b30aa0171c2a384d78b1ac81d65372502d4d71eccf184955c1f70bcf21acb94a2f3798e808dca5b7ca79
|
7
|
+
data.tar.gz: 061f95a38ea6a4533cb8be536d44012feaeb84f9a423fd1c63f55dab7ad91ac49b0761b0d79572b936cf59e698e7031d7a2cb7d80100f8faa72b6ed8e61881ef
|
data/lib/robinhood.rb
CHANGED
@@ -3,17 +3,11 @@ module RobinhoodModule
|
|
3
3
|
names.each do |name|
|
4
4
|
m = instance_method(name)
|
5
5
|
define_method(name) do |*args, &block|
|
6
|
-
|
7
|
-
|
8
|
-
if token_compliant?(name)
|
9
|
-
m.bind(self).(*args, &block)
|
10
|
-
else
|
11
|
-
puts "You have to run the login(<username>, <password>) method or a Robinhood.new instance before running the #{name} method"
|
12
|
-
exit 1
|
13
|
-
end
|
6
|
+
if token_compliant?(name)
|
7
|
+
m.bind(self).(*args, &block)
|
14
8
|
else
|
15
|
-
puts "You
|
16
|
-
exit
|
9
|
+
puts "You have to run the login(<username>, <password>) method or a Robinhood.new instance before running the #{name} method"
|
10
|
+
exit 1
|
17
11
|
end
|
18
12
|
end
|
19
13
|
end
|
@@ -64,8 +58,8 @@ module RobinhoodModule
|
|
64
58
|
JSON.parse(raw_response.body)
|
65
59
|
end
|
66
60
|
|
67
|
-
def portfolio
|
68
|
-
raw_response = HTTParty.get("https://api.robinhood.com/accounts/#{
|
61
|
+
def portfolio(account_number)
|
62
|
+
raw_response = HTTParty.get("https://api.robinhood.com/accounts/#{account_number}/portfolio/", headers: headers)
|
69
63
|
JSON.parse(raw_response.body)
|
70
64
|
end
|
71
65
|
|
@@ -79,11 +73,11 @@ module RobinhoodModule
|
|
79
73
|
JSON.parse(raw_response.body)
|
80
74
|
end
|
81
75
|
|
82
|
-
def buy(symbol, instrument_id, price, quantity)
|
76
|
+
def buy(account_number, symbol, instrument_id, price, quantity)
|
83
77
|
raw_response = HTTParty.post(
|
84
78
|
endpoints[:orders],
|
85
79
|
body: {
|
86
|
-
'account' => "https://api.robinhood.com/accounts/#{
|
80
|
+
'account' => "https://api.robinhood.com/accounts/#{account_number}/",
|
87
81
|
'instrument' => "https://api.robinhood.com/instruments/#{instrument_id}/",
|
88
82
|
'price' => price,
|
89
83
|
'quantity' => quantity,
|
@@ -97,11 +91,11 @@ module RobinhoodModule
|
|
97
91
|
)
|
98
92
|
end
|
99
93
|
|
100
|
-
def limit_buy(symbol, instrument_id, price, quantity)
|
94
|
+
def limit_buy(account_number, symbol, instrument_id, price, quantity)
|
101
95
|
raw_response = HTTParty.post(
|
102
96
|
endpoints[:orders],
|
103
97
|
body: {
|
104
|
-
'account' => "https://api.robinhood.com/accounts/#{
|
98
|
+
'account' => "https://api.robinhood.com/accounts/#{account_number}/",
|
105
99
|
'instrument' => "https://api.robinhood.com/instruments/#{instrument_id}/",
|
106
100
|
'price' => price,
|
107
101
|
'quantity' => quantity,
|
@@ -115,11 +109,11 @@ module RobinhoodModule
|
|
115
109
|
)
|
116
110
|
end
|
117
111
|
|
118
|
-
def sell(symbol, instrument_id, price, quantity)
|
112
|
+
def sell(account_number, symbol, instrument_id, price, quantity)
|
119
113
|
raw_response = HTTParty.post(
|
120
114
|
endpoints[:orders],
|
121
115
|
body: {
|
122
|
-
'account' => "https://api.robinhood.com/accounts/#{
|
116
|
+
'account' => "https://api.robinhood.com/accounts/#{account_number}/",
|
123
117
|
'instrument' => "https://api.robinhood.com/instruments/#{instrument_id}/",
|
124
118
|
'price' => price,
|
125
119
|
'quantity' => quantity,
|
@@ -133,11 +127,11 @@ module RobinhoodModule
|
|
133
127
|
)
|
134
128
|
end
|
135
129
|
|
136
|
-
def limit_sell(symbol, instrument_id, price, quantity)
|
130
|
+
def limit_sell(account_number, symbol, instrument_id, price, quantity)
|
137
131
|
raw_response = HTTParty.post(
|
138
132
|
endpoints[:orders],
|
139
133
|
body: {
|
140
|
-
'account' => "https://api.robinhood.com/accounts/#{
|
134
|
+
'account' => "https://api.robinhood.com/accounts/#{account_number}/",
|
141
135
|
'instrument' => "https://api.robinhood.com/instruments/#{instrument_id}/",
|
142
136
|
'price' => price,
|
143
137
|
'quantity' => quantity,
|
@@ -151,11 +145,11 @@ module RobinhoodModule
|
|
151
145
|
)
|
152
146
|
end
|
153
147
|
|
154
|
-
def stop_loss_sell(symbol, instrument_id, price, quantity)
|
148
|
+
def stop_loss_sell(account_number, symbol, instrument_id, price, quantity)
|
155
149
|
raw_response = HTTParty.post(
|
156
150
|
endpoints[:orders],
|
157
151
|
body: {
|
158
|
-
'account' => "https://api.robinhood.com/accounts/#{
|
152
|
+
'account' => "https://api.robinhood.com/accounts/#{account_number}/",
|
159
153
|
'instrument' => "https://api.robinhood.com/instruments/#{instrument_id}/",
|
160
154
|
'stop_price' => price,
|
161
155
|
'quantity' => quantity,
|
@@ -174,8 +168,8 @@ module RobinhoodModule
|
|
174
168
|
raw_response.code == 200
|
175
169
|
end
|
176
170
|
|
177
|
-
def positions(instrument_id)
|
178
|
-
raw_response = HTTParty.get("https://api.robinhood.com/accounts/#{
|
171
|
+
def positions(account_number, instrument_id)
|
172
|
+
raw_response = HTTParty.get("https://api.robinhood.com/accounts/#{account_number}/positions/#{instrument_id}/", headers: headers)
|
179
173
|
JSON.parse(raw_response.body)
|
180
174
|
end
|
181
175
|
|
@@ -215,14 +209,6 @@ module RobinhoodModule
|
|
215
209
|
}
|
216
210
|
end
|
217
211
|
|
218
|
-
def prerequisites?(method)
|
219
|
-
if methodlist.include?(method)
|
220
|
-
return ENV['ROBINHOOD_USERNAME'] && ENV['ROBINHOOD_PASSWORD']
|
221
|
-
else
|
222
|
-
return true
|
223
|
-
end
|
224
|
-
end
|
225
|
-
|
226
212
|
def token_compliant?(method)
|
227
213
|
|
228
214
|
if methodlist.include?(method)
|