fighter_base 0.1.0 → 0.2.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/CHANGELOG.md +3 -0
- data/Gemfile.lock +1 -1
- data/README.md +23 -7
- data/lib/fighter_base/exchange.rb +47 -2
- data/lib/fighter_base/level.rb +3 -2
- data/lib/fighter_base/order.rb +7 -0
- data/lib/fighter_base/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 436f0bd1cf8106875580bf6cbca527c54976b887
|
4
|
+
data.tar.gz: 888aabf3e8cd12362896282358b1c896616a6d02
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a2ab35cf19a7257c219874686447db5618d06c97cd1505d74a9bdd9f83fd85b19172f86bc1270a74031276d41115111158f3be48ce1acf48a6b9e9ac7da9f35e
|
7
|
+
data.tar.gz: b8b7a74cbe566fc92dc95bec8ad9dc5f6f88c5ec6930e14253c73dcfbc3befadcdf7cc600151a9a501faa9129150a0b77d36d57c7fb471eb580d9535ce9459d3
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,3 @@
|
|
1
|
+
Version 0.1.0: Initial version - dummy Level and Exchange classes, methods only check game and exchange heartbeat endpoints.
|
2
|
+
|
3
|
+
Version 0.2.0: Enable enough interaction to complete a level. Methods Exchange#quote, Exchange#place_order, Exchange#cancel_order, and Exchange#order_status work. Order class still not implemented.
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
# FighterBase
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
3
|
+
Wrapper methods for interacting with the APIs in the Stockfighter.io game.
|
6
4
|
|
7
5
|
## Installation
|
8
6
|
|
@@ -26,15 +24,33 @@ The main classes are
|
|
26
24
|
|
27
25
|
### Level
|
28
26
|
|
29
|
-
|
27
|
+
`level = FighterBase::Level.new(api_key, account, venue_symbol)`
|
28
|
+
|
29
|
+
Creating a Level instance also creates an Exchange instance of the given venue. You need the Exchange instance to get quotes and place orders.
|
30
|
+
|
31
|
+
### Exchange
|
32
|
+
|
33
|
+
Most interaction will be through this class. Quote for a stock, orderbook for a stock, place an order, cancel an order is done here. Methods return JSON from the APIs parsed into a hash.
|
34
|
+
|
35
|
+
`ex = level.exchange`
|
30
36
|
|
31
|
-
|
37
|
+
`quote = ex.get_quote("FAC")`
|
32
38
|
|
33
|
-
|
39
|
+
then get information from it as
|
40
|
+
|
41
|
+
`quote["ask"]` or `quote["bid_size"]`
|
34
42
|
|
35
43
|
### Order
|
36
44
|
|
37
|
-
|
45
|
+
Class is not implemented yet - still working how to model them in this system.
|
46
|
+
|
47
|
+
Orders can be placed and canceled through the `Exchange` insance
|
48
|
+
|
49
|
+
`order = ex.place_order(stock: symbol, price: ask, qty: size, direction: "buy", type: "limit")`
|
50
|
+
|
51
|
+
_Note:_ `Exchange#place_order` currently returns a hash. In the future it will return a propper `Order` instance.
|
52
|
+
|
53
|
+
_Note:_ Order method uses named argument style method. The rest of the methods will soon switch to that style.
|
38
54
|
|
39
55
|
## Notes
|
40
56
|
|
@@ -1,21 +1,66 @@
|
|
1
1
|
require "httparty"
|
2
|
+
require "json"
|
2
3
|
|
3
4
|
module FighterBase
|
4
|
-
|
5
5
|
class Exchange
|
6
6
|
attr_reader :venue_symbol, :level
|
7
7
|
|
8
8
|
def initialize(venue_symbol, level)
|
9
|
+
@base_url = "https://api.stockfighter.io/ob/api"
|
9
10
|
@venue_symbol = venue_symbol
|
10
11
|
@level = level
|
11
12
|
end
|
12
13
|
|
13
14
|
def heartbeat
|
14
|
-
response = HTTParty.get("
|
15
|
+
response = HTTParty.get("#{@base_url}/venues/#{@venue_symbol}/heartbeat")
|
15
16
|
ok = response.parsed_response["ok"] rescue false
|
16
17
|
|
17
18
|
raise "World is on fire!" unless ok
|
18
19
|
puts "lump lump, lump lump" if ok
|
19
20
|
end
|
21
|
+
|
22
|
+
def get_quote(stock)
|
23
|
+
response = HTTParty.get("#{@base_url}/venues/#{@venue_symbol}/stocks/#{stock}/quote")
|
24
|
+
return response.parsed_response
|
25
|
+
end
|
26
|
+
|
27
|
+
def get_order_book(stock)
|
28
|
+
response = HTTParty.get("#{@base_url}/venues/#{venue_symbol}/stocks/#{stock}")
|
29
|
+
return response.parsed_response
|
30
|
+
end
|
31
|
+
|
32
|
+
# def place_order(order)
|
33
|
+
# response = HTTParty.post("#{@base_url}/venues/#{venue_symbol}/stocks/#{stock}/orders",
|
34
|
+
# :body => JSON.dump(order),
|
35
|
+
# :headers => {"X-Starfighter-Authorization" => apikey}
|
36
|
+
# )
|
37
|
+
# return response.parsed_response
|
38
|
+
# end
|
39
|
+
|
40
|
+
def place_order(stock:, price:, qty:, direction:, type: "limit")
|
41
|
+
order_data = {
|
42
|
+
"account" => @level.account,
|
43
|
+
"venue" => @venue_symbol,
|
44
|
+
"symbol" => stock,
|
45
|
+
"price" => price,
|
46
|
+
"qty" => qty,
|
47
|
+
"direction" => direction,
|
48
|
+
"orderType" => type
|
49
|
+
}
|
50
|
+
|
51
|
+
response = HTTParty.post("#{@base_url}/venues/#{@venue_symbol}/stocks/#{stock}/orders",
|
52
|
+
:body => JSON.dump(order_data),
|
53
|
+
:headers => {"X-Starfighter-Authorization" => @level.api_key}
|
54
|
+
)
|
55
|
+
return response.parsed_response
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
def cancel_order(stock, order_id)
|
60
|
+
response = HTTParty.delete("#{@base_url}/venues/#{venue_symbol}/stocks/#{stock}/orders/#{order_id}",
|
61
|
+
:headers => {"X-Starfighter-Authorization" => @level.api_key}
|
62
|
+
)
|
63
|
+
return response.parsed_response
|
64
|
+
end
|
20
65
|
end
|
21
66
|
end
|
data/lib/fighter_base/level.rb
CHANGED
@@ -2,10 +2,11 @@ require "httparty"
|
|
2
2
|
|
3
3
|
module FighterBase
|
4
4
|
class Level
|
5
|
-
attr_reader :api_key, :exchange
|
5
|
+
attr_reader :api_key, :account, :exchange
|
6
6
|
|
7
|
-
def initialize(api_key, venue_symbol)
|
7
|
+
def initialize(api_key, account, venue_symbol)
|
8
8
|
@api_key = api_key
|
9
|
+
@account = account
|
9
10
|
@exchange = Exchange.new(venue_symbol, self)
|
10
11
|
end
|
11
12
|
|
data/lib/fighter_base/order.rb
CHANGED
data/lib/fighter_base/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fighter_base
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brian Broom
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-12-
|
11
|
+
date: 2015-12-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -78,6 +78,7 @@ files:
|
|
78
78
|
- ".gitignore"
|
79
79
|
- ".rspec"
|
80
80
|
- ".travis.yml"
|
81
|
+
- CHANGELOG.md
|
81
82
|
- Gemfile
|
82
83
|
- Gemfile.lock
|
83
84
|
- README.md
|