peatio 0.6.3 → 2.4.0.pre.alpha
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rubocop.yml +148 -8
- data/Gemfile +3 -1
- data/Gemfile.lock +42 -30
- data/lib/peatio.rb +15 -2
- data/lib/peatio/command/inject.rb +3 -1
- data/lib/peatio/command/root.rb +0 -2
- data/lib/peatio/command/security.rb +2 -3
- data/lib/peatio/command/service.rb +18 -4
- data/lib/peatio/injectors/peatio_events.rb +117 -53
- data/lib/peatio/logger.rb +9 -7
- data/lib/peatio/metrics/server.rb +15 -0
- data/lib/peatio/mq/client.rb +35 -14
- data/lib/peatio/ranger/connection.rb +110 -0
- data/lib/peatio/ranger/events.rb +11 -0
- data/lib/peatio/ranger/router.rb +234 -0
- data/lib/peatio/ranger/web_socket.rb +68 -0
- data/lib/peatio/version.rb +1 -1
- data/peatio.gemspec +21 -17
- metadata +76 -32
- data/lib/peatio/command/amqp.rb +0 -9
- data/lib/peatio/mq/events.rb +0 -128
- data/lib/peatio/ranger.rb +0 -135
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b90fd394ac94dbc75f0b370eae2bc13e4c86fb2a564222fa0f75ccae721cce9e
|
4
|
+
data.tar.gz: bc3ad24b91bb0c905d60e1fc90e5cd8de075458d14d9afb375214378b506a956
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e0d3a3cd4910ac623c3bd2befe3f6e3e525d72db15d9b8a190fe962387574290097dd46098fd9543f364b3fbda328ba404c853a132ebeb5b29843946a7f4f31c
|
7
|
+
data.tar.gz: c7cb647b6723e39bc3d7a124b347c0ed186a81b3882772395486efeffe0c74baa9477fb391152b6023e1c7c7496013913a550a9f4679f5e67a08518f9a517df1
|
data/.gitignore
CHANGED
data/.rubocop.yml
CHANGED
@@ -1,8 +1,148 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
1
|
+
# Commonly used screens these days easily fit more than 80 characters.
|
2
|
+
Metrics/LineLength:
|
3
|
+
Max: 120
|
4
|
+
|
5
|
+
# Too short methods lead to extraction of single-use methods, which can make
|
6
|
+
# the code easier to read (by naming things), but can also clutter the class
|
7
|
+
Metrics/MethodLength:
|
8
|
+
Max: 20
|
9
|
+
|
10
|
+
# The guiding principle of classes is SRP, SRP can't be accurately measured by LoC
|
11
|
+
Metrics/ClassLength:
|
12
|
+
Max: 1500
|
13
|
+
|
14
|
+
# No space makes the method definition shorter and differentiates
|
15
|
+
# from a regular assignment.
|
16
|
+
Layout/SpaceAroundEqualsInParameterDefault:
|
17
|
+
EnforcedStyle: no_space
|
18
|
+
|
19
|
+
# Single quotes being faster is hardly measurable and only affects parse time.
|
20
|
+
# Enforcing double quotes reduces the times where you need to change them
|
21
|
+
# when introducing an interpolation. Use single quotes only if their semantics
|
22
|
+
# are needed.
|
23
|
+
Style/StringLiterals:
|
24
|
+
EnforcedStyle: double_quotes
|
25
|
+
|
26
|
+
# We do not need to support Ruby 1.9, so this is good to use.
|
27
|
+
Style/SymbolArray:
|
28
|
+
Enabled: true
|
29
|
+
|
30
|
+
# Most readable form.
|
31
|
+
Layout/AlignHash:
|
32
|
+
EnforcedHashRocketStyle: table
|
33
|
+
EnforcedColonStyle: table
|
34
|
+
|
35
|
+
# Mixing the styles looks just silly.
|
36
|
+
Style/HashSyntax:
|
37
|
+
EnforcedStyle: ruby19_no_mixed_keys
|
38
|
+
|
39
|
+
# has_key? and has_value? are far more readable than key? and value?
|
40
|
+
Style/PreferredHashMethods:
|
41
|
+
Enabled: false
|
42
|
+
|
43
|
+
# String#% is by far the least verbose and only object oriented variant.
|
44
|
+
Style/FormatString:
|
45
|
+
EnforcedStyle: percent
|
46
|
+
|
47
|
+
Style/CollectionMethods:
|
48
|
+
Enabled: true
|
49
|
+
PreferredMethods:
|
50
|
+
# inject seems more common in the community.
|
51
|
+
reduce: "inject"
|
52
|
+
|
53
|
+
|
54
|
+
# Either allow this style or don't. Marking it as safe with parenthesis
|
55
|
+
# is silly. Let's try to live without them for now.
|
56
|
+
Style/ParenthesesAroundCondition:
|
57
|
+
AllowSafeAssignment: false
|
58
|
+
Lint/AssignmentInCondition:
|
59
|
+
AllowSafeAssignment: false
|
60
|
+
|
61
|
+
# A specialized exception class will take one or more arguments and construct the message from it.
|
62
|
+
# So both variants make sense.
|
63
|
+
Style/RaiseArgs:
|
64
|
+
Enabled: false
|
65
|
+
|
66
|
+
# Indenting the chained dots beneath each other is not supported by this cop,
|
67
|
+
# see https://github.com/bbatsov/rubocop/issues/1633
|
68
|
+
Layout/MultilineOperationIndentation:
|
69
|
+
Enabled: false
|
70
|
+
|
71
|
+
# Fail is an alias of raise. Avoid aliases, it's more cognitive load for no gain.
|
72
|
+
# The argument that fail should be used to abort the program is wrong too,
|
73
|
+
# there's Kernel#abort for that.
|
74
|
+
Style/SignalException:
|
75
|
+
EnforcedStyle: only_raise
|
76
|
+
|
77
|
+
# Suppressing exceptions can be perfectly fine, and be it to avoid to
|
78
|
+
# explicitly type nil into the rescue since that's what you want to return,
|
79
|
+
# or suppressing LoadError for optional dependencies
|
80
|
+
Lint/HandleExceptions:
|
81
|
+
Enabled: false
|
82
|
+
|
83
|
+
Layout/SpaceInsideBlockBraces:
|
84
|
+
# The space here provides no real gain in readability while consuming
|
85
|
+
# horizontal space that could be used for a better parameter name.
|
86
|
+
# Also {| differentiates better from a hash than { | does.
|
87
|
+
SpaceBeforeBlockParameters: false
|
88
|
+
|
89
|
+
# No trailing space differentiates better from the block:
|
90
|
+
# foo} means hash, foo } means block.
|
91
|
+
Layout/SpaceInsideHashLiteralBraces:
|
92
|
+
EnforcedStyle: no_space
|
93
|
+
|
94
|
+
# { ... } for multi-line blocks is okay, follow Weirichs rule instead:
|
95
|
+
# https://web.archive.org/web/20140221124509/http://onestepback.org/index.cgi/Tech/Ruby/BraceVsDoEnd.rdoc
|
96
|
+
Style/BlockDelimiters:
|
97
|
+
Enabled: false
|
98
|
+
|
99
|
+
# do / end blocks should be used for side effects,
|
100
|
+
# methods that run a block for side effects and have
|
101
|
+
# a useful return value are rare, assign the return
|
102
|
+
# value to a local variable for those cases.
|
103
|
+
Style/MethodCalledOnDoEndBlock:
|
104
|
+
Enabled: true
|
105
|
+
|
106
|
+
# Enforcing the names of variables? To single letter ones? Just no.
|
107
|
+
Style/SingleLineBlockParams:
|
108
|
+
Enabled: false
|
109
|
+
|
110
|
+
# Shadowing outer local variables with block parameters is often useful
|
111
|
+
# to not reinvent a new name for the same thing, it highlights the relation
|
112
|
+
# between the outer variable and the parameter. The cases where it's actually
|
113
|
+
# confusing are rare, and usually bad for other reasons already, for example
|
114
|
+
# because the method is too long.
|
115
|
+
Lint/ShadowingOuterLocalVariable:
|
116
|
+
Enabled: false
|
117
|
+
|
118
|
+
# Check with yard instead.
|
119
|
+
Style/Documentation:
|
120
|
+
Enabled: false
|
121
|
+
|
122
|
+
# This is just silly. Calling the argument `other` in all cases makes no sense.
|
123
|
+
Naming/BinaryOperatorParameterName:
|
124
|
+
Enabled: false
|
125
|
+
|
126
|
+
# There are valid cases, for example debugging Cucumber steps,
|
127
|
+
# also they'll fail CI anyway
|
128
|
+
Lint/Debugger:
|
129
|
+
Enabled: false
|
130
|
+
|
131
|
+
# Style preference
|
132
|
+
Style/MethodDefParentheses:
|
133
|
+
Enabled: false
|
134
|
+
|
135
|
+
Style/TrailingCommaInArrayLiteral:
|
136
|
+
Enabled: false
|
137
|
+
|
138
|
+
Style/TrailingCommaInHashLiteral:
|
139
|
+
Enabled: false
|
140
|
+
|
141
|
+
Style/ClassAndModuleChildren:
|
142
|
+
EnforcedStyle: compact
|
143
|
+
|
144
|
+
Layout/IndentHeredoc:
|
145
|
+
Enabled: false
|
146
|
+
|
147
|
+
Style/MethodCallWithoutArgsParentheses:
|
148
|
+
Enabled: false
|
data/Gemfile
CHANGED
@@ -1,6 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
source "https://rubygems.org"
|
2
4
|
|
3
|
-
git_source(:github) {
|
5
|
+
git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
|
4
6
|
|
5
7
|
# Specify your gem's dependencies in peatio.gemspec
|
6
8
|
gemspec
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
peatio (0.
|
4
|
+
peatio (2.4.0.pre.alpha)
|
5
5
|
activemodel (> 5.2, <= 6.0.0)
|
6
6
|
amqp
|
7
7
|
bunny
|
@@ -10,6 +10,8 @@ PATH
|
|
10
10
|
eventmachine
|
11
11
|
jwt
|
12
12
|
mysql2
|
13
|
+
prometheus-client
|
14
|
+
thin
|
13
15
|
|
14
16
|
GEM
|
15
17
|
remote: https://rubygems.org/
|
@@ -27,17 +29,18 @@ GEM
|
|
27
29
|
amq-protocol (>= 2.2.0)
|
28
30
|
eventmachine
|
29
31
|
ast (2.4.0)
|
30
|
-
bump (0.
|
31
|
-
bunny (2.
|
32
|
-
amq-protocol (~> 2.3.0)
|
32
|
+
bump (0.8.0)
|
33
|
+
bunny (2.14.3)
|
34
|
+
amq-protocol (~> 2.3, >= 2.3.0)
|
33
35
|
bunny-mock (1.7.0)
|
34
36
|
bunny (>= 1.7)
|
35
37
|
byebug (11.0.1)
|
36
38
|
clamp (1.3.1)
|
37
39
|
coderay (1.1.2)
|
38
40
|
concurrent-ruby (1.1.5)
|
41
|
+
daemons (1.3.1)
|
39
42
|
diff-lcs (1.3)
|
40
|
-
docile (1.3.
|
43
|
+
docile (1.3.2)
|
41
44
|
em-spec (0.2.7)
|
42
45
|
eventmachine
|
43
46
|
em-websocket (0.5.1)
|
@@ -50,51 +53,55 @@ GEM
|
|
50
53
|
http_parser.rb (0.6.0)
|
51
54
|
i18n (1.7.0)
|
52
55
|
concurrent-ruby (~> 1.0)
|
53
|
-
|
54
|
-
|
56
|
+
irb (1.0.0)
|
57
|
+
jaro_winkler (1.5.4)
|
58
|
+
json (2.2.0)
|
55
59
|
jwt (2.2.1)
|
56
60
|
method_source (0.9.2)
|
57
61
|
minitest (5.13.0)
|
58
62
|
mysql2 (0.5.2)
|
59
|
-
parallel (1.
|
60
|
-
parser (2.5.
|
63
|
+
parallel (1.19.0)
|
64
|
+
parser (2.6.5.0)
|
61
65
|
ast (~> 2.4.0)
|
62
|
-
|
66
|
+
prometheus-client (1.0.0)
|
63
67
|
pry (0.12.2)
|
64
68
|
coderay (~> 1.1.0)
|
65
69
|
method_source (~> 0.9.0)
|
66
70
|
pry-byebug (3.7.0)
|
67
71
|
byebug (~> 11.0)
|
68
72
|
pry (~> 0.10)
|
73
|
+
rack (2.0.7)
|
69
74
|
rainbow (3.0.0)
|
70
75
|
rake (10.5.0)
|
71
|
-
rspec (3.
|
72
|
-
rspec-core (~> 3.
|
73
|
-
rspec-expectations (~> 3.
|
74
|
-
rspec-mocks (~> 3.
|
75
|
-
rspec-core (3.
|
76
|
-
rspec-support (~> 3.
|
77
|
-
rspec-expectations (3.
|
76
|
+
rspec (3.9.0)
|
77
|
+
rspec-core (~> 3.9.0)
|
78
|
+
rspec-expectations (~> 3.9.0)
|
79
|
+
rspec-mocks (~> 3.9.0)
|
80
|
+
rspec-core (3.9.0)
|
81
|
+
rspec-support (~> 3.9.0)
|
82
|
+
rspec-expectations (3.9.0)
|
78
83
|
diff-lcs (>= 1.2.0, < 2.0)
|
79
|
-
rspec-support (~> 3.
|
80
|
-
rspec-mocks (3.
|
84
|
+
rspec-support (~> 3.9.0)
|
85
|
+
rspec-mocks (3.9.0)
|
81
86
|
diff-lcs (>= 1.2.0, < 2.0)
|
82
|
-
rspec-support (~> 3.
|
83
|
-
rspec-support (3.
|
87
|
+
rspec-support (~> 3.9.0)
|
88
|
+
rspec-support (3.9.0)
|
84
89
|
rspec_junit_formatter (0.4.1)
|
85
90
|
rspec-core (>= 2, < 4, != 2.12.0)
|
86
|
-
rubocop (0.
|
91
|
+
rubocop (0.76.0)
|
87
92
|
jaro_winkler (~> 1.5.1)
|
88
93
|
parallel (~> 1.10)
|
89
|
-
parser (>= 2.
|
90
|
-
powerpack (~> 0.1)
|
94
|
+
parser (>= 2.6)
|
91
95
|
rainbow (>= 2.2.2, < 4.0)
|
92
96
|
ruby-progressbar (~> 1.7)
|
93
|
-
unicode-display_width (
|
94
|
-
rubocop-github (0.
|
95
|
-
rubocop (~> 0.
|
96
|
-
|
97
|
-
|
97
|
+
unicode-display_width (>= 1.4.0, < 1.7)
|
98
|
+
rubocop-github (0.13.0)
|
99
|
+
rubocop (~> 0.70)
|
100
|
+
rubocop-performance (~> 1.3.0)
|
101
|
+
rubocop-performance (1.3.0)
|
102
|
+
rubocop (>= 0.68.0)
|
103
|
+
ruby-progressbar (1.10.1)
|
104
|
+
simplecov (0.17.1)
|
98
105
|
docile (~> 1.1)
|
99
106
|
json (>= 1.8, < 3)
|
100
107
|
simplecov-html (~> 0.10.0)
|
@@ -102,10 +109,14 @@ GEM
|
|
102
109
|
simplecov-json (0.2)
|
103
110
|
json
|
104
111
|
simplecov
|
112
|
+
thin (1.7.2)
|
113
|
+
daemons (~> 1.0, >= 1.0.9)
|
114
|
+
eventmachine (~> 1.0, >= 1.0.4)
|
115
|
+
rack (>= 1, < 3)
|
105
116
|
thread_safe (0.3.6)
|
106
117
|
tzinfo (1.2.5)
|
107
118
|
thread_safe (~> 0.1)
|
108
|
-
unicode-display_width (1.
|
119
|
+
unicode-display_width (1.6.0)
|
109
120
|
websocket (1.2.8)
|
110
121
|
zeitwerk (2.2.1)
|
111
122
|
|
@@ -118,6 +129,7 @@ DEPENDENCIES
|
|
118
129
|
bunny-mock
|
119
130
|
em-spec
|
120
131
|
em-websocket-client
|
132
|
+
irb
|
121
133
|
peatio!
|
122
134
|
pry-byebug
|
123
135
|
rake (~> 10.0)
|
data/lib/peatio.rb
CHANGED
@@ -1,9 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "logger"
|
2
4
|
require "json"
|
5
|
+
require "base64"
|
3
6
|
require "mysql2"
|
4
7
|
require "bunny"
|
5
8
|
require "eventmachine"
|
6
9
|
require "em-websocket"
|
10
|
+
require "socket"
|
11
|
+
require "securerandom"
|
12
|
+
require "rack"
|
13
|
+
require "prometheus/client"
|
14
|
+
require "prometheus/client/push"
|
15
|
+
require "prometheus/client/data_stores/single_threaded"
|
16
|
+
require "prometheus/middleware/exporter"
|
7
17
|
|
8
18
|
module Peatio
|
9
19
|
require_relative "peatio/error"
|
@@ -12,8 +22,11 @@ module Peatio
|
|
12
22
|
require_relative "peatio/sql/client"
|
13
23
|
require_relative "peatio/sql/schema"
|
14
24
|
require_relative "peatio/mq/client"
|
15
|
-
require_relative "peatio/
|
16
|
-
require_relative "peatio/ranger"
|
25
|
+
require_relative "peatio/metrics/server"
|
26
|
+
require_relative "peatio/ranger/events"
|
27
|
+
require_relative "peatio/ranger/router"
|
28
|
+
require_relative "peatio/ranger/connection"
|
29
|
+
require_relative "peatio/ranger/web_socket"
|
17
30
|
require_relative "peatio/injectors/peatio_events"
|
18
31
|
require_relative "peatio/security/key_generator"
|
19
32
|
require_relative "peatio/auth/jwt_authenticator"
|
@@ -1,8 +1,10 @@
|
|
1
1
|
module Peatio::Command
|
2
2
|
class Inject < Peatio::Command::Base
|
3
3
|
class PeatioEvents < Peatio::Command::Base
|
4
|
+
option ["-e", "--exchange"], "NAME", "exchange name to inject messages to", default: "peatio.events.ranger"
|
4
5
|
def execute
|
5
|
-
Peatio::
|
6
|
+
Peatio::Logger.logger.level = :debug
|
7
|
+
Peatio::Injectors::PeatioEvents.new.run!(exchange)
|
6
8
|
end
|
7
9
|
end
|
8
10
|
|
data/lib/peatio/command/root.rb
CHANGED
@@ -1,13 +1,11 @@
|
|
1
1
|
require "peatio/command/base"
|
2
2
|
require "peatio/command/service"
|
3
3
|
require "peatio/command/db"
|
4
|
-
require "peatio/command/amqp"
|
5
4
|
require "peatio/command/inject"
|
6
5
|
require "peatio/command/security"
|
7
6
|
|
8
7
|
module Peatio
|
9
8
|
class Root < Command::Base
|
10
|
-
subcommand "amqp", "AMQP related sub-commands", Peatio::Command::AMQP::Root
|
11
9
|
subcommand "db", "Database related sub-commands", Peatio::Command::DB::Root
|
12
10
|
subcommand "service", "Services management related sub-commands", Peatio::Command::Service::Root
|
13
11
|
subcommand "inject", "Data injectors", Peatio::Command::Inject
|
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Peatio::Command
|
4
4
|
class Security < Peatio::Command::Base
|
@@ -17,9 +17,8 @@ module Peatio::Command
|
|
17
17
|
begin
|
18
18
|
keypair.save(path)
|
19
19
|
puts "Files saved in #{File.join(path, 'rsa-key')}"
|
20
|
-
|
21
20
|
rescue IOError => e
|
22
|
-
abort(
|
21
|
+
abort("Failed saving files")
|
23
22
|
end
|
24
23
|
end
|
25
24
|
end
|
@@ -1,10 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Peatio::Command::Service
|
2
4
|
class Start < Peatio::Command::Base
|
3
5
|
class Ranger < Peatio::Command::Base
|
6
|
+
option ["-e", "--exchange"], "NAME", "exchange name to inject messages to", default: "peatio.events.ranger"
|
7
|
+
option "--[no-]stats", :flag, "display periodically connections statistics", default: true
|
8
|
+
option "--stats-period", "SECONDS", "period of displaying stats in seconds", default: 30
|
4
9
|
def execute
|
5
|
-
if ENV["JWT_PUBLIC_KEY"].
|
6
|
-
raise ArgumentError, "JWT_PUBLIC_KEY was not specified."
|
7
|
-
end
|
10
|
+
raise ArgumentError, "JWT_PUBLIC_KEY was not specified." if ENV["JWT_PUBLIC_KEY"].to_s.empty?
|
8
11
|
|
9
12
|
key_decoded = Base64.urlsafe_decode64(ENV["JWT_PUBLIC_KEY"])
|
10
13
|
|
@@ -13,7 +16,18 @@ module Peatio::Command::Service
|
|
13
16
|
raise ArgumentError, "JWT_PUBLIC_KEY was set to private key, however it should be public."
|
14
17
|
end
|
15
18
|
|
16
|
-
|
19
|
+
raise "stats period missing" if stats? && !stats_period
|
20
|
+
|
21
|
+
Prometheus::Client.config.data_store = Prometheus::Client::DataStores::SingleThreaded.new()
|
22
|
+
registry = Prometheus::Client.registry
|
23
|
+
|
24
|
+
opts = {
|
25
|
+
display_stats: stats?,
|
26
|
+
stats_period: stats_period.to_f,
|
27
|
+
metrics_port: 8082,
|
28
|
+
registry: registry
|
29
|
+
}
|
30
|
+
::Peatio::Ranger.run!(jwt_public_key, exchange, opts)
|
17
31
|
end
|
18
32
|
end
|
19
33
|
|
@@ -1,8 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Peatio::Injectors
|
2
4
|
class PeatioEvents
|
3
5
|
attr_accessor :market, :market_name, :base_unit, :quote_unit, :seller_uid, :buyer_uid, :logger
|
4
6
|
|
5
|
-
def run!
|
7
|
+
def run!(exchange_name)
|
6
8
|
require "time"
|
7
9
|
@logger = Peatio::Logger.logger
|
8
10
|
@market = "eurusd"
|
@@ -12,24 +14,24 @@ module Peatio::Injectors
|
|
12
14
|
@seller_uid = 21
|
13
15
|
@buyer_uid = 42
|
14
16
|
@messages = create_messages
|
15
|
-
@
|
16
|
-
|
17
|
+
@opts = {
|
18
|
+
ex_name: exchange_name
|
19
|
+
}
|
17
20
|
EventMachine.run do
|
18
|
-
|
19
|
-
Peatio::MQ::Client.connect!
|
20
|
-
Peatio::MQ::Client.create_channel!
|
21
|
-
inject_message
|
21
|
+
inject_message()
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
-
def inject_message
|
25
|
+
def inject_message()
|
26
26
|
if message = @messages.shift
|
27
27
|
type, id, event, data = message
|
28
|
-
Peatio::
|
29
|
-
|
30
|
-
|
28
|
+
Peatio::Ranger::Events.publish(type, id, event, data, @opts)
|
29
|
+
EM.next_tick do
|
30
|
+
inject_message()
|
31
|
+
end
|
31
32
|
else
|
32
|
-
Peatio::MQ::Client.disconnect
|
33
|
+
Peatio::MQ::Client.disconnect
|
34
|
+
EventMachine.stop
|
33
35
|
end
|
34
36
|
end
|
35
37
|
|
@@ -41,6 +43,10 @@ module Peatio::Injectors
|
|
41
43
|
private_trade_user1,
|
42
44
|
private_trade_user2,
|
43
45
|
public_trade,
|
46
|
+
public_orderbook_increment1,
|
47
|
+
public_orderbook_snapshot1,
|
48
|
+
public_orderbook_increment2,
|
49
|
+
public_orderbook_increment3,
|
44
50
|
]
|
45
51
|
end
|
46
52
|
|
@@ -52,8 +58,8 @@ module Peatio::Injectors
|
|
52
58
|
Time.now
|
53
59
|
end
|
54
60
|
|
55
|
-
alias
|
56
|
-
alias
|
61
|
+
alias completed_at updated_at
|
62
|
+
alias canceled_at updated_at
|
57
63
|
|
58
64
|
def public_orderbook
|
59
65
|
[
|
@@ -62,19 +68,78 @@ module Peatio::Injectors
|
|
62
68
|
"update",
|
63
69
|
{
|
64
70
|
"asks": [
|
65
|
-
["1020.0","0.005"],
|
66
|
-
["1026.0","0.03"]
|
71
|
+
["1020.0", "0.005"],
|
72
|
+
["1026.0", "0.03"]
|
73
|
+
],
|
74
|
+
"bids": [
|
75
|
+
["1000.0", "0.25"],
|
76
|
+
["999.0", "0.005"],
|
77
|
+
["994.0", "0.005"],
|
78
|
+
["1.0", "11.0"]
|
79
|
+
]
|
80
|
+
}
|
81
|
+
]
|
82
|
+
end
|
83
|
+
|
84
|
+
def public_orderbook_snapshot1
|
85
|
+
[
|
86
|
+
"public",
|
87
|
+
market,
|
88
|
+
"ob-snap",
|
89
|
+
{
|
90
|
+
"asks": [
|
91
|
+
["1020.0", "0.005"],
|
92
|
+
["1026.0", "0.03"]
|
67
93
|
],
|
68
94
|
"bids": [
|
69
|
-
["1000.0","0.25"],
|
70
|
-
["999.0","0.005"],
|
71
|
-
["994.0","0.005"],
|
72
|
-
["1.0","11.0"]
|
95
|
+
["1000.0", "0.25"],
|
96
|
+
["999.0", "0.005"],
|
97
|
+
["994.0", "0.005"],
|
98
|
+
["1.0", "11.0"]
|
73
99
|
]
|
74
100
|
}
|
75
101
|
]
|
76
102
|
end
|
77
103
|
|
104
|
+
def public_orderbook_increment1
|
105
|
+
[
|
106
|
+
"public",
|
107
|
+
market,
|
108
|
+
"ob-inc",
|
109
|
+
{
|
110
|
+
"asks": [
|
111
|
+
["1020.0", "0.015"],
|
112
|
+
],
|
113
|
+
}
|
114
|
+
]
|
115
|
+
end
|
116
|
+
|
117
|
+
def public_orderbook_increment2
|
118
|
+
[
|
119
|
+
"public",
|
120
|
+
market,
|
121
|
+
"ob-inc",
|
122
|
+
{
|
123
|
+
"bids": [
|
124
|
+
["1000.0", "0"],
|
125
|
+
],
|
126
|
+
}
|
127
|
+
]
|
128
|
+
end
|
129
|
+
|
130
|
+
def public_orderbook_increment3
|
131
|
+
[
|
132
|
+
"public",
|
133
|
+
market,
|
134
|
+
"ob-inc",
|
135
|
+
{
|
136
|
+
"bids": [
|
137
|
+
["999.0", "0.001"],
|
138
|
+
],
|
139
|
+
}
|
140
|
+
]
|
141
|
+
end
|
142
|
+
|
78
143
|
def public_tickers
|
79
144
|
[
|
80
145
|
"public",
|
@@ -82,19 +147,19 @@ module Peatio::Injectors
|
|
82
147
|
"tickers",
|
83
148
|
{
|
84
149
|
market => {
|
85
|
-
"name":
|
86
|
-
"base_unit":
|
150
|
+
"name": market_name,
|
151
|
+
"base_unit": base_unit,
|
87
152
|
"quote_unit": quote_unit,
|
88
|
-
"low":
|
89
|
-
"high":
|
90
|
-
"last":
|
91
|
-
"open":
|
92
|
-
"volume":
|
93
|
-
"sell":
|
94
|
-
"buy":
|
95
|
-
"at":
|
96
|
-
}
|
153
|
+
"low": "1000.0",
|
154
|
+
"high": "10000.0",
|
155
|
+
"last": "1000.0",
|
156
|
+
"open": 1000.0,
|
157
|
+
"volume": "0.0",
|
158
|
+
"sell": "1020.0",
|
159
|
+
"buy": "1000.0",
|
160
|
+
"at": Time.now.to_i
|
97
161
|
}
|
162
|
+
}
|
98
163
|
]
|
99
164
|
end
|
100
165
|
|
@@ -104,14 +169,14 @@ module Peatio::Injectors
|
|
104
169
|
"IDABC0000001",
|
105
170
|
"order",
|
106
171
|
{
|
107
|
-
"id":
|
108
|
-
"at":
|
109
|
-
"market":
|
110
|
-
"kind":"bid",
|
111
|
-
"price":"1026.0",
|
112
|
-
"state":"wait",
|
113
|
-
"volume":"0.001",
|
114
|
-
"origin_volume":"0.001"
|
172
|
+
"id": 22,
|
173
|
+
"at": created_at.to_i,
|
174
|
+
"market": market,
|
175
|
+
"kind": "bid",
|
176
|
+
"price": "1026.0",
|
177
|
+
"state": "wait",
|
178
|
+
"volume": "0.001",
|
179
|
+
"origin_volume": "0.001"
|
115
180
|
}
|
116
181
|
]
|
117
182
|
end
|
@@ -122,10 +187,10 @@ module Peatio::Injectors
|
|
122
187
|
"IDABC0000001",
|
123
188
|
"trade",
|
124
189
|
{
|
125
|
-
"id":
|
126
|
-
"kind":
|
127
|
-
"at":
|
128
|
-
"price":
|
190
|
+
"id": 7,
|
191
|
+
"kind": "ask",
|
192
|
+
"at": created_at.to_i,
|
193
|
+
"price": "1020.0",
|
129
194
|
"volume": "0.001",
|
130
195
|
"ask_id": 15,
|
131
196
|
"bid_id": 22,
|
@@ -140,10 +205,10 @@ module Peatio::Injectors
|
|
140
205
|
"IDABC0000002",
|
141
206
|
"trade",
|
142
207
|
{
|
143
|
-
"id":
|
144
|
-
"kind":
|
145
|
-
"at":
|
146
|
-
"price":
|
208
|
+
"id": 7,
|
209
|
+
"kind": "bid",
|
210
|
+
"at": created_at.to_i,
|
211
|
+
"price": "1020.0",
|
147
212
|
"volume": "0.001",
|
148
213
|
"ask_id": 15,
|
149
214
|
"bid_id": 22,
|
@@ -160,17 +225,16 @@ module Peatio::Injectors
|
|
160
225
|
{
|
161
226
|
"trades": [
|
162
227
|
{
|
163
|
-
"tid":
|
164
|
-
"
|
165
|
-
"date":
|
166
|
-
"price":
|
228
|
+
"tid": 7,
|
229
|
+
"taker_type": "buy",
|
230
|
+
"date": created_at.to_i,
|
231
|
+
"price": "1020.0",
|
167
232
|
"amount":
|
168
|
-
|
233
|
+
"0.001"
|
169
234
|
}
|
170
235
|
]
|
171
236
|
}
|
172
237
|
]
|
173
238
|
end
|
174
|
-
|
175
239
|
end
|
176
240
|
end
|