1
1
import json
2
+ from datetime import datetime
2
3
from typing import Union , List , Generator
3
4
from decimal import Decimal
4
5
from privex .helpers import empty
5
6
7
+ AnyNum = Union [Decimal , float , str ]
8
+
9
+
6
10
class ObjBase :
7
11
"""
8
12
A base class to be extended by data storage classes, allowing their attributes to be
@@ -50,6 +54,10 @@ def from_list(cls, obj_list: List[dict]):
50
54
for tx in obj_list :
51
55
yield cls (** tx )
52
56
57
+ def __repr__ (self ):
58
+ return self .__str__ ()
59
+
60
+
53
61
class TokenMetadata (ObjBase ):
54
62
"""
55
63
Represents the ``metadata`` field on a token object on SteemEngine
@@ -132,7 +140,6 @@ def __str__(self):
132
140
return f"<SETransaction symbol='{ self .symbol } ' sender='{ self .sender } ' to='{ self .to } ' quantity='{ self .quantity } '>"
133
141
134
142
135
-
136
143
class SEBalance (ObjBase ):
137
144
"""
138
145
Represents an account token balance on SteemEngine
@@ -150,4 +157,74 @@ def __str__(self):
150
157
return f"<SEBalance account='{ self .account } ' symbol='{ self .symbol } ' balance='{ self .balance } '>"
151
158
152
159
160
+ class SETrade (ObjBase ):
161
+ """
162
+ Represents a past trade on the SE market.
163
+
164
+ :ivar str symbol: The symbol this order is for
165
+ :ivar Decimal quantity: The amount of tokens being bought/sold
166
+ :ivar Decimal price: The price per token ( :py:attr:`.symbol` ) in STEEM
167
+ :ivar datetime timestamp: The date/time which the order was placed
168
+ :ivar str direction: The type of order as a string, either ``'buy'`` or ``'sell'``
169
+ :ivar str type: Alias for ``direction`` - either ``'buy'`` or ``'sell'``
170
+ """
171
+
172
+ def __init__ (self , symbol : str , quantity : AnyNum , price : AnyNum , timestamp : int , volume : AnyNum ,
173
+ direction : str = None , ** kwargs ):
174
+
175
+ direction = kwargs .get ('type' ) if not direction else direction
176
+ self .raw_data = {
177
+ ** kwargs ,
178
+ ** dict (symbol = symbol , quantity = quantity , price = price , timestamp = timestamp ,
179
+ volume = volume , direction = direction )
180
+ }
181
+ self .volume = Decimal (volume )
182
+ self .price = Decimal (price )
183
+ self .quantity = Decimal (quantity )
184
+ self .timestamp = datetime .utcfromtimestamp (int (timestamp ))
185
+ self .symbol = symbol .upper ()
186
+ self .direction = self .type = direction .lower ()
187
+ if self .type not in ['buy' , 'sell' ]:
188
+ raise AttributeError ('SEOrder.type must be either buy or sell' )
189
+
190
+ def __str__ (self ):
191
+ return f"<SETrade type='{ self .type } ' price='{ self .price } ' symbol='{ self .symbol } ' quantity='{ self .quantity } '>"
192
+
193
+
194
+ class SEOrder (ObjBase ):
195
+ """
196
+ Represents an open order on the SE market.
197
+
198
+ :ivar str symbol: The symbol this order is for
199
+ :ivar Decimal quantity: The amount of tokens being bought/sold
200
+ :ivar Decimal price: The price per token ( :py:attr:`.symbol` ) in STEEM
201
+ :ivar Decimal tokens_locked: The amount of STEEM locked into the order
202
+ :ivar Decimal tokensLocked: Alias of ``tokens_locked``
203
+ :ivar datetime timestamp: The date/time which the order was placed
204
+ :ivar datetime expiration: ?????
205
+ :ivar str account: The username of the person who placed the order
206
+ :ivar str txid: The transaction ID of the order
207
+ """
208
+ def __init__ (self , symbol : str , quantity : AnyNum , price : AnyNum , timestamp : int , account : str , expiration : int ,
209
+ txid : str = None , tokens_locked : AnyNum = None , ** kwargs ):
210
+ txid = kwargs .get ('txId' ) if not txid else txid
211
+ tokens_locked = kwargs .get ('tokensLocked' ) if not tokens_locked else tokens_locked
212
+ self .raw_data = {
213
+ ** kwargs ,
214
+ ** dict (symbol = symbol , quantity = quantity , price = price , timestamp = timestamp , account = account ,
215
+ tokens_locked = tokens_locked , expiration = expiration , txid = txid )
216
+ }
217
+ self .tokens_locked = self .tokensLocked = None if not tokens_locked else Decimal (tokens_locked )
218
+ self .price = Decimal (price )
219
+ self .quantity = Decimal (quantity )
220
+ self .timestamp = datetime .utcfromtimestamp (int (timestamp ))
221
+ self .expiration = datetime .utcfromtimestamp (int (expiration ))
222
+ self .symbol = symbol .upper ()
223
+ self .account = str (account ).lower ()
224
+ self .txid = str (txid )
225
+
226
+ pass
227
+
228
+ def __str__ (self ):
229
+ return f"<SEOrder account='{ self .account } ' price='{ self .price } ' symbol='{ self .symbol } ' quantity='{ self .quantity } '>"
153
230
0 commit comments