Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
52367d54e1 | ||
|
|
c8090ba334 | ||
|
|
854bee9f9e | ||
|
|
3a603db3cf | ||
|
|
3906a203a6 | ||
|
|
a49db4397c | ||
|
|
3d947bc558 | ||
|
|
2af7dfd648 | ||
|
|
bde8c980ef | ||
|
|
e63dcddbea | ||
|
|
cedbd76d0e | ||
|
|
52be955e6e | ||
|
|
ecc1070f1c | ||
|
|
126eab66f7 | ||
|
|
8a5f3142ef | ||
|
|
9cfd36a891 | ||
|
|
034c9a50ea | ||
|
|
17bea4f2a3 | ||
|
|
747b257432 | ||
|
|
e6bd5852c2 |
No files matched your search
@@ -209,3 +209,5 @@ __marimo__/
|
|||||||
*.ipynb
|
*.ipynb
|
||||||
requirements.txt
|
requirements.txt
|
||||||
*test*.py
|
*test*.py
|
||||||
|
|
||||||
|
.vscode
|
||||||
@@ -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
|
||||||
@@ -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
|
||||||
|
|
||||||
@@ -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
@@ -2,3 +2,7 @@ from .__tse_ifb import (
|
|||||||
DataEngine_TseIfb_SyncClient,
|
DataEngine_TseIfb_SyncClient,
|
||||||
DataEngine_TseIfb_AsyncClient
|
DataEngine_TseIfb_AsyncClient
|
||||||
)
|
)
|
||||||
|
from .__ime import (
|
||||||
|
DataEngine_Ime_SyncClient,
|
||||||
|
DataEngine_Ime_AsyncClient
|
||||||
|
)
|
||||||
@@ -9,6 +9,7 @@ from typing import (
|
|||||||
Dict,
|
Dict,
|
||||||
Optional,
|
Optional,
|
||||||
TypedDict,
|
TypedDict,
|
||||||
|
Literal,
|
||||||
)
|
)
|
||||||
|
|
||||||
# ========================================|======================================== #
|
# ========================================|======================================== #
|
||||||
@@ -37,7 +38,15 @@ class WebsocketBase_symbolIsin(TypedDict):
|
|||||||
>>> message["symbolIsin"]
|
>>> message["symbolIsin"]
|
||||||
'IR0001234567'
|
'IR0001234567'
|
||||||
"""
|
"""
|
||||||
channel: str
|
channel: Literal[
|
||||||
|
"best-limit",
|
||||||
|
"order-book",
|
||||||
|
"ohlcv-last-1m",
|
||||||
|
"aggregate",
|
||||||
|
"institutional-vs-individual",
|
||||||
|
"contract-info",
|
||||||
|
"fund-info",
|
||||||
|
]
|
||||||
symbolIsin: str
|
symbolIsin: str
|
||||||
timestamp: str
|
timestamp: str
|
||||||
|
|
||||||
@@ -64,7 +73,15 @@ class WebsocketBase_symbolName(TypedDict):
|
|||||||
>>> message["symbolName"]
|
>>> message["symbolName"]
|
||||||
'ETF001'
|
'ETF001'
|
||||||
"""
|
"""
|
||||||
channel: str
|
channel: Literal[
|
||||||
|
"best-limit",
|
||||||
|
"order-book",
|
||||||
|
"ohlcv-last-1m",
|
||||||
|
"aggregate",
|
||||||
|
"institutional-vs-individual",
|
||||||
|
"contract-info",
|
||||||
|
"fund-info",
|
||||||
|
]
|
||||||
symbolName: str
|
symbolName: str
|
||||||
timestamp: str
|
timestamp: str
|
||||||
|
|
||||||
@@ -734,7 +751,6 @@ class Instruments(TypedDict):
|
|||||||
|
|
||||||
# +--------------------------------------------------------------------------------------+ #
|
# +--------------------------------------------------------------------------------------+ #
|
||||||
|
|
||||||
|
|
||||||
class BestLimitItem(TypedDict):
|
class BestLimitItem(TypedDict):
|
||||||
"""
|
"""
|
||||||
Represents the best limit order information at a given price level for a financial instrument.
|
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_quantity: int
|
||||||
sell_price: 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):
|
class BestLimitResponse(TypedDict):
|
||||||
"""
|
"""
|
||||||
Response structure for best limit orders from a REST API call.
|
Response structure for best limit orders from a REST API call.
|
||||||
@@ -810,7 +793,18 @@ class BestLimitResponse(TypedDict):
|
|||||||
|
|
||||||
Example:
|
Example:
|
||||||
>>> response: BestLimitResponse = {
|
>>> 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": {
|
... "Status": {
|
||||||
... "State": True,
|
... "State": True,
|
||||||
... "ServerTimeStamp": 1700350200.0,
|
... "ServerTimeStamp": 1700350200.0,
|
||||||
@@ -825,7 +819,13 @@ class BestLimitResponse(TypedDict):
|
|||||||
>>> response["Status"]["State"]
|
>>> response["Status"]["State"]
|
||||||
True
|
True
|
||||||
"""
|
"""
|
||||||
Data: BestLimit
|
Data: Dict[
|
||||||
|
str,
|
||||||
|
Dict[
|
||||||
|
Literal['1','2','3','4','5','6',],
|
||||||
|
BestLimitItem
|
||||||
|
]
|
||||||
|
]
|
||||||
Status: Status
|
Status: Status
|
||||||
|
|
||||||
|
|
||||||
@@ -867,7 +867,10 @@ class BestLimit_WS_symbolIsin(WebsocketBase_symbolIsin):
|
|||||||
>>> ws_data["data"]["1"]["sell_price"]
|
>>> ws_data["data"]["1"]["sell_price"]
|
||||||
12100
|
12100
|
||||||
"""
|
"""
|
||||||
data: Dict[str, BestLimitItem]
|
data: Dict[
|
||||||
|
Literal['1','2','3','4','5','6',],
|
||||||
|
BestLimitItem,
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
class BestLimit_WS_symbolName(WebsocketBase_symbolName):
|
class BestLimit_WS_symbolName(WebsocketBase_symbolName):
|
||||||
@@ -908,7 +911,10 @@ class BestLimit_WS_symbolName(WebsocketBase_symbolName):
|
|||||||
>>> ws_data["data"]["2"]["buy_price"]
|
>>> ws_data["data"]["2"]["buy_price"]
|
||||||
11950
|
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"]
|
>>> overview["FundInfo"]["nav"]
|
||||||
12500.0
|
12500.0
|
||||||
"""
|
"""
|
||||||
BestLimit: Dict[str, BestLimitItem]
|
BestLimit: Dict[
|
||||||
|
Literal['1','2','3','4','5','6',],
|
||||||
|
BestLimitItem,
|
||||||
|
]
|
||||||
Aggregate: Aggregate
|
Aggregate: Aggregate
|
||||||
institutional_vs_individual: institutional_vs_individual
|
institutional_vs_individual: institutional_vs_individual
|
||||||
FundInfo: FundInfo
|
FundInfo: FundInfo
|
||||||
@@ -1649,7 +1658,10 @@ class OverviewTreasuryBonds(TreasuryBonds):
|
|||||||
FundInfo (FundInfo)
|
FundInfo (FundInfo)
|
||||||
ContractInfo (ContractInfo)
|
ContractInfo (ContractInfo)
|
||||||
"""
|
"""
|
||||||
BestLimit: Dict[str, BestLimitItem]
|
BestLimit: Dict[
|
||||||
|
Literal['1','2','3','4','5','6',],
|
||||||
|
BestLimitItem,
|
||||||
|
]
|
||||||
Aggregate: Aggregate
|
Aggregate: Aggregate
|
||||||
institutional_vs_individual: institutional_vs_individual
|
institutional_vs_individual: institutional_vs_individual
|
||||||
FundInfo: FundInfo
|
FundInfo: FundInfo
|
||||||
@@ -1670,7 +1682,10 @@ class OverviewStockOptions(StockOptions):
|
|||||||
FundInfo (FundInfo)
|
FundInfo (FundInfo)
|
||||||
ContractInfo (ContractInfo)
|
ContractInfo (ContractInfo)
|
||||||
"""
|
"""
|
||||||
BestLimit: Dict[str, BestLimitItem]
|
BestLimit: Dict[
|
||||||
|
Literal['1','2','3','4','5','6',],
|
||||||
|
BestLimitItem,
|
||||||
|
]
|
||||||
Aggregate: Aggregate
|
Aggregate: Aggregate
|
||||||
institutional_vs_individual: institutional_vs_individual
|
institutional_vs_individual: institutional_vs_individual
|
||||||
FundInfo: FundInfo
|
FundInfo: FundInfo
|
||||||
@@ -1691,7 +1706,10 @@ class OverviewStockFuturess(StockFutures):
|
|||||||
FundInfo (FundInfo)
|
FundInfo (FundInfo)
|
||||||
ContractInfo (ContractInfo)
|
ContractInfo (ContractInfo)
|
||||||
"""
|
"""
|
||||||
BestLimit: Dict[str, BestLimitItem]
|
BestLimit: Dict[
|
||||||
|
Literal['1','2','3','4','5','6',],
|
||||||
|
BestLimitItem,
|
||||||
|
]
|
||||||
Aggregate: Aggregate
|
Aggregate: Aggregate
|
||||||
institutional_vs_individual: institutional_vs_individual
|
institutional_vs_individual: institutional_vs_individual
|
||||||
FundInfo: FundInfo
|
FundInfo: FundInfo
|
||||||
@@ -1728,7 +1746,8 @@ class OverviewResponse:
|
|||||||
True
|
True
|
||||||
"""
|
"""
|
||||||
Data : Dict[
|
Data : Dict[
|
||||||
str,Optional[
|
str,
|
||||||
|
Optional[
|
||||||
Union[
|
Union[
|
||||||
OverviewSecuritiesAndFunds,
|
OverviewSecuritiesAndFunds,
|
||||||
OverviewTreasuryBonds,
|
OverviewTreasuryBonds,
|
||||||
|
|||||||
@@ -93,6 +93,13 @@ class Order:
|
|||||||
self.Price : int = Price
|
self.Price : int = Price
|
||||||
self.Volume : int = Volume
|
self.Volume : int = Volume
|
||||||
self.is_deleted : bool = False
|
self.is_deleted : bool = False
|
||||||
|
self.OrderStatus : Literal[
|
||||||
|
None,
|
||||||
|
'InQueue' ,
|
||||||
|
'Cancelled',
|
||||||
|
'Broken',
|
||||||
|
'Settled',
|
||||||
|
]
|
||||||
|
|
||||||
self.OrderId : HexUUID | None = None
|
self.OrderId : HexUUID | None = None
|
||||||
|
|
||||||
@@ -118,6 +125,8 @@ class Order:
|
|||||||
'953097ac6ced45ca8ef205b76ca6faf2'
|
'953097ac6ced45ca8ef205b76ca6faf2'
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
try :
|
||||||
|
|
||||||
if self.OrderId is None :
|
if self.OrderId is None :
|
||||||
|
|
||||||
SendOrder_Response = await self.__AuthASyncClient.httpx_Client.post(**self.__SendOrder_RequestInfo)
|
SendOrder_Response = await self.__AuthASyncClient.httpx_Client.post(**self.__SendOrder_RequestInfo)
|
||||||
@@ -133,6 +142,8 @@ class Order:
|
|||||||
|
|
||||||
else : return None
|
else : return None
|
||||||
|
|
||||||
|
except : return None
|
||||||
|
|
||||||
# +--------------------------------------------------------------------------------------+ #
|
# +--------------------------------------------------------------------------------------+ #
|
||||||
async def Edit(
|
async def Edit(
|
||||||
self,
|
self,
|
||||||
@@ -177,6 +188,8 @@ class Order:
|
|||||||
)
|
)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
try :
|
||||||
|
|
||||||
if self.OrderId is not None:
|
if self.OrderId is not None:
|
||||||
|
|
||||||
Edit_response = await self.__AuthASyncClient.httpx_Client.patch(
|
Edit_response = await self.__AuthASyncClient.httpx_Client.patch(
|
||||||
@@ -202,13 +215,40 @@ class Order:
|
|||||||
self.ValidityDate = ValidityDate
|
self.ValidityDate = ValidityDate
|
||||||
self.Price = Edit_response['Data']['order_price']
|
self.Price = Edit_response['Data']['order_price']
|
||||||
self.Volume = Edit_response['Data']['order_volume']
|
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
|
return None
|
||||||
|
|
||||||
case _ : return None
|
else : return None
|
||||||
|
|
||||||
else : return None
|
else : return None
|
||||||
|
|
||||||
|
except : return None
|
||||||
|
|
||||||
# +--------------------------------------------------------------------------------------+ #
|
# +--------------------------------------------------------------------------------------+ #
|
||||||
|
|
||||||
async def Status(self)-> OrderStatus | None:
|
async def Status(self)-> OrderStatus | None:
|
||||||
@@ -246,6 +286,7 @@ class Order:
|
|||||||
'ValidityDate': 0
|
'ValidityDate': 0
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
|
try :
|
||||||
|
|
||||||
if self.OrderId is not None:
|
if self.OrderId is not None:
|
||||||
|
|
||||||
@@ -258,12 +299,17 @@ class Order:
|
|||||||
|
|
||||||
case 200:
|
case 200:
|
||||||
|
|
||||||
return status_respnse.json()['Data']
|
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
|
||||||
|
|
||||||
# +--------------------------------------------------------------------------------------+ #
|
# +--------------------------------------------------------------------------------------+ #
|
||||||
|
|
||||||
async def Delete(self)-> None:
|
async def Delete(self)-> None:
|
||||||
@@ -284,6 +330,8 @@ class Order:
|
|||||||
True
|
True
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
try :
|
||||||
|
|
||||||
if self.OrderId is not None:
|
if self.OrderId is not None:
|
||||||
|
|
||||||
Delete_respnse = await self.__AuthASyncClient.httpx_Client.delete(
|
Delete_respnse = await self.__AuthASyncClient.httpx_Client.delete(
|
||||||
@@ -297,12 +345,28 @@ class Order:
|
|||||||
case 200:
|
case 200:
|
||||||
|
|
||||||
self.is_deleted = True
|
self.is_deleted = True
|
||||||
|
self.OrderStatus = 'Cancelled'
|
||||||
return None
|
return None
|
||||||
|
|
||||||
case _ : 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
|
||||||
|
|
||||||
|
else : return None
|
||||||
|
|
||||||
|
except : return None
|
||||||
|
|
||||||
# ================================================================================= #
|
# ================================================================================= #
|
||||||
|
|
||||||
class EmsEngine_TseIfb_AsyncClient:
|
class EmsEngine_TseIfb_AsyncClient:
|
||||||
@@ -369,6 +433,7 @@ class EmsEngine_TseIfb_AsyncClient:
|
|||||||
OMS : Literal[
|
OMS : Literal[
|
||||||
'Omex | Parsian',
|
'Omex | Parsian',
|
||||||
'Sahra | Karamad',
|
'Sahra | Karamad',
|
||||||
|
'Sahra | NIBB',
|
||||||
]
|
]
|
||||||
)-> ImageFile:
|
)-> ImageFile:
|
||||||
|
|
||||||
|
|||||||
@@ -92,6 +92,13 @@ class Order:
|
|||||||
self.Price : int = Price
|
self.Price : int = Price
|
||||||
self.Volume : int = Volume
|
self.Volume : int = Volume
|
||||||
self.is_deleted : bool = False
|
self.is_deleted : bool = False
|
||||||
|
self.OrderStatus : Literal[
|
||||||
|
None,
|
||||||
|
'InQueue' ,
|
||||||
|
'Cancelled',
|
||||||
|
'Broken',
|
||||||
|
'Settled',
|
||||||
|
]
|
||||||
|
|
||||||
self.OrderId : HexUUID | None = None
|
self.OrderId : HexUUID | None = None
|
||||||
|
|
||||||
@@ -122,6 +129,8 @@ class Order:
|
|||||||
'0xA23F...'
|
'0xA23F...'
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
try :
|
||||||
|
|
||||||
if self.OrderId is None :
|
if self.OrderId is None :
|
||||||
|
|
||||||
SendOrder_Response = self.__AuthSyncClient.httpx_Client.post(**self.__SendOrder_RequestInfo)
|
SendOrder_Response = self.__AuthSyncClient.httpx_Client.post(**self.__SendOrder_RequestInfo)
|
||||||
@@ -137,6 +146,8 @@ class Order:
|
|||||||
|
|
||||||
else : return None
|
else : return None
|
||||||
|
|
||||||
|
except : return None
|
||||||
|
|
||||||
# +--------------------------------------------------------------------------------------+ #
|
# +--------------------------------------------------------------------------------------+ #
|
||||||
|
|
||||||
def Edit(
|
def Edit(
|
||||||
@@ -189,6 +200,8 @@ class Order:
|
|||||||
)
|
)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
try :
|
||||||
|
|
||||||
if self.OrderId is not None:
|
if self.OrderId is not None:
|
||||||
|
|
||||||
Edit_response = self.__AuthSyncClient.httpx_Client.patch(
|
Edit_response = self.__AuthSyncClient.httpx_Client.patch(
|
||||||
@@ -214,13 +227,40 @@ class Order:
|
|||||||
self.ValidityDate = ValidityDate
|
self.ValidityDate = ValidityDate
|
||||||
self.Price = Edit_response['Data']['order_price']
|
self.Price = Edit_response['Data']['order_price']
|
||||||
self.Volume = Edit_response['Data']['order_volume']
|
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
|
return None
|
||||||
|
|
||||||
case _ : return None
|
else : return None
|
||||||
|
|
||||||
else : return None
|
else : return None
|
||||||
|
|
||||||
|
except : return None
|
||||||
|
|
||||||
# +--------------------------------------------------------------------------------------+ #
|
# +--------------------------------------------------------------------------------------+ #
|
||||||
|
|
||||||
def Status(self)-> OrderStatus | None:
|
def Status(self)-> OrderStatus | None:
|
||||||
@@ -310,6 +350,8 @@ class Order:
|
|||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
try :
|
||||||
|
|
||||||
if self.OrderId is not None:
|
if self.OrderId is not None:
|
||||||
|
|
||||||
status_respnse = self.__AuthSyncClient.httpx_Client.get(
|
status_respnse = self.__AuthSyncClient.httpx_Client.get(
|
||||||
@@ -321,12 +363,17 @@ class Order:
|
|||||||
|
|
||||||
case 200:
|
case 200:
|
||||||
|
|
||||||
return status_respnse.json()['Data']
|
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
|
||||||
|
|
||||||
# +--------------------------------------------------------------------------------------+ #
|
# +--------------------------------------------------------------------------------------+ #
|
||||||
|
|
||||||
def Delete(self)-> None :
|
def Delete(self)-> None :
|
||||||
@@ -351,6 +398,8 @@ class Order:
|
|||||||
True
|
True
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
try :
|
||||||
|
|
||||||
if self.OrderId is not None:
|
if self.OrderId is not None:
|
||||||
|
|
||||||
Delete_respnse = self.__AuthSyncClient.httpx_Client.delete(
|
Delete_respnse = self.__AuthSyncClient.httpx_Client.delete(
|
||||||
@@ -364,12 +413,28 @@ class Order:
|
|||||||
case 200:
|
case 200:
|
||||||
|
|
||||||
self.is_deleted = True
|
self.is_deleted = True
|
||||||
|
self.OrderStatus = 'Cancelled'
|
||||||
return None
|
return None
|
||||||
|
|
||||||
case _ : 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
|
||||||
|
|
||||||
|
else : return None
|
||||||
|
|
||||||
|
except : return None
|
||||||
|
|
||||||
# ================================================================================= #
|
# ================================================================================= #
|
||||||
|
|
||||||
class EmsEngine_TseIfb_SyncClient:
|
class EmsEngine_TseIfb_SyncClient:
|
||||||
@@ -401,6 +466,7 @@ class EmsEngine_TseIfb_SyncClient:
|
|||||||
OMS : Literal[
|
OMS : Literal[
|
||||||
'Omex | Parsian',
|
'Omex | Parsian',
|
||||||
'Sahra | Karamad',
|
'Sahra | Karamad',
|
||||||
|
'Sahra | NIBB',
|
||||||
]
|
]
|
||||||
)-> ImageFile:
|
)-> ImageFile:
|
||||||
|
|
||||||
|
|||||||
@@ -367,7 +367,7 @@ See LICENSE file.
|
|||||||
|
|
||||||
## Support
|
## Support
|
||||||
|
|
||||||
GitHub Issues: https://github.com/HedgeTech-ir/HedgeTech/issues
|
GitHub Issues: https://gitea.hedgetech.ir/HedgeTech/HedgeTech/issues
|
||||||
|
|
||||||
Email: info@hedgetech.ir
|
Email: info@hedgetech.ir
|
||||||
|
|
||||||
|
|||||||
+4
-4
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|||||||
|
|
||||||
[project]
|
[project]
|
||||||
name = "HedgeTech"
|
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."
|
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"
|
readme = "README.md"
|
||||||
requires-python = ">=3.10"
|
requires-python = ">=3.10"
|
||||||
@@ -33,7 +33,7 @@ classifiers = [
|
|||||||
"License :: OSI Approved :: Apache Software License",
|
"License :: OSI Approved :: Apache Software License",
|
||||||
"Operating System :: OS Independent",
|
"Operating System :: OS Independent",
|
||||||
|
|
||||||
"Development Status :: 5 - Production/Stable",
|
"Development Status :: 4 - Beta",
|
||||||
|
|
||||||
"Intended Audience :: Developers",
|
"Intended Audience :: Developers",
|
||||||
"Intended Audience :: Financial and Insurance Industry",
|
"Intended Audience :: Financial and Insurance Industry",
|
||||||
@@ -59,5 +59,5 @@ dependencies = [
|
|||||||
|
|
||||||
[project.urls]
|
[project.urls]
|
||||||
Homepage = "https://hedgetech.ir/landing/"
|
Homepage = "https://hedgetech.ir/landing/"
|
||||||
Documentation = "https://github.com/HedgeTech-ir/HedgeTech/blob/main/README.md"
|
Documentation = "https://gitea.hedgetech.ir/HedgeTech/HedgeTech/src/branch/main/README.md"
|
||||||
Repository = "https://github.com/HedgeTech-ir/HedgeTech"
|
Repository = "https://gitea.hedgetech.ir/HedgeTech/HedgeTech"
|
||||||
Reference in new issue
Block a user