Skip to content

Commit b49ae16

Browse files
committed
feat: subscribe to price rates
1 parent 48f0b34 commit b49ae16

File tree

2 files changed

+75
-0
lines changed

2 files changed

+75
-0
lines changed

lib/cryptomarket/websocket/marketDataClient.rb

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,55 @@ def subscribe_to_top_of_book_in_batches(callback:, speed:, symbols:["*"], result
315315
params = {'symbols'=>symbols}
316316
send_channel_subscription("orderbook/top/#{speed}/batch", params, callback, intercept_result_callback(result_callback))
317317
end
318+
319+
320+
# subscribe to a feed of the top of the orderbook
321+
#
322+
# subscription is for all currencies or for the specified currencies
323+
#
324+
# https://api.exchange.cryptomkt.com/#subscribe-to-top-of-book-in-batches
325+
#
326+
# ==== Params
327+
# +Proc+ +callback+:: A +Proc+ that recieves notifications as a hash of top of orderbooks indexed by symbol, and the type of notification (only 'data')
328+
# +String+ +speed+:: The speed of the feed. '1s' or '3s'
329+
# +String+ +target_currency+:: Quote currency of the rate
330+
# +Array[String]+ +currencies+:: Optional. A list of currencies ids
331+
# +Proc+ +result_callback+:: Optional. A +Proc+ of two arguments, An exception and a result, called either with the exception or with the result, a list of subscribed symbols
332+
333+
def subscribe_to_price_rates(callback:, speed:, target_currency: ,currencies:["*"], result_callback:nil)
334+
params = {
335+
speed:speed,
336+
target_currency:target_currency,
337+
currencies:currencies
338+
}
339+
send_channel_subscription("price/rate/#{speed}", params, callback, intercept_result_callback(result_callback))
340+
end
341+
342+
343+
344+
# subscribe to a feed of the top of the orderbook
345+
#
346+
# subscription is for all currencies or for the specified currencies
347+
#
348+
# batch subscriptions have a joined update for all currencies
349+
#
350+
# https://api.exchange.cryptomkt.com/#subscribe-to-price-rates-in-batches
351+
#
352+
# ==== Params
353+
# +Proc+ +callback+:: A +Proc+ that recieves notifications as a hash of top of orderbooks indexed by symbol, and the type of notification (only 'data')
354+
# +String+ +speed+:: The speed of the feed. '1s' or '3s'
355+
# +String+ +target_currency+:: Quote currency of the rate
356+
# +Array[String]+ +currencies+:: Optional. A list of currencies ids
357+
# +Proc+ +result_callback+:: Optional. A +Proc+ of two arguments, An exception and a result, called either with the exception or with the result, a list of subscribed symbols
358+
359+
def subscribe_to_price_rates_in_batches(callback:, speed:, target_currency: ,currencies:["*"], result_callback:nil)
360+
params = {
361+
speed:speed,
362+
target_currency:target_currency,
363+
currencies:currencies
364+
}
365+
send_channel_subscription("price/rate/#{speed}/batch", params, callback, intercept_result_callback(result_callback))
366+
end
318367
end
319368
end
320369
end

tests/websocket/publicSubs.rb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,4 +158,30 @@ def test_subscribe_to_top_of_book_in_batches
158158
)
159159
sleep(20 * @@SECOND)
160160
end
161+
162+
163+
def test_subscribe_to_price_rates
164+
puts "***PRICE RATES TEST***"
165+
@wsclient.subscribe_to_price_rates(
166+
speed:"1s",
167+
callback:gen_print_callback(),
168+
target_currency:"ETH",
169+
currencies:['eos', 'btc'],
170+
result_callback:gen_result_callback()
171+
)
172+
sleep(20 * @@SECOND)
173+
end
174+
175+
176+
def test_subscribe_to_price_rates_in_batches
177+
puts "***PRICE RATES TEST***"
178+
@wsclient.subscribe_to_price_rates_in_batches(
179+
speed:"1s",
180+
callback:gen_print_callback(),
181+
target_currency:"ETH",
182+
currencies:['eos', 'btc'],
183+
result_callback:gen_result_callback()
184+
)
185+
sleep(20 * @@SECOND)
186+
end
161187
end

0 commit comments

Comments
 (0)