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 Jan 8, 2025
2 parents deb60a7 + 4cb27c3 commit 237e244
Show file tree
Hide file tree
Showing 15 changed files with 201 additions and 116 deletions.
1 change: 1 addition & 0 deletions .ruby-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.1.6
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
To install Cryptomarket use gem

```
gem install cryptomarket-sdk -v 3.2.0
gem install cryptomarket-sdk -v 3.3.0
```

# Documentation
Expand Down
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.2.0"
s.version = "3.3.0"
s.platform = Gem::Platform::RUBY
s.authors = ["T. Ismael Verdugo"]
s.email = ["[email protected]"]
Expand Down
234 changes: 158 additions & 76 deletions lib/cryptomarket/client.rb

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions lib/cryptomarket/http_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,16 @@ class HttpManager

def initialize(api_key:, api_secret:, window: nil)
@credential_factory = Cryptomarket::CredentialsFactory.new(
api_version: @@API_VERSION, api_key: api_key, api_secret: api_secret, window: window
api_version: @@API_VERSION, api_key:, api_secret:, window:
)
end

def change_credentials(api_key:, api_secret:)
@credential_factory.change_credentials(api_key: api_key, api_secret: api_secret)
@credential_factory.change_credentials(api_key:, api_secret:)
end

def change_window(window:)
@credential_factory.change_window(window: window)
@credential_factory.change_window(window:)
end

def make_request(method:, endpoint:, params: nil, public: false)
Expand Down Expand Up @@ -77,7 +77,7 @@ def build_payload(params)
end

def do_request(method, uri, payload, headers)
args = { method: method.downcase.to_sym, url: uri.to_s, headers: headers }
args = { method: method.downcase.to_sym, url: uri.to_s, headers: }
if post?(method) || patch?(method)
args[:payload] = post?(method) ? payload.to_json : payload
end
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 @@ -12,7 +12,7 @@ def initialize(url:, api_key:, api_secret:, subscription_keys:, window: nil)
@api_key = api_key
@api_secret = api_secret
@window = window
super url: url, subscription_keys: subscription_keys
super(url:, subscription_keys:)
@authed = false
end

