stockfighter 0.0.2 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/lib/stockfighter/gm.rb +49 -11
- data/lib/stockfighter/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2a4dbaa3414c3edfb0c0d4e0982e283aa5d758a8
|
4
|
+
data.tar.gz: 3a699ce75deabe0078c0af18a3b21e5173bdec0b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a85ba12c74fae4f8ad5bde80a4bb9fe89d5089441ccf18c4227f32ff1bacbac2969bf1badcc15cdea25283bb43538463eddb4ea5513466f90e6f472b7fd5abcc
|
7
|
+
data.tar.gz: 7d2e5aa2e96c0ab13b342d57b99a4653376940b93de785613e6bccba96bd1a6155e7cc21d8d45d05b9139a035f7ceb547865381448a78d61e40f62da1c665e19
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Stockfighter
|
2
2
|
|
3
|
-
A gem for interacting with the Stockfighter.io API.
|
3
|
+
A gem for interacting with the [Stockfighter.io](https://www.stockfighter.io) API.
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -27,7 +27,7 @@ require 'stockfighter'
|
|
27
27
|
# Use the GM to fetch the info automatically
|
28
28
|
|
29
29
|
gm = Stockfighter::GM.new("supersecretapikey1234567")
|
30
|
-
first_steps_config = gm.
|
30
|
+
first_steps_config = gm.config_for(level: "first_steps")
|
31
31
|
|
32
32
|
api = Stockfighter::Api.new(first_steps_config)
|
33
33
|
|
data/lib/stockfighter/gm.rb
CHANGED
@@ -2,24 +2,62 @@ require 'httparty'
|
|
2
2
|
|
3
3
|
module Stockfighter
|
4
4
|
class GM
|
5
|
-
|
5
|
+
GM_URL = "https://www.stockfighter.io/gm"
|
6
|
+
|
7
|
+
attr_accessor :instance_id
|
8
|
+
|
9
|
+
def initialize(key:, level:)
|
6
10
|
@api_key = key
|
7
|
-
|
11
|
+
@level = level
|
8
12
|
|
9
|
-
|
10
|
-
resp = HTTParty.post("https://www.stockfighter.io/gm/levels/#{level}", :headers => {"X-Starfighter-Authorization" => @api_key})
|
13
|
+
resp = HTTParty.post("#{GM_URL}/levels/#{level}", :headers => {"X-Starfighter-Authorization" => @api_key})
|
11
14
|
|
12
|
-
|
13
|
-
|
14
|
-
config[:venue] = resp["venues"][0]
|
15
|
-
config[:symbol] = resp["tickers"][0]
|
16
|
-
config[:key] = @api_key
|
15
|
+
update_config(resp)
|
16
|
+
end
|
17
17
|
|
18
|
-
|
19
|
-
|
18
|
+
def config
|
19
|
+
if @config[:account] && @config[:venue] && @config[:symbol]
|
20
|
+
@config
|
20
21
|
else
|
21
22
|
nil
|
22
23
|
end
|
23
24
|
end
|
25
|
+
|
26
|
+
def restart
|
27
|
+
if @instance_id
|
28
|
+
resp = HTTParty.post("#{GM_URL}/instances/#{@instance_id}/restart", :headers => {"X-Starfighter-Authorization" => @api_key})
|
29
|
+
udpate_config(resp)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def stop
|
34
|
+
if @instance_id
|
35
|
+
resp = HTTParty.post("#{GM_URL}/instances/#{@instance_id}/stop", :headers => {"X-Starfighter-Authorization" => @api_key})
|
36
|
+
update_config(resp)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def resume
|
41
|
+
if @instance_id
|
42
|
+
resp = HTTParty.post("#{GM_URL}/instances/#{@instance_id}/resume", :headers => {"X-Starfighter-Authorization" => @api_key})
|
43
|
+
update_config(resp)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def active?
|
48
|
+
response = HTTParty.get("#{GM_URL}/instances/#{@instance_id}", :headers => {"X-Starfighter-Authorization" => @api_key})
|
49
|
+
response["done"] && response["ok"]
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def update_config(resp)
|
54
|
+
@config = {}
|
55
|
+
@config[:key] = @api_key
|
56
|
+
@config[:account] = resp["account"]
|
57
|
+
@config[:venue] = resp["venues"][0]
|
58
|
+
@config[:symbol] = resp["tickers"][0]
|
59
|
+
|
60
|
+
@instance_id = resp["instanceId"]
|
24
61
|
end
|
62
|
+
private :update_config
|
25
63
|
end
|
data/lib/stockfighter/version.rb
CHANGED