stock_fighter 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1772c0c095e420f7c9248a2ff8d21fa7a1bda054
4
- data.tar.gz: ace3c4c4def2ebb9374fc2cb06696168f0243a98
3
+ metadata.gz: 78f82c2fabb15a27796591a636df40601513dcaf
4
+ data.tar.gz: ca204c4866044ed2a6a19dac5ef4c1a34d4bff91
5
5
  SHA512:
6
- metadata.gz: 7d222076e658d09f0322e5cf01eafb8c158a16cd831368d3363220ff9dd68c0bdbd02dde78ac5eda70c8a4fb98367a6d3e1e43dd31c46f7d5a2d297857b85660
7
- data.tar.gz: 5f86da62fcbfd4685272391f74ff4284e1692cc34bd9549ba925e468efb38bfad0509f600269bba997016f68440586e38603a55577067396dba482a3f983d372
6
+ metadata.gz: dd8008fa11475409f7c041e87b416d7a6de41e92027777eeb7c995ad36f0d8f4ab7f3dc3e6c99ee7b03cea83c1a4592ebd3db2d191087b0dfd26b83c463fd0c7
7
+ data.tar.gz: 669deb5087dbd3cf2d49cec76f5a3d0965357fe85f6d36bd089969b721908aa82735e05acde003fefe204778abbe0240ebb26fcaafaa44a9013da11b45fcae46
data/README.md CHANGED
@@ -67,7 +67,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
67
67
 
68
68
  ## Contributing
69
69
 
70
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/stock_fighter.
70
+ Bug reports and pull requests are welcome on GitHub at https://github.com/ditsing/stock_fighter.
71
71
 
72
72
 
73
73
  ## License
@@ -1,85 +1,31 @@
1
- require 'httparty'
2
- require 'json'
1
+ require 'stock_fighter/api_mixin/trading_api'
2
+ require 'stock_fighter/api_mixin/game_master_api'
3
3
 
4
- # TODO: better testing.
5
4
  module StockFighter
6
5
  module ApiMixin
7
6
  def self.included base
8
7
  base.extend ClassMethods
9
8
  end
10
9
 
11
- def set_api_key api_key
12
- http.headers "X-Starfighter-Authorization" => api_key
13
- end
14
-
15
- def send_heartbeat
16
- http.get "/heartbeat"
17
- end
18
-
19
- def send_venue_heartbeat venue
20
- http.get "/venues/#{venue}/heartbeat"
21
- end
22
-
23
- def list_stocks venue
24
- http.get "/venues/#{venue}/stocks"
25
- end
26
-
27
- def get_orderbook venue, stock
28
- http.get "/venues/#{venue}/stocks/#{stock}"
29
- end
30
-
31
- def place_order venue, stock, account, price:, qty:, direction: "buy", order_type: "limit"
32
- params = method(__method__).parameters.map(&:last)
33
- body = params.map { |p| [p, eval(p.to_s)] }.to_h
34
-
35
- body[:orderType] = body.delete(:order_type)
36
-
37
- http.post "/venues/#{venue}/stocks/#{stock}/orders", body: JSON.dump(body)
38
- end
39
-
40
- def show_order venue, stock, order
41
- http.post "/venues/#{venue}/stocks/#{stock}/orders/#{order}"
42
- end
43
-
44
- def cancel_order venue, stock, order
45
- http.delete "/venues/#{venue}/stocks/#{stock}/orders/#{order}"
46
- end
47
-
48
- def get_quote venue, stock
49
- http.get "/venues/#{venue}/stocks/#{stock}/quote"
50
- end
51
-
52
- def list_account_orders venue, account
53
- http.get "/venues/#{venue}/accounts/#{account}/orders"
54
- end
55
-
56
- def list_account_stock_orders venue, account, stock
57
- http.get "get/venues/#{venue}/accounts/#{account}/stocks/#{stock}/orders"
58
- end
59
-
60
- private
61
- def http
62
- # TODO: how do we create module specific vars?
63
- @http_delegator ||= ApiMixin.create_partified_module
64
- end
65
-
66
- def self.create_partified_module
67
- Module.new do
68
- include HTTParty
69
-
70
- base_uri 'https://api.stockfighter.io/ob/api'
71
- format :json
72
- end
73
- end
10
+ include TradingApi
11
+ include GameMasterApi
74
12
 
13
+ # TODO: maybe move this to the mixins?
75
14
  module ClassMethods
76
15
  private
77
- def share_http_delegator
78
- http_delegator = ApiMixin.create_partified_module
79
- define_method :http do
80
- http_delegator
16
+ def share_class_http_delegator
17
+ trading_http_delegator = TradingApi.create_partified_module
18
+ game_master_http_delegator = GameMasterApi.create_partified_module
19
+
20
+ define_method :trading_http do
21
+ trading_http_delegator
22
+ end
23
+ private :trading_http
24
+
25
+ define_method :game_master_http do
26
+ game_master_http_delegator
81
27
  end
82
- private :http
28
+ private :game_master_http
83
29
  end
84
30
  end
85
31
  end
