Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/remove cron dependency #260

Merged
merged 8 commits into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ poetry run pytest -v
```

### Changelogs
**0.10**
* 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 @@ -108,13 +107,8 @@
)
self.stubExplorer = explorer_rpc_grpc.InjectiveExplorerRPCStub(self.explorer_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 @@ -163,11 +157,11 @@

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

Check warning on line 160 in pyinjective/async_client.py

View check run for this annotation

Codecov / codecov/patch

pyinjective/async_client.py#L160

Added line #L160 was not covered by tests

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

Check warning on line 164 in pyinjective/async_client.py

View check run for this annotation

Codecov / codecov/patch

pyinjective/async_client.py#L164

Added line #L164 was not covered by tests

async def sync_timeout_height(self):
try:
Expand Down Expand Up @@ -1009,3 +1003,17 @@
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()

Check warning on line 1018 in pyinjective/async_client.py

View check run for this annotation

Codecov / codecov/patch

pyinjective/async_client.py#L1018

Added line #L1018 was not covered by tests
self._timeout_height_sync_task = None
13 changes: 1 addition & 12 deletions pyinjective/core/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,6 @@ def mainnet(cls, node="lb"):
nodes = [
"lb", # us, asia, prod
"lb_k8s",
"sentry0", # ca, prod
"sentry1", # ca, prod
"sentry3", # us, prod
]
if node not in nodes:
raise ValueError("Must be one of {}".format(nodes))
Expand All @@ -259,22 +256,14 @@ def mainnet(cls, node="lb"):
grpc_explorer_endpoint = "sentry.explorer.grpc.injective.network:443"
cookie_assistant = BareMetalLoadBalancedCookieAssistant()
use_secure_connection = True
elif node == "lb_k8s":
else:
lcd_endpoint = "https://k8s.global.mainnet.lcd.injective.network:443"
tm_websocket_endpoint = "wss://k8s.global.mainnet.tm.injective.network:443/websocket"
grpc_endpoint = "k8s.global.mainnet.chain.grpc.injective.network:443"
grpc_exchange_endpoint = "k8s.global.mainnet.exchange.grpc.injective.network:443"
grpc_explorer_endpoint = "k8s.global.mainnet.explorer.grpc.injective.network:443"
cookie_assistant = KubernetesLoadBalancedCookieAssistant()
use_secure_connection = True
else:
lcd_endpoint = f"http://{node}.injective.network:10337"
tm_websocket_endpoint = f"ws://{node}.injective.network:26657/websocket"
grpc_endpoint = f"{node}.injective.network:9900"
grpc_exchange_endpoint = f"{node}.injective.network:9910"
grpc_explorer_endpoint = f"{node}.injective.network:9911"
cookie_assistant = DisabledCookieAssistant()
use_secure_connection = False

return cls(
lcd_endpoint=lcd_endpoint,
Expand Down
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.9.2"
version = "0.10dev"
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
Loading