Skip to content

Commit 27def96

Browse files
committed
feat: get_estimated_fees
1 parent 4ae2e59 commit 27def96

6 files changed

Lines changed: 71 additions & 4 deletions

File tree

cryptomarket/args.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,13 @@ class OrderRequest:
178178
make_rate: Optional[str] = None
179179

180180

181+
@dataclass
182+
class FeeRequest:
183+
currency: str
184+
amount: str
185+
network_code: Optional[str] = None
186+
187+
181188
@dataclass
182189
class ACLSettings:
183190
sub_account_id: str = None
@@ -445,6 +452,9 @@ def subscription_mode(self, val: str):
445452
def target_currency(self, val: str):
446453
return self.add('target_currency', val)
447454

455+
def preferred_network(self, val: str):
456+
return self.add('preferred_network', val)
457+
448458
def type(self, val: str):
449459
return self.add('type', val)
450460

cryptomarket/client.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from dataclasses import asdict
12
from enum import Enum
23
from typing import Any, Dict, List, Optional, Union
34

@@ -8,7 +9,7 @@
89
from cryptomarket.dataclasses import (Address, AmountLock, Balance, Candle,
910
Commission, Currency, Order, OrderBook,
1011
Price, PriceHistory, SubAccount, Symbol,
11-
Ticker, Trade, Transaction)
12+
Ticker, Trade, Transaction, Fee)
1213
from cryptomarket.dataclasses.aclSettings import ACLSettings
1314
from cryptomarket.dataclasses.publicTrade import PublicTrade
1415
from cryptomarket.http_client import HttpClient
@@ -52,18 +53,20 @@ def _delete(self, endpoint: str, params=None):
5253

5354
# PUBLIC METHOD CALLS
5455

55-
def get_currencies(self, currencies: List[str] = None) -> Dict[str, Currency]:
56+
def get_currencies(self, currencies: List[str] = None, preferred_network: Optional[str] = None) -> Dict[str, Currency]:
5657
"""Get a dict of all currencies or specified currencies
5758
5859
Requires no API key Access Rights
5960
6061
https://api.exchange.cryptomkt.com/#currencies
6162
6263
:param currencies: Optional. A list of currencies ids
64+
:param preferred_network: Optional. Code of the default network for currencies
6365
6466
:returns: A dict of available currencies. indexed by currency id
6567
"""
66-
params = args.DictBuilder().currencies(currencies).build()
68+
params = args.DictBuilder().currencies(
69+
currencies).preferred_network(preferred_network).build()
6770
response = self._get(endpoint='public/currency', params=params)
6871
return {key: from_dict(data_class=Currency, data=response[key])
6972
for key in response}
@@ -981,6 +984,20 @@ def get_estimate_withdrawal_fee(self, currency: str, amount: str) -> str:
981984
params = args.DictBuilder().amount(amount).currency(currency).build()
982985
return self._get(endpoint='wallet/crypto/fee/estimate', params=params)['fee']
983986

987+
def get_estimate_withdrawal_fees(self, fee_requests: List[args.FeeRequest]) -> List[Fee]:
988+
"""Get a list of estimates of withdrawal fees
989+
990+
Requires the "Payment information" API key Access Right
991+
992+
https://api.exchange.cryptomkt.com/#estimate-withdraw-fee
993+
994+
:returns: A list of expected withdrawal fees
995+
"""
996+
params = [asdict(fee_request) for fee_request in fee_requests]
997+
result = self._post(
998+
endpoint='wallet/crypto/fees/estimate', params=params)
999+
return [Fee.from_dict(fee_data) for fee_data in result]
1000+
9841001
def check_if_crypto_address_belong_to_current_account(self, address: str) -> bool:
9851002
"""Check if an address is from this account
9861003

cryptomarket/dataclasses/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
from .wsTicker import WSTicker
3131
from .wsTrade import WSTrade
3232
from .wsPriceRate import WSPriceRate
33+
from .fee import Fee
3334
__all__ = [
3435
ACLSettings,
3536
Address,
@@ -63,5 +64,6 @@
6364
WSTicker,
6465
WSTrade,
6566
WSPriceRate,
66-
SubAccount
67+
SubAccount,
68+
Fee,
6769
]

cryptomarket/dataclasses/fee.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from dataclasses import dataclass
2+
from typing import Any, Dict, List
3+
4+
from cryptomarket.dataclasses.orderBookLevel import OrderBookLevel
5+
6+
7+
@dataclass
8+
class Fee:
9+
fee: str
10+
network_fee: str
11+
amount: str
12+
currency: str
13+
14+
@classmethod
15+
def from_dict(cls, data: Dict[str, Any]):
16+
return cls(data.get('fee'), data.get('networkFee'), data.get('amount'), data.get('currency'))

tests/rest/test_helpers.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
OrderBook, OrderBookLevel, Price,
88
PriceHistory, PricePoint, PublicTrade,
99
Symbol, Ticker, Transaction)
10+
from cryptomarket.dataclasses.fee import Fee
1011

1112

1213
# defined checks if a key is present in a dict, and if its value is str, checks if its defined.
@@ -104,6 +105,18 @@ def good_symbol(symbol: Symbol) -> bool:
104105
)
105106

106107

108+
def good_fee(fee: Fee) -> bool:
109+
return good_dict(
110+
asdict(fee),
111+
[
112+
"fee",
113+
"network_fee",
114+
"amount",
115+
"currency",
116+
]
117+
)
118+
119+
107120
def good_ticker(ticker: Ticker) -> bool:
108121
return good_dict(
109122
asdict(ticker),

tests/rest/test_wallet_management.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,15 @@ def test_successfull_call(self):
134134
if not success:
135135
self.fail("not a successful rollback")
136136

137+
class TestGetEstimateWithdrawalFees(AuthCallsTestCase):
138+
def test_successfull_call(self):
139+
fees = self.client.get_estimate_withdrawal_fees([
140+
args.FeeRequest("EOS", "123"),
141+
args.FeeRequest("ETH", "22"),
142+
])
143+
if not good_list(good_fee, fees):
144+
self.fail("not a good fee")
145+
137146

138147
class TestGetEstimateWithdrawalFee(AuthCallsTestCase):
139148
def test_successfull_call(self):

0 commit comments

Comments
 (0)