Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Pedro Pablo Bustamante Barrera committed Mar 13, 2024
2 parents b3f92c2 + ef387e0 commit 7c40b3f
Show file tree
Hide file tree
Showing 9 changed files with 169 additions and 32 deletions.
2 changes: 1 addition & 1 deletion cryptomarket-sdk.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ["[email protected]"]
Expand Down
118 changes: 102 additions & 16 deletions lib/cryptomarket/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 #
################
Expand Down Expand Up @@ -154,7 +185,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(
Expand Down Expand Up @@ -202,7 +233,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(
Expand All @@ -224,8 +255,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(
Expand Down Expand Up @@ -280,7 +311,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
Expand All @@ -293,7 +324,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(
Expand All @@ -303,7 +334,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
Expand All @@ -316,8 +347,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(
Expand All @@ -326,6 +357,61 @@ 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 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 or 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
# +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 1_000

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 or 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 #
######################
Expand Down Expand Up @@ -567,8 +653,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,
Expand All @@ -594,8 +680,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,
Expand Down Expand Up @@ -906,8 +992,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
Expand Down Expand Up @@ -971,7 +1057,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
Expand Down
2 changes: 1 addition & 1 deletion lib/cryptomarket/websocket/auth_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
36 changes: 29 additions & 7 deletions lib/cryptomarket/websocket/market_data_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -40,18 +40,15 @@ 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 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)
Expand All @@ -60,6 +57,31 @@ def subscribe_to_candles(callback:, period:, symbols:, limit: nil, result_callba
intercept_result_callback(result_callback), params)
end

# 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 or ask price, the last price is returned.
#
# Requires no API key Access Rights
#
# 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).
# +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
# +Proc+ +result_callback+:: Optional. A +Proc+ called with a list of subscribed symbols

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)
end

# subscribe to a feed of mini tickers
#
# subscription is for all symbols or for the specified symbols
Expand Down Expand Up @@ -258,7 +280,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')
Expand Down
5 changes: 5 additions & 0 deletions lib/cryptomarket/websocket/trading_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions lib/cryptomarket/websocket/wallet_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -151,8 +154,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
Expand Down
Loading

0 comments on commit 7c40b3f

Please sign in to comment.