From a3e39c06b4ceca2ec956d1fbe630dd44a49501a8 Mon Sep 17 00:00:00 2001 From: "T. Ismael Verdugo" Date: Fri, 1 Mar 2024 02:47:29 -0300 Subject: [PATCH 1/7] fix: price rates link --- lib/cryptomarket/websocket/market_data_client.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/cryptomarket/websocket/market_data_client.rb b/lib/cryptomarket/websocket/market_data_client.rb index 22caac8..b3642a5 100644 --- a/lib/cryptomarket/websocket/market_data_client.rb +++ b/lib/cryptomarket/websocket/market_data_client.rb @@ -258,7 +258,7 @@ def subscribe_to_top_of_book_in_batches(callback:, speed:, symbols: ['*'], resul # # subscription is for all currencies or for the specified currencies # - # https://api.exchange.cryptomkt.com/#subscribe-to-top-of-book-in-batches + # https://api.exchange.cryptomkt.com/#subscribe-to-price-rates # # ==== Params # +Proc+ +callback+:: A +Proc+ that recieves notifications as a hash of top of orderbooks indexed by symbol, and the type of notification (only 'data') From d35cc8a213c87677d73d3a99953f90706de7a3df Mon Sep 17 00:00:00 2001 From: "T. Ismael Verdugo" Date: Fri, 1 Mar 2024 02:58:11 -0300 Subject: [PATCH 2/7] test: remove unused test function --- tests/checker_generator.rb | 4 ---- 1 file changed, 4 deletions(-) diff --git a/tests/checker_generator.rb b/tests/checker_generator.rb index 908bc16..83cb490 100644 --- a/tests/checker_generator.rb +++ b/tests/checker_generator.rb @@ -91,10 +91,6 @@ def gen_check_notification_list_callback(check_fn, veredict_checker) ->(notification) { check_list(notification, check_fn, veredict_checker) } end -def |(check_fn, veredict_checker) - ->(notification, _notification_type) { check_list(notification, check_fn, veredict_checker) } -end - def gen_check_notification_hash_list_callback(check_fn, veredict_checker) ->(notification, _notification_type) { check_hash_list(notification, check_fn, veredict_checker) } end From 5ef2c425c124c2ed8b68e1d53f004fcffd920c6e Mon Sep 17 00:00:00 2001 From: "T. Ismael Verdugo" Date: Fri, 1 Mar 2024 10:54:26 -0300 Subject: [PATCH 3/7] feat: get_converted_candles rest and websocket methods --- lib/cryptomarket/client.rb | 25 +++++++++++++++++++ .../websocket/market_data_client.rb | 23 +++++++++++++++++ tests/rest/market_data.rb | 11 +++++++- tests/websocket/market_data_client.rb | 11 ++++++++ 4 files changed, 69 insertions(+), 1 deletion(-) diff --git a/lib/cryptomarket/client.rb b/lib/cryptomarket/client.rb index f7f7258..324a68d 100644 --- a/lib/cryptomarket/client.rb +++ b/lib/cryptomarket/client.rb @@ -326,6 +326,31 @@ def get_candles_by_symbol(symbol:, period: nil, sort: nil, from: nil, till: nil, ) end + # Gets OHLCV data regarding the last price converted to the target currency for all symbols or for the specified symbols + # + # Candles are used for the representation of a specific symbol as an OHLC chart + # + # 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. + # + # Requires no API key Access Rights + # + # https://api.exchange.cryptomkt.com/#candles + # + # +String+ +target_currency+:: Target currency for conversion + # +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' + # +Array[String]+ +symbols+:: Optional. A list of symbols + # +String+ +sort+:: Optional. Sort direction. 'ASC' or 'DESC'. Default is 'DESC' + # +String+ +from+:: Optional. Initial value of the queried interval. As DateTime + # +String+ +till+:: Optional. Last value of the queried interval. As DateTime + # +Integer+ +limit+:: Optional. Prices per currency pair. Defaul is 100. Min is 1. Max is 1000 + + def get_converted_candles(target_currency:, period: nil, symbols: nil, sort: nil, from: nil, till: nil, limit: nil) # rubocop:disable Metrics/ParameterLists + public_get( + 'public/converted/candles', + { target_currency: target_currency, symbols: symbols, period: period, sort: sort, from: from, till: till, limit: limit } + ) + end + ###################### # Spot Trading calls # ###################### diff --git a/lib/cryptomarket/websocket/market_data_client.rb b/lib/cryptomarket/websocket/market_data_client.rb index b3642a5..92cb036 100644 --- a/lib/cryptomarket/websocket/market_data_client.rb +++ b/lib/cryptomarket/websocket/market_data_client.rb @@ -60,6 +60,29 @@ def subscribe_to_candles(callback:, period:, symbols:, limit: nil, result_callba intercept_result_callback(result_callback), params) end + # Gets OHLCV data regarding the last price converted to the target currency for all symbols or for the specified symbols + # + # Candles are used for the representation of a specific symbol as an OHLC chart + # + # 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. + # + # Requires no API key Access Rights + # + # https://api.exchange.cryptomkt.com/#candles + # + # +String+ +target_currency+:: Target currency for conversion + # +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' + # +Array[String]+ +symbols+:: Optional. A list of symbols + # +String+ +from+:: Optional. Initial value of the queried interval. As DateTime + # +String+ +till+:: Optional. Last value of the queried interval. As DateTime + # +Integer+ +limit+:: Optional. Prices per currency pair. Defaul is 100. Min is 1. Max is 1000 + + def subscribe_to_converted_candles(callback:, target_currency:, period:, symbols:, limit: nil, result_callback: nil) # rubocop:disable Metrics/ParameterLists + params = { 'target_currency' => target_currency, 'symbols' => symbols, 'limit' => limit } + send_channel_subscription("converted/candles/#{period}", callback, + intercept_result_callback(result_callback), params) + end + # subscribe to a feed of mini tickers # # subscription is for all symbols or for the specified symbols diff --git a/tests/rest/market_data.rb b/tests/rest/market_data.rb index 978a6f3..ae62834 100644 --- a/tests/rest/market_data.rb +++ b/tests/rest/market_data.rb @@ -4,7 +4,7 @@ require_relative '../../lib/cryptomarket/client' require_relative '../checks' -class TestMarketDataMethods < Test::Unit::TestCase # rubocop:disable Style/Documentation +class TestMarketDataMethods < Test::Unit::TestCase # rubocop:disable Style/Documentation,Metrics/ClassLength def setup @client = Cryptomarket::Client.new end @@ -127,4 +127,13 @@ def test_get_candles_by_symbol assert(Check.good_candle(candle)) end end + + def test_get_converted_candles + symbols = %w[EOSETH BTCUSDT] + result = @client.get_converted_candles(symbols: symbols, limit: 2, target_currency: 'usdt') + result['data'].each do |symbol, candles| + assert(symbols.include?(symbol)) + candles.each { |val| assert(Check.good_candle(val)) } + end + end end diff --git a/tests/websocket/market_data_client.rb b/tests/websocket/market_data_client.rb index 8bfcfc5..0f4ba44 100644 --- a/tests/websocket/market_data_client.rb +++ b/tests/websocket/market_data_client.rb @@ -45,6 +45,17 @@ def test_candles_subscriptions assert(veredict_checker.good_veredict?) end + def test_converted_candles_subscription + veredict_checker = VeredictChecker.new + @wsclient.subscribe_to_converted_candles( + period: 'M1', target_currency: 'usdt', symbols: %w[eoseth ethbtc], limit: 2, + callback: gen_check_notification_hash_list_callback(WSCheck.good_ws_public_candle, veredict_checker), + result_callback: gen_result_callback(veredict_checker) + ) + sleep(10 * @@SECOND) + assert(veredict_checker.good_veredict?) + end + def test_subscribe_to_mini_ticker veredict_checker = VeredictChecker.new @wsclient.subscribe_to_mini_ticker( From 140d0ee25a6ede749dc1d9c77a96b6c77b1d9b26 Mon Sep 17 00:00:00 2001 From: "T. Ismael Verdugo" Date: Fri, 1 Mar 2024 11:33:53 -0300 Subject: [PATCH 4/7] feat: get converted candles by symbol --- lib/cryptomarket/client.rb | 70 +++++++++++++------ lib/cryptomarket/websocket/auth_client.rb | 2 +- .../websocket/market_data_client.rb | 12 ++-- lib/cryptomarket/websocket/wallet_client.rb | 4 +- tests/rest/market_data.rb | 5 ++ 5 files changed, 65 insertions(+), 28 deletions(-) diff --git a/lib/cryptomarket/client.rb b/lib/cryptomarket/client.rb index 324a68d..7057393 100644 --- a/lib/cryptomarket/client.rb +++ b/lib/cryptomarket/client.rb @@ -154,7 +154,7 @@ def get_prices(to:, from: nil) # +String+ +sort+:: Optional. Sort direction. 'ASC' or 'DESC'. Default is 'DESC' # +String+ +since+:: Optional. Initial value of the queried interval # +String+ +until+:: Optional. Last value of the queried interval - # +Integer+ +limit+:: Optional. Prices per currency pair. Defaul is 1. Min is 1. Max is 1000 + # +Integer+ +limit+:: Optional. Prices per currency pair. Defaul is 1. Min is 1. Max is 1_000 def get_price_history(to:, from: nil, till: nil, since: nil, limit: nil, period: nil, sort: nil) # rubocop:disable Metrics/ParameterLists public_get( @@ -202,7 +202,7 @@ def get_ticker_price(symbol:) # +String+ +sort+:: Optional. Sort direction. 'ASC' or 'DESC'. Default is 'DESC' # +String+ +since+:: Optional. Initial value of the queried interval # +String+ +until+:: Optional. Last value of the queried interval - # +Integer+ +limit+:: Optional. Prices per currency pair. Defaul is 10. Min is 1. Max is 1000 + # +Integer+ +limit+:: Optional. Prices per currency pair. Defaul is 10. Min is 1. Max is 1_000 def get_trades(symbols: nil, by: nil, sort: nil, from: nil, till: nil, limit: nil, offset: nil) # rubocop:disable Metrics/ParameterLists public_get( @@ -224,8 +224,8 @@ def get_trades(symbols: nil, by: nil, sort: nil, from: nil, till: nil, limit: ni # +String+ +sort+:: Optional. Sort direction. 'ASC' or 'DESC'. Default is 'DESC' # +String+ +since+:: Optional. Initial value of the queried interval # +String+ +until+:: Optional. Last value of the queried interval - # +Integer+ +limit+:: Optional. Prices per currency pair. Defaul is 10. Min is 1. Max is 1000 - # +Integer+ +offset+:: Optional. Default is 0. Min is 0. Max is 100000 + # +Integer+ +limit+:: Optional. Prices per currency pair. Defaul is 10. Min is 1. Max is 1_000 + # +Integer+ +offset+:: Optional. Default is 0. Min is 0. Max is 100_000 def get_trades_by_symbol(symbol: nil, by: nil, sort: nil, from: nil, till: nil, limit: nil, offset: nil) # rubocop:disable Metrics/ParameterLists public_get( @@ -280,7 +280,7 @@ def get_orderbook_volume(symbol:, volume: nil) end # Get a Hash of candles for all symbols or for specified symbols - # Candels are used for OHLC representation + # Candles are used for OHLC representation # The result contains candles with non-zero volume only (no trades = no candles) # # Requires no API key Access Rights @@ -293,7 +293,7 @@ def get_orderbook_volume(symbol:, volume: nil) # +String+ +sort+:: Optional. Sort direction. 'ASC' or 'DESC'. Default is 'DESC' # +String+ +from+:: Optional. Initial value of the queried interval. As DateTime # +String+ +till+:: Optional. Last value of the queried interval. As DateTime - # +Integer+ +limit+:: Optional. Prices per currency pair. Defaul is 10. Min is 1. Max is 1000 + # +Integer+ +limit+:: Optional. Prices per currency pair. Defaul is 10. Min is 1. Max is 1_000 def get_candles(symbols: nil, period: nil, sort: nil, from: nil, till: nil, limit: nil, offset: nil) # rubocop:disable Metrics/ParameterLists public_get( @@ -303,7 +303,7 @@ def get_candles(symbols: nil, period: nil, sort: nil, from: nil, till: nil, limi end # Get candles of a symbol - # Candels are used for OHLC representation + # Candles are used for OHLC representation # The result contains candles with non-zero volume only (no trades = no candles) # # Requires no API key Access Rights @@ -316,8 +316,8 @@ def get_candles(symbols: nil, period: nil, sort: nil, from: nil, till: nil, limi # +String+ +sort+:: Optional. Sort direction. 'ASC' or 'DESC'. Default is 'DESC' # +String+ +from+:: Optional. Initial value of the queried interval. As DateTime # +String+ +till+:: Optional. Last value of the queried interval. As DateTime - # +Integer+ +limit+:: Optional. Prices per currency pair. Defaul is 100. Min is 1. Max is 1000 - # +Integer+ +offset+:: Optional. Default is 0. Min is 0. Max is 100000 + # +Integer+ +limit+:: Optional. Prices per currency pair. Defaul is 100. Min is 1. Max is 1_000 + # +Integer+ +offset+:: Optional. Default is 0. Min is 0. Max is 100_000 def get_candles_by_symbol(symbol:, period: nil, sort: nil, from: nil, till: nil, limit: nil, offset: nil) # rubocop:disable Metrics/ParameterLists public_get( @@ -328,7 +328,9 @@ def get_candles_by_symbol(symbol:, period: nil, sort: nil, from: nil, till: nil, # Gets OHLCV data regarding the last price converted to the target currency for all symbols or for the specified symbols # - # Candles are used for the representation of a specific symbol as an OHLC chart + # Candles are used for OHLC representation + # + # The result contains candles with non-zero volume only (no trades = no candles) # # 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. # @@ -337,20 +339,48 @@ def get_candles_by_symbol(symbol:, period: nil, sort: nil, from: nil, till: nil, # https://api.exchange.cryptomkt.com/#candles # # +String+ +target_currency+:: Target currency for conversion - # +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' # +Array[String]+ +symbols+:: Optional. A list of symbols + # +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' # +String+ +sort+:: Optional. Sort direction. 'ASC' or 'DESC'. Default is 'DESC' # +String+ +from+:: Optional. Initial value of the queried interval. As DateTime # +String+ +till+:: Optional. Last value of the queried interval. As DateTime - # +Integer+ +limit+:: Optional. Prices per currency pair. Defaul is 100. Min is 1. Max is 1000 + # +Integer+ +limit+:: Optional. Prices per currency pair. Defaul is 100. Min is 1. Max is 1_000 - def get_converted_candles(target_currency:, period: nil, symbols: nil, sort: nil, from: nil, till: nil, limit: nil) # rubocop:disable Metrics/ParameterLists + def get_converted_candles(target_currency:, symbols: nil, period: nil, sort: nil, from: nil, till: nil, limit: nil) # rubocop:disable Metrics/ParameterLists public_get( 'public/converted/candles', { target_currency: target_currency, symbols: symbols, period: period, sort: sort, from: from, till: till, limit: limit } ) end + # Gets OHLCV data regarding the last price converted to the target currency for the specified symbol + # + # Candles are used for OHLC representation + # + # The result contains candles with non-zero volume only (no trades = no candles) + # + # 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. + # + # Requires no API key Access Rights + # + # https://api.exchange.cryptomkt.com/#candles + # + # +String+ +target_currency+:: Target currency for conversion + # +String+ +symbol+:: A symbol id + # +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' + # +String+ +sort+:: Optional. Sort direction. 'ASC' or 'DESC'. Default is 'DESC' + # +String+ +from+:: Optional. Initial value of the queried interval. As DateTime + # +String+ +till+:: Optional. Last value of the queried interval. As DateTime + # +Integer+ +limit+:: Optional. Prices per currency pair. Defaul is 100. Min is 1. Max is 1_000 + # +Integer+ +offset+:: Optional. Default is 0. Min is 0. Max is 100_000 + + 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 + public_get( + "public/converted/candles/#{symbol}", + { target_currency: target_currency, period: period, sort: sort, from: from, till: till, limit: limit, offset: offset } + ) + end + ###################### # Spot Trading calls # ###################### @@ -592,8 +622,8 @@ def get_trading_commission(symbol:) # +String+ +sort+:: Optional. Sort direction. 'ASC' or 'DESC'. Default is 'DESC' # +String+ +from+:: Optional. Initial value of the queried interval # +String+ +till+:: Optional. Last value of the queried interval - # +Integer+ +limit+:: Optional. Prices per currency pair. Defaul is 100. Max is 1000 - # +Integer+ +offset+:: Optional. Default is 0. Max is 100000 + # +Integer+ +limit+:: Optional. Prices per currency pair. Defaul is 100. Max is 1_000 + # +Integer+ +offset+:: Optional. Default is 0. Max is 100_000 def get_spot_orders_history( # rubocop:disable Metrics/ParameterLists 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 # +String+ +sort+:: Optional. Sort direction. 'ASC' or 'DESC'. Default is 'DESC' # +String+ +from+:: Optional. Initial value of the queried interval # +String+ +till+:: Optional. Last value of the queried interval - # +Integer+ +limit+:: Optional. Prices per currency pair. Defaul is 100. Max is 1000 - # +Integer+ +offset+:: Optional. Default is 0. Max is 100000 + # +Integer+ +limit+:: Optional. Prices per currency pair. Defaul is 100. Max is 1_000 + # +Integer+ +offset+:: Optional. Default is 0. Max is 100_000 def get_spot_trades_history( # rubocop:disable Metrics/ParameterLists 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:) # +String+ +id_from+:: Optional. Interval initial value when ordering by id. Min is 0 # +String+ +id_till+:: Optional. Interval end value when ordering by id. Min is 0 # +String+ +sort+:: Optional. Sort direction. 'ASC' or 'DESC'. Default is 'DESC' - # +Integer+ +limit+:: Optional. Transactions per query. Defaul is 100. Max is 1000 - # +Integer+ +offset+:: Optional. Default is 0. Max is 100000 + # +Integer+ +limit+:: Optional. Transactions per query. Defaul is 100. Max is 1_000 + # +Integer+ +offset+:: Optional. Default is 0. Max is 100_000 # +bool+ +group_transactions+:: Optional. Flag indicating whether the returned transactions will be parts of a single operation. Default is false def get_transaction_history( # rubocop:disable Metrics/ParameterLists @@ -996,7 +1026,7 @@ def offchain_available?( # ==== Params # +String+ +currency+:: Optional. Currency code # +bool+ +active+:: Optional. value showing whether the lock is active - # +Integer+ +limit+:: Optional. Dafault is 100. Min is 0. Max is 1000 + # +Integer+ +limit+:: Optional. Dafault is 100. Min is 0. Max is 1_000 # +Integer+ +offset+:: Optional. Default is 0. Min is 0 # +String+ +from+:: Optional. Interval initial value. As Datetime # +String+ +till+:: Optional. Interval end value. As Datetime diff --git a/lib/cryptomarket/websocket/auth_client.rb b/lib/cryptomarket/websocket/auth_client.rb index 88f189f..93b8056 100644 --- a/lib/cryptomarket/websocket/auth_client.rb +++ b/lib/cryptomarket/websocket/auth_client.rb @@ -48,7 +48,7 @@ def wait_authed # err is None for successful calls, result is None for calls with error: Proc.new {|err, result| ...} def authenticate(callback = nil) - timestamp = Time.now.to_i * 1000 + timestamp = Time.now.to_i * 1_000 digest = OpenSSL::Digest.new 'sha256' message = timestamp.to_s message += @window.to_s unless @window.nil? diff --git a/lib/cryptomarket/websocket/market_data_client.rb b/lib/cryptomarket/websocket/market_data_client.rb index 92cb036..8af6c6b 100644 --- a/lib/cryptomarket/websocket/market_data_client.rb +++ b/lib/cryptomarket/websocket/market_data_client.rb @@ -26,7 +26,7 @@ class MarketDataClient < MarketDataClientCore # ==== Params # +Proc+ +callback+:: A +Proc+ that recieves notifications as a hash of trades indexed by symbol, and the type of notification (either 'snapshot' or 'update') # +Array[String]+ +symbols+:: A list of symbol ids - # +Integer+ +limit+:: Number of historical entries returned in the first feed. Min is 0. Max is 1000. Default is 0 + # +Integer+ +limit+:: Number of historical entries returned in the first feed. Min is 0. Max is 1_000. Default is 0 # +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 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) # +Proc+ +callback+:: A +Proc+ that recieves notifications as a hash of candles indexed by symbol, and the type of notification (either 'snapshot' or 'update') # +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' # +Array[String]+ +symbols+:: Optional. A list of symbol ids - # +Integer+ +limit+:: Number of historical entries returned in the first feed. Min is 0. Max is 1000. Default is 0 + # +Integer+ +limit+:: Number of historical entries returned in the first feed. Min is 0. Max is 1_000. Default is 0 # +Proc+ +result_callback+:: Optional. A +Proc+ called with a list of subscribed symbols 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 # # https://api.exchange.cryptomkt.com/#candles # + # +Proc+ +callback+:: A +Proc+ that recieves notifications as a hash of candles indexed by symbol, and the type of notification (either 'snapshot' or 'update') # +String+ +target_currency+:: Target currency for conversion - # +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' # +Array[String]+ +symbols+:: Optional. A list of symbols + # +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' # +String+ +from+:: Optional. Initial value of the queried interval. As DateTime # +String+ +till+:: Optional. Last value of the queried interval. As DateTime - # +Integer+ +limit+:: Optional. Prices per currency pair. Defaul is 100. Min is 1. Max is 1000 + # +Integer+ +limit+:: Optional. Prices per currency pair. Defaul is 100. Min is 1. Max is 1_000 + # +Proc+ +result_callback+:: Optional. A +Proc+ called with a list of subscribed symbols - def subscribe_to_converted_candles(callback:, target_currency:, period:, symbols:, limit: nil, result_callback: nil) # rubocop:disable Metrics/ParameterLists + def subscribe_to_converted_candles(callback:, target_currency:, symbols:, period:, limit: nil, result_callback: nil) # rubocop:disable Metrics/ParameterLists params = { 'target_currency' => target_currency, 'symbols' => symbols, 'limit' => limit } send_channel_subscription("converted/candles/#{period}", callback, intercept_result_callback(result_callback), params) diff --git a/lib/cryptomarket/websocket/wallet_client.rb b/lib/cryptomarket/websocket/wallet_client.rb index 8631baf..3790cfc 100644 --- a/lib/cryptomarket/websocket/wallet_client.rb +++ b/lib/cryptomarket/websocket/wallet_client.rb @@ -151,8 +151,8 @@ def get_wallet_balance(currency:, callback:) # +String+ +id_till+:: Optional. Interval end value when ordering by id. Min is 0 # +String+ +order_by+:: Optional. sorting parameter.'created_at' or 'id'. Default is 'created_at' # +String+ +sort+:: Optional. Sort direction. 'ASC' or 'DESC'. Default is 'DESC' - # +Integer+ +limit+:: Optional. Transactions per query. Defaul is 100. Max is 1000 - # +Integer+ +offset+:: Optional. Default is 0. Max is 100000 + # +Integer+ +limit+:: Optional. Transactions per query. Defaul is 100. Max is 1_000 + # +Integer+ +offset+:: Optional. Default is 0. Max is 100_000 # +bool+ +group_transactions+:: Optional. Flag indicating whether the returned transactions will be parts of a single operation. Default is false def get_transactions( # rubocop:disable Metrics/ParameterLists diff --git a/tests/rest/market_data.rb b/tests/rest/market_data.rb index ae62834..3932918 100644 --- a/tests/rest/market_data.rb +++ b/tests/rest/market_data.rb @@ -136,4 +136,9 @@ def test_get_converted_candles candles.each { |val| assert(Check.good_candle(val)) } end end + + def test_get_converted_candles_by_symbol + result = @client.get_converted_candles_by_symbol(symbol: 'eoseth', limit: 2, target_currency: 'usdt') + result['data'].each { |val| assert(Check.good_candle(val)) } + end end From 2560a6de78529db4ed9f03324fc75d98971de8d6 Mon Sep 17 00:00:00 2001 From: "T. Ismael Verdugo" Date: Fri, 1 Mar 2024 13:17:28 -0300 Subject: [PATCH 5/7] docs: symbols in subscribe converted candles are not optional --- lib/cryptomarket/websocket/market_data_client.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/cryptomarket/websocket/market_data_client.rb b/lib/cryptomarket/websocket/market_data_client.rb index 8af6c6b..812babd 100644 --- a/lib/cryptomarket/websocket/market_data_client.rb +++ b/lib/cryptomarket/websocket/market_data_client.rb @@ -72,7 +72,7 @@ def subscribe_to_candles(callback:, period:, symbols:, limit: nil, result_callba # # +Proc+ +callback+:: A +Proc+ that recieves notifications as a hash of candles indexed by symbol, and the type of notification (either 'snapshot' or 'update') # +String+ +target_currency+:: Target currency for conversion - # +Array[String]+ +symbols+:: Optional. A list of symbols + # +Array[String]+ +symbols+:: A list of symbols # +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' # +String+ +from+:: Optional. Initial value of the queried interval. As DateTime # +String+ +till+:: Optional. Last value of the queried interval. As DateTime From 072597b4e1e0f0e50b1fa659065c7eb58d0dd635 Mon Sep 17 00:00:00 2001 From: "T. Ismael Verdugo" Date: Tue, 12 Mar 2024 10:42:03 -0300 Subject: [PATCH 6/7] feat: method aliases --- lib/cryptomarket/client.rb | 35 +++++++++++++++++-- .../websocket/market_data_client.rb | 13 +++---- lib/cryptomarket/websocket/trading_client.rb | 5 +++ lib/cryptomarket/websocket/wallet_client.rb | 3 ++ 4 files changed, 46 insertions(+), 10 deletions(-) diff --git a/lib/cryptomarket/client.rb b/lib/cryptomarket/client.rb index 7057393..3c04aa0 100644 --- a/lib/cryptomarket/client.rb +++ b/lib/cryptomarket/client.rb @@ -39,6 +39,37 @@ def delete(endpoint, params = nil) @http_manager.make_request(method: 'delete', endpoint: endpoint, params: params) end + ########### + # aliases # + ########### + + # market data + + # alias of get ticker + alias get_ticker_by_symbol get_ticker + alias get_ticker_of_symbol get_ticker + alias get_ticker_price_by_symbol get_ticker_price + alias get_ticker_price_of_symbol get_ticker_price + alias get_trades_of_symbol get_trades_by_symbol + alias get_orderbook_by_symbol get_orderbook + alias get_orderbook_of_symbol get_orderbook + alias get_orderbook_volume_by_symbol get_orderbook_volume + alias get_orderbook_volume_of_symbol get_orderbook_volume + alias get_candles_of_symbol get_candles_by_symbol + alias get_converted_candles_of_symbol get_converted_candles_by_symbol + # spot trading + alias get_spot_trading_balance_of_currency get_spot_trading_balance + alias get_spot_trading_balance_by_currency get_spot_trading_balance + alias get_all_trading_commissions get_all_trading_commission + alias get_trading_commission get_all_trading_commission + alias get_trading_commission_of_symbol get_trading_commission + alias get_trading_commission_by_symbol get_trading_commission + # wallet management + alias get_wallet_balance_of_currency get_wallet_balance + alias get_wallet_balance_by_currency get_wallet_balance + alias get_deposit_crypto_address_of_cyrrency get_deposit_crypto_address + alias get_deposit_crypto_address_by_cyrrency get_deposit_crypto_address + ################ # public calls # ################ @@ -332,7 +363,7 @@ def get_candles_by_symbol(symbol:, period: nil, sort: nil, from: nil, till: nil, # # The result contains candles with non-zero volume only (no trades = no candles) # - # 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. + # 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 or ask price, the last price is returned. # # Requires no API key Access Rights # @@ -359,7 +390,7 @@ def get_converted_candles(target_currency:, symbols: nil, period: nil, sort: nil # # The result contains candles with non-zero volume only (no trades = no candles) # - # 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. + # 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 or ask price, the last price is returned. # # Requires no API key Access Rights # diff --git a/lib/cryptomarket/websocket/market_data_client.rb b/lib/cryptomarket/websocket/market_data_client.rb index 812babd..7e2d21b 100644 --- a/lib/cryptomarket/websocket/market_data_client.rb +++ b/lib/cryptomarket/websocket/market_data_client.rb @@ -40,16 +40,13 @@ def subscribe_to_trades(callback:, symbols:, limit: nil, result_callback: nil) # # normal subscriptions have one update message per symbol # - # the first notification are n candles, with n defined by the limit argument, - # the next notification are updates, with one candle at a time - # # Requires no API key Access Rights # # https://api.exchange.cryptomkt.com/#subscribe-to-candles # # ==== Params # +Proc+ +callback+:: A +Proc+ that recieves notifications as a hash of candles indexed by symbol, and the type of notification (either 'snapshot' or 'update') - # +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' + # +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). # +Array[String]+ +symbols+:: Optional. A list of symbol ids # +Integer+ +limit+:: Number of historical entries returned in the first feed. Min is 0. Max is 1_000. Default is 0 # +Proc+ +result_callback+:: Optional. A +Proc+ called with a list of subscribed symbols @@ -60,20 +57,20 @@ def subscribe_to_candles(callback:, period:, symbols:, limit: nil, result_callba intercept_result_callback(result_callback), params) end - # Gets OHLCV data regarding the last price converted to the target currency for all symbols or for the specified symbols + # subscribes to a feed of candles regarding the last price converted to the target currency for all symbols or for the specified symbols # # Candles are used for the representation of a specific symbol as an OHLC chart # - # 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. + # 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 or ask price, the last price is returned. # # Requires no API key Access Rights # - # https://api.exchange.cryptomkt.com/#candles + # https://api.exchange.cryptomkt.com/#subscribe-to-converted-candles # # +Proc+ +callback+:: A +Proc+ that recieves notifications as a hash of candles indexed by symbol, and the type of notification (either 'snapshot' or 'update') # +String+ +target_currency+:: Target currency for conversion # +Array[String]+ +symbols+:: A list of symbols - # +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' + # +String+ +period+:: A valid tick interval. 'M1' (one minute), 'M3', 'M5', 'M15', 'M30', 'H1' (one hour), 'H4', 'D1' (one day), 'D7', '1M' (one month). # +String+ +from+:: Optional. Initial value of the queried interval. As DateTime # +String+ +till+:: Optional. Last value of the queried interval. As DateTime # +Integer+ +limit+:: Optional. Prices per currency pair. Defaul is 100. Min is 1. Max is 1_000 diff --git a/lib/cryptomarket/websocket/trading_client.rb b/lib/cryptomarket/websocket/trading_client.rb index fc998c9..7bd0168 100644 --- a/lib/cryptomarket/websocket/trading_client.rb +++ b/lib/cryptomarket/websocket/trading_client.rb @@ -35,6 +35,11 @@ def build_subscription_hash 'spot_balance' => [balances, Args::NotificationType::SNAPSHOT] } end + alias get_spot_trading_balance_of_currency get_spot_trading_balance + alias get_spot_trading_balance_by_currency get_spot_trading_balance + alias get_spot_commission_of_symbol get_spot_commission + alias get_spot_commission_by_symbol get_spot_commission + # subscribe to a feed of execution reports of the user's orders # # https://api.exchange.cryptomkt.com/#socket-spot-trading diff --git a/lib/cryptomarket/websocket/wallet_client.rb b/lib/cryptomarket/websocket/wallet_client.rb index 3790cfc..fe28d90 100644 --- a/lib/cryptomarket/websocket/wallet_client.rb +++ b/lib/cryptomarket/websocket/wallet_client.rb @@ -37,6 +37,9 @@ def build_subscription_hash 'wallet_balance_update' => [balance, Args::NotificationType::UPDATE] } end + alias get_wallet_balance_of_currency get_wallet_balance + alias get_wallet_balance_by_currency get_wallet_balance + # A transaction notification occurs each time a transaction has been changed, such as creating a transaction, updating the pending state (e.g., the hash assigned) or completing a transaction # # https://api.exchange.cryptomkt.com/#subscribe-to-transactions From ef387e054022dd147b43fbb048e6fd693fdbb5fb Mon Sep 17 00:00:00 2001 From: Pedro Pablo Bustamante Barrera Date: Wed, 13 Mar 2024 15:26:05 -0300 Subject: [PATCH 7/7] chore: update version --- cryptomarket-sdk.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cryptomarket-sdk.gemspec b/cryptomarket-sdk.gemspec index 31c2c47..954d129 100644 --- a/cryptomarket-sdk.gemspec +++ b/cryptomarket-sdk.gemspec @@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__) Gem::Specification.new do |s| s.name = "cryptomarket-sdk" - s.version = "3.0.0" + s.version = "3.1.0" s.platform = Gem::Platform::RUBY s.authors = ["T. Ismael Verdugo"] s.email = ["ismael@dysopsis.com"]