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
- #dividends ⇒ Object
- #fundamentals(ticker) ⇒ Object
- #historicals(symbol, intv, span) ⇒ Object
- #instruments(symbol) ⇒ Object
- #investment_profile ⇒ Object
- #markets ⇒ Object
- #news(symbol) ⇒ Object
- #orders ⇒ Object
- #place_buy_order(options) ⇒ Object
-
#place_order(options) ⇒ Object
def cancel_order(order) if(order.cancel){ return _request.post({ uri: _apiUrl + order.cancel }, callback); }else{ callback({message: order.state==“cancelled” ? “Order already cancelled.” : “Order cannot be cancelled.”, order: order }, null, null); }; }.
- #place_sell_order(options) ⇒ Object
- #positions ⇒ Object
- #quote_data(symbol) ⇒ Object
- #sp500_down ⇒ Object
- #sp500_up ⇒ Object
- #splits(instrument) ⇒ 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 8 9 |
# File 'lib/robinhood-ruby/rest/api.rb', line 4 def account url = URI(@api_url + @endpoints[:accounts]) response = http_request(url) puts response.read_body JSON.parse(response.read_body) end |
#dividends ⇒ Object
47 48 49 50 51 52 |
# File 'lib/robinhood-ruby/rest/api.rb', line 47 def dividends url = URI(@api_url + @endpoints[:dividends]) response = http_request(url) puts response.read_body JSON.parse(response.read_body) end |
#fundamentals(ticker) ⇒ Object
18 19 20 21 22 23 |
# File 'lib/robinhood-ruby/rest/api.rb', line 18 def fundamentals(ticker) url = URI(@api_url + @endpoints[:fundamentals] + "?symbols=" + ticker.to_s) response = http_request(url) puts response.read_body JSON.parse(response.read_body) end |
#historicals(symbol, intv, span) ⇒ Object
175 176 177 178 179 180 |
# File 'lib/robinhood-ruby/rest/api.rb', line 175 def historicals(symbol, intv, span) url = URI(@api_url + @endpoints[:quotes] + "historicals/" + symbol + "?interval" + intv.to_s + "&span=" + span) response = http_request(url) puts response.read_body JSON.parse(response.read_body) end |
#instruments(symbol) ⇒ Object
25 26 27 28 29 30 |
# File 'lib/robinhood-ruby/rest/api.rb', line 25 def instruments(symbol) url = URI(@api_url + @endpoints[:instruments] + "?query=" + symbol.to_s) response = http_request(url) puts response.read_body JSON.parse(response.read_body) end |
#investment_profile ⇒ Object
11 12 13 14 15 16 |
# File 'lib/robinhood-ruby/rest/api.rb', line 11 def investment_profile url = URI(@api_url + @endpoints[:investment_profile]) response = http_request(url) puts response.read_body JSON.parse(response.read_body) end |
#markets ⇒ Object
131 132 133 134 135 136 |
# File 'lib/robinhood-ruby/rest/api.rb', line 131 def markets url = URI(@api_url + @endpoints[:markets]) response = http_request(url) puts response.read_body JSON.parse(response.read_body) end |
#news(symbol) ⇒ Object
124 125 126 127 128 129 |
# File 'lib/robinhood-ruby/rest/api.rb', line 124 def news(symbol) url = URI(@api_url + @endpoints[:news] + symbol.to_s + "/") response = http_request(url) puts response.read_body JSON.parse(response.read_body) end |
#orders ⇒ Object
54 55 56 57 58 59 |
# File 'lib/robinhood-ruby/rest/api.rb', line 54 def orders url = URI(@api_url + @endpoints[:orders]) response = http_request(url) puts response.read_body JSON.parse(response.read_body) end |
#place_buy_order(options) ⇒ Object
107 108 109 110 |
# File 'lib/robinhood-ruby/rest/api.rb', line 107 def place_buy_order() [:transaction] = 'buy' place_order() end |
#place_order(options) ⇒ Object
def cancel_order(order)
if(order.cancel){
return _request.post({
uri: _apiUrl + order.cancel
}, callback);
}else{
callback({message: order.state=="cancelled" ? "Order already cancelled." : "Order cannot be cancelled.", order: order }, null, null);
};
}
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 |
# File 'lib/robinhood-ruby/rest/api.rb', line 71 def place_order() url = URI(@api_url + @endpoints[:orders]) http = Net::HTTP.new(url.host, url.port) http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_NONE form = { account: _private.account, instrument: .instrument.url, price: .bid_price, stop_price: .stop_price, quantity: .quantity, side: .transaction, symbol: .instrument.symbol.toUpperCase(), time_in_force: .time || 'gfd', trigger: .trigger || 'immediate', type: .type || 'market' } request = Net::HTTP::Post.new(url) request["accept"] = '*/*' request["accept-encoding"] = 'gzip, deflate' request["accept-language"] = 'en;q=1, fr;q=0.9, de;q=0.8, ja;q=0.7, nl;q=0.6, it;q=0.5' request["content-type"] = 'multipart/form-data; boundary=---011000010111000001101001' request["x-robinhood-api-version"] = '1.0.0' request["connection"] = 'keep-alive' request["user-agent"] = 'Robinhood/823 (iPhone; iOS 7.1.2; Scale/2.00)' request["authorization"] = 'Token ' + @private[:auth_token] request["cache-control"] = 'no-cache' request.body = "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"account\"\r\n\r\n"+form[:account]+"\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"instrument\"\r\n\r\n"+form[:instrument]+"\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"price\"\r\n\r\n"+form[:price]+"\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"stop_price\"\r\n\r\n"+form[:stop_price]+"\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"quantity\"\r\n\r\n"+form[:quantity]+"\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"side\"\r\n\r\n"+form[:side]+"\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"symbol\"\r\n\r\n"+form[:symbol]+"\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"time_in_force\"\r\n\r\n"+form[:time_in_force]+"\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"trigger\"\r\n\r\n"+form[:trigger]+"\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"type\"\r\n\r\n"+form[:type]+"\r\n-----011000010111000001101001--" response = http.request(request) puts response.read_body JSON.parse(response.read_body) end |
#place_sell_order(options) ⇒ Object
112 113 114 115 |
# File 'lib/robinhood-ruby/rest/api.rb', line 112 def place_sell_order() [:transaction] = 'sell' place_order() end |
#positions ⇒ Object
117 118 119 120 121 122 |
# File 'lib/robinhood-ruby/rest/api.rb', line 117 def positions url = URI(@api_url + @endpoints[:positions]) response = http_request(url) puts response.read_body JSON.parse(response.read_body) end |
#quote_data(symbol) ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/robinhood-ruby/rest/api.rb', line 32 def quote_data(symbol) symbol = symbol.is_a?(Array) ? symbol.join(',') : symbol; url = URI(@api_url + @endpoints[:quotes] + "?symbols=" + symbol.to_s) response = http_request(url) puts response.read_body JSON.parse(response.read_body) end |
#sp500_down ⇒ Object
145 146 147 148 149 150 |
# File 'lib/robinhood-ruby/rest/api.rb', line 145 def sp500_down url = URI(@api_url + @endpoints[:sp500_down]) response = http_request(url) puts response.read_body JSON.parse(response.read_body) end |
#sp500_up ⇒ Object
138 139 140 141 142 143 |
# File 'lib/robinhood-ruby/rest/api.rb', line 138 def sp500_up url = URI(@api_url + @endpoints[:sp500_up]) response = http_request(url) puts response.read_body JSON.parse(response.read_body) end |
#splits(instrument) ⇒ Object
168 169 170 171 172 173 |
# File 'lib/robinhood-ruby/rest/api.rb', line 168 def splits(instrument) url = URI(@api_url + @endpoints[:instruments] + "/splits/" + instrument.to_s) response = http_request(url) puts response.read_body JSON.parse(response.read_body) end |
#user ⇒ Object
40 41 42 43 44 45 |
# File 'lib/robinhood-ruby/rest/api.rb', line 40 def user url = URI(@api_url + @endpoints[:user]) response = http_request(url) puts response.read_body JSON.parse(response.read_body) end |
#watchlists ⇒ Object
def create_watch_list(name, callback) return _request.post({
uri: @api_url + @endpoints.watchlists,
form: {
name: name
}
}, callback); end
161 162 163 164 165 166 |
# File 'lib/robinhood-ruby/rest/api.rb', line 161 def watchlists url = URI(@api_url + @endpoints[:watchlists]) response = http_request(url) puts response.read_body JSON.parse(response.read_body) end |