-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.py
58 lines (45 loc) · 1.44 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import asyncio
import sys
from utils.public import update_snipe_list
try:
import uvloop
asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())
except:
pass
from loguru import logger
from tortoise import Tortoise
from settings.config import AppConfig
from settings.global_variables import GlobalVariables
from solana_dex.solana.wallet import Wallet
from solana_dex.websocket import openbook, liquidity
async def init_db():
await Tortoise.init(
db_url='sqlite://db.sqlite3',
modules={'models': ['orm.models.raydium', 'orm.models.tasks']}
)
await Tortoise.generate_schemas()
async def init_wallet():
wallet = Wallet(AppConfig.PRIVATE_KEY)
await wallet.update_token_accounts()
sol_balance = await wallet.get_sol_balance()
logger.info(f"当前账户地址 {wallet.pubkey} SOL余额 {sol_balance}")
GlobalVariables.default_wallet = wallet
async def run():
try:
# 初始化数据库
await init_db()
# 初始化钱包
await init_wallet()
# 启动websocket监控
asyncio.create_task(openbook.run())
asyncio.create_task(liquidity.run())
# 初始化狙击列表
asyncio.create_task(update_snipe_list())
# 等待结束指令
await GlobalVariables.stop_event.wait()
finally:
# 关闭数据库
await Tortoise.close_connections()
sys.exit(0)
if __name__ == '__main__':
asyncio.run(run())