Class: Stockfighter::GM

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

Constant Summary collapse

GM_URL =
"https://www.stockfighter.io/gm"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key:, level:) ⇒ GM

Returns a new instance of GM.



9
10
11
12
13
14
15
16
# File 'lib/stockfighter/gm.rb', line 9

def initialize(key:, level:)
  @api_key = key
  @level = level

  resp = HTTParty.post("#{GM_URL}/levels/#{level}", :headers => {"X-Starfighter-Authorization" => @api_key})

  update_config(resp)
end

Instance Attribute Details

#instance_idObject

Returns the value of attribute instance_id.



7
8
9
# File 'lib/stockfighter/gm.rb', line 7

def instance_id
  @instance_id
end

Instance Method Details

#active?Boolean

Returns:

  • (Boolean)


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

def active?
  response = HTTParty.get("#{GM_URL}/instances/#{@instance_id}", :headers => {"X-Starfighter-Authorization" => @api_key})
  response["done"] && response["ok"]
end

#configObject



18
19
20
21
22
23
24
# File 'lib/stockfighter/gm.rb', line 18

def config
  if @config[:account] && @config[:venue] && @config[:symbol]
    @config
  else
    nil
  end
end

#restartObject



26
27
28
29
30
31
# File 'lib/stockfighter/gm.rb', line 26

def restart
  if @instance_id
    resp = HTTParty.post("#{GM_URL}/instances/#{@instance_id}/restart", :headers => {"X-Starfighter-Authorization" => @api_key})
    update_config(resp)
  end
end

#resumeObject



40
41
42
43
44
45
# File 'lib/stockfighter/gm.rb', line 40

def resume
  if @instance_id
    resp = HTTParty.post("#{GM_URL}/instances/#{@instance_id}/resume", :headers => {"X-Starfighter-Authorization" => @api_key})
    update_config(resp)
  end
end

#stopObject



33
34
35
36
37
38
# File 'lib/stockfighter/gm.rb', line 33

def stop
  if @instance_id
    resp = HTTParty.post("#{GM_URL}/instances/#{@instance_id}/stop", :headers => {"X-Starfighter-Authorization" => @api_key})
    update_config(resp)
  end
end