gekko 0.2.1 → 0.3.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/lib/gekko/book.rb +61 -33
- data/lib/gekko/order.rb +8 -1
- data/lib/gekko/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4aa84d5ef89d634ca0486aada06125be7d6b82dd
|
4
|
+
data.tar.gz: b99d3bb758325ff8fedb867ccb61959e1002f024
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f82104b6dae8bb86079fce21996b6eccaa5c024703888b553e85a06451693e7380e158b88fdb6f19e3d113ae6a2e67d454a4550ce32326b7a97ed4064916a53f
|
7
|
+
data.tar.gz: 94bcc19c7d06bf532bf1da8984788395df44d4f38dcdaec8ac61e2f4814c27f53b275c8b19819cf424aef0645d3e0c79243ea74beedf21fefc517039943499bb
|
data/lib/gekko/book.rb
CHANGED
@@ -30,7 +30,10 @@ module Gekko
|
|
30
30
|
raise 'Order must be a Gekko::LimitOrder or a Gekko::MarketOrder' unless [LimitOrder, MarketOrder].include?(order.class)
|
31
31
|
|
32
32
|
if received.has_key?(order.id.to_s)
|
33
|
-
tape << order.message(:reject, reason:
|
33
|
+
tape << order.message(:reject, reason: :duplicate_id)
|
34
|
+
|
35
|
+
elsif order.expired?
|
36
|
+
tape << order.message(:reject, reason: :expired)
|
34
37
|
|
35
38
|
else
|
36
39
|
old_ticker = ticker
|
@@ -43,40 +46,46 @@ module Gekko
|
|
43
46
|
next_match = opposite_side.first
|
44
47
|
|
45
48
|
while !order.done? && order.crosses?(next_match)
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
49
|
+
if next_match.expired?
|
50
|
+
tape << opposite_side.shift.message(:done, reason: :expired)
|
51
|
+
next_match = opposite_side.first
|
52
|
+
|
53
|
+
else
|
54
|
+
trade_price = next_match.price
|
55
|
+
base_size = [next_match.remaining, order.remaining].min
|
56
|
+
|
57
|
+
if order.is_a?(LimitOrder)
|
58
|
+
quote_size = (base_size * trade_price) / (10 ** base_precision)
|
59
|
+
|
60
|
+
elsif order.is_a?(MarketOrder)
|
61
|
+
if order.ask? || (order.remaining_quote_margin > ((trade_price * base_size) / (10 ** base_precision)))
|
62
|
+
quote_size = ((trade_price * base_size) / (10 ** base_precision))
|
63
|
+
order.remaining_quote_margin -= quote_size if order.bid?
|
64
|
+
elsif order.bid?
|
65
|
+
quote_size = order.remaining_quote_margin
|
66
|
+
base_size = (order.remaining_quote_margin * (10 ** base_precision)) / trade_price
|
67
|
+
order.remaining_quote_margin -= quote_size
|
68
|
+
end
|
60
69
|
end
|
61
|
-
end
|
62
70
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
71
|
+
tape << {
|
72
|
+
type: :execution,
|
73
|
+
price: trade_price,
|
74
|
+
base_size: base_size,
|
75
|
+
quote_size: quote_size,
|
76
|
+
maker_order_id: next_match.id.to_s,
|
77
|
+
taker_order_id: order.id.to_s,
|
78
|
+
time: Time.now.to_f,
|
79
|
+
tick: order.bid? ? :up : :down
|
80
|
+
}
|
81
|
+
|
82
|
+
order.remaining -= base_size
|
83
|
+
next_match.remaining -= base_size
|
84
|
+
|
85
|
+
if next_match.filled?
|
86
|
+
tape << opposite_side.shift.message(:done, reason: :filled)
|
87
|
+
next_match = opposite_side.first
|
88
|
+
end
|
80
89
|
end
|
81
90
|
end
|
82
91
|
|
@@ -109,6 +118,25 @@ module Gekko
|
|
109
118
|
tick! if (prev_bid != bid) || (prev_ask != ask)
|
110
119
|
end
|
111
120
|
|
121
|
+
#
|
122
|
+
# Removes all expired orders from the book
|
123
|
+
#
|
124
|
+
def remove_expired!
|
125
|
+
prev_bid = bid
|
126
|
+
prev_ask = ask
|
127
|
+
|
128
|
+
[bids, asks].each do |bs|
|
129
|
+
bs.reject! do |order|
|
130
|
+
if order.expired?
|
131
|
+
tape << order.message(:done, reason: :expired)
|
132
|
+
true
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
tick! if (prev_bid != bid) || (prev_ask != ask)
|
138
|
+
end
|
139
|
+
|
112
140
|
#
|
113
141
|
# Returns the current best ask price or +nil+ if there
|
114
142
|
# are currently no asks
|
data/lib/gekko/order.rb
CHANGED
@@ -9,7 +9,7 @@ module Gekko
|
|
9
9
|
|
10
10
|
attr_accessor :id, :side, :size, :remaining, :price, :expiration, :created_at
|
11
11
|
|
12
|
-
def initialize(side, id, size,
|
12
|
+
def initialize(side, id, size, expiration = nil)
|
13
13
|
@id = id
|
14
14
|
@side = side && side.to_sym
|
15
15
|
@size = size
|
@@ -82,5 +82,12 @@ module Gekko
|
|
82
82
|
is_a?(Gekko::MarketOrder)
|
83
83
|
end
|
84
84
|
|
85
|
+
#
|
86
|
+
# Returns +true+ if this order is expired
|
87
|
+
#
|
88
|
+
def expired?
|
89
|
+
expiration && (expiration <= Time.now.to_i)
|
90
|
+
end
|
91
|
+
|
85
92
|
end
|
86
93
|
end
|
data/lib/gekko/version.rb
CHANGED
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.
|
4
|
+
version: 0.3.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: 2015-
|
11
|
+
date: 2015-03-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: uuidtools
|