peatio 2.4.0.pre.alpha → 2.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -1
- data/Gemfile.lock +46 -9
- data/lib/peatio.rb +3 -0
- data/lib/peatio/upstream/base.rb +111 -0
- data/lib/peatio/upstream/registry.rb +14 -0
- data/lib/peatio/version.rb +1 -1
- data/peatio.gemspec +3 -0
- metadata +49 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 76e861ebc60635c251cf135769a45e86e968c4c54811c6e16fb1e73c1495f0ce
|
4
|
+
data.tar.gz: e549b7e2ed045691d17344d95b55be7ee862b39ee2c9e77c86bab06a55d5250c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: adfd9dac25a5797b7c5204ac5f262edde8e1a6647395bc8a6debf3ae68283923d84c4adf49d2b8d27ac640dcff45af6b25c2bad18827ecb82350aa3bb56747b5
|
7
|
+
data.tar.gz: c68562fe7a6deec16e954cbec695837861116b726ed8534c0efd7d0bf70695c89924f19702c2896d054e684a29c40144e5136ad0d588fed869bd7a766187cee3
|
data/.travis.yml
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,13 +1,16 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
peatio (2.4.0
|
4
|
+
peatio (2.4.0)
|
5
5
|
activemodel (> 5.2, <= 6.0.0)
|
6
6
|
amqp
|
7
7
|
bunny
|
8
8
|
clamp
|
9
|
+
em-synchrony (~> 1.0)
|
9
10
|
em-websocket
|
10
11
|
eventmachine
|
12
|
+
faraday_middleware (~> 0.13.1)
|
13
|
+
faye (~> 1.2)
|
11
14
|
jwt
|
12
15
|
mysql2
|
13
16
|
prometheus-client
|
@@ -24,6 +27,8 @@ GEM
|
|
24
27
|
minitest (~> 5.1)
|
25
28
|
tzinfo (~> 1.1)
|
26
29
|
zeitwerk (~> 2.1, >= 2.1.8)
|
30
|
+
addressable (2.7.0)
|
31
|
+
public_suffix (>= 2.0.2, < 5.0)
|
27
32
|
amq-protocol (2.3.0)
|
28
33
|
amqp (1.8.0)
|
29
34
|
amq-protocol (>= 2.2.0)
|
@@ -37,12 +42,23 @@ GEM
|
|
37
42
|
byebug (11.0.1)
|
38
43
|
clamp (1.3.1)
|
39
44
|
coderay (1.1.2)
|
40
|
-
concurrent-ruby (1.1.
|
45
|
+
concurrent-ruby (1.1.6)
|
46
|
+
cookiejar (0.3.3)
|
41
47
|
daemons (1.3.1)
|
42
48
|
diff-lcs (1.3)
|
43
49
|
docile (1.3.2)
|
50
|
+
em-http-request (1.1.5)
|
51
|
+
addressable (>= 2.3.4)
|
52
|
+
cookiejar (!= 0.3.1)
|
53
|
+
em-socksify (>= 0.3)
|
54
|
+
eventmachine (>= 1.0.3)
|
55
|
+
http_parser.rb (>= 0.6.0)
|
56
|
+
em-socksify (0.3.2)
|
57
|
+
eventmachine (>= 1.0.0.beta.4)
|
44
58
|
em-spec (0.2.7)
|
45
59
|
eventmachine
|
60
|
+
em-synchrony (1.0.6)
|
61
|
+
eventmachine (>= 1.0.0.beta.1)
|
46
62
|
em-websocket (0.5.1)
|
47
63
|
eventmachine (>= 0.12.9)
|
48
64
|
http_parser.rb (~> 0.6.0)
|
@@ -50,27 +66,45 @@ GEM
|
|
50
66
|
eventmachine
|
51
67
|
websocket
|
52
68
|
eventmachine (1.2.7)
|
69
|
+
faraday (0.17.3)
|
70
|
+
multipart-post (>= 1.2, < 3)
|
71
|
+
faraday_middleware (0.13.1)
|
72
|
+
faraday (>= 0.7.4, < 1.0)
|
73
|
+
faye (1.2.4)
|
74
|
+
cookiejar (>= 0.3.0)
|
75
|
+
em-http-request (>= 0.3.0)
|
76
|
+
eventmachine (>= 0.12.0)
|
77
|
+
faye-websocket (>= 0.9.1)
|
78
|
+
multi_json (>= 1.0.0)
|
79
|
+
rack (>= 1.0.0)
|
80
|
+
websocket-driver (>= 0.5.1)
|
81
|
+
faye-websocket (0.10.9)
|
82
|
+
eventmachine (>= 0.12.0)
|
83
|
+
websocket-driver (>= 0.5.1)
|
53
84
|
http_parser.rb (0.6.0)
|
54
|
-
i18n (1.
|
85
|
+
i18n (1.8.2)
|
55
86
|
concurrent-ruby (~> 1.0)
|
56
87
|
irb (1.0.0)
|
57
88
|
jaro_winkler (1.5.4)
|
58
89
|
json (2.2.0)
|
59
90
|
jwt (2.2.1)
|
60
91
|
method_source (0.9.2)
|
61
|
-
minitest (5.
|
62
|
-
|
92
|
+
minitest (5.14.0)
|
93
|
+
multi_json (1.14.1)
|
94
|
+
multipart-post (2.1.1)
|
95
|
+
mysql2 (0.5.3)
|
63
96
|
parallel (1.19.0)
|
64
97
|
parser (2.6.5.0)
|
65
98
|
ast (~> 2.4.0)
|
66
|
-
prometheus-client (
|
99
|
+
prometheus-client (2.0.0)
|
67
100
|
pry (0.12.2)
|
68
101
|
coderay (~> 1.1.0)
|
69
102
|
method_source (~> 0.9.0)
|
70
103
|
pry-byebug (3.7.0)
|
71
104
|
byebug (~> 11.0)
|
72
105
|
pry (~> 0.10)
|
73
|
-
|
106
|
+
public_suffix (4.0.3)
|
107
|
+
rack (2.2.2)
|
74
108
|
rainbow (3.0.0)
|
75
109
|
rake (10.5.0)
|
76
110
|
rspec (3.9.0)
|
@@ -114,11 +148,14 @@ GEM
|
|
114
148
|
eventmachine (~> 1.0, >= 1.0.4)
|
115
149
|
rack (>= 1, < 3)
|
116
150
|
thread_safe (0.3.6)
|
117
|
-
tzinfo (1.2.
|
151
|
+
tzinfo (1.2.6)
|
118
152
|
thread_safe (~> 0.1)
|
119
153
|
unicode-display_width (1.6.0)
|
120
154
|
websocket (1.2.8)
|
121
|
-
|
155
|
+
websocket-driver (0.7.1)
|
156
|
+
websocket-extensions (>= 0.1.0)
|
157
|
+
websocket-extensions (0.1.4)
|
158
|
+
zeitwerk (2.3.0)
|
122
159
|
|
123
160
|
PLATFORMS
|
124
161
|
ruby
|
data/lib/peatio.rb
CHANGED
@@ -39,6 +39,9 @@ module Peatio
|
|
39
39
|
require_relative "peatio/wallet/error"
|
40
40
|
require_relative "peatio/wallet/registry"
|
41
41
|
|
42
|
+
require_relative "peatio/upstream/base"
|
43
|
+
require_relative "peatio/upstream/registry"
|
44
|
+
|
42
45
|
require_relative "peatio/transaction"
|
43
46
|
require_relative "peatio/block"
|
44
47
|
end
|
@@ -0,0 +1,111 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Peatio
|
4
|
+
module Upstream
|
5
|
+
class Base
|
6
|
+
DEFAULT_DELAY = 1
|
7
|
+
WEBSOCKET_CONNECTION_RETRY_DELAY = 2
|
8
|
+
|
9
|
+
attr_accessor :logger
|
10
|
+
|
11
|
+
def initialize(config)
|
12
|
+
@host = config["rest"]
|
13
|
+
@adapter = config[:faraday_adapter] || :em_synchrony
|
14
|
+
@config = config
|
15
|
+
@ws_status = false
|
16
|
+
@market = config['source']
|
17
|
+
@target = config['target']
|
18
|
+
@public_trades_cb = []
|
19
|
+
@logger = Peatio::Logger.logger
|
20
|
+
@peatio_mq = config['amqp']
|
21
|
+
mount
|
22
|
+
end
|
23
|
+
|
24
|
+
def mount
|
25
|
+
@public_trades_cb << method(:on_trade)
|
26
|
+
end
|
27
|
+
|
28
|
+
def ws_connect
|
29
|
+
logger.info { "Websocket connecting to #{@ws_url}" }
|
30
|
+
raise "websocket url missing for account #{id}" unless @ws_url
|
31
|
+
|
32
|
+
@ws = Faye::WebSocket::Client.new(@ws_url)
|
33
|
+
|
34
|
+
@ws.on(:open) do |_e|
|
35
|
+
subscribe_trades(@target, @ws)
|
36
|
+
logger.info { "Websocket connected" }
|
37
|
+
end
|
38
|
+
|
39
|
+
@ws.on(:message) do |msg|
|
40
|
+
ws_read_message(msg)
|
41
|
+
end
|
42
|
+
|
43
|
+
@ws.on(:close) do |e|
|
44
|
+
@ws = nil
|
45
|
+
@ws_status = false
|
46
|
+
logger.error "Websocket disconnected: #{e.code} Reason: #{e.reason}"
|
47
|
+
Fiber.new do
|
48
|
+
EM::Synchrony.sleep(WEBSOCKET_CONNECTION_RETRY_DELAY)
|
49
|
+
ws_connect
|
50
|
+
end.resume
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def ws_connect_public
|
55
|
+
ws_connect
|
56
|
+
end
|
57
|
+
|
58
|
+
def subscribe_trades(_market, _ws)
|
59
|
+
method_not_implemented
|
60
|
+
end
|
61
|
+
|
62
|
+
def ws_read_public_message(msg)
|
63
|
+
logger.info { "received public message: #{msg}" }
|
64
|
+
end
|
65
|
+
|
66
|
+
def ws_read_message(msg)
|
67
|
+
logger.debug {"received websocket message: #{msg.data}" }
|
68
|
+
|
69
|
+
object = JSON.parse(msg.data)
|
70
|
+
ws_read_public_message(object)
|
71
|
+
end
|
72
|
+
|
73
|
+
def on_trade(trade)
|
74
|
+
logger.info { "Publishing trade event: #{trade.inspect}" }
|
75
|
+
@peatio_mq.enqueue_event("public", @market, "trades", {trades: [trade]})
|
76
|
+
@peatio_mq.publish :trade, trade_json(trade), {
|
77
|
+
headers: {
|
78
|
+
type: :upstream,
|
79
|
+
market: @market,
|
80
|
+
}
|
81
|
+
}
|
82
|
+
end
|
83
|
+
|
84
|
+
def trade_json(trade)
|
85
|
+
trade.deep_symbolize_keys!
|
86
|
+
{
|
87
|
+
id: trade[:tid],
|
88
|
+
price: trade[:price],
|
89
|
+
amount: trade[:amount],
|
90
|
+
market_id: @market,
|
91
|
+
created_at: Time.at(trade[:date]),
|
92
|
+
taker_type: trade[:taker_type]
|
93
|
+
}
|
94
|
+
end
|
95
|
+
|
96
|
+
def notify_public_trade(trade)
|
97
|
+
@public_trades_cb.each {|cb| cb&.call(trade) }
|
98
|
+
end
|
99
|
+
|
100
|
+
def to_s
|
101
|
+
"Exchange::#{self.class} config: #{@opts}"
|
102
|
+
end
|
103
|
+
|
104
|
+
def build_error(response)
|
105
|
+
JSON.parse(response.body)
|
106
|
+
rescue StandardError => e
|
107
|
+
"Code: #{response.env.status} Message: #{response.env.reason_phrase}"
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
data/lib/peatio/version.rb
CHANGED
data/peatio.gemspec
CHANGED
@@ -27,8 +27,11 @@ Gem::Specification.new do |spec|
|
|
27
27
|
spec.add_dependency "amqp"
|
28
28
|
spec.add_dependency "bunny"
|
29
29
|
spec.add_dependency "clamp"
|
30
|
+
spec.add_dependency "em-synchrony", "~> 1.0"
|
30
31
|
spec.add_dependency "em-websocket"
|
31
32
|
spec.add_dependency "eventmachine"
|
33
|
+
spec.add_dependency "faraday_middleware", "~> 0.13.1"
|
34
|
+
spec.add_dependency "faye", "~> 1.2"
|
32
35
|
spec.add_dependency "jwt"
|
33
36
|
spec.add_dependency "mysql2"
|
34
37
|
spec.add_dependency "prometheus-client"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: peatio
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.4.0
|
4
|
+
version: 2.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Louis B.
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2020-03-10 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activemodel
|
@@ -73,6 +73,20 @@ dependencies:
|
|
73
73
|
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: '0'
|
76
|
+
- !ruby/object:Gem::Dependency
|
77
|
+
name: em-synchrony
|
78
|
+
requirement: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.0'
|
83
|
+
type: :runtime
|
84
|
+
prerelease: false
|
85
|
+
version_requirements: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '1.0'
|
76
90
|
- !ruby/object:Gem::Dependency
|
77
91
|
name: em-websocket
|
78
92
|
requirement: !ruby/object:Gem::Requirement
|
@@ -101,6 +115,34 @@ dependencies:
|
|
101
115
|
- - ">="
|
102
116
|
- !ruby/object:Gem::Version
|
103
117
|
version: '0'
|
118
|
+
- !ruby/object:Gem::Dependency
|
119
|
+
name: faraday_middleware
|
120
|
+
requirement: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 0.13.1
|
125
|
+
type: :runtime
|
126
|
+
prerelease: false
|
127
|
+
version_requirements: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: 0.13.1
|
132
|
+
- !ruby/object:Gem::Dependency
|
133
|
+
name: faye
|
134
|
+
requirement: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '1.2'
|
139
|
+
type: :runtime
|
140
|
+
prerelease: false
|
141
|
+
version_requirements: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - "~>"
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '1.2'
|
104
146
|
- !ruby/object:Gem::Dependency
|
105
147
|
name: jwt
|
106
148
|
requirement: !ruby/object:Gem::Requirement
|
@@ -389,6 +431,8 @@ files:
|
|
389
431
|
- lib/peatio/sql/client.rb
|
390
432
|
- lib/peatio/sql/schema.rb
|
391
433
|
- lib/peatio/transaction.rb
|
434
|
+
- lib/peatio/upstream/base.rb
|
435
|
+
- lib/peatio/upstream/registry.rb
|
392
436
|
- lib/peatio/version.rb
|
393
437
|
- lib/peatio/wallet/abstract.rb
|
394
438
|
- lib/peatio/wallet/error.rb
|
@@ -408,11 +452,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
408
452
|
version: '0'
|
409
453
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
410
454
|
requirements:
|
411
|
-
- - "
|
455
|
+
- - ">="
|
412
456
|
- !ruby/object:Gem::Version
|
413
|
-
version:
|
457
|
+
version: '0'
|
414
458
|
requirements: []
|
415
|
-
rubygems_version: 3.0.
|
459
|
+
rubygems_version: 3.0.6
|
416
460
|
signing_key:
|
417
461
|
specification_version: 4
|
418
462
|
summary: Peatio is a gem for running critical core services
|