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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c2cb2ebc74ae084de20a9fe8cee990dad05c5d24
4
- data.tar.gz: 8b0cdd25d782ab58e1f74dec128b496ada0e0274
3
+ metadata.gz: 436f0bd1cf8106875580bf6cbca527c54976b887
4
+ data.tar.gz: 888aabf3e8cd12362896282358b1c896616a6d02
5
5
  SHA512:
6
- metadata.gz: 0c372802c94fe8ee476279494e6d8731b4ed49f3cb3bcf1eff68f0f159c423d98e4687027540d90344b94a2a476bbae7e7da5e6e414fb1afd796ba7a6e5663d4
7
- data.tar.gz: b91091078eff40a9e8734237aa21c373ea7450b7e862bcb9e820394e7e1983449204318f66a9a9e2a3bbf5550950516aa51a0333a97b46bae70cae0239610648
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
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- fighter_base (0.1.0)
4
+ fighter_base (0.2.0)
5
5
  httparty (~> 0.13.7)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -1,8 +1,6 @@
1
1
  # FighterBase
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/fighter_base`. To experiment with that code, run `bin/console` for an interactive prompt.
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
- Stores the `api_key`, and trading account
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
- ### Venue
37
+ `quote = ex.get_quote("FAC")`
32
38
 
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.
39
+ then get information from it as
40
+
41
+ `quote["ask"]` or `quote["bid_size"]`
34
42
 
35
43
  ### Order
36
44
 
37
- Create orders, then place them using Venue#place_order
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("https://api.stockfighter.io/ob/api/venues/#{@venue_symbol}/heartbeat")
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
@@ -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
 
@@ -0,0 +1,7 @@
1
+ require 'httparty'
2
+
3
+ module FighterBase
4
+ class Order
5
+ attr_accessor :type, :price, :quantity, :total_filled, :open, :symbol, :fills
6
+ end
7
+ end
@@ -1,3 +1,3 @@
1
1
  module FighterBase
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
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.1.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-18 00:00:00.000000000 Z
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