Skip to content

Commit

Permalink
Merge branch 'dev' of https://github.com/InjectiveLabs/sdk-python int…
Browse files Browse the repository at this point in the history
…o feat/add_chain_streams_support
  • Loading branch information
abel committed Oct 25, 2023
2 parents 0a51a5e + cb38b09 commit f12c856
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 108 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@ All notable changes to this project will be documented in this file.

## [0.10.0] - 2023-10-04
### Added
- Added logic to support use of Client Order ID (CID) new identifier in OrderInfo
- New chain stream support

### Changed
- Moved changelog from the README.md file to its own CHANGELOG.md file
- Remove `aiocron` dependency. Use plain asyncio tasks to solve the timeout height synchronization

## [0.9.3]
* Updated TIA/USDT-30NOV2023 market id in denoms_mainnet.ini file

## [0.9.2]
* Added fix to the grpc import error in Mac with M1 and M2 chips
Expand Down
104 changes: 9 additions & 95 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 18 additions & 10 deletions pyinjective/async_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from decimal import Decimal
from typing import Coroutine, Dict, List, Optional, Tuple, Union

import aiocron
import grpc

from pyinjective.composer import Composer
Expand Down Expand Up @@ -117,13 +116,8 @@ def __init__(
)
self.chain_stream_stub = stream_rpc_grpc.StreamStub(channel=self.chain_stream_channel)

# timeout height update routine
self.cron = aiocron.crontab(
"* * * * * */{}".format(DEFAULT_TIMEOUTHEIGHT_SYNC_INTERVAL),
func=self.sync_timeout_height,
args=(),
start=True,
)
self._timeout_height_sync_task = None
self._initialize_timeout_height_sync_task()

self._tokens_and_markets_initialization_lock = asyncio.Lock()
self._tokens: Optional[Dict[str, Token]] = None
Expand Down Expand Up @@ -172,11 +166,11 @@ async def get_tx(self, tx_hash):

async def close_exchange_channel(self):
await self.exchange_channel.close()
self.cron.stop()
self._cancel_timeout_height_sync_task()

async def close_chain_channel(self):
await self.chain_channel.close()
self.cron.stop()
self._cancel_timeout_height_sync_task()

async def sync_timeout_height(self):
try:
Expand Down Expand Up @@ -1046,3 +1040,17 @@ def _chain_cookie_metadata_requestor(self) -> Coroutine:
def _exchange_cookie_metadata_requestor(self) -> Coroutine:
request = exchange_meta_rpc_pb.VersionRequest()
return self.stubMeta.Version(request).initial_metadata()

def _initialize_timeout_height_sync_task(self):
self._cancel_timeout_height_sync_task()
self._timeout_height_sync_task = asyncio.create_task(self._timeout_height_sync_process())

async def _timeout_height_sync_process(self):
while True:
await self.sync_timeout_height()
await asyncio.sleep(DEFAULT_TIMEOUTHEIGHT_SYNC_INTERVAL)

def _cancel_timeout_height_sync_task(self):
if self._timeout_height_sync_task is not None:
self._timeout_height_sync_task.cancel()
self._timeout_height_sync_task = None
2 changes: 1 addition & 1 deletion pyinjective/denoms_mainnet.ini
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ min_display_price_tick_size = 0.0001
min_quantity_tick_size = 0.1
min_display_quantity_tick_size = 0.1

[0x4b7a550e1760cbd2c6ccb97562c56878083b92e32d07e9e3326945c6e60e6b60]
[0x64c3a57b693ede854b0a2794ed5c99546925d1fbe74d91a2e3286e4155a00dee]
description = 'Mainnet Derivative TIA/USDT-30NOV2023 PERP'
base = 0
quote = 6
Expand Down
3 changes: 1 addition & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "injective-py"
version = "0.10.dev1"
version = "0.10.dev7"
description = "Injective Python SDK, with Exchange API Client"
authors = ["Injective Labs <[email protected]>"]
license = "Apache-2.0"
Expand All @@ -22,7 +22,6 @@ include = [

[tool.poetry.dependencies]
python = "^3.9"
aiocron = "*"
aiohttp = "*"
asyncio = "*"
bech32 = "*"
Expand Down

0 comments on commit f12c856

Please sign in to comment.