-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata_types.py
More file actions
138 lines (107 loc) · 3.54 KB
/
Copy pathdata_types.py
File metadata and controls
138 lines (107 loc) · 3.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
from enum import Enum
from dataclasses import dataclass
from typing import Tuple, Any, overload
class ExchangePairs(str, Enum):
def __str__(self) -> str:
return str.__str__(self)
class BTCUSDExchangePairs(ExchangePairs):
"""
Enum representing BTC to USD exchange pairs.
Values:
COINBASE (str): Coinbase exchange pair.
KRAKEN (str): Kraken exchange pair.
GEMINI (str): Gemini exchange pair.
"""
COINBASE = "BTC-USD"
KRAKEN = "XBTUSD"
GEMINI = "BTCUSD"
class ETHUSDExchangePairs(ExchangePairs):
"""
Enum representing ETH to USD exchange pairs.
Values:
COINBASE (str): Coinbase exchange pair.
KRAKEN (str): Kraken exchange pair.
GEMINI (str): Gemini exchange pair.
"""
COINBASE = "ETH-USD"
KRAKEN = "ETHUSD"
GEMINI = "ETHUSD"
class OrderStatus(str, Enum):
"""
Enum representing order statuses.
Values:
FILLED (str): Order is filled.
PARTIALLY_FILLED (str): Order is partially filled.
CANCELLED (str): Order is cancelled.
PENDING (str): Order is pending.
"""
FILLED = "FILLED"
PARTIALLY_FILLED = "PARTIALLY_FILLED"
CANCELLED = "CANCELLED"
PENDING = "PENDING"
def __str__(self) -> str:
return str.__str__(self)
class Operation(str, Enum):
"""
Enum representing buy (BUY) or sell (SELL) operations.
Values:
BUY (str): Buy operation.
SELL (str): Sell operation.
"""
BUY = "BUY"
SELL = "SELL"
def __str__(self) -> str:
return str.__str__(self)
@dataclass(frozen=True)
class OrderData:
"""
Dataclass representing order data.
Attributes:
price (float): The price of the order.
amount (float): The amount of cryptocurrency in the order.
timestamp (int): The timestamp of the order.
exchange (str): The exchange where the order is placed.
Class Methods:
from_order(cls, item: Tuple) -> OrderData: Create OrderData from a
tuple.
from_order(cls, item: dict) -> OrderData: Create OrderData from a
dictionary.
from_order(cls, item: Any) -> OrderData: Create OrderData from a
generic item.
"""
__slots__ = ("price", "amount", "timestamp", "exchange")
price: float
amount: float
timestamp: int
exchange: str
@overload
@classmethod
def from_order(cls, item: Tuple, exchange: str) -> "OrderData":
...
@overload
@classmethod
def from_order(cls, item: dict, exchange: str) -> "OrderData":
...
@classmethod
def from_order(cls, item: Any, exchange: str) -> "OrderData":
"""
Create an OrderData instance from a generic item.
Args:
item (Any): The item representing order data, either a tuple or a
dictionary.
Returns:
OrderData: An instance of OrderData.
Raises:
TypeError: If the type of 'item' is not supported.
"""
if isinstance(item, list):
price = float(item[0])
amount = float(item[1])
timestamp = int(item[2])
elif isinstance(item, dict):
price = float(item["price"])
amount = float(item["amount"])
timestamp = int(item["timestamp"])
else:
raise TypeError(f"Unsupported type for 'item': {type(item)}")
return cls(price, amount, timestamp, exchange)