Class: ChockABlock::Stock
- Inherits:
-
Object
- Object
- ChockABlock::Stock
- Includes:
- Errors
- Defined in:
- lib/chock_a_block/stock.rb
Instance Method Summary collapse
-
#best_bidding ⇒ Hash
Get the best bidding currently available on the orderbook.
-
#get_orderbook ⇒ Hash
Get the orderbook for specific STOCK_SYMBOL in a specific VENUE API Consumer.
-
#get_quote ⇒ Hash
Get the qoute for a specific STOCK_SYMBOL in a specifc VENUE API Consumer.
-
#initialize(venue, symbol) ⇒ Stock
constructor
Initialize a Stock resource API consumer.
Constructor Details
#initialize(venue, symbol) ⇒ Stock
Initialize a Stock resource API consumer
9 10 11 12 |
# File 'lib/chock_a_block/stock.rb', line 9 def initialize(venue, symbol) @venue = venue @symbol = symbol end |
Instance Method Details
#best_bidding ⇒ Hash
Get the best bidding currently available on the orderbook
or retry if best_bid is nil
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/chock_a_block/stock.rb', line 39 def best_bidding order_book = get_orderbook best_bid = order_book['bids']&.last return best_bid unless best_bid.nil? # retryl few seconds later sleep 2 best_bidding end |
#get_orderbook ⇒ Hash
Get the orderbook for specific STOCK_SYMBOL in a specific VENUE API Consumer
18 19 20 21 22 23 |
# File 'lib/chock_a_block/stock.rb', line 18 def get_orderbook response = HTTP.get(BASE_URL + "/venues/#{@venue}/stocks/#{@symbol}") fail StockNotFoundError, @symbol if response.code == 500 fail VenueNotFoundError, @venue if response.code == 404 JSON.parse response.body end |
#get_quote ⇒ Hash
Get the qoute for a specific STOCK_SYMBOL in a specifc VENUE API Consumer
29 30 31 32 33 |
# File 'lib/chock_a_block/stock.rb', line 29 def get_quote response = HTTP.get(BASE_URL + "/venues/#{@venue}/stocks/#{@symbol}/quote") fail StockNotFoundError, @symbol if response.code == 404 JSON.parse response.body end |