20 Commits
Author SHA1 Message Date
mtrshirazi21 52367d54e1 unify sync and async order management logic 2026-07-22 01:00:37 +03:30
mtrshirazi21 c8090ba334 update pyproject.toml 2026-07-22 00:09:06 +03:30
mtrshirazi21 854bee9f9e improve order edit recovery using status verification 2026-07-22 00:05:15 +03:30
mtrshirazi21 3a603db3cf add .vscode dir 2026-07-21 11:59:14 +03:30
mtrshirazi21 3906a203a6 edit version 2026-05-31 14:23:48 +03:30
mtrshirazi21 a49db4397c solve bug Generator 2026-05-31 14:23:37 +03:30
mtrshirazi21 3d947bc558 add in init files 2026-05-31 14:05:45 +03:30
mtrshirazi21 2af7dfd648 update class ime clients 2026-05-29 17:02:30 +03:30
mtrshirazi21 bde8c980ef set new beta version 2026-05-29 16:36:37 +03:30
mtrshirazi21 e63dcddbea define sync and async client in ime DE 2026-05-29 16:33:47 +03:30
mtrshirazi21 cedbd76d0e edit README and pyproject toml 2026-05-29 15:38:41 +03:30
mtrshirazi21 52be955e6e expose types 2026-05-25 19:30:05 +03:30
mtrshirazi21 ecc1070f1c defin websocket io types 2026-05-25 19:12:00 +03:30
mtrshirazi21 126eab66f7 edit io types 2026-05-25 19:11:10 +03:30
mtrshirazi21 8a5f3142ef edit io_types 2026-05-24 21:18:57 +03:30
mtrshirazi21 9cfd36a891 define io types 2026-05-24 21:18:41 +03:30
mtrshirazi21 034c9a50ea define DE IME 2026-05-24 19:27:24 +03:30
mtrshirazi21 17bea4f2a3 Modifications to the terms and conditions related to Internet force majeure during times of war. 2026-05-17 21:44:05 +03:30
mtrshirazi21 747b257432 update version 2026-02-17 17:46:56 +03:30
mtrshirazi21 e6bd5852c2 Refactor order class functions in sync and async versions for improved error handling 2026-02-17 17:46:15 +03:30
12 changed files with 2359 additions and 190 deletions

No files matched your search

