gekko 0.10.2 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -8
- data/lib/gekko/book.rb +11 -0
- data/lib/gekko/limit_order.rb +3 -3
- data/lib/gekko/market_order.rb +3 -3
- data/lib/gekko/order.rb +5 -2
- 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: c6a62cd6a603df96f06b4d067339fd3099fa7210
|
4
|
+
data.tar.gz: 89b432fea332373c19f364503f978bd48e36acb6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5bafd1be42f260eb676f90c849d32bd862a70001bd1cd46d89dc609bd125235618d59cc69299bfd489bf15270e26c442cc29a2f75cf7918f8d0008085a1049ae
|
7
|
+
data.tar.gz: 487cf829c967a2737ce01ad0caaf53a415de0bc1106a442f90df1643d08dd4291d109385a59b1e23fc29fb3ccb9ec83f68f874f5a0748637eeb99a956de2b063
|
data/README.md
CHANGED
@@ -2,14 +2,8 @@ Gekko [![Build Status](https://secure.travis-ci.org/Paymium/gekko.png?branch=mas
|
|
2
2
|
=
|
3
3
|
|
4
4
|
## What Gekko is
|
5
|
-
Gekko is
|
5
|
+
Gekko is an in-memory trade order matching engine. It supports limit and market orders.
|
6
6
|
|
7
7
|
## What Gekko is not
|
8
|
-
Gekko is not intended to maintain an accounting database, it just matches trade orders associated to accounts, and returns the necessary data for an accounting system to record the trades
|
9
|
-
|
10
|
-
## Left to do
|
11
|
-
The following items are left to do and will need to be implemented before gekko is considered production-ready.
|
12
|
-
|
13
|
-
- Add and enforce minimum and maximum order sizes
|
14
|
-
- Correctly handle order expiration
|
8
|
+
Gekko is not intended to maintain an accounting database, it just matches trade orders associated to accounts, and returns the necessary data for an accounting system to record the trades.
|
15
9
|
|
data/lib/gekko/book.rb
CHANGED
@@ -49,12 +49,23 @@ module Gekko
|
|
49
49
|
order_side = order.bid? ? bids : asks
|
50
50
|
opposite_side = order.bid? ? asks : bids
|
51
51
|
next_match = opposite_side.first
|
52
|
+
prev_match_id = nil
|
52
53
|
|
53
54
|
while !order.done? && order.crosses?(next_match)
|
55
|
+
# If we match against the same order twice in a row, something went seriously
|
56
|
+
# wrong, we'd rather noisily die at this point.
|
57
|
+
raise 'Infinite matching loop detected !!' if (prev_match_id == next_match.id)
|
58
|
+
prev_match_id = next_match.id
|
59
|
+
|
54
60
|
if next_match.expired?
|
55
61
|
tape << opposite_side.shift.message(:done, reason: :expired)
|
56
62
|
next_match = opposite_side.first
|
57
63
|
|
64
|
+
elsif order.uid == next_match.uid
|
65
|
+
# Same user/account associated to order, we cancel the next match
|
66
|
+
tape << opposite_side.shift.message(:done, reason: :canceled)
|
67
|
+
next_match = opposite_side.first
|
68
|
+
|
58
69
|
else
|
59
70
|
execute_trade(next_match, order)
|
60
71
|
|
data/lib/gekko/limit_order.rb
CHANGED
@@ -7,8 +7,8 @@ module Gekko
|
|
7
7
|
|
8
8
|
attr_accessor :price
|
9
9
|
|
10
|
-
def initialize(side, id, size, price, expiration = nil)
|
11
|
-
super(side, id, size, expiration)
|
10
|
+
def initialize(side, id, uid, size, price, expiration = nil)
|
11
|
+
super(side, id, uid, size, expiration)
|
12
12
|
@price = price
|
13
13
|
|
14
14
|
raise 'Price must be a positive integer' if @price.nil? || (!@price.is_a?(Fixnum) || (@price <= 0))
|
@@ -45,7 +45,7 @@ module Gekko
|
|
45
45
|
# @return [Gekko::LimitOrder] A limit order
|
46
46
|
#
|
47
47
|
def self.from_hash(hsh)
|
48
|
-
order = LimitOrder.new(hsh[:side], UUID.parse(hsh[:id]), hsh[:size], hsh[:price], hsh[:expiration])
|
48
|
+
order = LimitOrder.new(hsh[:side], UUID.parse(hsh[:id]), UUID.parse(hsh[:uid]), hsh[:size], hsh[:price], hsh[:expiration])
|
49
49
|
order.remaining = hsh[:remaining] || hsh[:size]
|
50
50
|
order.created_at = hsh[:created_at] if hsh[:created_at]
|
51
51
|
order
|
data/lib/gekko/market_order.rb
CHANGED
@@ -8,8 +8,8 @@ module Gekko
|
|
8
8
|
|
9
9
|
attr_accessor :quote_margin, :remaining_quote_margin, :max_precision
|
10
10
|
|
11
|
-
def initialize(side, id, size, quote_margin, expiration = nil)
|
12
|
-
super(side, id, size, expiration)
|
11
|
+
def initialize(side, id, uid, size, quote_margin, expiration = nil)
|
12
|
+
super(side, id, uid, size, expiration)
|
13
13
|
|
14
14
|
@quote_margin = quote_margin
|
15
15
|
@remaining_quote_margin = @quote_margin
|
@@ -46,7 +46,7 @@ module Gekko
|
|
46
46
|
# @return [Gekko::MarketOrder] A market order
|
47
47
|
#
|
48
48
|
def self.from_hash(hsh)
|
49
|
-
order = MarketOrder.new(hsh[:side], UUID.parse(hsh[:id]), hsh[:size], hsh[:quote_margin], hsh[:expiration])
|
49
|
+
order = MarketOrder.new(hsh[:side], UUID.parse(hsh[:id]), UUID.parse(hsh[:uid]), hsh[:size], hsh[:quote_margin], hsh[:expiration])
|
50
50
|
order.created_at = hsh[:created_at] if hsh[:created_at]
|
51
51
|
order
|
52
52
|
end
|
data/lib/gekko/order.rb
CHANGED
@@ -9,10 +9,11 @@ module Gekko
|
|
9
9
|
|
10
10
|
include Serialization
|
11
11
|
|
12
|
-
attr_accessor :id, :side, :size, :remaining, :price, :expiration, :created_at
|
12
|
+
attr_accessor :id, :uid, :side, :size, :remaining, :price, :expiration, :created_at
|
13
13
|
|
14
|
-
def initialize(side, id, size, expiration = nil)
|
14
|
+
def initialize(side, id, uid, size, expiration = nil)
|
15
15
|
@id = id
|
16
|
+
@uid = uid
|
16
17
|
@side = side && side.to_sym
|
17
18
|
@size = size
|
18
19
|
@remaining = @size
|
@@ -20,6 +21,7 @@ module Gekko
|
|
20
21
|
@created_at = Time.now.to_f
|
21
22
|
|
22
23
|
raise 'Orders must have an UUID' unless @id && @id.is_a?(UUID)
|
24
|
+
raise 'Orders must have a user ID' unless @uid && @uid.is_a?(UUID)
|
23
25
|
raise 'Side must be either :bid or :ask' unless [:bid, :ask].include?(@side)
|
24
26
|
raise 'Size must be a positive integer' if (@size && (!@size.is_a?(Fixnum) || @size <= 0))
|
25
27
|
raise 'Expiration must be omitted or be an integer' unless (@expiration.nil? || (@expiration.is_a?(Fixnum) && @expiration > 0))
|
@@ -108,6 +110,7 @@ module Gekko
|
|
108
110
|
def to_hash
|
109
111
|
hsh = {
|
110
112
|
id: id.to_s,
|
113
|
+
uid: uid.to_s,
|
111
114
|
side: side,
|
112
115
|
size: size,
|
113
116
|
price: price,
|
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: 1.0.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-
|
11
|
+
date: 2016-02-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: uuidtools
|