peatio 0.4.4 → 0.4.5
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 -0
- data/Gemfile.lock +9 -9
- data/lib/peatio/auth/jwt_authenticator.rb +1 -1
- data/lib/peatio/injectors/peatio_events.rb +98 -131
- data/lib/peatio/mq/events.rb +3 -3
- data/lib/peatio/ranger.rb +62 -33
- data/lib/peatio/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8cc7f7dae49e5e34e71138ae6f7c5097516309d421fe9a048d3fffc5aa4c4081
|
4
|
+
data.tar.gz: 209f063cd346d27742b57a12a991904cd7c9c320154aab9fb7d50eb9ce45d736
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9b85df8a9f919dadc29dfaff264555cfecefd1b5477e0161ccf517f1370c1a7a4e6f7b663cdc7b8982b70f937c85bf522f94b887ce30d5ec86710385814f2f37
|
7
|
+
data.tar.gz: 0b2081360b0f23ca898dbef3e0a0d3327f9355ff0e2e5de3c45fb45d30ff0da7fc30d6d2885abbe74210cf87b619578b0dccc1606c4f218bad772882df9cd197
|
data/.travis.yml
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
peatio (0.4.
|
4
|
+
peatio (0.4.5)
|
5
5
|
amqp
|
6
6
|
bunny
|
7
7
|
clamp
|
@@ -19,8 +19,8 @@ GEM
|
|
19
19
|
eventmachine
|
20
20
|
ast (2.4.0)
|
21
21
|
bump (0.6.1)
|
22
|
-
bunny (2.
|
23
|
-
amq-protocol (~> 2.3
|
22
|
+
bunny (2.11.0)
|
23
|
+
amq-protocol (~> 2.3.0)
|
24
24
|
bunny-mock (1.7.0)
|
25
25
|
bunny (>= 1.7)
|
26
26
|
clamp (1.3.0)
|
@@ -52,7 +52,7 @@ GEM
|
|
52
52
|
rspec-mocks (~> 3.8.0)
|
53
53
|
rspec-core (3.8.0)
|
54
54
|
rspec-support (~> 3.8.0)
|
55
|
-
rspec-expectations (3.8.
|
55
|
+
rspec-expectations (3.8.1)
|
56
56
|
diff-lcs (>= 1.2.0, < 2.0)
|
57
57
|
rspec-support (~> 3.8.0)
|
58
58
|
rspec-mocks (3.8.0)
|
@@ -61,16 +61,16 @@ GEM
|
|
61
61
|
rspec-support (3.8.0)
|
62
62
|
rspec_junit_formatter (0.4.1)
|
63
63
|
rspec-core (>= 2, < 4, != 2.12.0)
|
64
|
-
rubocop (0.
|
64
|
+
rubocop (0.58.2)
|
65
65
|
jaro_winkler (~> 1.5.1)
|
66
66
|
parallel (~> 1.10)
|
67
67
|
parser (>= 2.5, != 2.5.1.1)
|
68
68
|
powerpack (~> 0.1)
|
69
69
|
rainbow (>= 2.2.2, < 4.0)
|
70
70
|
ruby-progressbar (~> 1.7)
|
71
|
-
unicode-display_width (~> 1.
|
72
|
-
rubocop-github (0.
|
73
|
-
rubocop (~> 0.
|
71
|
+
unicode-display_width (~> 1.0, >= 1.0.1)
|
72
|
+
rubocop-github (0.10.0)
|
73
|
+
rubocop (~> 0.51)
|
74
74
|
ruby-progressbar (1.10.0)
|
75
75
|
simplecov (0.16.1)
|
76
76
|
docile (~> 1.1)
|
@@ -101,4 +101,4 @@ DEPENDENCIES
|
|
101
101
|
simplecov-json
|
102
102
|
|
103
103
|
BUNDLED WITH
|
104
|
-
1.17.
|
104
|
+
1.17.3
|
@@ -1,11 +1,14 @@
|
|
1
1
|
module Peatio::Injectors
|
2
2
|
class PeatioEvents
|
3
|
-
attr_accessor :market, :seller_uid, :buyer_uid, :logger
|
3
|
+
attr_accessor :market, :market_name, :base_unit, :quote_unit, :seller_uid, :buyer_uid, :logger
|
4
4
|
|
5
5
|
def run!
|
6
6
|
require "time"
|
7
7
|
@logger = Peatio::Logger.logger
|
8
8
|
@market = "eurusd"
|
9
|
+
@market_name = "EUR/USD"
|
10
|
+
@base_unit = "eur"
|
11
|
+
@quote_unit = "usd"
|
9
12
|
@seller_uid = 21
|
10
13
|
@buyer_uid = 42
|
11
14
|
@messages = create_messages
|
@@ -32,12 +35,12 @@ module Peatio::Injectors
|
|
32
35
|
|
33
36
|
def create_messages
|
34
37
|
[
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
38
|
+
public_tickers,
|
39
|
+
public_orderbook,
|
40
|
+
private_order,
|
41
|
+
private_trade_user1,
|
42
|
+
private_trade_user2,
|
43
|
+
public_trade,
|
41
44
|
]
|
42
45
|
end
|
43
46
|
|
@@ -52,158 +55,122 @@ module Peatio::Injectors
|
|
52
55
|
alias :completed_at :updated_at
|
53
56
|
alias :canceled_at :updated_at
|
54
57
|
|
55
|
-
def
|
58
|
+
def public_orderbook
|
56
59
|
[
|
57
|
-
"
|
58
|
-
|
59
|
-
"
|
60
|
+
"public",
|
61
|
+
market,
|
62
|
+
"update",
|
60
63
|
{
|
61
|
-
|
62
|
-
|
64
|
+
"asks": [
|
65
|
+
["1020.0","0.005"],
|
66
|
+
["1026.0","0.03"]
|
67
|
+
],
|
68
|
+
"bids": [
|
69
|
+
["1000.0","0.25"],
|
70
|
+
["999.0","0.005"],
|
71
|
+
["994.0","0.005"],
|
72
|
+
["1.0","11.0"]
|
73
|
+
]
|
74
|
+
}
|
63
75
|
]
|
64
76
|
end
|
65
77
|
|
66
|
-
def
|
78
|
+
def public_tickers
|
67
79
|
[
|
68
80
|
"public",
|
69
|
-
|
70
|
-
"
|
81
|
+
"global",
|
82
|
+
"tickers",
|
71
83
|
{
|
72
|
-
market
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
price: "0.03",
|
87
|
-
state: "open",
|
88
|
-
trades_count: 0,
|
89
|
-
created_at: created_at.iso8601,
|
90
|
-
},
|
84
|
+
market => {
|
85
|
+
"name": market_name,
|
86
|
+
"base_unit": base_unit,
|
87
|
+
"quote_unit": quote_unit,
|
88
|
+
"low": "1000.0",
|
89
|
+
"high": "10000.0",
|
90
|
+
"last": "1000.0",
|
91
|
+
"open": 1000.0,
|
92
|
+
"volume": "0.0",
|
93
|
+
"sell": "1020.0",
|
94
|
+
"buy": "1000.0",
|
95
|
+
"at": Time.now.to_i
|
96
|
+
}
|
97
|
+
}
|
91
98
|
]
|
92
99
|
end
|
93
100
|
|
94
|
-
def
|
101
|
+
def private_order
|
95
102
|
[
|
96
|
-
"
|
97
|
-
|
98
|
-
"
|
103
|
+
"private",
|
104
|
+
"IDABC0000001",
|
105
|
+
"order",
|
99
106
|
{
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
initial_income_amount: "3.0",
|
110
|
-
current_income_amount: "3.0",
|
111
|
-
initial_outcome_amount: "100.0",
|
112
|
-
current_outcome_amount: "100.0",
|
113
|
-
strategy: "limit",
|
114
|
-
price: "0.03",
|
115
|
-
state: "canceled",
|
116
|
-
trades_count: 0,
|
117
|
-
created_at: created_at.iso8601,
|
118
|
-
canceled_at: canceled_at.iso8601,
|
119
|
-
},
|
107
|
+
"id": 22,
|
108
|
+
"at": created_at.to_i,
|
109
|
+
"market": market,
|
110
|
+
"kind":"bid",
|
111
|
+
"price":"1026.0",
|
112
|
+
"state":"wait",
|
113
|
+
"volume":"0.001",
|
114
|
+
"origin_volume":"0.001"
|
115
|
+
}
|
120
116
|
]
|
121
117
|
end
|
122
118
|
|
123
|
-
def
|
119
|
+
def private_trade_user1
|
124
120
|
[
|
125
|
-
"
|
126
|
-
|
127
|
-
"
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
current_income_amount: "0.0",
|
139
|
-
previous_income_amount: "3.0",
|
140
|
-
initial_outcome_amount: "100.0",
|
141
|
-
current_outcome_amount: "0.0",
|
142
|
-
previous_outcome_amount: "100.0",
|
143
|
-
strategy: "limit",
|
144
|
-
price: "0.03",
|
145
|
-
state: "completed",
|
146
|
-
trades_count: 1,
|
147
|
-
created_at: created_at.iso8601,
|
148
|
-
completed_at: completed_at.iso8601,
|
149
|
-
},
|
121
|
+
"private",
|
122
|
+
"IDABC0000001",
|
123
|
+
"trade",
|
124
|
+
{
|
125
|
+
"id": 7,
|
126
|
+
"kind": "ask",
|
127
|
+
"at": created_at.to_i,
|
128
|
+
"price": "1020.0",
|
129
|
+
"volume": "0.001",
|
130
|
+
"ask_id": 15,
|
131
|
+
"bid_id": 22,
|
132
|
+
"market": market
|
133
|
+
}
|
150
134
|
]
|
151
135
|
end
|
152
136
|
|
153
|
-
def
|
137
|
+
def private_trade_user2
|
154
138
|
[
|
155
|
-
"
|
156
|
-
|
157
|
-
"
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
current_income_amount: "2.4",
|
169
|
-
previous_income_amount: "3.0",
|
170
|
-
initial_outcome_amount: "100.0",
|
171
|
-
current_outcome_amount: "80.0",
|
172
|
-
previous_outcome_amount: "100.0",
|
173
|
-
strategy: "limit",
|
174
|
-
price: "0.03",
|
175
|
-
state: "open",
|
176
|
-
trades_count: 1,
|
177
|
-
created_at: created_at.iso8601,
|
178
|
-
updated_at: updated_at.iso8601,
|
179
|
-
},
|
139
|
+
"private",
|
140
|
+
"IDABC0000002",
|
141
|
+
"trade",
|
142
|
+
{
|
143
|
+
"id": 7,
|
144
|
+
"kind": "bid",
|
145
|
+
"at": created_at.to_i,
|
146
|
+
"price": "1020.0",
|
147
|
+
"volume": "0.001",
|
148
|
+
"ask_id": 15,
|
149
|
+
"bid_id": 22,
|
150
|
+
"market": market
|
151
|
+
}
|
180
152
|
]
|
181
153
|
end
|
182
154
|
|
183
|
-
def
|
155
|
+
def public_trade
|
184
156
|
[
|
185
157
|
"public",
|
186
158
|
market,
|
187
|
-
"
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
seller_income_fee: "0.00063",
|
201
|
-
seller_outcome_unit: "btc",
|
202
|
-
seller_outcome_amount: "14.0",
|
203
|
-
seller_outcome_fee: "0.0",
|
204
|
-
completed_at: completed_at.iso8601,
|
205
|
-
},
|
159
|
+
"trades",
|
160
|
+
{
|
161
|
+
"trades": [
|
162
|
+
{
|
163
|
+
"tid": 7,
|
164
|
+
"type": "buy",
|
165
|
+
"date": created_at.to_i,
|
166
|
+
"price": "1020.0",
|
167
|
+
"amount":
|
168
|
+
"0.001"
|
169
|
+
}
|
170
|
+
]
|
171
|
+
}
|
206
172
|
]
|
207
173
|
end
|
174
|
+
|
208
175
|
end
|
209
176
|
end
|
data/lib/peatio/mq/events.rb
CHANGED
@@ -35,7 +35,7 @@ module Peatio::MQ::Events
|
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
|
-
def initialize(socket, streams)
|
38
|
+
def initialize(socket, streams = {})
|
39
39
|
@socket = socket
|
40
40
|
@streams = streams
|
41
41
|
|
@@ -108,7 +108,7 @@ module Peatio::MQ::Events
|
|
108
108
|
if type == "private"
|
109
109
|
Client.user(id) do |client|
|
110
110
|
if client.streams.include?(event)
|
111
|
-
client.send_payload
|
111
|
+
client.send_payload(event => payload_decoded)
|
112
112
|
end
|
113
113
|
end
|
114
114
|
|
@@ -119,7 +119,7 @@ module Peatio::MQ::Events
|
|
119
119
|
|
120
120
|
Client.all.each do |handler|
|
121
121
|
if handler.streams.include?(id) or handler.streams.include?(stream)
|
122
|
-
handler.send_payload
|
122
|
+
handler.send_payload(stream => payload_decoded)
|
123
123
|
end
|
124
124
|
end
|
125
125
|
end
|
data/lib/peatio/ranger.rb
CHANGED
@@ -4,7 +4,6 @@ module Peatio::Ranger
|
|
4
4
|
@authenticator = authenticator
|
5
5
|
@socket = socket
|
6
6
|
@logger = logger
|
7
|
-
@streams = []
|
8
7
|
end
|
9
8
|
|
10
9
|
def send(method, data)
|
@@ -13,50 +12,76 @@ module Peatio::Ranger
|
|
13
12
|
@socket.send payload
|
14
13
|
end
|
15
14
|
|
16
|
-
def
|
15
|
+
def authenticate(jwt)
|
16
|
+
payload = {}
|
17
17
|
authorized = false
|
18
18
|
begin
|
19
|
-
|
20
|
-
|
21
|
-
token = data["jwt"]
|
22
|
-
|
23
|
-
payload = @authenticator.authenticate!(token)
|
24
|
-
|
19
|
+
payload = @authenticator.authenticate!(jwt)
|
25
20
|
authorized = true
|
26
|
-
rescue
|
27
|
-
rescue => error
|
21
|
+
rescue Peatio::Auth::Error => error
|
28
22
|
@logger.error error.message
|
29
23
|
end
|
24
|
+
return [authorized, payload]
|
25
|
+
end
|
30
26
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
end
|
35
|
-
|
36
|
-
@client.user = payload[:uid]
|
37
|
-
@client.authorized = true
|
27
|
+
def update_streams
|
28
|
+
@socket.instance_variable_set(:@connection_handler, @client)
|
29
|
+
end
|
38
30
|
|
39
|
-
|
31
|
+
def subscribe(streams)
|
32
|
+
raise "Streams must be an array of strings" unless streams.is_a?(Array)
|
33
|
+
streams.each do |stream|
|
34
|
+
next if stream.nil?
|
35
|
+
@client.streams[stream] = true
|
36
|
+
end
|
37
|
+
send :success, message: "subscribed", streams: @client.streams.keys
|
38
|
+
end
|
40
39
|
|
41
|
-
|
40
|
+
def unsubscribe(streams)
|
41
|
+
raise "Streams must be an array of strings" unless streams.is_a?(Array)
|
42
|
+
streams.each do |stream|
|
43
|
+
next if stream.nil?
|
44
|
+
@client.streams.delete(stream)
|
45
|
+
end
|
46
|
+
send :success, message: "unsubscribed", streams: @client.streams.keys
|
42
47
|
end
|
43
48
|
|
44
|
-
def
|
45
|
-
|
49
|
+
def handle(msg)
|
50
|
+
begin
|
51
|
+
data = JSON.parse(msg)
|
46
52
|
|
47
|
-
|
48
|
-
|
49
|
-
|
53
|
+
case data["event"]
|
54
|
+
when "subscribe"
|
55
|
+
subscribe data["streams"]
|
56
|
+
when "unsubscribe"
|
57
|
+
unsubscribe data["streams"]
|
50
58
|
end
|
59
|
+
|
60
|
+
rescue JSON::ParserError => error
|
61
|
+
@logger.debug { "#{error}, msg: `#{msg}`" }
|
51
62
|
end
|
63
|
+
end
|
52
64
|
|
53
|
-
|
65
|
+
def handshake(hs)
|
66
|
+
@client = Peatio::MQ::Events::Client.new(@socket)
|
54
67
|
|
55
|
-
|
56
|
-
|
57
|
-
|
68
|
+
query = URI::decode_www_form(hs.query_string)
|
69
|
+
subscribe(query.map {|item| item.last if item.first == "stream"})
|
70
|
+
@logger.info "ranger: WebSocket connection openned"
|
58
71
|
|
59
|
-
|
72
|
+
if hs.headers_downcased.key?("authorization")
|
73
|
+
authorized, payload = authenticate(hs.headers["authorization"])
|
74
|
+
|
75
|
+
if !authorized
|
76
|
+
@logger.info "ranger: #{@client.user} authentication failed"
|
77
|
+
raise EM::WebSocket::HandshakeError, "Authorization failed"
|
78
|
+
else
|
79
|
+
@logger.info [authorized, payload].inspect
|
80
|
+
@client.user = payload[:uid]
|
81
|
+
@client.authorized = true
|
82
|
+
@logger.info "ranger: user #{@client.user} authenticated #{@client.streams}"
|
83
|
+
end
|
84
|
+
end
|
60
85
|
end
|
61
86
|
end
|
62
87
|
|
@@ -79,20 +104,24 @@ module Peatio::Ranger
|
|
79
104
|
EM::WebSocket.start(
|
80
105
|
host: host,
|
81
106
|
port: port,
|
82
|
-
secure: false
|
107
|
+
secure: false
|
83
108
|
) do |socket|
|
84
109
|
connection = Connection.new(authenticator, socket, logger)
|
85
110
|
|
86
|
-
socket.onopen do |
|
87
|
-
connection.handshake(
|
111
|
+
socket.onopen do |hs|
|
112
|
+
connection.handshake(hs)
|
88
113
|
end
|
89
114
|
|
90
115
|
socket.onmessage do |msg|
|
91
116
|
connection.handle(msg)
|
92
117
|
end
|
93
118
|
|
119
|
+
socket.onping do |value|
|
120
|
+
logger.info "Received ping: #{value}"
|
121
|
+
end
|
122
|
+
|
94
123
|
socket.onclose do
|
95
|
-
logger.info "ranger:
|
124
|
+
logger.info "ranger: websocket connection closed"
|
96
125
|
end
|
97
126
|
|
98
127
|
socket.onerror do |e|
|
data/lib/peatio/version.rb
CHANGED
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: 0.4.
|
4
|
+
version: 0.4.5
|
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: 2019-01-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: clamp
|