webhook in webui
This commit is contained in:
parent
e56f007082
commit
800cbede4d
1
.gitignore
vendored
1
.gitignore
vendored
@ -26,3 +26,4 @@ cache/*
|
||||
crypto/sol/logs/error.log
|
||||
crypto/sol/logs/token_info.json
|
||||
crypto/sol/logs/transation_details.json
|
||||
.env
|
||||
|
@ -228,7 +228,7 @@ async def follow_move(move):
|
||||
|
||||
token_info = SAPI.dex.TOKENS_INFO.get(move['token_in'])
|
||||
token_name_in = token_info.get('symbol') or await SAPI.get_token_metadata(move['token_in'])
|
||||
token_name_out = SAPI.dex.TOKENS_INFO[move['token_out']].get('symbol') or await solanaAPI.get_token_metadata_symbol(move['token_out'])
|
||||
token_name_out = SAPI.dex.TOKENS_INFO[move['token_out']].get('symbol') or await SAPI.get_token_metadata_symbol(move['token_out'])
|
||||
|
||||
if not your_balance:
|
||||
msg = f"<b>Move not followed:</b>\nNo balance found for token {move['symbol_in']}. Cannot follow move."
|
||||
@ -406,7 +406,7 @@ app = init_app()
|
||||
asgi_app = WsgiToAsgi(app)
|
||||
|
||||
async def main():
|
||||
global solanaAPI, bot, PROCESSING_LOG, pk
|
||||
global bot, PROCESSING_LOG, pk
|
||||
|
||||
pk = await get_pk()
|
||||
await telegram_utils.initialize()
|
||||
|
@ -24,6 +24,7 @@ async def init_db():
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
user_id INTEGER,
|
||||
address TEXT NOT NULL,
|
||||
secret TEXT NOT NULL,
|
||||
name TEXT,
|
||||
FOREIGN KEY (user_id) REFERENCES users(id)
|
||||
);
|
||||
@ -39,7 +40,6 @@ async def init_db():
|
||||
buy_currency TEXT,
|
||||
buy_amount REAL,
|
||||
buy_value REAL,
|
||||
closed BOOLEAN DEFAULT 0,
|
||||
details TEXT,
|
||||
solana_signature TEXT UNIQUE,
|
||||
FOREIGN KEY (wallet_id) REFERENCES wallets(id)
|
||||
@ -51,6 +51,7 @@ async def init_db():
|
||||
currency TEXT,
|
||||
amount REAL,
|
||||
last_updated TEXT,
|
||||
is_base BOOLEAN DEFAULT 0,
|
||||
FOREIGN KEY (wallet_id) REFERENCES wallets(id)
|
||||
);
|
||||
|
||||
@ -257,72 +258,3 @@ def store_api_key(user_id, api_key):
|
||||
# In a real application, you would store this in a database
|
||||
# For this example, we'll just print it
|
||||
print(f"Storing API key {api_key} for user {user_id}")
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# async def get_new_transactions(wallet_address, rpc_url):
|
||||
# async with AsyncClient(rpc_url) as client:
|
||||
# last_tx = await get_last_stored_transaction(wallet_address)
|
||||
|
||||
# if last_tx:
|
||||
# last_signature, last_timestamp = last_tx
|
||||
# else:
|
||||
# # If no transactions are stored, we'll fetch all transactions
|
||||
# last_signature = None
|
||||
# last_timestamp = None
|
||||
|
||||
# new_transactions = []
|
||||
|
||||
# # Get the transaction history for the wallet
|
||||
# tx_history = await client.get_signatures_for_address(wallet_address, before=last_signature)
|
||||
|
||||
# for tx in tx_history.value:
|
||||
# # Check if the transaction is newer than the last stored one
|
||||
# if not last_timestamp or tx.block_time > datetime.fromisoformat(last_timestamp).timestamp():
|
||||
# # Fetch the full transaction details
|
||||
# tx_details = await client.get_transaction(tx.signature, commitment=Confirmed)
|
||||
# new_transactions.append(tx_details)
|
||||
|
||||
# return new_transactions
|
||||
|
||||
# async def process_new_transactions(wallet_id, wallet_address, rpc_url):
|
||||
# new_transactions = await get_new_transactions(wallet_address, rpc_url)
|
||||
|
||||
# for tx in new_transactions:
|
||||
# # Process the transaction and extract relevant information
|
||||
# # This is a placeholder - you'll need to implement the actual logic based on your requirements
|
||||
# transaction_type = "swap" # Determine the type based on the transaction data
|
||||
# sell_currency = "SOL" # Extract from transaction data
|
||||
# sell_amount = 1.0 # Extract from transaction data
|
||||
# sell_value = 100.0 # Extract from transaction data
|
||||
# buy_currency = "USDC" # Extract from transaction data
|
||||
# buy_amount = 100.0 # Extract from transaction data
|
||||
# buy_value = 100.0 # Extract from transaction data
|
||||
# solana_signature = tx.transaction.signatures[0]
|
||||
|
||||
# # Store the transaction in the database
|
||||
# await store_transaction(
|
||||
# wallet_id, transaction_type, sell_currency, sell_amount, sell_value,
|
||||
# buy_currency, buy_amount, buy_value, solana_signature
|
||||
# )
|
||||
|
||||
# # Update holdings
|
||||
# await update_holdings(wallet_id, sell_currency, -sell_amount)
|
||||
# await update_holdings(wallet_id, buy_currency, buy_amount)
|
||||
|
||||
# # After processing all new transactions, close completed transactions
|
||||
# await close_completed_transactions(wallet_id)
|
||||
|
||||
|
||||
|
||||
# Example usage
|
||||
if __name__ == "__main__":
|
||||
import asyncio
|
||||
|
||||
async def main():
|
||||
await init_db()
|
||||
# Add more test functions here
|
||||
|
||||
asyncio.run(main())
|
@ -4,7 +4,7 @@ from flask_login import LoginManager, UserMixin, login_user, login_required, log
|
||||
import secrets
|
||||
from modules import storage, utils, SolanaAPI
|
||||
import os
|
||||
|
||||
import logging
|
||||
|
||||
def init_app():
|
||||
app = Flask(__name__, template_folder='../templates', static_folder='../static')
|
||||
@ -31,6 +31,54 @@ def init_app():
|
||||
login_manager = LoginManager()
|
||||
login_manager.init_app(app)
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
# API
|
||||
@app.route('/tr/<wallet>/<tx_signature>', methods=['GET', 'POST'])
|
||||
async def transaction_notified(wallet, tx_signature):
|
||||
try:
|
||||
logger.info(f"Processing transaction notification for wallet: {wallet}, tx: {tx_signature}")
|
||||
request_data = request.get_json()
|
||||
if not request_data:
|
||||
# Process the transaction
|
||||
# tr = await get_swap_transaction_details(tx_signature)
|
||||
tr = await SolanaAPI.SAPI.get_transaction_details_info(tx_signature, [])
|
||||
else:
|
||||
tr = request_data
|
||||
|
||||
|
||||
# ToDo - probably optimize
|
||||
tr['symbol_in'] = await SolanaAPI.SAPI.get_token_metadata_symbol(tr['token_in'])
|
||||
tr['symbol_out'] = await SolanaAPI.SAPI.get_token_metadata_symbol(tr['token_out'])
|
||||
|
||||
notification = (
|
||||
f"<b>Got TXN notification:</b>: {tr['amount_in']} {tr['symbol_in']} swapped for {tr['symbol_out']} \n"
|
||||
)
|
||||
logging.info(notification)
|
||||
await utils.telegram_utils.send_telegram_message(notification)
|
||||
|
||||
# Store the notified transaction in the database
|
||||
storage.store_transaction(tr)
|
||||
|
||||
# Attempt to execute the copytrade transaction
|
||||
try:
|
||||
await SolanaAPI.SAPI.follow_move(tr)
|
||||
# Store the successful copytrade transaction
|
||||
storage.store_copytrade_transaction(tr, success=True)
|
||||
except Exception as e:
|
||||
# Store the failed copytrade transaction
|
||||
storage.store_copytrade_transaction(tr, success=False, error=str(e))
|
||||
logging.error(f"Copytrade transaction failed: {e}")
|
||||
# ToDo - probably optimize
|
||||
await SolanaAPI.SAPI.save_token_info()
|
||||
return jsonify(tr), 200
|
||||
except Exception as e:
|
||||
logging.error(f"Error processing transaction: {e}")
|
||||
return jsonify({"error": "Failed to process transaction"}), 500
|
||||
|
||||
|
||||
|
||||
|
||||
@app.route('/login/google/authorized')
|
||||
def authorized():
|
||||
# resp = google.authorized_response()
|
||||
@ -135,33 +183,6 @@ def init_app():
|
||||
return jsonify({"error": "Failed to process log"}), 500
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#const webhookPath = `/tr/${followedWallet.toBase58()}/${logs.signature}`;
|
||||
@app.route('/tr/<wallet>/<tx_signature>', methods=['GET', 'POST'])
|
||||
async def transaction_notified(wallet, tx_signature):
|
||||
try:
|
||||
utils.log.info(f"Processing transaction notification for wallet: {wallet}, tx: {tx_signature}")
|
||||
# Process the transaction
|
||||
# tr = await get_swap_transaction_details(tx_signature)
|
||||
tr = await get_transaction_details_info(tx_signature, [])
|
||||
# ToDo - probably optimize
|
||||
await get_token_metadata_symbol(tr['token_in'])
|
||||
await get_token_metadata_symbol(tr['token_out'])
|
||||
await follow_move(tr)
|
||||
await save_token_info()
|
||||
return jsonify(tr), 200
|
||||
except Exception as e:
|
||||
utils.log.error(f"Error processing transaction: {e}")
|
||||
return jsonify({"error": "Failed to process transaction"}), 500
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return app
|
||||
|
||||
# Function to find the latest log file
|
||||
|
2
trading
2
trading
@ -1 +1 @@
|
||||
Subproject commit 78e4a087f0f71c8b8b1b743fa8bd79ef5d6ae5af
|
||||
Subproject commit 9d71f274f8e1e71daef697bed753bd44944d0f97
|
Loading…
x
Reference in New Issue
Block a user