Class: Stockfighter::GM
- Inherits:
-
Object
- Object
- Stockfighter::GM
- Defined in:
- lib/stockfighter/gm.rb
Constant Summary collapse
- GM_URL =
"https://www.stockfighter.io/gm"
Instance Attribute Summary collapse
-
#instance_id ⇒ Object
Returns the value of attribute instance_id.
Instance Method Summary collapse
- #active? ⇒ Boolean
- #config ⇒ Object
-
#initialize(key:, level:) ⇒ GM
constructor
A new instance of GM.
- #restart ⇒ Object
- #resume ⇒ Object
- #stop ⇒ Object
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_id ⇒ Object
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
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 |
#config ⇒ Object
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 |
#restart ⇒ Object
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 |
#resume ⇒ Object
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 |
#stop ⇒ Object
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 |