Skip to content

Commit deb60a7

Browse files
author
Pedro Pablo Bustamante Barrera
committed
Merge branch 'develop'
2 parents 7c40b3f + e15b030 commit deb60a7

File tree

13 files changed

+228
-49
lines changed

13 files changed

+228
-49
lines changed

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ GEM
5353
websocket-extensions (0.1.5)
5454

5555
PLATFORMS
56-
x86_64-linux
5756
arm64-darwin-23
5857
ruby
58+
x86_64-linux
5959

6060
DEPENDENCIES
6161
eventmachine (= 1.2.7)

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
To install Cryptomarket use gem
1010

1111
```
12-
gem install cryptomarket-sdk
12+
gem install cryptomarket-sdk -v 3.2.0
1313
```
1414

1515
# Documentation

cryptomarket-sdk.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
33

44
Gem::Specification.new do |s|
55
s.name = "cryptomarket-sdk"
6-
s.version = "3.1.0"
6+
s.version = "3.2.0"
77
s.platform = Gem::Platform::RUBY
88
s.authors = ["T. Ismael Verdugo"]
99
s.email = ["[email protected]"]

lib/cryptomarket/client.rb

Lines changed: 95 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -39,36 +39,24 @@ def delete(endpoint, params = nil)
3939
@http_manager.make_request(method: 'delete', endpoint: endpoint, params: params)
4040
end
4141

42-
###########
43-
# aliases #
44-
###########
42+
# Changes the user credentials used for authentication in calls
43+
#
44+
# ==== Params
45+
# +String+ +api_key+:: The user public key used in new calls
46+
# +String+ +api_secret+:: The user secret key used in new calls
4547

46-
# market data
48+
def change_credentials(api_key:, api_secret:)
49+
@http_manager.change_credentials(api_key: api_key, api_secret: api_secret)
50+
end
4751

48-
# alias of get ticker
49-
alias get_ticker_by_symbol get_ticker
50-
alias get_ticker_of_symbol get_ticker
51-
alias get_ticker_price_by_symbol get_ticker_price
52-
alias get_ticker_price_of_symbol get_ticker_price
53-
alias get_trades_of_symbol get_trades_by_symbol
54-
alias get_orderbook_by_symbol get_orderbook
55-
alias get_orderbook_of_symbol get_orderbook
56-
alias get_orderbook_volume_by_symbol get_orderbook_volume
57-
alias get_orderbook_volume_of_symbol get_orderbook_volume
58-
alias get_candles_of_symbol get_candles_by_symbol
59-
alias get_converted_candles_of_symbol get_converted_candles_by_symbol
60-
# spot trading
61-
alias get_spot_trading_balance_of_currency get_spot_trading_balance
62-
alias get_spot_trading_balance_by_currency get_spot_trading_balance
63-
alias get_all_trading_commissions get_all_trading_commission
64-
alias get_trading_commission get_all_trading_commission
65-
alias get_trading_commission_of_symbol get_trading_commission
66-
alias get_trading_commission_by_symbol get_trading_commission
67-
# wallet management
68-
alias get_wallet_balance_of_currency get_wallet_balance
69-
alias get_wallet_balance_by_currency get_wallet_balance
70-
alias get_deposit_crypto_address_of_cyrrency get_deposit_crypto_address
71-
alias get_deposit_crypto_address_by_cyrrency get_deposit_crypto_address
52+
# Changes the window used in authenticated calls
53+
#
54+
# ==== Params
55+
# +Integer+ +window+:: Acceptable time between request and server execution in millis
56+
57+
def change_window(window:)
58+
@http_manager.change_window(window: window)
59+
end
7260

7361
################
7462
# public calls #
@@ -863,11 +851,25 @@ def withdraw_crypto_rollback(id:)
863851
# ==== Params
864852
# +Array[]+ +fee_requests+:: the list of fee requests, each request is a Hash in the form {currency:"string", amount:"string", network_code:"optional string"}
865853

866-
def get_estimate_withdrawal_fees(fee_requests)
854+
def get_estimate_withdrawal_fees(fee_requests:)
867855
params = fee_requests
868856
post('wallet/crypto/fees/estimate', params)
869857
end
870858

