Skip to content

Commit 3284006

Browse files
authored
Merge pull request #24 from cryptomkt/feat/update-june-2024
Feat/update june 2024
2 parents b86e756 + fa00415 commit 3284006

32 files changed

+729
-545
lines changed

cryptomarket/args.py

Lines changed: 115 additions & 92 deletions
Large diffs are not rendered by default.

cryptomarket/client.py

Lines changed: 230 additions & 162 deletions
Large diffs are not rendered by default.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from dataclasses import dataclass
2+
from typing import Optional
3+
4+
5+
@dataclass
6+
class CommitRisk:
7+
score: Optional[int] = None
8+
rbf: Optional[str] = None
9+
low_fee: Optional[str] = None

cryptomarket/dataclasses/fee.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
from dataclasses import dataclass
2-
from typing import Any, Dict, List
3-
4-
from cryptomarket.dataclasses.orderBookLevel import OrderBookLevel
2+
from typing import Any, Dict, Optional
53

64

75
@dataclass
86
class Fee:
97
fee: str
10-
network_fee: str
8+
network_fee: Optional[str]
119
amount: str
1210
currency: str
1311

1412
@classmethod
1513
def from_dict(cls, data: Dict[str, Any]):
16-
return cls(data.get('fee'), data.get('networkFee'), data.get('amount'), data.get('currency'))
14+
return cls(data['fee'], data.get('networkFee'), data['amount'], data['currency'])

cryptomarket/dataclasses/network.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from dataclasses import dataclass
2-
from typing import Optional
2+
from typing import Mapping, Optional
33

44

55
@dataclass
@@ -21,3 +21,9 @@ class Network:
2121
avg_processing_time: Optional[str] = None
2222
crypto_payment_id_name: Optional[str] = None
2323
crypto_explorer: Optional[str] = None
24+
code: Optional[str] = None
25+
is_ens_available: Optional[bool] = None
26+
network_name: Optional[str] = None
27+
contract_address: Optional[str] = None
28+
is_multichain: Optional[bool] = None
29+
asset_id: Optional[Mapping[str,str]] = None

cryptomarket/dataclasses/transaction.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
from cryptomarket.args import (TransactionStatus, TransactionSubType,
55
TransactionType)
6+
from cryptomarket.dataclasses.CommitRisk import CommitRisk
67
from cryptomarket.dataclasses.metaTransaction import MetaTransaction
78
from cryptomarket.dataclasses.nativeTransaction import NativeTransaction
89

@@ -15,5 +16,7 @@ class Transaction:
1516
subtype: TransactionSubType
1617
created_at: str
1718
updated_at: str
19+
last_activity_at: str
1820
native: Optional[NativeTransaction] = None
1921
meta: Optional[MetaTransaction] = None
22+
commit_risk: Optional[CommitRisk] = None

cryptomarket/exceptions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import List
1+
from typing import List, Optional
22

33

44
class CryptomarketSDKException(Exception):
@@ -46,7 +46,7 @@ def __str__(self):
4646

4747

4848
class ArgumentFormatException(CryptomarketSDKException):
49-
def __init__(self, message, valid_options: List[str] = None):
49+
def __init__(self, message, valid_options: Optional[List[str]] = None):
5050
self.message = message
5151
if valid_options is not None:
5252
self.message += ' Valid options are:'

cryptomarket/hmac_auth.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22
from hashlib import sha256
33
from hmac import HMAC
44
from time import time
5+
from typing import Optional
56
from urllib.parse import urlsplit
67

78
from requests.auth import AuthBase
89

910

1011
class HmacAuth(AuthBase):
11-
def __init__(self, api_key: str, secret_key: str, window: int = None):
12+
def __init__(self, api_key: str, secret_key: str, window: Optional[int] = None):
1213
self.api_key = api_key
1314
self.secret_key = secret_key
1415
self.window = window

cryptomarket/http_client.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import json
2+
from typing import Optional
23

34
import requests
45

@@ -10,16 +11,11 @@
1011

1112
class HttpClient:
1213

13-
def __init__(self, api_key: str, secret_key: str, window: int = None):
14+
def __init__(self, api_key: str, api_secret: str, window: Optional[int] = None):
1415
self.api_key = api_key
15-
self.secret_key = secret_key
16+
self.api_secret = api_secret
1617
self.window = window
1718
self.session_is_open = False
18-
self.session = None
19-
self._init_session()
20-
21-
def _init_session(self):
22-
assert self.session_is_open == False
2319
session = requests.session()
2420
session.headers.update({'User-Agent': 'cryptomarket/python'})
2521
self.session = session
@@ -29,10 +25,10 @@ def close_session(self):
2925
self.session.close()
3026
self.session_is_open = False
3127

32-
def authorize(self):
28+
def reset_authorization(self):
3329
assert self.session_is_open == True
3430
self.session.auth = HmacAuth(
35-
self.api_key, self.secret_key, window=self.window)
31+
self.api_key, self.api_secret, window=self.window)
3632

3733
def get(self, endpoint, params=None):
3834
response = self.session.get(api_url + endpoint, params=params)
@@ -59,7 +55,7 @@ def delete(self, endpoint, params=None):
5955

6056
def _handle_response(self, response):
6157
"""Internal helper for handling API responses from the CryptoMarket server.
62-
Raises the appropriate exceptions when necessary; otherwise, returns the
58+
Raises the appropriate exceptions when necessary; otherwise, return the
6359
response.
6460
"""
6561
if not str(response.status_code).startswith('2'):
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from typing import Callable, Generic, Optional, TypeVar
2+
from dacite.data import Data
3+
4+
from cryptomarket.exceptions import CryptomarketAPIException
5+
6+
T = TypeVar('T')
7+
Callback = Callable[[Optional[CryptomarketAPIException], Optional[T]], None]

0 commit comments

Comments
 (0)