module StockFighterMixin
Public Class Methods
included(base)
click to toggle source
# File lib/stock_fighter_mixin.rb, line 5 def self.included base http_delegator = Class.new do include HTTParty base_uri 'https://api.stockfighter.io/ob/api' format :json end base.send :define_method, :http do http_delegator end base.send :private, :http end
Public Instance Methods
api_key(api_key)
click to toggle source
# File lib/stock_fighter_mixin.rb, line 19 def api_key api_key http.headers "X-Starfighter-Authorization" => api_key end
cancel_order(venue, stock, order)
click to toggle source
# File lib/stock_fighter_mixin.rb, line 49 def cancel_order venue, stock, order http.delete "/venues/#{venue}/stocks/#{stock}/orders/#{order}" end
get_orderbook(venue, stock)
click to toggle source
# File lib/stock_fighter_mixin.rb, line 35 def get_orderbook venue, stock http.get "/venues/#{venue}/stocks/#{stock}" end
get_quote(venue, stock)
click to toggle source
# File lib/stock_fighter_mixin.rb, line 53 def get_quote venue, stock http.get "/venues/#{venue}/stocks/#{stock}/quote" end
list_account_orders(venue, account)
click to toggle source
# File lib/stock_fighter_mixin.rb, line 57 def list_account_orders venue, account http.get "/venues/#{venue}/accounts/#{account}/orders" end
list_account_stock_orders(venue, account, stock)
click to toggle source
# File lib/stock_fighter_mixin.rb, line 61 def list_account_stock_orders venue, account, stock http.get "get/venues/#{venue}/accounts/#{account}/stocks/#{stock}/orders" end
list_stocks(venue)
click to toggle source
# File lib/stock_fighter_mixin.rb, line 31 def list_stocks venue http.get "/venues/#{venue}/stocks" end
place_order(venue, stock, account:, price:, qty:, direction: "buy", orderType: "limit")
click to toggle source
# File lib/stock_fighter_mixin.rb, line 39 def place_order venue, stock, account:, price:, qty:, direction: "buy", orderType: "limit" params = method(__method__).parameters.map(&:last) body = params.map { |p| [p, eval(p.to_s)] }.to_h http.post "/venues/#{venue}/stocks/#{stock}/orders", body: JSON.dump(body) end
send_heartbeat()
click to toggle source
# File lib/stock_fighter_mixin.rb, line 23 def send_heartbeat http.get "/heartbeat" end
send_venue_heartbeat(venue)
click to toggle source
# File lib/stock_fighter_mixin.rb, line 27 def send_venue_heartbeat venue http.get "/venues/#{venue}/heartbeat" end
show_order(venue, stock, order)
click to toggle source
# File lib/stock_fighter_mixin.rb, line 45 def show_order venue, stock, order http.post "/venues/#{venue}/stocks/#{stock}/orders/#{order}" end