HedgeTech 0.2.0b1__py3-none-any.whl → 0.2.2b0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- HedgeTech/Auth/__AuthAsyncClient.py +16 -12
- HedgeTech/Auth/__AuthSyncClient.py +18 -14
- HedgeTech/Auth/__utils/__RetriableAsyncClient.py +63 -0
- HedgeTech/Auth/__utils/__RetriableSyncClient.py +65 -0
- HedgeTech/Auth/__utils/__init__.py +2 -0
- HedgeTech/EmsEngine/__init__.py +1 -1
- HedgeTech/EmsEngine/__tse_ifb/__AsyncClient.py +543 -249
- HedgeTech/EmsEngine/__tse_ifb/__SyncClient.py +568 -245
- HedgeTech/EmsEngine/__tse_ifb/__init__.py +1 -1
- HedgeTech/EmsEngine/__tse_ifb/__io_types/__response.py +1 -1
- {hedgetech-0.2.0b1.dist-info → hedgetech-0.2.2b0.dist-info}/METADATA +91 -9
- hedgetech-0.2.2b0.dist-info/RECORD +24 -0
- {hedgetech-0.2.0b1.dist-info → hedgetech-0.2.2b0.dist-info}/WHEEL +1 -1
- hedgetech-0.2.0b1.dist-info/RECORD +0 -21
- {hedgetech-0.2.0b1.dist-info → hedgetech-0.2.2b0.dist-info}/licenses/LICENSE +0 -0
- {hedgetech-0.2.0b1.dist-info → hedgetech-0.2.2b0.dist-info}/licenses/NOTICE +0 -0
- {hedgetech-0.2.0b1.dist-info → hedgetech-0.2.2b0.dist-info}/top_level.txt +0 -0
|
@@ -13,17 +13,31 @@ from HedgeTech.Auth import AuthAsyncClient
|
|
|
13
13
|
from PIL.Image import open as image_open
|
|
14
14
|
from PIL.ImageFile import ImageFile
|
|
15
15
|
from io import BytesIO
|
|
16
|
+
from asyncio import sleep
|
|
16
17
|
|
|
17
18
|
# ========================================|======================================== #
|
|
18
19
|
# Class Definitions #
|
|
19
20
|
# ========================================|======================================== #
|
|
20
21
|
class Order:
|
|
21
22
|
|
|
23
|
+
"""
|
|
24
|
+
Represents a single trading order in EMS Engine.
|
|
25
|
+
|
|
26
|
+
This class provides methods to send, edit, check status,
|
|
27
|
+
and delete an order after creation.
|
|
28
|
+
|
|
29
|
+
An Order instance is usually created via
|
|
30
|
+
`EmsEngine_TseIfb_AsyncClient` methods.
|
|
31
|
+
"""
|
|
32
|
+
|
|
22
33
|
def __init__(
|
|
23
34
|
self,
|
|
24
35
|
*,
|
|
25
|
-
|
|
36
|
+
SendOrder_RequestInfo : dict,
|
|
26
37
|
AuthASyncClient : AuthAsyncClient,
|
|
38
|
+
SymbolNameOrIsin : str,
|
|
39
|
+
Price : int,
|
|
40
|
+
Volume :int,
|
|
27
41
|
Order_ValidityType : Literal[
|
|
28
42
|
'DAY',
|
|
29
43
|
'GTC', # Good Till Cancelled
|
|
@@ -32,26 +46,99 @@ class Order:
|
|
|
32
46
|
'FOK', # Fill Or Kill
|
|
33
47
|
] = 'DAY',
|
|
34
48
|
ValidityDate : int = 0,
|
|
35
|
-
SymbolNameOrIsin : str,
|
|
36
|
-
Price : int,
|
|
37
|
-
Volume :int,
|
|
38
49
|
):
|
|
50
|
+
|
|
51
|
+
"""
|
|
52
|
+
Represents a stock order in the EMS Engine for TSE IFB.
|
|
53
|
+
|
|
54
|
+
This class allows sending, editing, deleting, and checking the status
|
|
55
|
+
of a stock order using an asynchronous client.
|
|
56
|
+
|
|
57
|
+
Attributes
|
|
58
|
+
----------
|
|
59
|
+
ValidityType : str
|
|
60
|
+
Type of order validity ('DAY', 'GTC', 'GTD', 'FAK', 'FOK').
|
|
61
|
+
ValidityDate : int
|
|
62
|
+
Expiration date of the order (for 'GTD' type).
|
|
63
|
+
SymbolNameOrIsin : str
|
|
64
|
+
Symbol name or ISIN code of the security.
|
|
65
|
+
Price : int
|
|
66
|
+
Order price.
|
|
67
|
+
Volume : int
|
|
68
|
+
Order volume.
|
|
69
|
+
is_deleted : bool
|
|
70
|
+
True if the order has been deleted.
|
|
71
|
+
OrderId : HexUUID | None
|
|
72
|
+
Unique identifier of the order after submission.
|
|
73
|
+
|
|
74
|
+
Methods
|
|
75
|
+
-------
|
|
76
|
+
send()
|
|
77
|
+
Sends the order asynchronously to the EMS engine.
|
|
78
|
+
Edit(Order_ValidityType, ValidityDate, Price, Volume)
|
|
79
|
+
Edits the existing order asynchronously.
|
|
80
|
+
Status()
|
|
81
|
+
Retrieves the current status of the order asynchronously.
|
|
82
|
+
Delete()
|
|
83
|
+
Deletes the order asynchronously.
|
|
84
|
+
"""
|
|
85
|
+
|
|
39
86
|
|
|
40
87
|
self.__AuthASyncClient = AuthASyncClient
|
|
41
|
-
self.
|
|
88
|
+
self.__SendOrder_RequestInfo = SendOrder_RequestInfo
|
|
89
|
+
|
|
42
90
|
self.ValidityType : str = Order_ValidityType
|
|
43
91
|
self.ValidityDate : int = ValidityDate
|
|
44
92
|
self.SymbolNameOrIsin : str = SymbolNameOrIsin
|
|
45
93
|
self.Price : int = Price
|
|
46
94
|
self.Volume : int = Volume
|
|
47
95
|
self.is_deleted : bool = False
|
|
48
|
-
|
|
96
|
+
|
|
97
|
+
self.OrderId : HexUUID | None = None
|
|
49
98
|
|
|
50
99
|
# +--------------------------------------------------------------------------------------+ #
|
|
51
100
|
|
|
101
|
+
async def send(self)-> None:
|
|
102
|
+
|
|
103
|
+
"""
|
|
104
|
+
Sends the order to the EMS engine asynchronously.
|
|
105
|
+
|
|
106
|
+
If the order has not been sent before, it posts the request
|
|
107
|
+
using the provided AuthAsyncClient.
|
|
108
|
+
|
|
109
|
+
Returns
|
|
110
|
+
-------
|
|
111
|
+
None
|
|
112
|
+
|
|
113
|
+
Example
|
|
114
|
+
-------
|
|
115
|
+
>>> order = await client.Buy_by_Name(symbolName="اطلس", Price=100000, Volume=10)
|
|
116
|
+
>>> await order.send()
|
|
117
|
+
>>> print(order.OrderId)
|
|
118
|
+
'953097ac6ced45ca8ef205b76ca6faf2'
|
|
119
|
+
"""
|
|
120
|
+
|
|
121
|
+
if self.OrderId is None :
|
|
122
|
+
|
|
123
|
+
SendOrder_Response = await self.__AuthASyncClient.httpx_Client.post(**self.__SendOrder_RequestInfo)
|
|
124
|
+
|
|
125
|
+
match SendOrder_Response.status_code :
|
|
126
|
+
|
|
127
|
+
case 200 :
|
|
128
|
+
|
|
129
|
+
self.OrderId = SendOrder_Response.json()['Data']['order_uuid']
|
|
130
|
+
return None
|
|
131
|
+
|
|
132
|
+
case _ : return None
|
|
133
|
+
|
|
134
|
+
else : return None
|
|
135
|
+
|
|
136
|
+
# +--------------------------------------------------------------------------------------+ #
|
|
52
137
|
async def Edit(
|
|
53
138
|
self,
|
|
54
139
|
*,
|
|
140
|
+
Price : int,
|
|
141
|
+
Volume :int,
|
|
55
142
|
Order_ValidityType : Literal[
|
|
56
143
|
'DAY',
|
|
57
144
|
'GTC', # Good Till Cancelled
|
|
@@ -60,121 +147,214 @@ class Order:
|
|
|
60
147
|
'FOK', # Fill Or Kill
|
|
61
148
|
] = 'DAY',
|
|
62
149
|
ValidityDate : int = 0,
|
|
63
|
-
Price : int,
|
|
64
|
-
Volume :int,
|
|
65
150
|
)-> None:
|
|
66
151
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
152
|
+
"""
|
|
153
|
+
Edits an existing order asynchronously.
|
|
154
|
+
|
|
155
|
+
Parameters
|
|
156
|
+
----------
|
|
157
|
+
Order_ValidityType : str
|
|
158
|
+
The new order validity type.
|
|
159
|
+
ValidityDate : int
|
|
160
|
+
New expiration date if validity type is 'GTD'.
|
|
161
|
+
Price : int
|
|
162
|
+
New order price.
|
|
163
|
+
Volume : int
|
|
164
|
+
New order volume.
|
|
165
|
+
|
|
166
|
+
Returns
|
|
167
|
+
-------
|
|
168
|
+
None
|
|
169
|
+
|
|
170
|
+
Example
|
|
171
|
+
-------
|
|
172
|
+
>>> await order.Edit(Price=105, Volume=15)
|
|
173
|
+
"""
|
|
174
|
+
|
|
175
|
+
if self.OrderId is not None:
|
|
176
|
+
|
|
177
|
+
Edit_response = await self.__AuthASyncClient.httpx_Client.patch(
|
|
178
|
+
url='https://core.hedgetech.ir/ems-engine/tse-ifb/order/edit',
|
|
179
|
+
data={
|
|
180
|
+
'order_uuid' : self.OrderId,
|
|
181
|
+
'Order_ValidityType' : Order_ValidityType,
|
|
182
|
+
'ValidityDate' : ValidityDate,
|
|
183
|
+
'Price' : Price,
|
|
184
|
+
'Volume' : Volume
|
|
185
|
+
}
|
|
186
|
+
)
|
|
80
187
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
188
|
+
|
|
189
|
+
match Edit_response.status_code:
|
|
190
|
+
|
|
191
|
+
case 200:
|
|
192
|
+
|
|
193
|
+
Edit_response = Edit_response.json()
|
|
194
|
+
|
|
195
|
+
self.OrderId = Edit_response['Data']['order_uuid']
|
|
196
|
+
self.ValidityType = Edit_response['Data']['order_validity_type']
|
|
197
|
+
self.ValidityDate = ValidityDate
|
|
198
|
+
self.Price = Edit_response['Data']['order_price']
|
|
199
|
+
self.Volume = Edit_response['Data']['order_volume']
|
|
200
|
+
|
|
201
|
+
return None
|
|
202
|
+
|
|
203
|
+
case _ : return None
|
|
204
|
+
|
|
205
|
+
else : return None
|
|
98
206
|
|
|
99
207
|
# +--------------------------------------------------------------------------------------+ #
|
|
100
|
-
|
|
101
|
-
async def Status(self)-> OrderStatus:
|
|
102
|
-
|
|
103
|
-
status_respnse = await self.__AuthASyncClient.httpx_Client.get(
|
|
104
|
-
url='https://core.hedgetech.ir/ems-engine/tse-ifb/order/status',
|
|
105
|
-
params={'order_uuid' : self.__order_uuid}
|
|
106
|
-
)
|
|
208
|
+
|
|
209
|
+
async def Status(self)-> OrderStatus | None:
|
|
107
210
|
|
|
108
|
-
|
|
211
|
+
"""
|
|
212
|
+
Retrieves the current status of the order asynchronously.
|
|
213
|
+
|
|
214
|
+
Returns
|
|
215
|
+
-------
|
|
216
|
+
OrderStatus | None
|
|
217
|
+
A dictionary containing the current order status with the following keys:
|
|
218
|
+
- order_uuid: HexUUID, unique identifier of the order.
|
|
219
|
+
- order_status: 'InQueue' | 'Cancelled' | 'Broken' | 'Settled'
|
|
220
|
+
- Price: int, the order price.
|
|
221
|
+
- Volume: int, the original order volume.
|
|
222
|
+
- RemainedVolume: int, volume remaining unexecuted.
|
|
223
|
+
- ExecutedVolume: int, executed volume.
|
|
224
|
+
- OrderSide: 'Buy' | 'Sell', the order side.
|
|
225
|
+
- ValidityType: 'DAY' | 'GTC' | 'GTD', the type of order validity.
|
|
226
|
+
- ValidityDate: int, expiration date if applicable.
|
|
227
|
+
|
|
228
|
+
Example
|
|
229
|
+
-------
|
|
230
|
+
>>> status = await order.Status()
|
|
231
|
+
>>> print(status)
|
|
232
|
+
{
|
|
233
|
+
'order_uuid': '953097ac6ced45ca8ef205b76ca6faf2',
|
|
234
|
+
'order_status': 'InQueue',
|
|
235
|
+
'Price': 100,
|
|
236
|
+
'Volume': 10,
|
|
237
|
+
'RemainedVolume': 10,
|
|
238
|
+
'ExecutedVolume': 0,
|
|
239
|
+
'OrderSide': 'Buy',
|
|
240
|
+
'ValidityType': 'DAY',
|
|
241
|
+
'ValidityDate': 0
|
|
242
|
+
}
|
|
243
|
+
"""
|
|
244
|
+
|
|
245
|
+
if self.OrderId is not None:
|
|
246
|
+
|
|
247
|
+
status_respnse = await self.__AuthASyncClient.httpx_Client.get(
|
|
248
|
+
url='https://core.hedgetech.ir/ems-engine/tse-ifb/order/status',
|
|
249
|
+
params={'order_uuid' : self.OrderId}
|
|
250
|
+
)
|
|
109
251
|
|
|
110
|
-
|
|
252
|
+
match status_respnse.status_code :
|
|
111
253
|
|
|
112
|
-
|
|
254
|
+
case 200:
|
|
255
|
+
|
|
256
|
+
return status_respnse.json()['Data']
|
|
257
|
+
|
|
258
|
+
case _ : return None
|
|
113
259
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
raise ValueError(status_respnse.json()['detail']['Status']['Description']['en'])
|
|
117
|
-
|
|
118
|
-
case _ :
|
|
119
|
-
|
|
120
|
-
raise ValueError(status_respnse.text)
|
|
121
|
-
|
|
122
|
-
# +--------------------------------------------------------------------------------------+ #
|
|
123
|
-
|
|
124
|
-
@property
|
|
125
|
-
async def order_is_valid(self)-> bool:
|
|
126
|
-
|
|
127
|
-
status = await self.Status
|
|
128
|
-
|
|
129
|
-
if (status['Price'] == self.Price) and (
|
|
130
|
-
status['Volume'] == self.Volume
|
|
131
|
-
) and (status['ValidityType'] == self.ValidityType) and status['OrderInQueue']:
|
|
260
|
+
else : return None
|
|
132
261
|
|
|
133
|
-
return True
|
|
134
|
-
|
|
135
|
-
else : return False
|
|
136
|
-
|
|
137
262
|
# +--------------------------------------------------------------------------------------+ #
|
|
138
263
|
|
|
139
|
-
|
|
140
|
-
async def Delete(self)-> bool :
|
|
141
|
-
|
|
142
|
-
Delete_respnse = await self.__AuthASyncClient.httpx_Client.delete(
|
|
143
|
-
url= 'https://core.hedgetech.ir/ems-engine/tse-ifb/order/delete',
|
|
144
|
-
params={'order_uuid' : self.__order_uuid}
|
|
145
|
-
)
|
|
264
|
+
async def Delete(self)-> None:
|
|
146
265
|
|
|
266
|
+
"""
|
|
267
|
+
Deletes the order asynchronously.
|
|
268
|
+
|
|
269
|
+
Sets `is_deleted` to True if successful.
|
|
147
270
|
|
|
148
|
-
|
|
271
|
+
Returns
|
|
272
|
+
-------
|
|
273
|
+
None
|
|
274
|
+
|
|
275
|
+
Example
|
|
276
|
+
-------
|
|
277
|
+
>>> await order.Delete()
|
|
278
|
+
>>> print(order.is_deleted)
|
|
279
|
+
True
|
|
280
|
+
"""
|
|
281
|
+
|
|
282
|
+
if self.OrderId is not None:
|
|
283
|
+
|
|
284
|
+
Delete_respnse = await self.__AuthASyncClient.httpx_Client.delete(
|
|
285
|
+
url= 'https://core.hedgetech.ir/ems-engine/tse-ifb/order/delete',
|
|
286
|
+
params={'order_uuid' : self.OrderId}
|
|
287
|
+
)
|
|
149
288
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
raise ValueError(Delete_respnse.text)
|
|
289
|
+
|
|
290
|
+
match Delete_respnse.status_code :
|
|
291
|
+
|
|
292
|
+
case 200:
|
|
293
|
+
|
|
294
|
+
self.is_deleted = True
|
|
295
|
+
return None
|
|
296
|
+
|
|
297
|
+
case _ : return None
|
|
161
298
|
|
|
299
|
+
else : return None
|
|
162
300
|
|
|
163
301
|
# ================================================================================= #
|
|
164
302
|
|
|
165
|
-
class
|
|
303
|
+
class EmsEngine_TseIfb_AsyncClient:
|
|
304
|
+
|
|
305
|
+
"""
|
|
306
|
+
Asynchronous EMS Engine client for TSE/IFB markets.
|
|
307
|
+
|
|
308
|
+
This client manages authentication, OMS login,
|
|
309
|
+
and order creation.
|
|
310
|
+
"""
|
|
166
311
|
|
|
167
312
|
def __init__(
|
|
168
313
|
self,
|
|
169
314
|
AuthASyncClient : AuthAsyncClient,
|
|
170
315
|
):
|
|
171
|
-
|
|
316
|
+
|
|
317
|
+
"""
|
|
318
|
+
Asynchronous client for interacting with the EMS Engine (TSE IFB).
|
|
319
|
+
|
|
320
|
+
Provides methods for logging in, retrieving CAPTCHA, and creating buy/sell orders
|
|
321
|
+
by symbol name or ISIN.
|
|
322
|
+
|
|
323
|
+
Attributes
|
|
324
|
+
----------
|
|
325
|
+
Customer_FullName : str | None
|
|
326
|
+
Full name of the logged-in customer.
|
|
327
|
+
Customer_TSEBourseCode : str | None
|
|
328
|
+
TSE bourse code of the customer.
|
|
329
|
+
oms_session : HexUUID | None
|
|
330
|
+
Session token obtained after login.
|
|
331
|
+
|
|
332
|
+
Methods
|
|
333
|
+
-------
|
|
334
|
+
Get_Captcha(OMS)
|
|
335
|
+
Retrieves the login CAPTCHA image asynchronously.
|
|
336
|
+
|
|
337
|
+
oms_login(username, password, captcha_value)
|
|
338
|
+
Logs into the OMS asynchronously.
|
|
339
|
+
|
|
340
|
+
Buy_by_Name(Order_ValidityType, ValidityDate, symbolName, Price, Volume)
|
|
341
|
+
Creates a new buy order by symbol name asynchronously.
|
|
342
|
+
|
|
343
|
+
Sell_by_Name(Order_ValidityType, ValidityDate, symbolName, Price, Volume)
|
|
344
|
+
Creates a new sell order by symbol name asynchronously.
|
|
345
|
+
|
|
346
|
+
Buy_by_isin(Order_ValidityType, ValidityDate, symbolIsin, Price, Volume)
|
|
347
|
+
Creates a new buy order by ISIN asynchronously.
|
|
348
|
+
|
|
349
|
+
Sell_by_isin(Order_ValidityType, ValidityDate, symbolIsin, Price, Volume)
|
|
350
|
+
Creates a new sell order by ISIN asynchronously.
|
|
351
|
+
"""
|
|
172
352
|
|
|
173
353
|
self.__AuthASyncClient = AuthASyncClient
|
|
174
354
|
|
|
175
355
|
self.Customer_FullName : str | None = None
|
|
176
356
|
self.Customer_TSEBourseCode : str | None = None
|
|
177
|
-
self.oms_session :
|
|
357
|
+
self.oms_session : HexUUID | None = None
|
|
178
358
|
|
|
179
359
|
# +--------------------------------------------------------------------------------------+ #
|
|
180
360
|
|
|
@@ -187,6 +367,30 @@ class EmsEngine_TseIfb_ASyncClient:
|
|
|
187
367
|
]
|
|
188
368
|
)-> ImageFile:
|
|
189
369
|
|
|
370
|
+
"""
|
|
371
|
+
Retrieves the CAPTCHA image for the specified OMS asynchronously.
|
|
372
|
+
|
|
373
|
+
Parameters
|
|
374
|
+
----------
|
|
375
|
+
OMS : str
|
|
376
|
+
OMS identifier ('Omex | Parsian' or 'Sahra | Karamad').
|
|
377
|
+
|
|
378
|
+
Returns
|
|
379
|
+
-------
|
|
380
|
+
ImageFile
|
|
381
|
+
The CAPTCHA image object.
|
|
382
|
+
|
|
383
|
+
Raises
|
|
384
|
+
------
|
|
385
|
+
ValueError
|
|
386
|
+
If the request fails or returns an error.
|
|
387
|
+
|
|
388
|
+
Example
|
|
389
|
+
-------
|
|
390
|
+
>>> captcha = await client.Get_Captcha('Omex | Parsian')
|
|
391
|
+
>>> captcha.show()
|
|
392
|
+
"""
|
|
393
|
+
|
|
190
394
|
Captcha = await self.__AuthASyncClient.httpx_Client.get(
|
|
191
395
|
url='https://core.hedgetech.ir/ems-engine/tse-ifb/oms/login',
|
|
192
396
|
params={'oms' : OMS }
|
|
@@ -205,6 +409,34 @@ class EmsEngine_TseIfb_ASyncClient:
|
|
|
205
409
|
password: str,
|
|
206
410
|
captcha_value: str,
|
|
207
411
|
) -> None :
|
|
412
|
+
|
|
413
|
+
"""
|
|
414
|
+
Logs into the OMS asynchronously with provided credentials and CAPTCHA.
|
|
415
|
+
|
|
416
|
+
Parameters
|
|
417
|
+
----------
|
|
418
|
+
username : str
|
|
419
|
+
OMS username.
|
|
420
|
+
password : str
|
|
421
|
+
OMS password.
|
|
422
|
+
captcha_value : str
|
|
423
|
+
Solved CAPTCHA value.
|
|
424
|
+
|
|
425
|
+
Returns
|
|
426
|
+
-------
|
|
427
|
+
None
|
|
428
|
+
|
|
429
|
+
Raises
|
|
430
|
+
------
|
|
431
|
+
ValueError
|
|
432
|
+
If login fails or CAPTCHA is invalid.
|
|
433
|
+
|
|
434
|
+
Example
|
|
435
|
+
-------
|
|
436
|
+
>>> await client.oms_login("user123", "pass123", "abcd")
|
|
437
|
+
>>> print(client.oms_session)
|
|
438
|
+
'session_token_here'
|
|
439
|
+
"""
|
|
208
440
|
|
|
209
441
|
response = await self.__AuthASyncClient.httpx_Client.post(
|
|
210
442
|
url='https://core.hedgetech.ir/ems-engine/tse-ifb/oms/login',
|
|
@@ -241,6 +473,9 @@ class EmsEngine_TseIfb_ASyncClient:
|
|
|
241
473
|
async def Buy_by_Name(
|
|
242
474
|
self,
|
|
243
475
|
*,
|
|
476
|
+
symbolName : str,
|
|
477
|
+
Price : int,
|
|
478
|
+
Volume :int,
|
|
244
479
|
Order_ValidityType : Literal[
|
|
245
480
|
'DAY',
|
|
246
481
|
'GTC', # Good Till Cancelled
|
|
@@ -249,55 +484,70 @@ class EmsEngine_TseIfb_ASyncClient:
|
|
|
249
484
|
'FOK', # Fill Or Kill
|
|
250
485
|
] = 'DAY',
|
|
251
486
|
ValidityDate : int = 0,
|
|
252
|
-
|
|
253
|
-
Price : int,
|
|
254
|
-
Volume :int,
|
|
255
|
-
)-> Order:
|
|
487
|
+
)-> Order | None:
|
|
256
488
|
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
order_uuid=order_response['Data']['order_uuid'],
|
|
278
|
-
AuthSyncClient=self.__AuthASyncClient,
|
|
279
|
-
Order_ValidityType=Order_ValidityType,
|
|
280
|
-
ValidityDate=ValidityDate,
|
|
281
|
-
SymbolNameOrIsin = symbolName,
|
|
282
|
-
Price=Price,
|
|
283
|
-
Volume=Volume
|
|
284
|
-
)
|
|
285
|
-
|
|
286
|
-
case 400:
|
|
287
|
-
|
|
288
|
-
raise ValueError(order_response.json()['detail']['Status']['Description']['en'])
|
|
289
|
-
|
|
290
|
-
case _ :
|
|
291
|
-
|
|
292
|
-
raise ValueError(order_response.text)
|
|
293
|
-
|
|
489
|
+
"""
|
|
490
|
+
Creates a new buy order by symbol name asynchronously.
|
|
491
|
+
|
|
492
|
+
Parameters
|
|
493
|
+
----------
|
|
494
|
+
Order_ValidityType : str
|
|
495
|
+
Order validity type.
|
|
496
|
+
ValidityDate : int
|
|
497
|
+
Expiration date if validity type is 'GTD'.
|
|
498
|
+
symbolName : str
|
|
499
|
+
Symbol name of the security.
|
|
500
|
+
Price : int
|
|
501
|
+
Order price.
|
|
502
|
+
Volume : int
|
|
503
|
+
Order volume.
|
|
504
|
+
|
|
505
|
+
Returns
|
|
506
|
+
-------
|
|
507
|
+
Order | None
|
|
508
|
+
A new Order instance if OMS session exists, else None.
|
|
294
509
|
|
|
510
|
+
Example
|
|
511
|
+
-------
|
|
512
|
+
>>> order = await client.Buy_by_Name(symbolName="اطلس", Price=100000, Volume=10)
|
|
513
|
+
>>> await order.send()
|
|
514
|
+
"""
|
|
515
|
+
|
|
516
|
+
await sleep(0)
|
|
517
|
+
|
|
518
|
+
if self.oms_session is not None:
|
|
519
|
+
|
|
520
|
+
return Order(
|
|
521
|
+
AuthASyncClient=self.__AuthASyncClient,
|
|
522
|
+
Order_ValidityType=Order_ValidityType,
|
|
523
|
+
ValidityDate=ValidityDate,
|
|
524
|
+
SymbolNameOrIsin = symbolName,
|
|
525
|
+
Price=Price,
|
|
526
|
+
Volume=Volume,
|
|
527
|
+
SendOrder_RequestInfo = {
|
|
528
|
+
'url' : 'https://core.hedgetech.ir/ems-engine/tse-ifb/order/new/buy/name',
|
|
529
|
+
'data' : {
|
|
530
|
+
'oms_session' : self.oms_session,
|
|
531
|
+
'Order_ValidityType' : Order_ValidityType,
|
|
532
|
+
'ValidityDate' : ValidityDate,
|
|
533
|
+
'symbolName' : symbolName,
|
|
534
|
+
'Price' : Price,
|
|
535
|
+
'Volume' : Volume
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
)
|
|
539
|
+
|
|
540
|
+
else : return None
|
|
541
|
+
|
|
295
542
|
# +--------------------------------------------------------------------------------------+ #
|
|
296
543
|
|
|
297
544
|
|
|
298
545
|
async def Sell_by_Name(
|
|
299
546
|
self,
|
|
300
547
|
*,
|
|
548
|
+
symbolName : str,
|
|
549
|
+
Price : int,
|
|
550
|
+
Volume :int,
|
|
301
551
|
Order_ValidityType : Literal[
|
|
302
552
|
'DAY',
|
|
303
553
|
'GTC', # Good Till Cancelled
|
|
@@ -306,53 +556,69 @@ class EmsEngine_TseIfb_ASyncClient:
|
|
|
306
556
|
'FOK', # Fill Or Kill
|
|
307
557
|
] = 'DAY',
|
|
308
558
|
ValidityDate : int = 0,
|
|
309
|
-
|
|
310
|
-
Price : int,
|
|
311
|
-
Volume :int,
|
|
312
|
-
)-> Order:
|
|
559
|
+
)-> Order | None:
|
|
313
560
|
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
561
|
+
"""
|
|
562
|
+
Creates a new sell order by symbol name asynchronously.
|
|
563
|
+
|
|
564
|
+
Parameters
|
|
565
|
+
----------
|
|
566
|
+
Order_ValidityType : str
|
|
567
|
+
Order validity type.
|
|
568
|
+
ValidityDate : int
|
|
569
|
+
Expiration date if validity type is 'GTD'.
|
|
570
|
+
symbolName : str
|
|
571
|
+
Symbol name of the security.
|
|
572
|
+
Price : int
|
|
573
|
+
Order price.
|
|
574
|
+
Volume : int
|
|
575
|
+
Order volume.
|
|
576
|
+
|
|
577
|
+
Returns
|
|
578
|
+
-------
|
|
579
|
+
Order | None
|
|
580
|
+
A new Order instance if OMS session exists, else None.
|
|
581
|
+
|
|
582
|
+
Example
|
|
583
|
+
-------
|
|
584
|
+
>>> order = await client.Sell_by_Name(symbolName="اطلس", Price=100000, Volume=10)
|
|
585
|
+
>>> await order.send()
|
|
586
|
+
"""
|
|
587
|
+
|
|
588
|
+
await sleep(0)
|
|
325
589
|
|
|
326
|
-
|
|
590
|
+
if self.oms_session is not None:
|
|
327
591
|
|
|
592
|
+
return Order(
|
|
593
|
+
AuthASyncClient=self.__AuthASyncClient,
|
|
594
|
+
Order_ValidityType=Order_ValidityType,
|
|
595
|
+
ValidityDate=ValidityDate,
|
|
596
|
+
SymbolNameOrIsin = symbolName,
|
|
597
|
+
Price=Price,
|
|
598
|
+
Volume=Volume,
|
|
599
|
+
SendOrder_RequestInfo = {
|
|
600
|
+
'url' : 'https://core.hedgetech.ir/ems-engine/tse-ifb/order/new/sell/name',
|
|
601
|
+
'data' : {
|
|
602
|
+
'oms_session' : self.oms_session,
|
|
603
|
+
'Order_ValidityType' : Order_ValidityType,
|
|
604
|
+
'ValidityDate' : ValidityDate,
|
|
605
|
+
'symbolName' : symbolName,
|
|
606
|
+
'Price' : Price,
|
|
607
|
+
'Volume' : Volume
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
)
|
|
328
611
|
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
order_response = order_response.json()
|
|
332
|
-
|
|
333
|
-
return Order(
|
|
334
|
-
order_uuid=order_response['Data']['order_uuid'],
|
|
335
|
-
AuthSyncClient=self.__AuthASyncClient,
|
|
336
|
-
Order_ValidityType=Order_ValidityType,
|
|
337
|
-
ValidityDate=ValidityDate,
|
|
338
|
-
SymbolNameOrIsin = symbolName,
|
|
339
|
-
Price=Price,
|
|
340
|
-
Volume=Volume
|
|
341
|
-
)
|
|
342
|
-
|
|
343
|
-
case 400:
|
|
344
|
-
|
|
345
|
-
raise ValueError(order_response.json()['detail']['Status']['Description']['en'])
|
|
346
|
-
|
|
347
|
-
case _ :
|
|
612
|
+
else : return None
|
|
348
613
|
|
|
349
|
-
raise ValueError(order_response.text)
|
|
350
|
-
|
|
351
614
|
# +--------------------------------------------------------------------------------------+ #
|
|
352
615
|
|
|
353
616
|
async def Buy_by_isin(
|
|
354
617
|
self,
|
|
355
618
|
*,
|
|
619
|
+
symbolIsin : str,
|
|
620
|
+
Price : int,
|
|
621
|
+
Volume :int,
|
|
356
622
|
Order_ValidityType : Literal[
|
|
357
623
|
'DAY',
|
|
358
624
|
'GTC', # Good Till Cancelled
|
|
@@ -361,54 +627,69 @@ class EmsEngine_TseIfb_ASyncClient:
|
|
|
361
627
|
'FOK', # Fill Or Kill
|
|
362
628
|
] = 'DAY',
|
|
363
629
|
ValidityDate : int = 0,
|
|
364
|
-
|
|
365
|
-
Price : int,
|
|
366
|
-
Volume :int,
|
|
367
|
-
)-> Order:
|
|
630
|
+
)-> Order | None:
|
|
368
631
|
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
632
|
+
"""
|
|
633
|
+
Creates a new buy order by symbol isin asynchronously.
|
|
634
|
+
|
|
635
|
+
Parameters
|
|
636
|
+
----------
|
|
637
|
+
Order_ValidityType : str
|
|
638
|
+
Order validity type.
|
|
639
|
+
ValidityDate : int
|
|
640
|
+
Expiration date if validity type is 'GTD'.
|
|
641
|
+
symbolIsin : str
|
|
642
|
+
Symbol name of the security.
|
|
643
|
+
Price : int
|
|
644
|
+
Order price.
|
|
645
|
+
Volume : int
|
|
646
|
+
Order volume.
|
|
647
|
+
|
|
648
|
+
Returns
|
|
649
|
+
-------
|
|
650
|
+
Order | None
|
|
651
|
+
A new Order instance if OMS session exists, else None.
|
|
652
|
+
|
|
653
|
+
Example
|
|
654
|
+
-------
|
|
655
|
+
>>> order = await client.Buy_by_isin(symbolIsin="اطلس", Price=100000, Volume=10)
|
|
656
|
+
>>> await order.send()
|
|
657
|
+
"""
|
|
380
658
|
|
|
381
|
-
|
|
382
|
-
|
|
659
|
+
await sleep(0)
|
|
660
|
+
|
|
661
|
+
if self.oms_session is not None:
|
|
383
662
|
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
663
|
+
return Order(
|
|
664
|
+
AuthASyncClient=self.__AuthASyncClient,
|
|
665
|
+
Order_ValidityType=Order_ValidityType,
|
|
666
|
+
ValidityDate=ValidityDate,
|
|
667
|
+
SymbolNameOrIsin = symbolIsin,
|
|
668
|
+
Price=Price,
|
|
669
|
+
Volume=Volume,
|
|
670
|
+
SendOrder_RequestInfo = {
|
|
671
|
+
'url' : 'https://core.hedgetech.ir/ems-engine/tse-ifb/order/new/buy/isin',
|
|
672
|
+
'data' : {
|
|
673
|
+
'oms_session' : self.oms_session,
|
|
674
|
+
'Order_ValidityType' : Order_ValidityType,
|
|
675
|
+
'ValidityDate' : ValidityDate,
|
|
676
|
+
'symbolIsin' : symbolIsin,
|
|
677
|
+
'Price' : Price,
|
|
678
|
+
'Volume' : Volume
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
)
|
|
682
|
+
|
|
683
|
+
else : return None
|
|
406
684
|
|
|
407
685
|
# +--------------------------------------------------------------------------------------+ #
|
|
408
686
|
|
|
409
687
|
async def Sell_by_isin(
|
|
410
688
|
self,
|
|
411
689
|
*,
|
|
690
|
+
symbolIsin : str,
|
|
691
|
+
Price : int,
|
|
692
|
+
Volume :int,
|
|
412
693
|
Order_ValidityType : Literal[
|
|
413
694
|
'DAY',
|
|
414
695
|
'GTC', # Good Till Cancelled
|
|
@@ -417,47 +698,60 @@ class EmsEngine_TseIfb_ASyncClient:
|
|
|
417
698
|
'FOK', # Fill Or Kill
|
|
418
699
|
] = 'DAY',
|
|
419
700
|
ValidityDate : int = 0,
|
|
420
|
-
|
|
421
|
-
Price : int,
|
|
422
|
-
Volume :int,
|
|
423
|
-
)-> Order:
|
|
701
|
+
)-> Order | None:
|
|
424
702
|
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
703
|
+
"""
|
|
704
|
+
Creates a new sell order by symbol isin asynchronously.
|
|
705
|
+
|
|
706
|
+
Parameters
|
|
707
|
+
----------
|
|
708
|
+
Order_ValidityType : str
|
|
709
|
+
Order validity type.
|
|
710
|
+
ValidityDate : int
|
|
711
|
+
Expiration date if validity type is 'GTD'.
|
|
712
|
+
symbolIsin : str
|
|
713
|
+
Symbol name of the security.
|
|
714
|
+
Price : int
|
|
715
|
+
Order price.
|
|
716
|
+
Volume : int
|
|
717
|
+
Order volume.
|
|
718
|
+
|
|
719
|
+
Returns
|
|
720
|
+
-------
|
|
721
|
+
Order | None
|
|
722
|
+
A new Order instance if OMS session exists, else None.
|
|
723
|
+
|
|
724
|
+
Example
|
|
725
|
+
-------
|
|
726
|
+
>>> order = await client.Sell_by_isin(symbolIsin="اطلس", Price=100000, Volume=10)
|
|
727
|
+
>>> await order.send()
|
|
728
|
+
"""
|
|
729
|
+
|
|
730
|
+
await sleep(0)
|
|
731
|
+
|
|
732
|
+
if self.oms_session is not None:
|
|
733
|
+
|
|
734
|
+
return Order(
|
|
735
|
+
AuthASyncClient=self.__AuthASyncClient,
|
|
736
|
+
Order_ValidityType=Order_ValidityType,
|
|
737
|
+
ValidityDate=ValidityDate,
|
|
738
|
+
SymbolNameOrIsin = symbolIsin,
|
|
739
|
+
Price=Price,
|
|
740
|
+
Volume=Volume,
|
|
741
|
+
SendOrder_RequestInfo = {
|
|
742
|
+
'url' : 'https://core.hedgetech.ir/ems-engine/tse-ifb/order/new/sell/isin',
|
|
743
|
+
'data' : {
|
|
744
|
+
'oms_session' : self.oms_session,
|
|
745
|
+
'Order_ValidityType' : Order_ValidityType,
|
|
746
|
+
'ValidityDate' : ValidityDate,
|
|
747
|
+
'symbolIsin' : symbolIsin,
|
|
748
|
+
'Price' : Price,
|
|
749
|
+
'Volume' : Volume
|
|
750
|
+
}
|
|
751
|
+
}
|
|
752
|
+
)
|
|
753
|
+
|
|
754
|
+
else : return None
|
|
461
755
|
|
|
462
756
|
# +--------------------------------------------------------------------------------------+ #
|
|
463
757
|
|