Class: Robinhood::REST::API

Inherits:
Object
  • Object
show all
Defined in:
lib/robinhood-ruby/rest/api.rb

Direct Known Subclasses

Client

Instance Method Summary collapse

Instance Method Details

#accountObject



4
5
6
7
# File 'lib/robinhood-ruby/rest/api.rb', line 4

def 
  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.,
      "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

#dividendsObject



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

#endpointsObject



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

#headersObject



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_profileObject



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.,
      "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.,
      "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

#marketsObject



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

#ordersObject



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

#positionsObject



139
140
141
142
# File 'lib/robinhood-ruby/rest/api.rb', line 139

def positions(instrument_id)
  raw_response = HTTParty.get(@private. + "/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.,
      "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_downObject



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_upObject



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.,
      "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

#userObject



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

#watchlistsObject

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