Skip to content

Commit 7f1fbdc

Browse files
committed
feat: update june 2024
1 parent 072597b commit 7f1fbdc

File tree

6 files changed

+124
-38
lines changed

6 files changed

+124
-38
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)

lib/cryptomarket/client.rb

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

42-
###########
43-
# aliases #
44-
###########
45-
46-
# market data
42+
def change_credentials(api_key:, api_secret:)
43+
@credential_factory.change_credentials(api_key, api_secret)
44+
end
4745

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
46+
def change_window(window:)
47+
@credential_factory.change_window(window)
48+
end
7249

7350
################
7451
# public calls #
@@ -863,11 +840,25 @@ def withdraw_crypto_rollback(id:)
863840
# ==== Params
864841
# +Array[]+ +fee_requests+:: the list of fee requests, each request is a Hash in the form {currency:"string", amount:"string", network_code:"optional string"}
865842

866-
def get_estimate_withdrawal_fees(fee_requests)
843+
def get_estimate_withdrawal_fees(fee_requests:)
867844
params = fee_requests
868845
post('wallet/crypto/fees/estimate', params)
869846
end
870847

848+
# Get an estimates for withdrawal fees of currencies
849+
#
850+
# Requires the "Payment information" API key Access Right
851+
#
852+
# https://api.exchange.cryptomkt.com/#bulk-estimate-withdrawal-fee
853+
#
854+
# ==== Params
855+
# +Array[]+ +fee_requests+:: the list of fee requests, each request is a Hash in the form {currency:"string", amount:"string", network_code:"optional string"}
856+
857+
def get_bulk_estimate_withdrawal_fees(fee_requests:)
858+
params = fee_requests
859+
post('wallet/crypto/fee/estimate/bulk', params)
860+
end
861+
871862
# Get an estimate of the withdrawal fee
872863
#
873864
# Requires the "Payment information" API key Access Right
@@ -883,6 +874,34 @@ def get_estimate_withdrawal_fee(currency:, amount:, network_code: nil)
883874
get('wallet/crypto/fee/estimate', params)['fee']
884875
end
885876

877+
# Get an estimates for deposit fees of currencies
878+
#
879+
# Requires the "Payment information" API key Access Right
880+
#
881+
# https://api.exchange.cryptomkt.com/#bulk-estimate-deposit-fee
882+
#
883+
# ==== Params
884+
# +Array[]+ +fee_requests+:: the list of fee requests, each request is a Hash in the form {currency:"string", amount:"string", network_code:"optional string"}
885+
def get_bulk_estimate_deposit_fees(fee_requests:)
886+
params = fee_requests
887+
post('wallet/crypto/fee/deposit/estimate/bulk', params)
888+
end
889+
890+
# Get an estimate of the deposit fee
891+
#
892+
# Requires the "Payment information" API key Access Right
893+
#
894+
# https://api.exchange.cryptomkt.com/#estimate-deposit-fee
895+
#
896+
# ==== Params
897+
# +String+ +currency+:: the currency code for deposit
898+
# +float+ +amount+:: the expected deposit amount
899+
900+
def get_estimate_deposit_fee(currency:, amount:, network_code: nil)
901+
params = { amount: amount, currency: currency, network_code: network_code }
902+
get('wallet/crypto/fee/deposit/estimate', params)['fee']
903+
end
904+
886905
# Converts between currencies
887906
# 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
888907
# To see whether a transaction has been finalized, call #get_transaction
@@ -986,9 +1005,9 @@ def transfer_money_to_another_user(currency:, amount:, by:, identifier:)
9861005
# +Array[String]+ +statuses+:: Optional. List of statuses to query. valid subtypes are: 'CREATED', 'PENDING', 'FAILED', 'SUCCESS' and 'ROLLED_BACK'
9871006
# +Array[String]+ +currencies+:: Optional. Currency codes of the transactions to fetch
9881007
# +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
1008+
# +String+ +order_by+:: Optional. sorting parameter.'created_at', 'updated_at', 'last_activity_at' 'or 'id'.
1009+
# +String+ +from+:: Optional. Optional. Interval initial value (inclusive). The value type depends on order_by
1010+
# +String+ +till+:: Optional. Interval end value (inclusive). The value type depends on order_BY
9921011
# +String+ +id_from+:: Optional. Interval initial value when ordering by id. Min is 0
9931012
# +String+ +id_till+:: Optional. Interval end value when ordering by id. Min is 0
9941013
# +String+ +sort+:: Optional. Sort direction. 'ASC' or 'DESC'. Default is 'DESC'
@@ -1238,5 +1257,38 @@ def get_sub_account_crypto_address(
12381257
"sub-account/crypto/address/#{sub_account_id}/#{currency}"
12391258
)['result']['address']
12401259
end
1260+
1261+
###########
1262+
# aliases #
1263+
###########
1264+
1265+
# market data
1266+
alias get_ticker_by_symbol get_ticker
1267+
alias get_ticker_of_symbol get_ticker
1268+
alias get_ticker_price_by_symbol get_ticker_price
1269+
alias get_ticker_price_of_symbol get_ticker_price
1270+
alias get_trades_of_symbol get_trades_by_symbol
1271+
alias get_orderbook_by_symbol get_orderbook
1272+
alias get_orderbook_of_symbol get_orderbook
1273+
alias get_orderbook_volume_by_symbol get_orderbook_volume
1274+
alias get_orderbook_volume_of_symbol get_orderbook_volume
1275+
alias get_candles_of_symbol get_candles_by_symbol
1276+
alias get_converted_candles_of_symbol get_converted_candles_by_symbol
1277+
1278+
# spot trading
1279+
alias get_spot_trading_balance_of_currency get_spot_trading_balance
1280+
alias get_spot_trading_balance_by_currency get_spot_trading_balance
1281+
alias get_all_trading_commissions get_all_trading_commission
1282+
alias get_trading_commissions get_all_trading_commission
1283+
alias get_trading_commission_of_symbol get_trading_commission
1284+
alias get_trading_commission_by_symbol get_trading_commission
1285+
1286+
# wallet management
1287+
alias get_wallet_balance_of_currency get_wallet_balance
1288+
alias get_wallet_balance_by_currency get_wallet_balance
1289+
alias get_deposit_crypto_address_of_cyrrency get_deposit_crypto_address
1290+
alias get_deposit_crypto_address_by_cyrrency get_deposit_crypto_address
12411291
end
12421292
end
1293+
1294+
# rubocop:enable Layout/LineLength