Expand Down
2 changes: 1 addition & 1 deletion lib/cryptomarket/websocket/client_base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class ClientBase
def initialize(url:, subscription_keys:, on_connect: -> {}, on_error: ->(error) {}, on_close: -> {})
@subscription_keys = subscription_keys
@callback_cache = CallbackCache.new
@ws_manager = WSManager.new self, url: url
@ws_manager = WSManager.new(self, url:)
@on_connect = on_connect
@on_error = on_error
@on_close = on_close
Expand Down
4 changes: 2 additions & 2 deletions lib/cryptomarket/websocket/market_data_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ def subscribe_to_top_of_book_in_batches(callback:, speed:, symbols: ['*'], resul

def subscribe_to_price_rates(callback:, speed:, target_currency:, currencies: ['*'], result_callback: nil)
params = {
speed: speed, target_currency: target_currency, currencies: currencies
speed:, target_currency:, currencies:
}
send_channel_subscription("price/rate/#{speed}", callback, intercept_result_callback(result_callback), params)
end
Expand All @@ -314,7 +314,7 @@ def subscribe_to_price_rates(callback:, speed:, target_currency:, currencies: ['
def subscribe_to_price_rates_in_batches(callback:, speed:, target_currency:, currencies: ['*'],
result_callback: nil)
params = {
speed: speed, target_currency: target_currency, currencies: currencies
speed:, target_currency:, currencies:
}
send_channel_subscription("price/rate/#{speed}/batch", callback,
intercept_result_callback(result_callback), params)
Expand Down
29 changes: 15 additions & 14 deletions lib/cryptomarket/websocket/trading_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ class TradingClient < AuthClient
def initialize(api_key:, api_secret:, window: nil)
super(
url: 'wss://api.exchange.cryptomkt.com/api/3/ws/trading',
api_key: api_key,
api_secret: api_secret,
window: window,
api_key:,
api_secret:,
window:,
subscription_keys: build_subscription_hash)
end

Expand Down Expand Up @@ -76,7 +76,7 @@ def subscribe_to_spot_balance(callback:, mode: nil, result_callback: nil)
interceptor = lambda { |notification, _type|
callback.call(notification)
}
send_subscription('spot_balance_subscribe', interceptor, { mode: mode }, result_callback)
send_subscription('spot_balance_subscribe', interceptor, { mode: }, result_callback)
end

# stop recieving the feed of balances changes
Expand Down Expand Up @@ -129,9 +129,9 @@ def create_spot_order( # rubocop:disable Metrics/ParameterLists
expire_time: nil, strict_validate: nil, post_only: nil, take_rate: nil, make_rate: nil, callback: nil
)
request('spot_new_order', callback,
{ client_order_id: client_order_id, symbol: symbol, side: side, quantity: quantity, type: type,
time_in_force: time_in_force, price: price, stop_price: stop_price, expire_time: expire_time,
strict_validate: strict_validate, post_only: post_only, take_rate: take_rate, make_rate: make_rate })
{ client_order_id:, symbol:, side:, quantity:, type:,
time_in_force:, price:, stop_price:, expire_time:,
strict_validate:, post_only:, take_rate:, make_rate: })
end

# creates a list of spot orders
Expand Down Expand Up @@ -174,7 +174,7 @@ def create_spot_order_list(
orders:, contingency_type:, order_list_id: nil, callback: nil
)
request('spot_new_order_list', callback, {
orders: orders, contingency_type: contingency_type, order_list_id: order_list_id
orders:, contingency_type:, order_list_id:
},
orders.count)
end
Expand All @@ -187,7 +187,7 @@ def create_spot_order_list(
# +String+ +client_order_id+:: the client order id of the order to cancel
# +Proc+ +callback+:: Optional. A +Proc+ of two arguments, An exception and a result, called either with the exception or with the result, a list of reports of the canceled orders
def cancel_spot_order(client_order_id:, callback: nil)
request('spot_cancel_order', callback, { client_order_id: client_order_id })
request('spot_cancel_order', callback, { client_order_id: })
end

# cancel all active spot orders and returns the ones that could not be canceled
Expand Down Expand Up @@ -222,7 +222,7 @@ def get_spot_trading_balances(callback:)
# +String+ +currency+:: The currency code to query the balance
# +Proc+ +callback+:: A +Proc+ of two arguments, An exception and a result, called either with the exception or with the result, a trading balance
def get_spot_trading_balance(currency:, callback:)
request('spot_balance', callback, { currency: currency })
request('spot_balance', callback, { currency: })
end

# changes the parameters of an existing order, quantity or price
Expand All @@ -234,14 +234,15 @@ def get_spot_trading_balance(currency:, callback:)
# +String+ +new_client_order_id+:: the new client order id for the modified order. must be unique within the trading day
# +String+ +quantity+:: new order quantity
# +String+ +price+:: new order price
# +String+ +stop_price+:: Required if order type is 'stopLimit', 'stopMarket', 'takeProfitLimit', or 'takeProfitMarket'. Order stop price
# +Bool+ +strict_validate+:: price and quantity will be checked for the incrementation with tick size and quantity step. See symbol's tick_size and quantity_increment
# +Proc+ +callback+:: Optional. A +Proc+ of two arguments, An exception and a result, called either with the exception or with the result, the new version of the order
def replace_spot_order( # rubocop:disable Metrics/ParameterLists
client_order_id:, new_client_order_id:, quantity:, price:, strict_validate: nil, callback: nil
client_order_id:, new_client_order_id:, quantity:, price:, stop_price: nil, strict_validate: nil, callback: nil
)
request('spot_replace_order', callback, {
client_order_id: client_order_id, new_client_order_id: new_client_order_id, quantity: quantity,
price: price, strict_validate: strict_validate
client_order_id:, new_client_order_id:, quantity:,
price:, stop_price:, strict_validate:
})
end

Expand All @@ -267,7 +268,7 @@ def get_spot_commissions(callback:)
# +String+ +symbol+:: The symbol of the commission rate
# +Proc+ +callback+:: A +Proc+ of two arguments, An exception and a result, called either with the exception or with the result, a commission for a symbol for the user
def get_spot_commission(symbol:, callback:)
request('spot_fee', callback, { symbol: symbol })
request('spot_fee', callback, { symbol: })
end

alias get_spot_trading_balance_of_currency get_spot_trading_balance
Expand Down
14 changes: 7 additions & 7 deletions lib/cryptomarket/websocket/wallet_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ class WalletClient < AuthClient
def initialize(api_key:, api_secret:, window: nil)
super(
url: 'wss://api.exchange.cryptomkt.com/api/3/ws/wallet',
api_key: api_key,
api_secret: api_secret,
window: window,
api_key:,
api_secret:,
window:,
subscription_keys: build_subscription_hash)
end

Expand Down Expand Up @@ -125,7 +125,7 @@ def get_wallet_balance(currency:, callback:)
balance['currency'] = currency
callback.call(err, balance)
}
request('wallet_balance', interceptor, { currency: currency })
request('wallet_balance', interceptor, { currency: })
end

# Get the transaction history of the account
Expand Down Expand Up @@ -160,9 +160,9 @@ def get_transactions( # rubocop:disable Metrics/ParameterLists
id_from: nil, id_till: nil, order_by: nil, sort: nil, limit: nil, offset: nil, group_transactions: nil
)
request('get_transactions', callback, {
tx_ids: tx_ids, types: types, subtypes: subtypes, statuses: statuses, currencies: currencies,
from: from, till: till, id_from: id_from, id_till: id_till, order_by: order_by, sort: sort,
limit: limit, offset: offset, group_transactions: group_transactions
tx_ids:, types:, subtypes:, statuses:, currencies:,
from:, till:, id_from:, id_till:, order_by:, sort:,
limit:, offset:, group_transactions:
})
end

Expand Down
4 changes: 3 additions & 1 deletion tests/checks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,9 @@ def self.good_ws_mini_ticker
end

def self.good_ticker
->(ticker) { good_params(ticker, %w[t o c h l v q p P L]) } # missing a A b B in some responses
lambda { |ticker|
good_params(ticker, %w[t h l v q L])
} # missing a A b B o c p P in some responses
end

def self.good_orderbook
Expand Down
2 changes: 1 addition & 1 deletion tests/rest/market_data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def test_get_candles_by_symbol

def test_get_converted_candles
symbols = %w[EOSETH BTCUSDT]
result = @client.get_converted_candles(symbols: symbols, limit: 2, target_currency: 'usdt')
result = @client.get_converted_candles(symbols:, limit: 2, target_currency: 'usdt')
result['data'].each do |symbol, candles|
assert(symbols.include?(symbol))
candles.each { |val| assert(Check.good_candle(val)) }
Expand Down
3 changes: 1 addition & 2 deletions tests/rest/spot_trading.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def test_spot_order_lifecycle
new_client_order_id = Time.now.to_i.to_s + '1'
order = @client.replace_spot_order(
client_order_id: order['client_order_id'],
new_client_order_id: new_client_order_id,
new_client_order_id:,
quantity: '0.02',
price: '999'
)
Expand Down Expand Up @@ -85,5 +85,4 @@ def test_create_order_list
)
# TODO: check missing
end

end
6 changes: 3 additions & 3 deletions tests/websocket/trading_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def test_order_work_flow # rubocop:disable Metrics/MethodLength,Metrics/AbcSize
timestamp = Time.now.to_i.to_s
symbol = 'EOSETH'
@wsclient.create_spot_order(
client_order_id: timestamp, symbol: symbol, side: 'sell', price: '10000', quantity: '0.01',
client_order_id: timestamp, symbol:, side: 'sell', price: '10000', quantity: '0.01',
callback: gen_check_result_callback(WSCheck.good_report, @veredict_checker)
)
sleep(3)
Expand Down Expand Up @@ -68,12 +68,12 @@ def test_cancel_spot_orders # rubocop:disable Metrics/AbcSize,Metrics/MethodLeng
@wsclient.cancel_spot_orders
symbol = 'EOSETH'
@wsclient.create_spot_order(
client_order_id: Time.now.to_i.to_s, symbol: symbol, side: 'sell', price: '10000', quantity: '0.01',
client_order_id: Time.now.to_i.to_s, symbol:, side: 'sell', price: '10000', quantity: '0.01',
callback: gen_check_result_callback(WSCheck.good_report, @veredict_checker)
)
sleep(3)
@wsclient.create_spot_order(
client_order_id: Time.now.to_i.to_s, symbol: symbol, side: 'sell', price: '10000', quantity: '0.01',
client_order_id: Time.now.to_i.to_s, symbol:, side: 'sell', price: '10000', quantity: '0.01',
callback: gen_check_result_callback(WSCheck.good_report, @veredict_checker)
)
sleep(3)
Expand Down
4 changes: 2 additions & 2 deletions tests/websocket/trading_client_subscriptions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def test_reports # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
timestamp = Time.now.to_i.to_s
symbol = 'EOSETH'
@wsclient.create_spot_order(
symbol: symbol, price: '10000', quantity: '0.01', side: 'sell', client_order_id: timestamp,
symbol:, price: '10000', quantity: '0.01', side: 'sell', client_order_id: timestamp,
callback: gen_check_result_callback(WSCheck.good_report, @veredict_checker)
)
sleep(10 * @@SECOND)
Expand All @@ -52,7 +52,7 @@ def test_spot_balance # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
timestamp = Time.now.to_i.to_s
symbol = 'EOSETH'
@wsclient.create_spot_order(
symbol: symbol, price: '10000', quantity: '0.01', side: 'sell', client_order_id: timestamp,
symbol:, price: '10000', quantity: '0.01', side: 'sell', client_order_id: timestamp,
callback: gen_result_callback(@veredict_checker)
)
sleep(5 * @@SECOND)
Expand Down

0 comments on commit 237e244

Please sign in to comment.