Class: Robinhood::REST::API
- Inherits:
-
Object
- Object
- Robinhood::REST::API
- Defined in:
- lib/robinhood-ruby/rest/api.rb
Direct Known Subclasses
Instance Method Summary collapse
- #account ⇒ Object
- #buy(symbol, instrument_id, price, quantity) ⇒ Object
- #cancel_order(order_id) ⇒ Object
- #dividends ⇒ Object
- #endpoints ⇒ Object
- #fundamentals(ticker) ⇒ Object
- #headers ⇒ Object
- #historicals(symbol, intv, span) ⇒ Object
- #instruments(symbol) ⇒ Object
- #investment_profile ⇒ Object
- #limit_buy(symbol, instrument_id, price, quantity) ⇒ Object
- #limit_sell(symbol, instrument_id, price, quantity) ⇒ Object
- #markets ⇒ Object
- #news(symbol) ⇒ Object
- #orders ⇒ Object
- #positions ⇒ Object
- #quote_data(symbol) ⇒ Object
- #sell(symbol, instrument_id, price, quantity) ⇒ Object
- #sp500_down ⇒ Object
- #sp500_up ⇒ Object
- #splits(instrument) ⇒ Object
- #stop_loss_sell(symbol, instrument_id, price, quantity) ⇒ Object
- #user ⇒ Object
-
#watchlists ⇒ Object
def create_watch_list(name, callback) return _request.post({ uri: @api_url + @endpoints.watchlists, form: { name: name } }, callback); end.
Instance Method Details
#account ⇒ Object
4 5 6 7 |
# File 'lib/robinhood-ruby/rest/api.rb', line 4 def account raw_response = HTTParty.get(endpoints[:accounts], headers: headers) JSON.parse(raw_response.body) end |
#buy(symbol, instrument_id, price, quantity) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/robinhood-ruby/rest/api.rb', line 44 def buy(symbol, instrument_id, price, quantity) raw_response = HTTParty.post( endpoints[:orders], body: { "account" => @private.account, "instrument" => @api_url + "instruments/#{instrument_id}/", "price" => price, "quantity" => quantity, "side" => "buy", "symbol" => symbol, "time_in_force" => "gfd", "trigger" => "immediate", "type" => "market" }.as_json, headers: headers ) end |
#cancel_order(order_id) ⇒ Object
134 135 136 137 |
# File 'lib/robinhood-ruby/rest/api.rb', line 134 def cancel_order(order_id) raw_response = HTTParty.post(@api_url + "orders/#{order_id}/cancel/", headers: headers) raw_response.code == 200 end |
#dividends ⇒ Object
34 35 36 37 |
# File 'lib/robinhood-ruby/rest/api.rb', line 34 def dividends raw_response = HTTParty.get(endpoints[:dividends], headers: headers) JSON.parse(raw_response.body) end |
#endpoints ⇒ Object
197 198 199 |
# File 'lib/robinhood-ruby/rest/api.rb', line 197 def endpoints Endpoints.endpoints end |
#fundamentals(ticker) ⇒ Object
14 15 16 17 |
# File 'lib/robinhood-ruby/rest/api.rb', line 14 def fundamentals(ticker) raw_response = HTTParty.get(endpoints[:fundamentals], query: {"symbols" => ticker.upcase}, headers: headers) JSON.parse(raw_response.body) end |
#headers ⇒ Object
193 194 195 |
# File 'lib/robinhood-ruby/rest/api.rb', line 193 def headers Client.headers end |
#historicals(symbol, intv, span) ⇒ Object
188 189 190 191 |
# File 'lib/robinhood-ruby/rest/api.rb', line 188 def historicals(symbol, intv, span) raw_response = HTTParty.get(endpoints[:quotes] + "historicals/" + symbol, query: {"interval" => intv.to_s, "span" => span}, headers: headers) JSON.parse(raw_response.body) end |
#instruments(symbol) ⇒ Object
19 20 21 22 |
# File 'lib/robinhood-ruby/rest/api.rb', line 19 def instruments(symbol) raw_response = HTTParty.get(endpoints[:instruments], query: {"query" => symbol.upcase}, headers: headers) JSON.parse(raw_response.body) end |
#investment_profile ⇒ Object
9 10 11 12 |
# File 'lib/robinhood-ruby/rest/api.rb', line 9 def investment_profile raw_response = HTTParty.get(endpoints[:investment_profile], headers: headers) JSON.parse(raw_response.body) end |
#limit_buy(symbol, instrument_id, price, quantity) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/robinhood-ruby/rest/api.rb', line 62 def limit_buy(symbol, instrument_id, price, quantity) raw_response = HTTParty.post( endpoints[:orders], body: { "account" => @private.account, "instrument" => @api_url + "instruments/#{instrument_id}/", "price" => price, "quantity" => quantity, "side" => "buy", "symbol" => symbol, "time_in_force" => "gfd", "trigger" => "immediate", "type" => "limit" }.as_json, headers: headers ) end |
#limit_sell(symbol, instrument_id, price, quantity) ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/robinhood-ruby/rest/api.rb', line 98 def limit_sell(symbol, instrument_id, price, quantity) raw_response = HTTParty.post( endpoints[:orders], body: { "account" => @private.account, "instrument" => @api_url + "instruments/#{instrument_id}/", "price" => price, "quantity" => quantity, "side" => "sell", "symbol" => symbol, "time_in_force" => "gfd", "trigger" => "immediate", "type" => "limit" }.as_json, headers: headers ) end |
#markets ⇒ Object
154 155 156 157 |
# File 'lib/robinhood-ruby/rest/api.rb', line 154 def markets raw_response = HTTParty.get(endpoints[:markets], headers: headers) JSON.parse(raw_response.body) end |
#news(symbol) ⇒ Object
149 150 151 152 |
# File 'lib/robinhood-ruby/rest/api.rb', line 149 def news(symbol) raw_response = HTTParty.get(endpoints[:news] + symbol.to_s + "/", headers: headers) JSON.parse(raw_response.body) end |
#orders ⇒ Object
39 40 41 42 |
# File 'lib/robinhood-ruby/rest/api.rb', line 39 def orders raw_response = HTTParty.get(endpoints[:orders], headers: headers) JSON.parse(raw_response.body) end |
#positions ⇒ Object
139 140 141 142 |
# File 'lib/robinhood-ruby/rest/api.rb', line 139 def positions(instrument_id) raw_response = HTTParty.get(@private.account + "/positions/#{instrument_id}/", headers: headers) JSON.parse(raw_response.body) end |
#quote_data(symbol) ⇒ Object
24 25 26 27 |
# File 'lib/robinhood-ruby/rest/api.rb', line 24 def quote_data(symbol) raw_response = HTTParty.post(@api_url + "quotes/#{symbol}/", headers: headers) JSON.parse(raw_response.body) end |
#sell(symbol, instrument_id, price, quantity) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/robinhood-ruby/rest/api.rb', line 80 def sell(symbol, instrument_id, price, quantity) raw_response = HTTParty.post( endpoints[:orders], body: { "account" => @private.account, "instrument" => @api_url + "instruments/#{instrument_id}/", "price" => price, "quantity" => quantity, "side" => "sell", "symbol" => symbol, "time_in_force" => "gfd", "trigger" => "immediate", "type" => "market" }.as_json, headers: headers ) end |
#sp500_down ⇒ Object
164 165 166 167 |
# File 'lib/robinhood-ruby/rest/api.rb', line 164 def sp500_down raw_response = HTTParty.get(endpoints[:sp500_down], headers: headers) JSON.parse(raw_response.body) end |
#sp500_up ⇒ Object
159 160 161 162 |
# File 'lib/robinhood-ruby/rest/api.rb', line 159 def sp500_up raw_response = HTTParty.get(endpoints[:sp500_up], headers: headers) JSON.parse(raw_response.body) end |
#splits(instrument) ⇒ Object
183 184 185 186 |
# File 'lib/robinhood-ruby/rest/api.rb', line 183 def splits(instrument) raw_response = HTTParty.get(endpoints[:instruments] + "/splits/" + instrument.to_s, headers: headers) JSON.parse(raw_response.body) end |
#stop_loss_sell(symbol, instrument_id, price, quantity) ⇒ Object
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/robinhood-ruby/rest/api.rb', line 116 def stop_loss_sell(symbol, instrument_id, price, quantity) raw_response = HTTParty.post( endpoints[:orders], body: { "account" => @private.account, "instrument" => @api_url + "instruments/#{instrument_id}/", "stop_price" => price, "quantity" => quantity, "side" => "sell", "symbol" => symbol, "time_in_force" => "gtc", "trigger" => "stop", "type" => "market" }.as_json, headers: headers ) end |
#user ⇒ Object
29 30 31 32 |
# File 'lib/robinhood-ruby/rest/api.rb', line 29 def user raw_response = HTTParty.get(endpoints[:user], headers: headers) JSON.parse(raw_response.body) end |
#watchlists ⇒ Object
def create_watch_list(name, callback) return _request.post({
uri: @api_url + @endpoints.watchlists,
form: {
name: name
}
}, callback); end
178 179 180 181 |
# File 'lib/robinhood-ruby/rest/api.rb', line 178 def watchlists raw_response = HTTParty.get(endpoints[:watchlists], headers: headers) JSON.parse(raw_response.body) end |