859+
# Get an estimates for withdrawal fees of currencies
860+
#
861+
# Requires the "Payment information" API key Access Right
862+
#
863+
# https://api.exchange.cryptomkt.com/#bulk-estimate-withdrawal-fee
864+
#
865+
# ==== Params
866+
# +Array[]+ +fee_requests+:: the list of fee requests, each request is a Hash in the form {currency:"string", amount:"string", network_code:"optional string"}
867+
868+
def get_bulk_estimate_withdrawal_fees(fee_requests:)
869+
params = fee_requests
870+
post('wallet/crypto/fee/estimate/bulk', params)
871+
end
872+
871873
# Get an estimate of the withdrawal fee
872874
#
873875
# Requires the "Payment information" API key Access Right
@@ -883,6 +885,34 @@ def get_estimate_withdrawal_fee(currency:, amount:, network_code: nil)
883885
get('wallet/crypto/fee/estimate', params)['fee']
884886
end
885887

888+
# # Get an estimates for deposit fees of currencies
889+
# #
890+
# # Requires the "Payment information" API key Access Right
891+
# #
892+
# # https://api.exchange.cryptomkt.com/#bulk-estimate-deposit-fee
893+
# #
894+
# # ==== Params
895+
# # +Array[]+ +fee_requests+:: the list of fee requests, each request is a Hash in the form {currency:"string", amount:"string", network_code:"optional string"}
896+
# def get_bulk_estimate_deposit_fees(fee_requests:)
897+
# params = fee_requests
898+
# post('wallet/crypto/fee/deposit/estimate/bulk', params)
899+
# end
900+
901+
# # Get an estimate of the deposit fee
902+
# #
903+
# # Requires the "Payment information" API key Access Right
904+
# #
905+
# # https://api.exchange.cryptomkt.com/#estimate-deposit-fee
906+
# #
907+
# # ==== Params
908+
# # +String+ +currency+:: the currency code for deposit
909+
# # +float+ +amount+:: the expected deposit amount
910+
911+
# def get_estimate_deposit_fee(currency:, amount:, network_code: nil)
912+
# params = { amount: amount, currency: currency, network_code: network_code }
913+
# get('wallet/crypto/fee/deposit/estimate', params)['fee']
914+
# end
915+
886916
# Converts between currencies
887917
# Successful response to the request does not necessarily mean the resulting transaction got executed immediately. It has to be processed first and may eventually be rolled back
888918
# To see whether a transaction has been finalized, call #get_transaction
@@ -986,9 +1016,9 @@ def transfer_money_to_another_user(currency:, amount:, by:, identifier:)
9861016
# +Array[String]+ +statuses+:: Optional. List of statuses to query. valid subtypes are: 'CREATED', 'PENDING', 'FAILED', 'SUCCESS' and 'ROLLED_BACK'
9871017
# +Array[String]+ +currencies+:: Optional. Currency codes of the transactions to fetch
9881018
# +Array[String]+ +networks+:: Optional. Network codes of the transactions to fetch
989-
# +String+ +order_by+:: Optional. sorting parameter.'created_at' or 'id'. Default is 'created_at'
990-
# +String+ +from+:: Optional. Interval initial value when ordering by 'created_at'. As Datetime
991-
# +String+ +till+:: Optional. Interval end value when ordering by 'created_at'. As Datetime
1019+
# +String+ +order_by+:: Optional. sorting parameter.'created_at', 'updated_at', 'last_activity_at' 'or 'id'.
1020+
# +String+ +from+:: Optional. Optional. Interval initial value (inclusive). The value type depends on order_by
1021+
# +String+ +till+:: Optional. Interval end value (inclusive). The value type depends on order_BY
9921022
# +String+ +id_from+:: Optional. Interval initial value when ordering by id. Min is 0
9931023
# +String+ +id_till+:: Optional. Interval end value when ordering by id. Min is 0
9941024
# +String+ +sort+:: Optional. Sort direction. 'ASC' or 'DESC'. Default is 'DESC'
@@ -1238,5 +1268,38 @@ def get_sub_account_crypto_address(
12381268
"sub-account/crypto/address/#{sub_account_id}/#{currency}"
12391269
)['result']['address']
12401270
end
1271+
1272+
###########
1273+
# aliases #
1274+
###########
1275+
1276+
# market data
1277+
alias get_ticker_by_symbol get_ticker
1278+
alias get_ticker_of_symbol get_ticker
1279+
alias get_ticker_price_by_symbol get_ticker_price
1280+
alias get_ticker_price_of_symbol get_ticker_price
1281+
alias get_trades_of_symbol get_trades_by_symbol
1282+
alias get_orderbook_by_symbol get_orderbook
1283+
alias get_orderbook_of_symbol get_orderbook
1284+
alias get_orderbook_volume_by_symbol get_orderbook_volume
1285+
alias get_orderbook_volume_of_symbol get_orderbook_volume
1286+
alias get_candles_of_symbol get_candles_by_symbol
1287+
alias get_converted_candles_of_symbol get_converted_candles_by_symbol
1288+
1289+
# spot trading
1290+
alias get_spot_trading_balance_of_currency get_spot_trading_balance
1291+
alias get_spot_trading_balance_by_currency get_spot_trading_balance
1292+
alias get_all_trading_commissions get_all_trading_commission
1293+
alias get_trading_commissions get_all_trading_commission
1294+
alias get_trading_commission_of_symbol get_trading_commission
1295+
alias get_trading_commission_by_symbol get_trading_commission
1296+
1297+
# wallet management
1298+
alias get_wallet_balance_of_currency get_wallet_balance
1299+
alias get_wallet_balance_by_currency get_wallet_balance
1300+
alias get_deposit_crypto_address_of_cyrrency get_deposit_crypto_address
1301+
alias get_deposit_crypto_address_by_cyrrency get_deposit_crypto_address
12411302
end
12421303
end
1304+
1305+
# rubocop:enable Layout/LineLength