lib/cryptomarket/credentials_factory.rb

Lines changed: 9 additions & 0 deletions
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)

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_secret)
42+
end
43+
44+
def change_window(window:)
45+
@credential_factory.change_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/wallet_client.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,11 +148,11 @@ def get_wallet_balance(currency:, callback:)
148148
# +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'
149149
# +Array[String]+ +statuses+:: Optional. List of statuses to query. valid subtypes are: 'CREATED', 'PENDING', 'FAILED', 'SUCCESS' and 'ROLLED_BACK'
150150
# +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
151+
# +String+ +from+:: Optional. Optional. Interval initial value (inclusive). The value type depends on order_by
152+
# +String+ +till+:: Optional. Interval end value (inclusive). The value type depends on order_by
153153
# +String+ +id_from+:: Optional. Interval initial value when ordering by id. Min is 0
154154
# +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'
155+
# +String+ +order_by+:: Optional. sorting parameter.'created_at', 'updated_at', 'last_activity_at' 'or 'id'.
156156
# +String+ +sort+:: Optional. Sort direction. 'ASC' or 'DESC'. Default is 'DESC'
157157
# +Integer+ +limit+:: Optional. Transactions per query. Defaul is 100. Max is 1_000
158158
# +Integer+ +offset+:: Optional. Default is 0. Max is 100_000

tests/rest/wallet_management.rb

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
require_relative '../checks'
66
require_relative '../../lib/cryptomarket/client'
77

8-
class TestRestTradingMethods < Test::Unit::TestCase # rubocop:disable Metrics/ClassLength,Style/Documentation
8+
class TestRestTradingMethods < Test::Unit::TestCase # rubocop:disable Style/Documentation
99
def setup
1010
@client = Cryptomarket::Client.new api_key: KeyLoader.api_key, api_secret: KeyLoader.api_secret
1111
end
@@ -50,11 +50,28 @@ def test_get_estimate_withdrawal_fees
5050
assert(result.count == 2)
5151
end
5252

53+
def test_get_bulk_estimate_withdrawal_fees
54+
result = @client.get_bulk_estimate_withdrawal_fees fee_requests: [{ currency: 'ETH', amount: '12' },
55+
{ currency: 'BTC', amount: '1' }]
56+
assert(result.count == 2)
57+
end
58+
5359
def test_get_estimate_withdrawal_fee
5460
result = @client.get_estimate_withdrawal_fee currency: 'XLM', amount: '3'
5561
assert(!result.empty?)
5662
end
5763

64+
def test_get_bulk_estimate_deposit_fees
65+
result = @client.get_bulk_estimate_deposit_fees fee_requests: [{ currency: 'ETH', amount: '12' },
66+
{ currency: 'BTC', amount: '1' }]
67+
assert(result.count == 2)
68+
end
69+
70+
def test_get_estimate_deposit_fee
71+
result = @client.get_estimate_deposit_fee currency: 'XLM', amount: '3'
72+
assert(!result.empty?)
73+
end
74+
5875
def test_crypto_address_belongs_to_current_account
5976
ada_address = @client.get_deposit_crypto_address(currency: 'ADA')['address']
6077
it_belongs = @client.crypto_address_belongs_to_current_account? address: ada_address

0 commit comments

Comments
 (0)