Class: FighterBase::Exchange
- Inherits:
-
Object
- Object
- FighterBase::Exchange
- Defined in:
- lib/fighter_base/exchange.rb
Instance Attribute Summary collapse
-
#level ⇒ Object
readonly
Returns the value of attribute level.
-
#venue_symbol ⇒ Object
readonly
Returns the value of attribute venue_symbol.
Instance Method Summary collapse
- #cancel_order(stock, order_id) ⇒ Object
- #get_order_book(stock) ⇒ Object
- #get_quote(stock) ⇒ Object
- #heartbeat ⇒ Object
-
#initialize(venue_symbol, level) ⇒ Exchange
constructor
A new instance of Exchange.
-
#place_order(stock:, price:, qty:, direction:, type: "limit") ⇒ Object
def place_order(order) response = HTTParty.post(“#@base_url/venues/##venue_symbol/stocks/#stock/orders”, :body => JSON.dump(order), :headers => => apikey ) return response.parsed_response end.
Constructor Details
#initialize(venue_symbol, level) ⇒ Exchange
Returns a new instance of Exchange.
8 9 10 11 12 |
# File 'lib/fighter_base/exchange.rb', line 8 def initialize(venue_symbol, level) @base_url = "https://api.stockfighter.io/ob/api" @venue_symbol = venue_symbol @level = level end |
Instance Attribute Details
#level ⇒ Object (readonly)
Returns the value of attribute level.
6 7 8 |
# File 'lib/fighter_base/exchange.rb', line 6 def level @level end |
#venue_symbol ⇒ Object (readonly)
Returns the value of attribute venue_symbol.
6 7 8 |
# File 'lib/fighter_base/exchange.rb', line 6 def venue_symbol @venue_symbol end |
Instance Method Details
#cancel_order(stock, order_id) ⇒ Object
59 60 61 62 63 64 |
# File 'lib/fighter_base/exchange.rb', line 59 def cancel_order(stock, order_id) response = HTTParty.delete("#{@base_url}/venues/#{venue_symbol}/stocks/#{stock}/orders/#{order_id}", :headers => {"X-Starfighter-Authorization" => @level.api_key} ) return response.parsed_response end |
#get_order_book(stock) ⇒ Object
27 28 29 30 |
# File 'lib/fighter_base/exchange.rb', line 27 def get_order_book(stock) response = HTTParty.get("#{@base_url}/venues/#{venue_symbol}/stocks/#{stock}") return response.parsed_response end |
#get_quote(stock) ⇒ Object
22 23 24 25 |
# File 'lib/fighter_base/exchange.rb', line 22 def get_quote(stock) response = HTTParty.get("#{@base_url}/venues/#{@venue_symbol}/stocks/#{stock}/quote") return response.parsed_response end |
#heartbeat ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/fighter_base/exchange.rb', line 14 def heartbeat response = HTTParty.get("#{@base_url}/venues/#{@venue_symbol}/heartbeat") ok = response.parsed_response["ok"] rescue false raise "World is on fire!" unless ok puts "lump lump, lump lump" if ok end |
#place_order(stock:, price:, qty:, direction:, type: "limit") ⇒ Object
def place_order(order)
response = HTTParty.post("#{@base_url}/venues/#{venue_symbol}/stocks/#{stock}/orders",
:body => JSON.dump(order),
:headers => {"X-Starfighter-Authorization" => apikey}
)
return response.parsed_response
end
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/fighter_base/exchange.rb', line 40 def place_order(stock:, price:, qty:, direction:, type: "limit") order_data = { "account" => @level.account, "venue" => @venue_symbol, "symbol" => stock, "price" => price, "qty" => qty, "direction" => direction, "orderType" => type } response = HTTParty.post("#{@base_url}/venues/#{@venue_symbol}/stocks/#{stock}/orders", :body => JSON.dump(order_data), :headers => {"X-Starfighter-Authorization" => @level.api_key} ) return response.parsed_response end |