mirror runs once if polling <= 0
This commit is contained in:
@@ -1,3 +1,17 @@
|
|||||||
|
"""
|
||||||
|
python -m dexorder.bin.mirror creates new pools on the rpc_url chain that mimic the tokens and prices of original
|
||||||
|
pools on a different mirror_source_rpc_url chain.
|
||||||
|
|
||||||
|
[config]
|
||||||
|
rpc_url=<destination for mock pools and tokens>
|
||||||
|
mirror_source_rpc_url = <source for original pools and tokens to copy>
|
||||||
|
mirror_pools = <required list of pool addresses to copy from mirror_source_rpc_url>
|
||||||
|
mirror_env = [address on rpc_url chain where MirrorEnv contract is deployed. If None, then discovered from deployment]
|
||||||
|
metadata = [if set, then a metadata.json file for the mock chain is written to this location]
|
||||||
|
polling = [seconds between price updates. If zero or negative, prices are updated once and the process exits]
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
@@ -105,7 +119,8 @@ async def main():
|
|||||||
if config.mirror_source_rpc_url is None:
|
if config.mirror_source_rpc_url is None:
|
||||||
log.error('Must configure mirror_source_rpc_url')
|
log.error('Must configure mirror_source_rpc_url')
|
||||||
return
|
return
|
||||||
delay = config.polling if config.polling > 0 else 1
|
delay = max(0.010, config.polling)
|
||||||
|
update_once = config.polling <= 0
|
||||||
global source_w3
|
global source_w3
|
||||||
source_w3 = await create_w3(config.mirror_source_rpc_url)
|
source_w3 = await create_w3(config.mirror_source_rpc_url)
|
||||||
pools = (config.mirror_pools or [])
|
pools = (config.mirror_pools or [])
|
||||||
@@ -173,7 +188,10 @@ async def main():
|
|||||||
mirror_pools.append((mirror_addr, mirror_inverted))
|
mirror_pools.append((mirror_addr, mirror_inverted))
|
||||||
await write_metadata(pools, mirror_pools)
|
await write_metadata(pools, mirror_pools)
|
||||||
|
|
||||||
log.info(f'Updating pools every {delay} seconds')
|
if update_once:
|
||||||
|
log.info(f'Updating pools once')
|
||||||
|
else:
|
||||||
|
log.info(f'Updating pools every {delay} seconds')
|
||||||
delay = timedelta(seconds=delay)
|
delay = timedelta(seconds=delay)
|
||||||
to_update = pools
|
to_update = pools
|
||||||
while True:
|
while True:
|
||||||
@@ -188,6 +206,9 @@ async def main():
|
|||||||
if isinstance(result, Exception):
|
if isinstance(result, Exception):
|
||||||
log.debug(f'Could not update {pool}: {result}')
|
log.debug(f'Could not update {pool}: {result}')
|
||||||
failed.append(pool)
|
failed.append(pool)
|
||||||
|
if update_once and not failed:
|
||||||
|
log.info('mirror completed')
|
||||||
|
break
|
||||||
to_update = failed if failed else pools
|
to_update = failed if failed else pools
|
||||||
sleep = (wake_up - now()).total_seconds()
|
sleep = (wake_up - now()).total_seconds()
|
||||||
if sleep > 0:
|
if sleep > 0:
|
||||||
|
|||||||
@@ -17,6 +17,8 @@ class Config:
|
|||||||
db_url: Optional[str] = 'postgresql://dexorder:redroxed@localhost/dexorder'
|
db_url: Optional[str] = 'postgresql://dexorder:redroxed@localhost/dexorder'
|
||||||
dump_sql: bool = False
|
dump_sql: bool = False
|
||||||
redis_url: Optional[str] = 'redis://localhost:6379'
|
redis_url: Optional[str] = 'redis://localhost:6379'
|
||||||
|
|
||||||
|
metadata: Optional[str] = None
|
||||||
ohlc_dir: Optional[str] = None # if empty string or None, then OHLC's are not saved to disk
|
ohlc_dir: Optional[str] = None # if empty string or None, then OHLC's are not saved to disk
|
||||||
|
|
||||||
concurrent_rpc_connections: int = 4
|
concurrent_rpc_connections: int = 4
|
||||||
@@ -33,6 +35,5 @@ class Config:
|
|||||||
walker_flush_interval: float = 300
|
walker_flush_interval: float = 300
|
||||||
|
|
||||||
mirror_source_rpc_url: Optional[str] = None # source RPC for original pools
|
mirror_source_rpc_url: Optional[str] = None # source RPC for original pools
|
||||||
mirror_env: Optional[str] = None
|
|
||||||
mirror_pools: list[str] = field(default_factory=list)
|
mirror_pools: list[str] = field(default_factory=list)
|
||||||
metadata: Optional[str] = None
|
mirror_env: Optional[str] = None
|
||||||
|
|||||||
Reference in New Issue
Block a user