gogo2/crypto/sol/app.py
Dobromir Popov fee5b516a1 wip (broken)
2024-11-15 00:22:20 +02:00

60 lines
1.5 KiB
Python

import asyncio
import logging
import uvicorn
from fastapi import FastAPI
from fastapi.middleware.wsgi import WSGIMiddleware
from asgiref.wsgi import WsgiToAsgi
from dotenv import load_dotenv
from modules.webui import init_app
from modules.utils import telegram_utils
from config import DO_WATCH_WALLET
from modules.SolanaAPI import SAPI
from modules.log_processor import LogProcessor
load_dotenv()
load_dotenv('.env.secret')
logger = logging.getLogger(__name__)
class Bot:
@staticmethod
async def initialize():
await telegram_utils.initialize()
await telegram_utils.send_telegram_message("Solana Agent Started")
asyncio.create_task(LogProcessor.watch_for_new_logs())
if DO_WATCH_WALLET:
asyncio.create_task(SAPI.wallet_watch_loop())
app = init_app()
asgi_app = WsgiToAsgi(app)
async def main():
global bot, PROCESSING_LOG, pk
await telegram_utils.initialize()
await telegram_utils.send_telegram_message("Solana Agent Started. Connecting to mainnet...")
# process_transaction
await SAPI.wallet_watch_loop()
def run_asyncio_tasks():
asyncio.run(main())
if __name__ == '__main__':
import multiprocessing
# Start the asyncio tasks in a separate process
process = multiprocessing.Process(target=run_asyncio_tasks)
process.start()
# Run the ASGI server
uvicorn.run(
"app:asgi_app",
host="0.0.0.0",
port=3001,
log_level="debug",
reload=True
)
# Wait for the asyncio tasks to complete
process.join()