Module: ChockABlock

Includes:
Errors
Defined in:
lib/chock_a_block.rb,
lib/chock_a_block/stock.rb,
lib/chock_a_block/broker.rb,
lib/chock_a_block/errors.rb,
lib/chock_a_block/algo_trader.rb

Overview

The Base Module to solve chock_a_block challange on stockerfighter.io Provide easy way of consuming the api to start level and configure the correct venue, stock and account

Defined Under Namespace

Modules: Errors Classes: AlgoTrader, Broker, Stock

Constant Summary collapse

BASE_URL =
'https://api.stockfighter.io/ob/api'
GAME_URL =
'https://www.stockfighter.io/gm/'

Class Method Summary collapse

Class Method Details

.start_level(api_key) ⇒ Object

Provide an easy way to start the game consuming the api instead of copying and pasting the account/venue/symbol of each game



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/chock_a_block.rb', line 22

def self.start_level(api_key)
  response = HTTP['X-Starfighter-Authorization' => api_key].post(
    GAME_URL + 'levels/chock_a_block'
  )
  response_body = JSON.parse response.body
  fail AuthenticationError, api_key unless response_body['ok']

  # Get the level data using the undocumented API here
  # https://discuss.starfighters.io/t/the-gm-api-how-to-start-stop-restart-resume-trading-levels-automagically/143
  @accout   = response_body['account']
  @venue    = response_body['venues'].first
  @symbol   = response_body['tickers'].first
  @instance = response_body['instanceId']

  p 'Game Started'
  p 'Please Navigate to:'
  p '   https://www.stockfighter.io/ui/play/blotter#chock_a_block'
  p 'to see the game in action'
  p '--------------------------------------------------------'
  # Start the AlgoTrader
  AlgoTrader.new(api_key, @accout, @venue, @symbol).basic_strategy
rescue AuthenticationError => e
  p "Invalid API_KEY #{e.message}"
  p 'Please use a correct API_KEY to start the level'
end