Module: StockFighter::ApiMixin::TradingApi
- Included in:
- StockFighter::ApiMixin
- Defined in:
- lib/stock_fighter/api_mixin/trading_api.rb
Instance Method Summary collapse
- #cancel_order(venue, stock, order) ⇒ Object
- #get_orderbook(venue, stock) ⇒ Object
- #get_quote(venue, stock) ⇒ Object
- #list_account_orders(venue, account) ⇒ Object
- #list_account_stock_orders(venue, account, stock) ⇒ Object
- #list_stocks(venue) ⇒ Object
- #place_order(venue, stock, account, price:, qty:, direction: "buy", order_type: "limit") ⇒ Object
- #send_heartbeat ⇒ Object
- #send_venue_heartbeat(venue) ⇒ Object
- #set_api_key(api_key) ⇒ Object
- #show_order(venue, stock, order) ⇒ Object
Instance Method Details
#cancel_order(venue, stock, order) ⇒ Object
39 40 41 |
# File 'lib/stock_fighter/api_mixin/trading_api.rb', line 39 def cancel_order venue, stock, order trading_http.delete "/venues/#{venue}/stocks/#{stock}/orders/#{order}" end |
#get_orderbook(venue, stock) ⇒ Object
22 23 24 |
# File 'lib/stock_fighter/api_mixin/trading_api.rb', line 22 def get_orderbook venue, stock trading_http.get "/venues/#{venue}/stocks/#{stock}" end |
#get_quote(venue, stock) ⇒ Object
43 44 45 |
# File 'lib/stock_fighter/api_mixin/trading_api.rb', line 43 def get_quote venue, stock trading_http.get "/venues/#{venue}/stocks/#{stock}/quote" end |
#list_account_orders(venue, account) ⇒ Object
47 48 49 |
# File 'lib/stock_fighter/api_mixin/trading_api.rb', line 47 def list_account_orders venue, account trading_http.get "/venues/#{venue}/accounts/#{account}/orders" end |
#list_account_stock_orders(venue, account, stock) ⇒ Object
51 52 53 |
# File 'lib/stock_fighter/api_mixin/trading_api.rb', line 51 def list_account_stock_orders venue, account, stock trading_http.get "/venues/#{venue}/accounts/#{account}/stocks/#{stock}/orders" end |
#list_stocks(venue) ⇒ Object
18 19 20 |
# File 'lib/stock_fighter/api_mixin/trading_api.rb', line 18 def list_stocks venue trading_http.get "/venues/#{venue}/stocks" end |
#place_order(venue, stock, account, price:, qty:, direction: "buy", order_type: "limit") ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/stock_fighter/api_mixin/trading_api.rb', line 26 def place_order venue, stock, account, price:, qty:, direction: "buy", order_type: "limit" params = method(__method__).parameters.map(&:last) body = params.map { |p| [p, eval(p.to_s)] }.to_h body[:orderType] = body.delete(:order_type) trading_http.post "/venues/#{venue}/stocks/#{stock}/orders", body: JSON.dump(body) end |
#send_heartbeat ⇒ Object
10 11 12 |
# File 'lib/stock_fighter/api_mixin/trading_api.rb', line 10 def send_heartbeat trading_http.get "/heartbeat" end |
#send_venue_heartbeat(venue) ⇒ Object
14 15 16 |
# File 'lib/stock_fighter/api_mixin/trading_api.rb', line 14 def send_venue_heartbeat venue trading_http.get "/venues/#{venue}/heartbeat" end |
#set_api_key(api_key) ⇒ Object
6 7 8 |
# File 'lib/stock_fighter/api_mixin/trading_api.rb', line 6 def set_api_key api_key trading_http.headers "X-Starfighter-Authorization" => api_key end |
#show_order(venue, stock, order) ⇒ Object
35 36 37 |
# File 'lib/stock_fighter/api_mixin/trading_api.rb', line 35 def show_order venue, stock, order trading_http.get "/venues/#{venue}/stocks/#{stock}/orders/#{order}" end |