lib/cryptomarket/credentials_factory.rb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,15 @@ def initialize(api_version:, api_key:, api_secret:, window: nil)
1818
@window = window
1919
end
2020

21+
def change_credentials(api_key:, api_secret:)
22+
@api_key = api_key
23+
@api_secret = api_secret
24+
end
25+
26+
def change_window(window:)
27+
@window = window
28+
end
29+
2130
def get_credential(http_method, method, params)
2231
timestamp = DateTime.now.strftime('%Q')
2332
msg = build_credential_message(http_method, method, timestamp, params)
@@ -37,7 +46,7 @@ def build_credential_message(http_method, method, timestamp, params)
3746
not_post_params(http_method, params)
3847
end
3948
msg += timestamp
40-
msg += @window unless @window.nil?
49+
msg += @window.to_s unless @window.nil?
4150
msg
4251
end
4352

lib/cryptomarket/http_manager.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ def initialize(api_key:, api_secret:, window: nil)
3737
)
3838
end
3939

40+
def change_credentials(api_key:, api_secret:)
41+
@credential_factory.change_credentials(api_key: api_key, api_secret: api_secret)
42+
end
43+
44+
def change_window(window:)
45+
@credential_factory.change_window(window: window)
46+
end
47+
4048
def make_request(method:, endpoint:, params: nil, public: false)
4149
uri = URI(@@API_URL + @@API_VERSION + endpoint)
4250
payload = build_payload(params)

lib/cryptomarket/websocket/trading_client.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,6 @@ def build_subscription_hash
3535
'spot_balance' => [balances, Args::NotificationType::SNAPSHOT] }
3636
end
3737

38-
alias get_spot_trading_balance_of_currency get_spot_trading_balance
39-
alias get_spot_trading_balance_by_currency get_spot_trading_balance
40-
alias get_spot_commission_of_symbol get_spot_commission
41-
alias get_spot_commission_by_symbol get_spot_commission
42-
4338
# subscribe to a feed of execution reports of the user's orders
4439
#
4540
# https://api.exchange.cryptomkt.com/#socket-spot-trading
@@ -274,6 +269,11 @@ def get_spot_commissions(callback:)
274269
def get_spot_commission(symbol:, callback:)
275270
request('spot_fee', callback, { symbol: symbol })
276271
end
272+
273+
alias get_spot_trading_balance_of_currency get_spot_trading_balance
274+
alias get_spot_trading_balance_by_currency get_spot_trading_balance
275+
alias get_spot_commission_of_symbol get_spot_commission
276+
alias get_spot_commission_by_symbol get_spot_commission
277277
end
278278
end
279279
end

lib/cryptomarket/websocket/wallet_client.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,6 @@ def build_subscription_hash
3737
'wallet_balance_update' => [balance, Args::NotificationType::UPDATE] }
3838
end
3939

