Skip to content

Commit 44f5c40

Browse files
Abel ArmoaAbel Armoa
authored andcommitted
(fix) Turned market classes and token class into dataclass with eq and hash support
1 parent d9b516a commit 44f5c40

File tree

2 files changed

+13
-23
lines changed

2 files changed

+13
-23
lines changed

pyinjective/core/market.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
from decimal import Decimal
33
from typing import Optional
44

5-
from constant import ADDITIONAL_CHAIN_FORMAT_DECIMALS, Denom
5+
from pyinjective.constant import ADDITIONAL_CHAIN_FORMAT_DECIMALS, Denom
66
from pyinjective.core.token import Token
77

88

9-
@dataclass
9+
@dataclass(eq=True, frozen=True)
1010
class SpotMarket:
1111
id: str
1212
status: str
@@ -34,7 +34,7 @@ def price_to_chain_format(self, human_readable_value: Decimal) -> Decimal:
3434

3535
return extended_chain_formatted_value
3636

37-
@dataclass
37+
@dataclass(eq=True, frozen=True)
3838
class DerivativeMarket:
3939
id: str
4040
status: str
@@ -92,7 +92,7 @@ def calculate_margin_in_chain_format(
9292

9393
return extended_chain_formatted_margin
9494

95-
@dataclass
95+
@dataclass(eq=True, frozen=True)
9696
class BinaryOptionMarket:
9797
id: str
9898
status: str

pyinjective/core/token.py

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,15 @@
1+
from dataclasses import dataclass
12
from decimal import Decimal
23

3-
4+
@dataclass(eq=True, frozen=True)
45
class Token:
5-
6-
def __init__(
7-
self,
8-
name: str,
9-
symbol: str,
10-
denom: str,
11-
address: str,
12-
decimals: int,
13-
logo: str,
14-
updated: int,
15-
):
16-
self.name = name
17-
self.symbol = symbol
18-
self.denom = denom
19-
self.address = address
20-
self.decimals = decimals
21-
self.logo = logo
22-
self.updated = updated
6+
name: str
7+
symbol: str
8+
denom: str
9+
address: str
10+
decimals: int
11+
logo: str
12+
updated: int
2313

2414
def chain_formatted_value(self, human_readable_value: Decimal) -> Decimal:
2515
return human_readable_value * Decimal(f"1e{self.decimals}")

0 commit comments

Comments
 (0)