+3 -1
View File
@@ -208,4 +208,6 @@ __marimo__/
*.env*
*.ipynb
requirements.txt
*test*.py
*test*.py
.vscode
+349
View File
@@ -0,0 +1,349 @@
# ========================================|======================================== #
# Imports #
# ========================================|======================================== #
from asyncio import (
Event,
wait_for,
TimeoutError,
sleep,
)
from websockets.asyncio.client import connect
from json import loads
from HedgeTech.Auth import AuthAsyncClient
from typing import (
Literal,
List,
AsyncGenerator,
)
from .__io_types import (
WebsocketBase_contractName,
WebsocketBase_contractId,
OverviewResponse,
Contracts,
ContractInfoResponse,
AllowedPriceRangeResponse,
AggregateResponse,
BestLimitResponse,
)
# ========================================|======================================== #
# Class Definitions #
# ========================================|======================================== #
class DataEngine_Ime_AsyncClient:
def __init__(
self,
AuthAsyncClient : AuthAsyncClient,
):
self.__AuthAsyncClient = AuthAsyncClient
# +--------------------------------------------------------------------------------------+ #
async def search_contracts(
self,
market : Literal[
"IMEDepositCertificate",
"IMEFutures",
"IMEOption",
],
Search_char : str,
)-> Contracts :
data = await self.__AuthAsyncClient.httpx_Client.get(
url='https://core.hedgetech.ir/data-engine/ime/static/data/contract/search',
params={
'market' : market,
'Search_char' : Search_char
}
)
if data.is_success :
return data.json()
else :
raise ValueError(data.json().get('detail'))
# +--------------------------------------------------------------------------------------+ #
async def contracts_static_info_by_name(self,contract_names : List[str])-> Contracts:
data = await self.__AuthAsyncClient.httpx_Client.get(
url='https://core.hedgetech.ir/data-engine/ime/static/data/contract/name',
params=[('contract_names', name) for name in contract_names]
)
if data.is_success :
return data.json()
else :
raise ValueError(data.json().get('detail'))
# +--------------------------------------------------------------------------------------+ #
async def contracts_static_info_by_id(self,contract_ids : List[str | int])-> Contracts:
data = await self.__AuthAsyncClient.httpx_Client.get(
url='https://core.hedgetech.ir/data-engine/ime/static/data/contract/id',
params=[('contract_ids', id) for id in contract_ids]
)
if data.is_success :
return data.json()
else :
raise ValueError(data.json().get('detail'))
# +--------------------------------------------------------------------------------------+ #
async def live_overview_by_name(self,contract_names : List[str])-> OverviewResponse:
data = await self.__AuthAsyncClient.httpx_Client.get(
url='https://core.hedgetech.ir/data-engine/ime/live/data/overview/contract/name',
params=[('contract_names', name) for name in contract_names]
)
if data.is_success :
return data.json()
else :
raise ValueError(data.json().get('detail'))
# +--------------------------------------------------------------------------------------+ #
async def live_overview_by_id(self,contract_ids : List[str | int])-> OverviewResponse:
data = await self.__AuthAsyncClient.httpx_Client.get(
url='https://core.hedgetech.ir/data-engine/ime/live/data/overview/contract/id',
params=[('contract_ids', id) for id in contract_ids]
)
if data.is_success :
return data.json()
else :
raise ValueError(data.json().get('detail'))
# +--------------------------------------------------------------------------------------+ #
async def live_best_limit_by_name(self,contract_names : List[str])-> BestLimitResponse:
data = await self.__AuthAsyncClient.httpx_Client.get(
url='https://core.hedgetech.ir/data-engine/ime/live/data/best-limit/contract/name',
params=[('contract_names', name) for name in contract_names]
)
if data.is_success :
return data.json()
else :
raise ValueError(data.json().get('detail'))
# +--------------------------------------------------------------------------------------+ #
async def live_best_limit_by_id(self,contract_ids : List[str | int])-> BestLimitResponse:
data = await self.__AuthAsyncClient.httpx_Client.get(
url='https://core.hedgetech.ir/data-engine/ime/live/data/best-limit/contract/id',
params=[('contract_ids', id) for id in contract_ids]
)
if data.is_success :
return data.json()
else :
raise ValueError(data.json().get('detail'))
# +--------------------------------------------------------------------------------------+ #
async def live_aggregate_by_name(self,contract_names : List[str])-> AggregateResponse:
data = await self.__AuthAsyncClient.httpx_Client.get(
url='https://core.hedgetech.ir/data-engine/ime/live/data/aggregate/contract/name',
params=[('contract_names', name) for name in contract_names]
)
if data.is_success :
return data.json()
else :
raise ValueError(data.json().get('detail'))
# +--------------------------------------------------------------------------------------+ #
async def live_aggregate_by_id(self,contract_ids : List[str | int])-> AggregateResponse :
data = await self.__AuthAsyncClient.httpx_Client.get(
url='https://core.hedgetech.ir/data-engine/ime/live/data/aggregate/contract/id',
params=[('contract_ids', id) for id in contract_ids]
)
if data.is_success :
return data.json()
else :
raise ValueError(data.json().get('detail'))
# +--------------------------------------------------------------------------------------+ #
async def live_contract_info_by_name(self,contract_names : List[str])-> ContractInfoResponse:
data = await self.__AuthAsyncClient.httpx_Client.get(
url='https://core.hedgetech.ir/data-engine/ime/live/data/contract-info/contract/name',
params=[('contract_names', name) for name in contract_names]
)
if data.is_success :
return data.json()
else :
raise ValueError(data.json().get('detail'))
# +--------------------------------------------------------------------------------------+ #
async def live_contract_info_by_id(self,contract_ids : List[str | int])-> ContractInfoResponse :
data = await self.__AuthAsyncClient.httpx_Client.get(
url='https://core.hedgetech.ir/data-engine/ime/live/data/contract-info/contract/id',
params=[('contract_ids', id) for id in contract_ids]
)
if data.is_success :
return data.json()
else :
raise ValueError(data.json().get('detail'))
# +--------------------------------------------------------------------------------------+ #
async def live_allowed_price_range_by_name(self,contract_names : List[str])-> AllowedPriceRangeResponse:
data = await self.__AuthAsyncClient.httpx_Client.get(
url='https://core.hedgetech.ir/data-engine/ime/live/data/allowed-price-range/contract/name',
params=[('contract_names', name) for name in contract_names]
)
if data.is_success :
return data.json()
else :
raise ValueError(data.json().get('detail'))
# +--------------------------------------------------------------------------------------+ #
async def live_allowed_price_range_by_id(self,contract_ids : List[str | int])-> AllowedPriceRangeResponse :
data = await self.__AuthAsyncClient.httpx_Client.get(
url='https://core.hedgetech.ir/data-engine/ime/live/data/allowed-price-range/contract/id',
params=[('contract_ids', id) for id in contract_ids]
)
if data.is_success :
return data.json()
else :
raise ValueError(data.json().get('detail'))
# +--------------------------------------------------------------------------------------+ #
async def websocket_by_name(
self,
contract_names: List[str],
event: Event | None = None,
)-> AsyncGenerator[
WebsocketBase_contractName,
None
]:
if not isinstance(event,Event):
event = Event()
event.set()
async with connect(
uri=(
f"wss://core.hedgetech.ir/data-engine/ime/live/data/websocket/contract/name?"
+ "&".join(f"contract_name={s}" for s in contract_names)
),
additional_headers=self.__AuthAsyncClient.token
) as ws:
while event.is_set():
try : yield loads(await wait_for(ws.recv(), timeout=2))
except TimeoutError:
await sleep(0)
continue
except Exception:
await ws.close()
break
# +--------------------------------------------------------------------------------------+ #
async def websocket_by_id(
self,
contract_ids: List[str | int],
event: Event | None = None,
)-> AsyncGenerator[
WebsocketBase_contractId,
None
]:
if not isinstance(event,Event):
event = Event()
event.set()
async with connect(
uri=(
f"wss://core.hedgetech.ir/data-engine/ime/live/data/websocket/contract/id?"
+ "&".join(f"contract_id={s}" for s in contract_ids)
),
additional_headers=self.__AuthAsyncClient.token
) as ws:
while event.is_set():
try : yield loads(await wait_for(ws.recv(), timeout=2))
except TimeoutError:
await sleep(0)
continue
except Exception:
await ws.close()
break
+339
View File
@@ -0,0 +1,339 @@
# ========================================|======================================== #
# Imports #
# ========================================|======================================== #
from threading import Event
from websockets.sync.client import connect
from json import loads
from HedgeTech.Auth import AuthSyncClient
from typing import (
Literal,
List,
Generator,
)
from .__io_types import (
WebsocketBase_contractName,
WebsocketBase_contractId,
OverviewResponse,
Contracts,
ContractInfoResponse,
AllowedPriceRangeResponse,
AggregateResponse,
BestLimitResponse,
)
# ========================================|======================================== #
# Class Definitions #
# ========================================|======================================== #
class DataEngine_Ime_SyncClient:
def __init__(
self,
AuthSyncClient : AuthSyncClient,
):
self.__AuthSyncClient = AuthSyncClient
# +--------------------------------------------------------------------------------------+ #
def search_contracts(
self,
market : Literal[
"IMEDepositCertificate",
"IMEFutures",
"IMEOption",
],
Search_char : str,
)-> Contracts :
data = self.__AuthSyncClient.httpx_Client.get(
url='https://core.hedgetech.ir/data-engine/ime/static/data/contract/search',
params={
'market' : market,
'Search_char' : Search_char
}
)
if data.is_success :
return data.json()
else :
raise ValueError(data.json().get('detail'))
# +--------------------------------------------------------------------------------------+ #
def contracts_static_info_by_name(self,contract_names : List[str])-> Contracts:
data = self.__AuthSyncClient.httpx_Client.get(
url='https://core.hedgetech.ir/data-engine/ime/static/data/contract/name',
params=[('contract_names', name) for name in contract_names]
)
if data.is_success :
return data.json()
else :
raise ValueError(data.json().get('detail'))
# +--------------------------------------------------------------------------------------+ #
def contracts_static_info_by_id(self,contract_ids : List[str | int])-> Contracts:
data = self.__AuthSyncClient.httpx_Client.get(
url='https://core.hedgetech.ir/data-engine/ime/static/data/contract/id',
params=[('contract_ids', id) for id in contract_ids]
)
if data.is_success :
return data.json()
else :
raise ValueError(data.json().get('detail'))
# +--------------------------------------------------------------------------------------+ #
def live_overview_by_name(self,contract_names : List[str])-> OverviewResponse:
data = self.__AuthSyncClient.httpx_Client.get(
url='https://core.hedgetech.ir/data-engine/ime/live/data/overview/contract/name',
params=[('contract_names', name) for name in contract_names]
)
if data.is_success :
return data.json()
else :
raise ValueError(data.json().get('detail'))
# +--------------------------------------------------------------------------------------+ #
def live_overview_by_id(self,contract_ids : List[str | int])-> OverviewResponse:
data = self.__AuthSyncClient.httpx_Client.get(
url='https://core.hedgetech.ir/data-engine/ime/live/data/overview/contract/id',
params=[('contract_ids', id) for id in contract_ids]
)
if data.is_success :
return data.json()
else :
raise ValueError(data.json().get('detail'))
# +--------------------------------------------------------------------------------------+ #
def live_best_limit_by_name(self,contract_names : List[str])-> BestLimitResponse:
data = self.__AuthSyncClient.httpx_Client.get(
url='https://core.hedgetech.ir/data-engine/ime/live/data/best-limit/contract/name',
params=[('contract_names', name) for name in contract_names]
)
if data.is_success :
return data.json()
else :
raise ValueError(data.json().get('detail'))
# +--------------------------------------------------------------------------------------+ #
def live_best_limit_by_id(self,contract_ids : List[str | int])-> BestLimitResponse:
data = self.__AuthSyncClient.httpx_Client.get(
url='https://core.hedgetech.ir/data-engine/ime/live/data/best-limit/contract/id',
params=[('contract_ids', id) for id in contract_ids]
)
if data.is_success :
return data.json()
else :
raise ValueError(data.json().get('detail'))
# +--------------------------------------------------------------------------------------+ #
def live_aggregate_by_name(self,contract_names : List[str])-> AggregateResponse:
data = self.__AuthSyncClient.httpx_Client.get(
url='https://core.hedgetech.ir/data-engine/ime/live/data/aggregate/contract/name',
params=[('contract_names', name) for name in contract_names]
)
if data.is_success :
return data.json()
else :
raise ValueError(data.json().get('detail'))
# +--------------------------------------------------------------------------------------+ #
def live_aggregate_by_id(self,contract_ids : List[str | int])-> AggregateResponse :
data = self.__AuthSyncClient.httpx_Client.get(
url='https://core.hedgetech.ir/data-engine/ime/live/data/aggregate/contract/id',
params=[('contract_ids', id) for id in contract_ids]
)
if data.is_success :
return data.json()
else :
raise ValueError(data.json().get('detail'))
# +--------------------------------------------------------------------------------------+ #
def live_contract_info_by_name(self,contract_names : List[str])-> ContractInfoResponse:
data = self.__AuthSyncClient.httpx_Client.get(
url='https://core.hedgetech.ir/data-engine/ime/live/data/contract-info/contract/name',
params=[('contract_names', name) for name in contract_names]
)
if data.is_success :
return data.json()
else :
raise ValueError(data.json().get('detail'))
# +--------------------------------------------------------------------------------------+ #
def live_contract_info_by_id(self,contract_ids : List[str | int])-> ContractInfoResponse :
data = self.__AuthSyncClient.httpx_Client.get(
url='https://core.hedgetech.ir/data-engine/ime/live/data/contract-info/contract/id',
params=[('contract_ids', id) for id in contract_ids]
)
if data.is_success :
return data.json()
else :
raise ValueError(data.json().get('detail'))
# +--------------------------------------------------------------------------------------+ #
def live_allowed_price_range_by_name(self,contract_names : List[str])-> AllowedPriceRangeResponse:
data = self.__AuthSyncClient.httpx_Client.get(
url='https://core.hedgetech.ir/data-engine/ime/live/data/allowed-price-range/contract/name',
params=[('contract_names', name) for name in contract_names]
)
if data.is_success :
return data.json()
else :
raise ValueError(data.json().get('detail'))
# +--------------------------------------------------------------------------------------+ #
def live_allowed_price_range_by_id(self,contract_ids : List[str | int])-> AllowedPriceRangeResponse :
data = self.__AuthSyncClient.httpx_Client.get(
url='https://core.hedgetech.ir/data-engine/ime/live/data/allowed-price-range/contract/id',
params=[('contract_ids', id) for id in contract_ids]
)
if data.is_success :
return data.json()
else :
raise ValueError(data.json().get('detail'))
# +--------------------------------------------------------------------------------------+ #
def websocket_by_name(
self,
contract_names: List[str],
event: Event | None = None,
)-> Generator[
WebsocketBase_contractName,
None,
None
]:
if not isinstance(event,Event):
event = Event()
event.set()
with connect(
uri=(
f"wss://core.hedgetech.ir/data-engine/ime/live/data/websocket/contract/name?"
+ "&".join(f"contract_name={s}" for s in contract_names)
),
additional_headers=self.__AuthSyncClient.token
) as ws:
while event.is_set():
try : yield loads(ws.recv(timeout=2))
except TimeoutError : continue
except Exception:
ws.close()
break
# +--------------------------------------------------------------------------------------+ #
def websocket_by_id(
self,
contract_ids: List[str | int],
event: Event | None = None,
)-> Generator[
WebsocketBase_contractId,
None,
None
]:
if not isinstance(event,Event):
event = Event()
event.set()
with connect(
uri=(
f"wss://core.hedgetech.ir/data-engine/ime/live/data/websocket/contract/id?"
+ "&".join(f"contract_id={s}" for s in contract_ids)
),
additional_headers=self.__AuthSyncClient.token
) as ws:
while event.is_set():
try : yield loads(ws.recv(timeout=2))
except TimeoutError : continue
except Exception:
ws.close()
break
+2
View File
@@ -0,0 +1,2 @@
from .__AsyncClient import DataEngine_Ime_AsyncClient
from .__SyncClient import DataEngine_Ime_SyncClient
@@ -0,0 +1,12 @@
from .__response import(
WebsocketBase_contractName,
WebsocketBase_contractId,
OverviewResponse,
Contracts,
ContractInfoResponse,
AllowedPriceRangeResponse,
AggregateResponse,
BestLimitResponse,
)
File diff suppressed because it is too large. Load diff
+4
View File
@@ -1,4 +1,8 @@
from .__tse_ifb import (
DataEngine_TseIfb_SyncClient,
DataEngine_TseIfb_AsyncClient
)
from .__ime import (
DataEngine_Ime_SyncClient,
DataEngine_Ime_AsyncClient
)
@@ -9,6 +9,7 @@ from typing import (
Dict,
Optional,
TypedDict,
Literal,
)
# ========================================|======================================== #
@@ -37,7 +38,15 @@ class WebsocketBase_symbolIsin(TypedDict):
>>> message["symbolIsin"]
'IR0001234567'
"""
channel: str
channel: Literal[
"best-limit",
"order-book",
"ohlcv-last-1m",
"aggregate",
"institutional-vs-individual",
"contract-info",
"fund-info",
]
symbolIsin: str
timestamp: str
@@ -64,7 +73,15 @@ class WebsocketBase_symbolName(TypedDict):
>>> message["symbolName"]
'ETF001'
"""
channel: str
channel: Literal[
"best-limit",
"order-book",
"ohlcv-last-1m",
"aggregate",
"institutional-vs-individual",
"contract-info",
"fund-info",
]
symbolName: str
timestamp: str
@@ -734,7 +751,6 @@ class Instruments(TypedDict):
# +--------------------------------------------------------------------------------------+ #
class BestLimitItem(TypedDict):
"""
Represents the best limit order information at a given price level for a financial instrument.
@@ -766,39 +782,6 @@ class BestLimitItem(TypedDict):
sell_quantity: int
sell_price: int
class BestLimit(TypedDict):
"""
Represents the aggregated best limit orders for multiple instruments.
The structure is a nested dictionary where the first key is typically a symbol
identifier (ISIN or symbolName) and the second key represents the order level or priority.
Attributes:
items (Dict[str, Dict[str, BestLimitItem]]): Nested dictionary of BestLimitItem objects.
- Outer key: Instrument identifier (e.g., ISIN or symbolName)
- Inner key: Price level or order priority
- Value: BestLimitItem for that level
Example:
>>> best_limit: BestLimit = {
... "ETF001": {
... "1": {
... "buy_order_count": 5,
... "buy_quantity": 1000,
... "buy_price": 12000,
... "sell_order_count": 3,
... "sell_quantity": 800,
... "sell_price": 12100
... }
... }
... }
>>> best_limit["ETF001"]["1"]["sell_quantity"]
800
"""
items: Dict[str, Dict[str, BestLimitItem]]
class BestLimitResponse(TypedDict):
"""
Response structure for best limit orders from a REST API call.
@@ -810,7 +793,18 @@ class BestLimitResponse(TypedDict):
Example:
>>> response: BestLimitResponse = {
... "Data": best_limit,
... "Data": {
... "ETF001": {
... "1": {
... "buy_order_count": 5,
... "buy_quantity": 1000,
... "buy_price": 12000,
... "sell_order_count": 3,
... "sell_quantity": 800,
... "sell_price": 12100
... },
... },
... },
... "Status": {
... "State": True,
... "ServerTimeStamp": 1700350200.0,
@@ -825,7 +819,13 @@ class BestLimitResponse(TypedDict):
>>> response["Status"]["State"]
True
"""
Data: BestLimit
Data: Dict[
str,
Dict[
Literal['1','2','3','4','5','6',],
BestLimitItem
]
]
Status: Status
@@ -867,7 +867,10 @@ class BestLimit_WS_symbolIsin(WebsocketBase_symbolIsin):
>>> ws_data["data"]["1"]["sell_price"]
12100
"""
data: Dict[str, BestLimitItem]
data: Dict[
Literal['1','2','3','4','5','6',],
BestLimitItem,
]
class BestLimit_WS_symbolName(WebsocketBase_symbolName):
@@ -908,7 +911,10 @@ class BestLimit_WS_symbolName(WebsocketBase_symbolName):
>>> ws_data["data"]["2"]["buy_price"]
11950
"""
data: Dict[str, BestLimitItem]
data: Dict[
Literal['1','2','3','4','5','6',],
BestLimitItem,
]
# +--------------------------------------------------------------------------------------+ #
@@ -1628,7 +1634,10 @@ class OverviewSecuritiesAndFunds(SecuritiesAndFunds):
>>> overview["FundInfo"]["nav"]
12500.0
"""
BestLimit: Dict[str, BestLimitItem]
BestLimit: Dict[
Literal['1','2','3','4','5','6',],
BestLimitItem,
]
Aggregate: Aggregate
institutional_vs_individual: institutional_vs_individual
FundInfo: FundInfo
@@ -1649,7 +1658,10 @@ class OverviewTreasuryBonds(TreasuryBonds):
FundInfo (FundInfo)
ContractInfo (ContractInfo)
"""
BestLimit: Dict[str, BestLimitItem]
BestLimit: Dict[
Literal['1','2','3','4','5','6',],
BestLimitItem,
]
Aggregate: Aggregate
institutional_vs_individual: institutional_vs_individual
FundInfo: FundInfo
@@ -1670,7 +1682,10 @@ class OverviewStockOptions(StockOptions):
FundInfo (FundInfo)
ContractInfo (ContractInfo)
"""
BestLimit: Dict[str, BestLimitItem]
BestLimit: Dict[
Literal['1','2','3','4','5','6',],
BestLimitItem,
]
Aggregate: Aggregate
institutional_vs_individual: institutional_vs_individual
FundInfo: FundInfo
@@ -1691,7 +1706,10 @@ class OverviewStockFuturess(StockFutures):
FundInfo (FundInfo)
ContractInfo (ContractInfo)
"""
BestLimit: Dict[str, BestLimitItem]
BestLimit: Dict[
Literal['1','2','3','4','5','6',],
BestLimitItem,
]
Aggregate: Aggregate
institutional_vs_individual: institutional_vs_individual
FundInfo: FundInfo
@@ -1728,7 +1746,8 @@ class OverviewResponse:
True
"""
Data : Dict[
str,Optional[
str,
Optional[
Union[
OverviewSecuritiesAndFunds,
OverviewTreasuryBonds,
+138 -73
View File
@@ -93,6 +93,13 @@ class Order:
self.Price : int = Price
self.Volume : int = Volume
self.is_deleted : bool = False
self.OrderStatus : Literal[
None,
'InQueue' ,
'Cancelled',
'Broken',
'Settled',
]
self.OrderId : HexUUID | None = None
@@ -118,20 +125,24 @@ class Order:
'953097ac6ced45ca8ef205b76ca6faf2'
"""
if self.OrderId is None :
try :
SendOrder_Response = await self.__AuthASyncClient.httpx_Client.post(**self.__SendOrder_RequestInfo)
if self.OrderId is None :
match SendOrder_Response.status_code :
SendOrder_Response = await self.__AuthASyncClient.httpx_Client.post(**self.__SendOrder_RequestInfo)
case 200 :
match SendOrder_Response.status_code :
self.OrderId = SendOrder_Response.json()['Data']['order_uuid']
return None
case _ : return None
else : return None
case 200 :
self.OrderId = SendOrder_Response.json()['Data']['order_uuid']
return None
case _ : return None
else : return None
except : return None
# +--------------------------------------------------------------------------------------+ #
async def Edit(
@@ -177,38 +188,67 @@ class Order:
)
"""
if self.OrderId is not None:
try :
if self.OrderId is not None:
Edit_response = await self.__AuthASyncClient.httpx_Client.patch(
url='https://core.hedgetech.ir/ems-engine/tse-ifb/order/edit',
data={
'order_uuid' : self.OrderId,
'Order_ValidityType' : Order_ValidityType,
'ValidityDate' : ValidityDate,
'Price' : Price,
'Volume' : Volume
}
)
match Edit_response.status_code:
case 200:
Edit_response = Edit_response.json()
self.OrderId = Edit_response['Data']['order_uuid']
self.ValidityType = Edit_response['Data']['order_validity_type']
self.ValidityDate = ValidityDate
self.Price = Edit_response['Data']['order_price']
self.Volume = Edit_response['Data']['order_volume']
self.OrderStatus = 'InQueue'
return None
case _ :
status_respnse = await self.Status()
if status_respnse and (
status_respnse['order_status'] == 'InQueue'
and status_respnse['RemainedVolume'] + status_respnse['ExecutedVolume'] == Volume
and status_respnse['Price'] == Price
and status_respnse['ValidityDate'] == ValidityDate
and status_respnse['ValidityType'] == Order_ValidityType
):
self.ValidityType = status_respnse['ValidityType']
self.ValidityDate = status_respnse['ValidityDate']
self.Price = status_respnse['Price']
self.Volume = status_respnse['RemainedVolume'] + status_respnse['ExecutedVolume']
self.OrderStatus = 'InQueue'
return None
elif status_respnse and status_respnse['order_status'] != 'InQueue' :
self.OrderStatus = status_respnse['order_status']
return None
else : return None
else : return None
except : return None
Edit_response = await self.__AuthASyncClient.httpx_Client.patch(
url='https://core.hedgetech.ir/ems-engine/tse-ifb/order/edit',
data={
'order_uuid' : self.OrderId,
'Order_ValidityType' : Order_ValidityType,
'ValidityDate' : ValidityDate,
'Price' : Price,
'Volume' : Volume
}
)
match Edit_response.status_code:
case 200:
Edit_response = Edit_response.json()
self.OrderId = Edit_response['Data']['order_uuid']
self.ValidityType = Edit_response['Data']['order_validity_type']
self.ValidityDate = ValidityDate
self.Price = Edit_response['Data']['order_price']
self.Volume = Edit_response['Data']['order_volume']
return None
case _ : return None
else : return None
# +--------------------------------------------------------------------------------------+ #
async def Status(self)-> OrderStatus | None:
@@ -246,24 +286,30 @@ class Order:
'ValidityDate': 0
}
"""
if self.OrderId is not None:
status_respnse = await self.__AuthASyncClient.httpx_Client.get(
url='https://core.hedgetech.ir/ems-engine/tse-ifb/order/status',
params={'order_uuid' : self.OrderId}
)
try :
match status_respnse.status_code :
case 200:
return status_respnse.json()['Data']
case _ : return None
else : return None
if self.OrderId is not None:
status_respnse = await self.__AuthASyncClient.httpx_Client.get(
url='https://core.hedgetech.ir/ems-engine/tse-ifb/order/status',
params={'order_uuid' : self.OrderId}
)
match status_respnse.status_code :
case 200:
status_respnse = status_respnse.json()['Data']
self.OrderStatus = status_respnse['order_status']
return status_respnse
case _ : return None
else : return None
except : return None
# +--------------------------------------------------------------------------------------+ #
async def Delete(self)-> None:
@@ -283,26 +329,44 @@ class Order:
>>> print(order.is_deleted)
True
"""
if self.OrderId is not None:
Delete_respnse = await self.__AuthASyncClient.httpx_Client.delete(
url= 'https://core.hedgetech.ir/ems-engine/tse-ifb/order/delete',
params={'order_uuid' : self.OrderId}
)
try :
match Delete_respnse.status_code :
if self.OrderId is not None:
Delete_respnse = await self.__AuthASyncClient.httpx_Client.delete(
url= 'https://core.hedgetech.ir/ems-engine/tse-ifb/order/delete',
params={'order_uuid' : self.OrderId}
)
case 200:
self.is_deleted = True
return None
case _ : return None
else : return None
match Delete_respnse.status_code :
case 200:
self.is_deleted = True
self.OrderStatus = 'Cancelled'
return None
case _ :
status_respnse = await self.Status()
if status_respnse and status_respnse['order_status'] == 'Cancelled':
self.is_deleted = True
self.OrderStatus = 'Cancelled'
return None
elif status_respnse and status_respnse['order_status'] != 'Cancelled' :
self.OrderStatus = status_respnse['order_status']
return None
else : return None
else : return None
except : return None
# ================================================================================= #
class EmsEngine_TseIfb_AsyncClient:
@@ -369,6 +433,7 @@ class EmsEngine_TseIfb_AsyncClient:
OMS : Literal[
'Omex | Parsian',
'Sahra | Karamad',
'Sahra | NIBB',
]
)-> ImageFile:
+132 -66
View File
@@ -92,6 +92,13 @@ class Order:
self.Price : int = Price
self.Volume : int = Volume
self.is_deleted : bool = False
self.OrderStatus : Literal[
None,
'InQueue' ,
'Cancelled',
'Broken',
'Settled',
]
self.OrderId : HexUUID | None = None
@@ -122,20 +129,24 @@ class Order:
'0xA23F...'
"""
if self.OrderId is None :
SendOrder_Response = self.__AuthSyncClient.httpx_Client.post(**self.__SendOrder_RequestInfo)
try :
match SendOrder_Response.status_code :
if self.OrderId is None :
SendOrder_Response = self.__AuthSyncClient.httpx_Client.post(**self.__SendOrder_RequestInfo)
case 200 :
match SendOrder_Response.status_code :
self.OrderId = SendOrder_Response.json()['Data']['order_uuid']
return None
case _ : return None
case 200 :
self.OrderId = SendOrder_Response.json()['Data']['order_uuid']
return None
case _ : return None
else : return None
else : return None
except : return None
# +--------------------------------------------------------------------------------------+ #
@@ -189,37 +200,66 @@ class Order:
)
"""
if self.OrderId is not None:
try :
Edit_response = self.__AuthSyncClient.httpx_Client.patch(
url='https://core.hedgetech.ir/ems-engine/tse-ifb/order/edit',
data={
'order_uuid' : self.OrderId,
'Order_ValidityType' : Order_ValidityType,
'ValidityDate' : ValidityDate,
'Price' : Price,
'Volume' : Volume
}
)
if self.OrderId is not None:
match Edit_response.status_code:
Edit_response = self.__AuthSyncClient.httpx_Client.patch(
url='https://core.hedgetech.ir/ems-engine/tse-ifb/order/edit',
data={
'order_uuid' : self.OrderId,
'Order_ValidityType' : Order_ValidityType,
'ValidityDate' : ValidityDate,
'Price' : Price,
'Volume' : Volume
}
)
case 200:
match Edit_response.status_code:
Edit_response = Edit_response.json()
self.OrderId = Edit_response['Data']['order_uuid']
self.ValidityType = Edit_response['Data']['order_validity_type']
self.ValidityDate = ValidityDate
self.Price = Edit_response['Data']['order_price']
self.Volume = Edit_response['Data']['order_volume']
return None
case _ : return None
else : return None
case 200:
Edit_response = Edit_response.json()
self.OrderId = Edit_response['Data']['order_uuid']
self.ValidityType = Edit_response['Data']['order_validity_type']
self.ValidityDate = ValidityDate
self.Price = Edit_response['Data']['order_price']
self.Volume = Edit_response['Data']['order_volume']
self.OrderStatus = 'InQueue'
return None
case _ :
status_respnse = self.Status()
if status_respnse and (
status_respnse['order_status'] == 'InQueue'
and status_respnse['RemainedVolume'] + status_respnse['ExecutedVolume'] == Volume
and status_respnse['Price'] == Price
and status_respnse['ValidityDate'] == ValidityDate
and status_respnse['ValidityType'] == Order_ValidityType
):
self.ValidityType = status_respnse['ValidityType']
self.ValidityDate = status_respnse['ValidityDate']
self.Price = status_respnse['Price']
self.Volume = status_respnse['RemainedVolume'] + status_respnse['ExecutedVolume']
self.OrderStatus = 'InQueue'
return None
elif status_respnse and status_respnse['order_status'] != 'InQueue' :
self.OrderStatus = status_respnse['order_status']
return None
else : return None
else : return None
except : return None
# +--------------------------------------------------------------------------------------+ #
@@ -310,22 +350,29 @@ class Order:
}
"""
if self.OrderId is not None:
status_respnse = self.__AuthSyncClient.httpx_Client.get(
url='https://core.hedgetech.ir/ems-engine/tse-ifb/order/status',
params={'order_uuid' : self.OrderId}
)
try :
match status_respnse.status_code :
if self.OrderId is not None:
status_respnse = self.__AuthSyncClient.httpx_Client.get(
url='https://core.hedgetech.ir/ems-engine/tse-ifb/order/status',
params={'order_uuid' : self.OrderId}
)
case 200:
match status_respnse.status_code :
return status_respnse.json()['Data']
case 200:
status_respnse = status_respnse.json()['Data']
self.OrderStatus = status_respnse['order_status']
return status_respnse
case _ : return None
case _ : return None
else : return None
else : return None
except : return None
# +--------------------------------------------------------------------------------------+ #
@@ -351,24 +398,42 @@ class Order:
True
"""
if self.OrderId is not None:
Delete_respnse = self.__AuthSyncClient.httpx_Client.delete(
url= 'https://core.hedgetech.ir/ems-engine/tse-ifb/order/delete',
params={'order_uuid' : self.OrderId}
)
match Delete_respnse.status_code :
case 200:
self.is_deleted = True
return None
case _ : return None
try :
else : return None
if self.OrderId is not None:
Delete_respnse = self.__AuthSyncClient.httpx_Client.delete(
url= 'https://core.hedgetech.ir/ems-engine/tse-ifb/order/delete',
params={'order_uuid' : self.OrderId}
)
match Delete_respnse.status_code :
case 200:
self.is_deleted = True
self.OrderStatus = 'Cancelled'
return None
case _ :
status_respnse = self.Status()
if status_respnse and status_respnse['order_status'] == 'Cancelled':
self.is_deleted = True
self.OrderStatus = 'Cancelled'
return None
elif status_respnse and status_respnse['order_status'] != 'Cancelled' :
self.OrderStatus = status_respnse['order_status']
return None
else : return None
else : return None
except : return None
# ================================================================================= #
@@ -401,6 +466,7 @@ class EmsEngine_TseIfb_SyncClient:
OMS : Literal[
'Omex | Parsian',
'Sahra | Karamad',
'Sahra | NIBB',
]
)-> ImageFile:
+1 -1
View File
@@ -367,7 +367,7 @@ See LICENSE file.
## Support
GitHub Issues: https://github.com/HedgeTech-ir/HedgeTech/issues
GitHub Issues: https://gitea.hedgetech.ir/HedgeTech/HedgeTech/issues
Email: info@hedgetech.ir
+4 -4
View File
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
[project]
name = "HedgeTech"
version = "0.2.4"
version = "0.3.1b2"
description = "A unified, high-performance API layer that powers all trading infrastructure across the HedgeTech ecosystem, providing modular, scalable, and real-time interfaces for market data, order management, and execution systems."
readme = "README.md"
requires-python = ">=3.10"
@@ -33,7 +33,7 @@ classifiers = [
"License :: OSI Approved :: Apache Software License",
"Operating System :: OS Independent",
"Development Status :: 5 - Production/Stable",
"Development Status :: 4 - Beta",
"Intended Audience :: Developers",
"Intended Audience :: Financial and Insurance Industry",
@@ -59,5 +59,5 @@ dependencies = [
[project.urls]
Homepage = "https://hedgetech.ir/landing/"
Documentation = "https://github.com/HedgeTech-ir/HedgeTech/blob/main/README.md"
Repository = "https://github.com/HedgeTech-ir/HedgeTech"
Documentation = "https://gitea.hedgetech.ir/HedgeTech/HedgeTech/src/branch/main/README.md"
Repository = "https://gitea.hedgetech.ir/HedgeTech/HedgeTech"