class Robinhood::REST::API

Public Instance Methods

account() click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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() click to toggle source
# 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
fundamentals(ticker) click to toggle source
# 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
historicals(symbol, intv, span) click to toggle source
# 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) click to toggle source
# 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() click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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() click to toggle source
# 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) click to toggle source
# 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() click to toggle source
# 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(instrument_id) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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() click to toggle source
# 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() click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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() click to toggle source
# 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() click to toggle source

def create_watch_list(name, callback) return _request.post({

uri: @api_url + @endpoints.watchlists,
form: {
  name: name
}

}, callback); end

# 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

Private Instance Methods

endpoints() click to toggle source
# File lib/robinhood-ruby/rest/api.rb, line 199
def endpoints
  Endpoints.endpoints
end
headers() click to toggle source
# File lib/robinhood-ruby/rest/api.rb, line 195
def headers
  Client.headers
end