gekko 0.9.5 → 0.10.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: d1b1e5234724a55544ac1f4bd8e1df4cf6574772
4
- data.tar.gz: 434bf684cc8a837c568317340618c2b346f5471c
3
+ metadata.gz: a1b7c4b20f6c578aec5aad59b627a88e872e2574
4
+ data.tar.gz: 71129f7815fba7b9117ea3cad2e096f1f10f2da3
5
5
  SHA512:
6
- metadata.gz: 97a6e80692ed6b73878a07836b11e333072778f90d3ded6c99c69e696c87f5b1b21f4af37b066289f77f24ace61735bb481980e0bc80603d985ac15d7e806f4c
7
- data.tar.gz: fce34e374fd353c296caf2723728b61a45e336d613149d68f983f740641f096cf2f2f8e0f9b69ed734905c664b252b6d7940bc13fcbde4cf2112b601159be3d2
6
+ metadata.gz: f2f58be1cfe7cd1e0855783def9d495aa973a487512902ab86227f1990b0353bd11793a6494b53af99638c55558f072ce5652b5d65185c917966d1298c83cf35
7
+ data.tar.gz: bdfdaca149bc21b996bd51d5758870dde8b915f822697985872f1aa18720f0758983fbef5510b07fb8618a32bb18caf6217881254420979b5a17d292411e950d
@@ -240,8 +240,8 @@ module Gekko
240
240
  #
241
241
  def self.from_hash(hsh)
242
242
  book = Book.new(hsh[:pair], {
243
- bids: BookSide.new(:bid, orders: hsh[:bids].map { |o| symbolize_keys(o) }.sort { |a, b| b[:price] <=> a[:price] }),
244
- asks: BookSide.new(:ask, orders: hsh[:asks].map { |o| symbolize_keys(o) }.sort { |a, b| a[:price] <=> b[:price] }),
243
+ bids: BookSide.new(:bid, orders: hsh[:bids].map { |o| symbolize_keys(o) }),
244
+ asks: BookSide.new(:ask, orders: hsh[:asks].map { |o| symbolize_keys(o) })
245
245
  })
246
246
 
247
247
  [:bids, :asks].each { |s| book.send(s).each { |ord| book.received[ord.id.to_s] = ord } }
@@ -5,16 +5,16 @@ module Gekko
5
5
  #
6
6
  class BookSide < Array
7
7
 
8
- # TODO: Insert orders more smartly by using a dichotomy search
9
-
10
8
  attr_accessor :side
11
9
 
12
10
  def initialize(side, opts = {})
13
- # TODO "WARNING: Sort orders ?"
14
11
  raise "Incorrect side <#{side}>" unless [:bid, :ask].include?(side)
15
12
  @side = side
16
13
 
17
- opts[:orders] && opts[:orders].each_with_index { |obj, idx| self[idx] = Order.from_hash(obj) }
14
+ if opts[:orders]
15
+ opts[:orders].each_with_index { |obj, idx| self[idx] = Order.from_hash(obj) }
16
+ sort!
17
+ end
18
18
  end
19
19
 
20
20
  #
@@ -43,7 +43,7 @@ module Gekko
43
43
  insert((idx || -1), order)
44
44
  end
45
45
 
46
- #
46
+ #
47
47
  # Returns the first order price, or +nil+ if there's no order
48
48
  #
49
49
  def top
@@ -25,6 +25,19 @@ module Gekko
25
25
  filled?
26
26
  end
27
27
 
28
+ #
29
+ # +LimitOrder+s are sorted by ASC price for asks, DESC price for bids,
30
+ # if prices are equal then creation timestamp is used, and older orders
31
+ # get priority.
32
+ #
33
+ # @return [Fixnum] 1 if self < other, -1 if not, 0 if equivalent
34
+ #
35
+ def <=>(other)
36
+ cmp = (ask? ? 1 : -1) * (price <=> other.price)
37
+ cmp = (created_at <=> other.created_at) if cmp.zero?
38
+ cmp
39
+ end
40
+
28
41
  end
29
42
  end
30
43
 
@@ -11,7 +11,7 @@ module Gekko
11
11
  SECONDS_IN_24H = 60 * 60 * 24
12
12
 
13
13
  attr_accessor :logger, :last_trade_price
14
- attr_reader :volume_24h, :high_24h, :low_24h, :open_24h, :var_24h
14
+ attr_reader :volume_24h, :high_24h, :low_24h, :open_24h, :var_24h, :cursor
15
15
 
16
16
  def initialize(opts = {})
17
17
  @logger = opts[:logger]
@@ -179,6 +179,8 @@ module Gekko
179
179
  def self.from_hash(hsh)
180
180
  tape = Tape.new
181
181
 
182
+ tape.instance_variable_set(:@cursor, hsh[:cursor])
183
+
182
184
  hsh[:events].each do |evt|
183
185
  e = symbolize_keys(evt)
184
186
  e[:type] = e[:type].to_sym
@@ -1,6 +1,6 @@
1
1
  module Gekko
2
2
 
3
3
  # The Gekko version string
4
- VERSION = '0.9.5'
4
+ VERSION = '0.10.0'
5
5
 
6
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gekko
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.5
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - David FRANCOIS
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-08 00:00:00.000000000 Z
11
+ date: 2016-02-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: uuidtools