Class: Stockfighter::Api

Inherits:
Object
  • Object
show all
Defined in:
lib/stockfighter/api.rb

Instance Method Summary collapse

Constructor Details

#initialize(key:, account:, symbol:, venue:, base_url: "https://api.stockfighter.io/ob/api") ⇒ Api

Returns a new instance of Api.



5
6
7
8
9
10
11
# File 'lib/stockfighter/api.rb', line 5

def initialize(key:, account:, symbol:, venue:, base_url: "https://api.stockfighter.io/ob/api")
  @base_url = base_url
  @api_key = key
  @account = 
  @symbol = symbol
  @venue = venue
end

Instance Method Details

#cancel_order(order_id) ⇒ Object



30
31
32
# File 'lib/stockfighter/api.rb', line 30

def cancel_order(order_id)
  perform_request("delete", "#{@base_url}/venues/#{@venue}/stocks/#{@symbol}/orders/#{order_id}")
end

#get_quoteObject



13
14
15
# File 'lib/stockfighter/api.rb', line 13

def get_quote
  perform_request("get", "#{@base_url}/venues/#{@venue}/stocks/#{@symbol}/quote")
end

#order_bookObject



38
39
40
# File 'lib/stockfighter/api.rb', line 38

def order_book
  perform_request("get", "#{@base_url}/venues/#{@venue}/stocks/#{@symbol}")
end

#order_status(order_id) ⇒ Object



34
35
36
# File 'lib/stockfighter/api.rb', line 34

def order_status(order_id)
  perform_request("get", "#{@base_url}/venues/#{@venue}/stocks/#{@symbol}/orders/#{order_id}")
end

#place_order(price:, quantity:, direction:, order_type:) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/stockfighter/api.rb', line 17

def place_order(price:, quantity:, direction:, order_type:)
  order = {
    "account" => @account,
    "venue" => @venue,
    "symbol" => @symbol,
    "price" => price,
    "qty" => quantity,
    "direction" => direction,
    "orderType" => order_type
  }
  perform_request("post", "#{@base_url}/venues/#{@venue}/stocks/#{@symbol}/orders", body: JSON.dump(order))
end

#status_allObject



47
48
49
# File 'lib/stockfighter/api.rb', line 47

def status_all
  perform_request("get", "#{@base_url}/venues/#{@venue}/accounts/#{@account}/orders")
end

#venue_up?Boolean

Returns:

  • (Boolean)


42
43
44
45
# File 'lib/stockfighter/api.rb', line 42

def venue_up?
  response = perform_request("get", "#{@base_url}/venues/#{@venue}/heartbeat")
  response["ok"]
end