Skip to content

Commit 140d0ee

Browse files
committed
feat: get converted candles by symbol
1 parent 5ef2c42 commit 140d0ee

File tree

5 files changed

+65
-28
lines changed

5 files changed

+65
-28
lines changed

lib/cryptomarket/client.rb

Lines changed: 50 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ def get_prices(to:, from: nil)
154154
# +String+ +sort+:: Optional. Sort direction. 'ASC' or 'DESC'. Default is 'DESC'
155155
# +String+ +since+:: Optional. Initial value of the queried interval
156156
# +String+ +until+:: Optional. Last value of the queried interval
157-
# +Integer+ +limit+:: Optional. Prices per currency pair. Defaul is 1. Min is 1. Max is 1000
157+
# +Integer+ +limit+:: Optional. Prices per currency pair. Defaul is 1. Min is 1. Max is 1_000
158158

159159
def get_price_history(to:, from: nil, till: nil, since: nil, limit: nil, period: nil, sort: nil) # rubocop:disable Metrics/ParameterLists
160160
public_get(
@@ -202,7 +202,7 @@ def get_ticker_price(symbol:)
202202
# +String+ +sort+:: Optional. Sort direction. 'ASC' or 'DESC'. Default is 'DESC'
203203
# +String+ +since+:: Optional. Initial value of the queried interval
204204
# +String+ +until+:: Optional. Last value of the queried interval
205-
# +Integer+ +limit+:: Optional. Prices per currency pair. Defaul is 10. Min is 1. Max is 1000
205+
# +Integer+ +limit+:: Optional. Prices per currency pair. Defaul is 10. Min is 1. Max is 1_000
206206

207207
def get_trades(symbols: nil, by: nil, sort: nil, from: nil, till: nil, limit: nil, offset: nil) # rubocop:disable Metrics/ParameterLists
208208
public_get(
@@ -224,8 +224,8 @@ def get_trades(symbols: nil, by: nil, sort: nil, from: nil, till: nil, limit: ni
224224
# +String+ +sort+:: Optional. Sort direction. 'ASC' or 'DESC'. Default is 'DESC'
225225
# +String+ +since+:: Optional. Initial value of the queried interval
226226
# +String+ +until+:: Optional. Last value of the queried interval
227-
# +Integer+ +limit+:: Optional. Prices per currency pair. Defaul is 10. Min is 1. Max is 1000
228-
# +Integer+ +offset+:: Optional. Default is 0. Min is 0. Max is 100000
227+
# +Integer+ +limit+:: Optional. Prices per currency pair. Defaul is 10. Min is 1. Max is 1_000
228+
# +Integer+ +offset+:: Optional. Default is 0. Min is 0. Max is 100_000
229229

230230
def get_trades_by_symbol(symbol: nil, by: nil, sort: nil, from: nil, till: nil, limit: nil, offset: nil) # rubocop:disable Metrics/ParameterLists
231231
public_get(
@@ -280,7 +280,7 @@ def get_orderbook_volume(symbol:, volume: nil)
280280
end
281281

282282
# Get a Hash of candles for all symbols or for specified symbols
283-
# Candels are used for OHLC representation
283+
# Candles are used for OHLC representation
284284
# The result contains candles with non-zero volume only (no trades = no candles)
285285
#
286286
# Requires no API key Access Rights
@@ -293,7 +293,7 @@ def get_orderbook_volume(symbol:, volume: nil)
293293
# +String+ +sort+:: Optional. Sort direction. 'ASC' or 'DESC'. Default is 'DESC'
294294
# +String+ +from+:: Optional. Initial value of the queried interval. As DateTime
295295
# +String+ +till+:: Optional. Last value of the queried interval. As DateTime
296-
# +Integer+ +limit+:: Optional. Prices per currency pair. Defaul is 10. Min is 1. Max is 1000
296+
# +Integer+ +limit+:: Optional. Prices per currency pair. Defaul is 10. Min is 1. Max is 1_000
297297

298298
def get_candles(symbols: nil, period: nil, sort: nil, from: nil, till: nil, limit: nil, offset: nil) # rubocop:disable Metrics/ParameterLists
299299
public_get(
@@ -303,7 +303,7 @@ def get_candles(symbols: nil, period: nil, sort: nil, from: nil, till: nil, limi
303303
end
304304

305305
# Get candles of a symbol
306-
# Candels are used for OHLC representation
306+
# Candles are used for OHLC representation
307307
# The result contains candles with non-zero volume only (no trades = no candles)
308308
#
309309
# Requires no API key Access Rights
@@ -316,8 +316,8 @@ def get_candles(symbols: nil, period: nil, sort: nil, from: nil, till: nil, limi
316316
# +String+ +sort+:: Optional. Sort direction. 'ASC' or 'DESC'. Default is 'DESC'
317317
# +String+ +from+:: Optional. Initial value of the queried interval. As DateTime
318318
# +String+ +till+:: Optional. Last value of the queried interval. As DateTime
319-
# +Integer+ +limit+:: Optional. Prices per currency pair. Defaul is 100. Min is 1. Max is 1000
320-
# +Integer+ +offset+:: Optional. Default is 0. Min is 0. Max is 100000
319+
# +Integer+ +limit+:: Optional. Prices per currency pair. Defaul is 100. Min is 1. Max is 1_000
320+
# +Integer+ +offset+:: Optional. Default is 0. Min is 0. Max is 100_000
321321

322322
def get_candles_by_symbol(symbol:, period: nil, sort: nil, from: nil, till: nil, limit: nil, offset: nil) # rubocop:disable Metrics/ParameterLists
323323
public_get(
@@ -328,7 +328,9 @@ def get_candles_by_symbol(symbol:, period: nil, sort: nil, from: nil, till: nil,
328328

329329
# Gets OHLCV data regarding the last price converted to the target currency for all symbols or for the specified symbols
330330
#
331-
# Candles are used for the representation of a specific symbol as an OHLC chart
331+
# Candles are used for OHLC representation
332+
#
333+
# The result contains candles with non-zero volume only (no trades = no candles)
332334
#
333335
# Conversion from the symbol quote currency to the target currency is the mean of "best" bid price and "best" ask price in the order book. If there is no "best" bid of ask price, the last price is returned.
334336
#
@@ -337,20 +339,48 @@ def get_candles_by_symbol(symbol:, period: nil, sort: nil, from: nil, till: nil,
337339
# https://api.exchange.cryptomkt.com/#candles
338340
#
339341
# +String+ +target_currency+:: Target currency for conversion
340-
# +String+ +period+:: Optional. A valid tick interval. 'M1' (one minute), 'M3', 'M5', 'M15', 'M30', 'H1' (one hour), 'H4', 'D1' (one day), 'D7', '1M' (one month). Default is 'M30'
341342
# +Array[String]+ +symbols+:: Optional. A list of symbols
343+
# +String+ +period+:: Optional. A valid tick interval. 'M1' (one minute), 'M3', 'M5', 'M15', 'M30', 'H1' (one hour), 'H4', 'D1' (one day), 'D7', '1M' (one month). Default is 'M30'
342344
# +String+ +sort+:: Optional. Sort direction. 'ASC' or 'DESC'. Default is 'DESC'
343345
# +String+ +from+:: Optional. Initial value of the queried interval. As DateTime
344346
# +String+ +till+:: Optional. Last value of the queried interval. As DateTime
345-
# +Integer+ +limit+:: Optional. Prices per currency pair. Defaul is 100. Min is 1. Max is 1000
347+
# +Integer+ +limit+:: Optional. Prices per currency pair. Defaul is 100. Min is 1. Max is 1_000
346348

347-
def get_converted_candles(target_currency:, period: nil, symbols: nil, sort: nil, from: nil, till: nil, limit: nil) # rubocop:disable Metrics/ParameterLists
349+
def get_converted_candles(target_currency:, symbols: nil, period: nil, sort: nil, from: nil, till: nil, limit: nil) # rubocop:disable Metrics/ParameterLists
348350
public_get(
349351
'public/converted/candles',
350352
{ target_currency: target_currency, symbols: symbols, period: period, sort: sort, from: from, till: till, limit: limit }
351353
)
352354
end
353355

356+
# Gets OHLCV data regarding the last price converted to the target currency for the specified symbol
357+
#
358+
# Candles are used for OHLC representation
359+
#
360+
# The result contains candles with non-zero volume only (no trades = no candles)
361+
#
362+
# Conversion from the symbol quote currency to the target currency is the mean of "best" bid price and "best" ask price in the order book. If there is no "best" bid of ask price, the last price is returned.
363+
#
364+
# Requires no API key Access Rights
365+
#
366+
# https://api.exchange.cryptomkt.com/#candles
367+
#
368+
# +String+ +target_currency+:: Target currency for conversion
369+
# +String+ +symbol+:: A symbol id
370+
# +String+ +period+:: Optional. A valid tick interval. 'M1' (one minute), 'M3', 'M5', 'M15', 'M30', 'H1' (one hour), 'H4', 'D1' (one day), 'D7', '1M' (one month). Default is 'M30'
371+
# +String+ +sort+:: Optional. Sort direction. 'ASC' or 'DESC'. Default is 'DESC'
372+
# +String+ +from+:: Optional. Initial value of the queried interval. As DateTime
373+
# +String+ +till+:: Optional. Last value of the queried interval. As DateTime
374+
# +Integer+ +limit+:: Optional. Prices per currency pair. Defaul is 100. Min is 1. Max is 1_000
375+
# +Integer+ +offset+:: Optional. Default is 0. Min is 0. Max is 100_000
376+
377+
def get_converted_candles_by_symbol(target_currency:, symbol:, period: nil, sort: nil, from: nil, till: nil, limit: nil, offset: nil) # rubocop:disable Metrics/ParameterLists
378+
public_get(
379+
"public/converted/candles/#{symbol}",
380+
{ target_currency: target_currency, period: period, sort: sort, from: from, till: till, limit: limit, offset: offset }
381+
)
382+
end
383+
354384
######################
355385
# Spot Trading calls #
356386
######################
@@ -592,8 +622,8 @@ def get_trading_commission(symbol:)
592622
# +String+ +sort+:: Optional. Sort direction. 'ASC' or 'DESC'. Default is 'DESC'
593623
# +String+ +from+:: Optional. Initial value of the queried interval
594624
# +String+ +till+:: Optional. Last value of the queried interval
595-
# +Integer+ +limit+:: Optional. Prices per currency pair. Defaul is 100. Max is 1000
596-
# +Integer+ +offset+:: Optional. Default is 0. Max is 100000
625+
# +Integer+ +limit+:: Optional. Prices per currency pair. Defaul is 100. Max is 1_000
626+
# +Integer+ +offset+:: Optional. Default is 0. Max is 100_000
597627

598628
def get_spot_orders_history( # rubocop:disable Metrics/ParameterLists
599629
client_order_id: nil, symbol: nil, sort: nil, by: nil, from: nil,
@@ -619,8 +649,8 @@ def get_spot_orders_history( # rubocop:disable Metrics/ParameterLists
619649
# +String+ +sort+:: Optional. Sort direction. 'ASC' or 'DESC'. Default is 'DESC'
620650
# +String+ +from+:: Optional. Initial value of the queried interval
621651
# +String+ +till+:: Optional. Last value of the queried interval
622-
# +Integer+ +limit+:: Optional. Prices per currency pair. Defaul is 100. Max is 1000
623-
# +Integer+ +offset+:: Optional. Default is 0. Max is 100000
652+
# +Integer+ +limit+:: Optional. Prices per currency pair. Defaul is 100. Max is 1_000
653+
# +Integer+ +offset+:: Optional. Default is 0. Max is 100_000
624654

625655
def get_spot_trades_history( # rubocop:disable Metrics/ParameterLists
626656
order_id: nil, symbol: nil, sort: nil, by: nil, from: nil,
@@ -931,8 +961,8 @@ def transfer_money_to_another_user(currency:, amount:, by:, identifier:)
931961
# +String+ +id_from+:: Optional. Interval initial value when ordering by id. Min is 0
932962
# +String+ +id_till+:: Optional. Interval end value when ordering by id. Min is 0
933963
# +String+ +sort+:: Optional. Sort direction. 'ASC' or 'DESC'. Default is 'DESC'
934-
# +Integer+ +limit+:: Optional. Transactions per query. Defaul is 100. Max is 1000
935-
# +Integer+ +offset+:: Optional. Default is 0. Max is 100000
964+
# +Integer+ +limit+:: Optional. Transactions per query. Defaul is 100. Max is 1_000
965+
# +Integer+ +offset+:: Optional. Default is 0. Max is 100_000
936966
# +bool+ +group_transactions+:: Optional. Flag indicating whether the returned transactions will be parts of a single operation. Default is false
937967

938968
def get_transaction_history( # rubocop:disable Metrics/ParameterLists
@@ -996,7 +1026,7 @@ def offchain_available?(
9961026
# ==== Params
9971027
# +String+ +currency+:: Optional. Currency code
9981028
# +bool+ +active+:: Optional. value showing whether the lock is active
999-
# +Integer+ +limit+:: Optional. Dafault is 100. Min is 0. Max is 1000
1029+
# +Integer+ +limit+:: Optional. Dafault is 100. Min is 0. Max is 1_000
10001030
# +Integer+ +offset+:: Optional. Default is 0. Min is 0
10011031
# +String+ +from+:: Optional. Interval initial value. As Datetime
10021032
# +String+ +till+:: Optional. Interval end value. As Datetime

lib/cryptomarket/websocket/auth_client.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def wait_authed
4848
# err is None for successful calls, result is None for calls with error: Proc.new {|err, result| ...}
4949

5050
def authenticate(callback = nil)
51-
timestamp = Time.now.to_i * 1000
51+
timestamp = Time.now.to_i * 1_000
5252
digest = OpenSSL::Digest.new 'sha256'
5353
message = timestamp.to_s
5454
message += @window.to_s unless @window.nil?

lib/cryptomarket/websocket/market_data_client.rb

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class MarketDataClient < MarketDataClientCore
2626
# ==== Params
2727
# +Proc+ +callback+:: A +Proc+ that recieves notifications as a hash of trades indexed by symbol, and the type of notification (either 'snapshot' or 'update')
2828
# +Array[String]+ +symbols+:: A list of symbol ids
29-
# +Integer+ +limit+:: Number of historical entries returned in the first feed. Min is 0. Max is 1000. Default is 0
29+
# +Integer+ +limit+:: Number of historical entries returned in the first feed. Min is 0. Max is 1_000. Default is 0
3030
# +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
3131

3232
def subscribe_to_trades(callback:, symbols:, limit: nil, result_callback: nil)
@@ -51,7 +51,7 @@ def subscribe_to_trades(callback:, symbols:, limit: nil, result_callback: nil)
5151
# +Proc+ +callback+:: A +Proc+ that recieves notifications as a hash of candles indexed by symbol, and the type of notification (either 'snapshot' or 'update')
5252
# +String+ +period+:: Optional. A valid tick interval. 'M1' (one minute), 'M3', 'M5', 'M15', 'M30', 'H1' (one hour), 'H4', 'D1' (one day), 'D7', '1M' (one month). Default is 'M30'
5353
# +Array[String]+ +symbols+:: Optional. A list of symbol ids
54-
# +Integer+ +limit+:: Number of historical entries returned in the first feed. Min is 0. Max is 1000. Default is 0
54+
# +Integer+ +limit+:: Number of historical entries returned in the first feed. Min is 0. Max is 1_000. Default is 0
5555
# +Proc+ +result_callback+:: Optional. A +Proc+ called with a list of subscribed symbols
5656

5757
def subscribe_to_candles(callback:, period:, symbols:, limit: nil, result_callback: nil)
@@ -70,14 +70,16 @@ def subscribe_to_candles(callback:, period:, symbols:, limit: nil, result_callba
7070
#
7171
# https://api.exchange.cryptomkt.com/#candles
7272
#
73+
# +Proc+ +callback+:: A +Proc+ that recieves notifications as a hash of candles indexed by symbol, and the type of notification (either 'snapshot' or 'update')
7374
# +String+ +target_currency+:: Target currency for conversion
74-
# +String+ +period+:: A valid tick interval. 'M1' (one minute), 'M3', 'M5', 'M15', 'M30', 'H1' (one hour), 'H4', 'D1' (one day), 'D7', '1M' (one month). Default is 'M30'
7575
# +Array[String]+ +symbols+:: Optional. A list of symbols
76+
# +String+ +period+:: A valid tick interval. 'M1' (one minute), 'M3', 'M5', 'M15', 'M30', 'H1' (one hour), 'H4', 'D1' (one day), 'D7', '1M' (one month). Default is 'M30'
7677
# +String+ +from+:: Optional. Initial value of the queried interval. As DateTime
7778
# +String+ +till+:: Optional. Last value of the queried interval. As DateTime
78-
# +Integer+ +limit+:: Optional. Prices per currency pair. Defaul is 100. Min is 1. Max is 1000
79+
# +Integer+ +limit+:: Optional. Prices per currency pair. Defaul is 100. Min is 1. Max is 1_000
80+
# +Proc+ +result_callback+:: Optional. A +Proc+ called with a list of subscribed symbols
7981

80-
def subscribe_to_converted_candles(callback:, target_currency:, period:, symbols:, limit: nil, result_callback: nil) # rubocop:disable Metrics/ParameterLists
82+
def subscribe_to_converted_candles(callback:, target_currency:, symbols:, period:, limit: nil, result_callback: nil) # rubocop:disable Metrics/ParameterLists
8183
params = { 'target_currency' => target_currency, 'symbols' => symbols, 'limit' => limit }
8284
send_channel_subscription("converted/candles/#{period}", callback,
8385
intercept_result_callback(result_callback), params)

lib/cryptomarket/websocket/wallet_client.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,8 @@ def get_wallet_balance(currency:, callback:)
151151
# +String+ +id_till+:: Optional. Interval end value when ordering by id. Min is 0
152152
# +String+ +order_by+:: Optional. sorting parameter.'created_at' or 'id'. Default is 'created_at'
153153
# +String+ +sort+:: Optional. Sort direction. 'ASC' or 'DESC'. Default is 'DESC'
154-
# +Integer+ +limit+:: Optional. Transactions per query. Defaul is 100. Max is 1000
155-
# +Integer+ +offset+:: Optional. Default is 0. Max is 100000
154+
# +Integer+ +limit+:: Optional. Transactions per query. Defaul is 100. Max is 1_000
155+
# +Integer+ +offset+:: Optional. Default is 0. Max is 100_000
156156
# +bool+ +group_transactions+:: Optional. Flag indicating whether the returned transactions will be parts of a single operation. Default is false
157157

158158
def get_transactions( # rubocop:disable Metrics/ParameterLists

tests/rest/market_data.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,4 +136,9 @@ def test_get_converted_candles
136136
candles.each { |val| assert(Check.good_candle(val)) }
137137
end
138138
end
139+
140+
def test_get_converted_candles_by_symbol
141+
result = @client.get_converted_candles_by_symbol(symbol: 'eoseth', limit: 2, target_currency: 'usdt')
142+
result['data'].each { |val| assert(Check.good_candle(val)) }
143+
end
139144
end

0 commit comments

Comments
 (0)