40-
alias get_wallet_balance_of_currency get_wallet_balance
41-
alias get_wallet_balance_by_currency get_wallet_balance
42-
4340
# 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
4441
#
4542
# https://api.exchange.cryptomkt.com/#subscribe-to-transactions
@@ -148,11 +145,11 @@ def get_wallet_balance(currency:, callback:)
148145
# +Array[String]+ +subtyes+:: Optional. List of subtypes to query. valid subtypes are: 'UNCLASSIFIED', 'BLOCKCHAIN', 'AIRDROP', 'AFFILIATE', 'STAKING', 'BUY_CRYPTO', 'OFFCHAIN', 'FIAT', 'SUB_ACCOUNT', 'WALLET_TO_SPOT', 'SPOT_TO_WALLET', 'WALLET_TO_DERIVATIVES', 'DERIVATIVES_TO_WALLET', 'CHAIN_SWITCH_FROM', 'CHAIN_SWITCH_TO' and 'INSTANT_EXCHANGE'
149146
# +Array[String]+ +statuses+:: Optional. List of statuses to query. valid subtypes are: 'CREATED', 'PENDING', 'FAILED', 'SUCCESS' and 'ROLLED_BACK'
150147
# +Array[String] +currencies+:: Optional. List of currencies ids.
151-
# +String+ +from+:: Optional. Interval initial value when ordering by 'created_at'. As Datetime
152-
# +String+ +till+:: Optional. Interval end value when ordering by 'created_at'. As Datetime
148+
# +String+ +from+:: Optional. Optional. Interval initial value (inclusive). The value type depends on order_by
149+
# +String+ +till+:: Optional. Interval end value (inclusive). The value type depends on order_by
153150
# +String+ +id_from+:: Optional. Interval initial value when ordering by id. Min is 0
154151
# +String+ +id_till+:: Optional. Interval end value when ordering by id. Min is 0
155-
# +String+ +order_by+:: Optional. sorting parameter.'created_at' or 'id'. Default is 'created_at'
152+
# +String+ +order_by+:: Optional. sorting parameter.'created_at', 'updated_at', 'last_activity_at' 'or 'id'.
156153
# +String+ +sort+:: Optional. Sort direction. 'ASC' or 'DESC'. Default is 'DESC'
157154
# +Integer+ +limit+:: Optional. Transactions per query. Defaul is 100. Max is 1_000
158155
# +Integer+ +offset+:: Optional. Default is 0. Max is 100_000
@@ -168,6 +165,9 @@ def get_transactions( # rubocop:disable Metrics/ParameterLists
168165
limit: limit, offset: offset, group_transactions: group_transactions
169166
})
170167
end
168+
169+
alias get_wallet_balance_of_currency get_wallet_balance
170+
alias get_wallet_balance_by_currency get_wallet_balance
171171
end
172172
end
173173
end

tests/rest/change_credentials.rb

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# frozen_string_literal: true
2+
3+
require 'test/unit'
4+
require_relative '../key_loader'
5+
require_relative '../checks'
6+
require_relative '../../lib/cryptomarket/client'
7+
8+
class ChangeCredentials < Test::Unit::TestCase # rubocop:disable Style/Documentation
9+
def setup
10+
@client = Cryptomarket::Client.new api_key: KeyLoader.api_key, api_secret: KeyLoader.api_secret
11+
end
12+
13+
def test_change_credentials
14+
result = @client.get_wallet_balances
15+
assert(good_list(->(balance) { Check.good_balance(balance) }, result))
16+
17+
@client.change_credentials api_key: '', api_secret: ''
18+
begin
19+
@client.get_wallet_balances
20+
assert(false)
21+
rescue Cryptomarket::APIException
22+
nil
23+
end
24+
25+
@client.change_credentials api_key: KeyLoader.api_key, api_secret: KeyLoader.api_secret
26+
result = @client.get_wallet_balances
27+
assert(good_list(->(balance) { Check.good_balance(balance) }, result))
28+
end
29+
end

tests/rest/change_window.rb

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# frozen_string_literal: true
2+
3+
require 'test/unit'
4+
require_relative '../key_loader'
5+
require_relative '../checks'
6+
require_relative '../../lib/cryptomarket/client'
7+
8+
class ChangeWindow < Test::Unit::TestCase # rubocop:disable Style/Documentation
9+
def setup
10+
@client = Cryptomarket::Client.new api_key: KeyLoader.api_key, api_secret: KeyLoader.api_secret
11+
end
12+
13+
def test_change_window
14+
result = @client.get_wallet_balances
15+
assert(good_list(->(balance) { Check.good_balance(balance) }, result))
16+
17+
@client.change_window window: 100
18+
begin
19+
@client.get_wallet_balances
20+
assert(false)
21+
rescue Cryptomarket::APIException
22+
nil
23+
end
24+
25+
@client.change_window window: 10_000
26+
result = @client.get_wallet_balances
27+
assert(good_list(->(balance) { Check.good_balance(balance) }, result))
28+
end
29+
end

0 commit comments

Comments
 (0)