@@ -0,0 +1,46 @@
1
+ require 'httparty'
2
+ require 'json'
3
+
4
+ module StockFighter::ApiMixin
5
+ module GameMasterApi
6
+ def list_levels
7
+ raise NotImplementedError
8
+
9
+ game_master_http.get '/levels'
10
+ end
11
+
12
+ def start_current_level
13
+ game_master_http.post '/levels/first_steps'
14
+ end
15
+
16
+ def restart_instance instance
17
+ game_master_http.post "/instances/#{instance}/restart"
18
+ end
19
+
20
+ def stop_instance instance
21
+ game_master_http.post "/instances/#{instance}/stop"
22
+ end
23
+
24
+ def resume_instance instance
25
+ game_master_http.post "/instances/#{instance}/resume"
26
+ end
27
+
28
+ def show_instance instance
29
+ game_master_http.get "/instances/#{instance}"
30
+ end
31
+
32
+ private
33
+ def game_master_http
34
+ @game_master_http_delegator ||= GameMasterApi.create_partified_module
35
+ end
36
+
37
+ def self.create_partified_module
38
+ Module.new do
39
+ include HTTParty
40
+
41
+ base_uri 'https://www.stockfighter.io/gm'
42
+ format :json
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,71 @@
1
+ require 'httparty'
2
+ require 'json'
3
+
4
+ module StockFighter::ApiMixin
5
+ module TradingApi
6
+ def set_api_key api_key
7
+ trading_http.headers "X-Starfighter-Authorization" => api_key
8
+ end
9
+
10
+ def send_heartbeat
11
+ trading_http.get "/heartbeat"
12
+ end
13
+
14
+ def send_venue_heartbeat venue
15
+ trading_http.get "/venues/#{venue}/heartbeat"
16
+ end
17
+
18
+ def list_stocks venue
19
+ trading_http.get "/venues/#{venue}/stocks"
20
+ end
21
+
22
+ def get_orderbook venue, stock
23
+ trading_http.get "/venues/#{venue}/stocks/#{stock}"
24
+ end
25
+
26
+ def place_order venue, stock, account, price:, qty:, direction: "buy", order_type: "limit"
27
+ params = method(__method__).parameters.map(&:last)
28
+ body = params.map { |p| [p, eval(p.to_s)] }.to_h
29
+
30
+ body[:orderType] = body.delete(:order_type)
31
+
32
+ trading_http.post "/venues/#{venue}/stocks/#{stock}/orders", body: JSON.dump(body)
33
+ end
34
+
35
+ def show_order venue, stock, order
36
+ trading_http.get "/venues/#{venue}/stocks/#{stock}/orders/#{order}"
37
+ end
38
+
39
+ def cancel_order venue, stock, order
40
+ trading_http.delete "/venues/#{venue}/stocks/#{stock}/orders/#{order}"
41
+ end
42
+
43
+ def get_quote venue, stock
44
+ trading_http.get "/venues/#{venue}/stocks/#{stock}/quote"
45
+ end
46
+
47
+ def list_account_orders venue, account
48
+ trading_http.get "/venues/#{venue}/accounts/#{account}/orders"
49
+ end
50
+
51
+ def list_account_stock_orders venue, account, stock
52
+ trading_http.get "/venues/#{venue}/accounts/#{account}/stocks/#{stock}/orders"
53
+ end
54
+
55
+ private
56
+ def trading_http
57
+ # TODO: how do we create module specific vars?
58
+ @trading_http_delegator ||= TradingApi.create_partified_module
59
+ end
60
+
61
+ def self.create_partified_module
62
+ Module.new do
63
+ include HTTParty
64
+
65
+ base_uri 'https://api.stockfighter.io/ob/api'
66
+ format :json
67
+ headers 'Content-Type' => 'application/json'
68
+ end
69
+ end
70
+ end
71
+ end
@@ -1,3 +1,3 @@
1
1
  module StockFighter
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -25,4 +25,5 @@ Gem::Specification.new do |spec|
25
25
  spec.add_development_dependency "bundler", "~> 1.11"
26
26
  spec.add_development_dependency "rake", "~> 10.0"
27
27
  spec.add_development_dependency "minitest", "~> 5.0"
28
+ spec.add_development_dependency "webmock", "~> 1.22"
28
29
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stock_fighter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jing Yang
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-05 00:00:00.000000000 Z
11
+ date: 2016-01-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '5.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: webmock
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.22'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.22'
83
97
  description: API for http://stockfighter.io. Run bin/console and start playing!
84
98
  email:
85
99
  - ditsing@gmail.com
@@ -101,6 +115,8 @@ files:
101
115
  - lib/stock_fighter.rb
102
116
  - lib/stock_fighter/api.rb
103
117
  - lib/stock_fighter/api_mixin.rb
118
+ - lib/stock_fighter/api_mixin/game_master_api.rb
119
+ - lib/stock_fighter/api_mixin/trading_api.rb
104
120
  - lib/stock_fighter/level.rb
105
121
  - lib/stock_fighter/version.rb
106
122
  - stock_fighter.gemspec