Merge branch 'stable' of https://git.d-popov.com/popov/ai-kevin into stable

This commit is contained in:
Dobromir Popov 2024-10-16 12:15:47 +03:00
commit be0e9b54ac
3 changed files with 154 additions and 41 deletions

12
.vscode/launch.json vendored
View File

@ -39,8 +39,8 @@
"console": "integratedTerminal", "console": "integratedTerminal",
"internalConsoleOptions": "neverOpen", "internalConsoleOptions": "neverOpen",
"env": { "env": {
"NODE_ENV": "demo" "NODE_ENV": "demo",
"OPENAI_API_KEY": "OPENAI_API_KEY":""
}, },
"skipFiles": [ "skipFiles": [
"<node_internals>/**" "<node_internals>/**"
@ -69,7 +69,13 @@
"program": "${file}" "program": "${file}"
}, },
{ {
"name": "Python Debugger: Python File with Conda", "name": "py: Sol app.py",
"type": "debugpy",
"request": "launch",
"program": "${workspaceFolder}/crypto/sol/app.py",
},
{
"name": "Python Debugger: Python File with Conda (py)",
"type": "debugpy", "type": "debugpy",
"request": "launch", "request": "launch",
"program": "${file}", "program": "${file}",

View File

@ -816,7 +816,8 @@ async def get_transaction_details_with_retry(transaction_id, retry_delay = 8, ma
break break
except Exception as e: except Exception as e:
logging.error(f"Error fetching transaction details: {e}") logging.error(f"Error fetching transaction details: {e}")
logging.info(f"({_} of {max_retries}) Waiting for transaction details for {transaction_id}") retry_delay = retry_delay * 1.2
logging.info(f"({_} of {max_retries}) Waiting for transaction details for {transaction_id}. retry in {retry_delay} s.")
await asyncio.sleep(retry_delay) await asyncio.sleep(retry_delay)
return tx_details return tx_details
@ -886,7 +887,7 @@ async def process_log(log_result):
i += 1 i += 1
# calculatte percentage swapped by digging before_source_balance, source_token_change and after_source_balance # calculate percentage swapped by digging before_source_balance, source_token_change and after_source_balance
# "Program log: before_source_balance: 19471871, before_destination_balance: 0, amount_in: 19471871, expect_amount_out: 770877527, min_return: 763168752", # "Program log: before_source_balance: 19471871, before_destination_balance: 0, amount_in: 19471871, expect_amount_out: 770877527, min_return: 763168752",
# "Program log: after_source_balance: 0, after_destination_balance: 770570049", # "Program log: after_source_balance: 0, after_destination_balance: 770570049",
@ -1023,7 +1024,7 @@ async def follow_move(move):
# Calculate the amount to swap based on the same percentage as the followed move # Calculate the amount to swap based on the same percentage as the followed move
amount_to_swap = your_balance * (move['percentage_swapped'] / 100) amount_to_swap = your_balance * (move['percentage_swapped'] / 100)
amount_to_swap = min( min(amount_to_swap, your_balance), 300) # amount_to_swap = min( min(amount_to_swap, your_balance), 300)
# # always get 99% of the amount to swap # # always get 99% of the amount to swap
# amount_to_swap = amount_to_swap * 0.95 # amount_to_swap = amount_to_swap * 0.95
@ -1062,7 +1063,7 @@ async def follow_move(move):
input_mint=move['token_in'], input_mint=move['token_in'],
output_mint=move['token_out'], output_mint=move['token_out'],
amount=amount, amount=amount,
slippage_bps=100, # Increased to 1% slippage_bps=300, # Increased to 3%
) )
logging.info(f"Initiating move. Transaction data:\n {transaction_data}") logging.info(f"Initiating move. Transaction data:\n {transaction_data}")
error_logger.info(f"Initiating move. Transaction data:\n {transaction_data}") error_logger.info(f"Initiating move. Transaction data:\n {transaction_data}")
@ -1140,7 +1141,7 @@ SOLANA_ENDPOINTS = [
# "wss://mainnet.rpcpool.com", # "wss://mainnet.rpcpool.com",
] ]
PING_INTERVAL = 30 PING_INTERVAL = 30
SUBSCRIBE_INTERVAL = 1*60 # Resubscribe every 10 minutes SUBSCRIBE_INTERVAL = 10*60 # Resubscribe every 10 minutes
# async def heartbeat(websocket): # async def heartbeat(websocket):
@ -1176,7 +1177,7 @@ async def wallet_watch_loop():
if first_subscription: if first_subscription:
asyncio.create_task( list_initial_wallet_states()) asyncio.create_task( list_initial_wallet_states())
first_subscription = False first_subscription = False
process_task = asyncio.create_task(process_messages(websocket, subscription_id)) process_task = asyncio.create_task(process_messages(websocket))
while True: while True:
try: try:
await asyncio.wait_for(process_task, timeout=SUBSCRIBE_INTERVAL) await asyncio.wait_for(process_task, timeout=SUBSCRIBE_INTERVAL)
@ -1198,7 +1199,7 @@ async def wallet_watch_loop():
# Already subscribed # Already subscribed
logger.info("Already subscribed, continuing with existing subscription") logger.info("Already subscribed, continuing with existing subscription")
if subscription_id: if subscription_id:
process_task = asyncio.create_task(process_messages(websocket, subscription_id)) process_task = asyncio.create_task(process_messages(websocket))
else: else:
# process_messages completed (shouldn't happen unless there's an error) # process_messages completed (shouldn't happen unless there's an error)
@ -1216,7 +1217,7 @@ async def wallet_watch_loop():
await unsubscribe(websocket, subscription_id) await unsubscribe(websocket, subscription_id)
await send_telegram_message("reconnecting...") await send_telegram_message("reconnecting...")
logger.info(f"Attempting to reconnect in {reconnect_delay} seconds...") logger.info(f"Attempting to reconnect in {reconnect_delay} seconds...")
websocket.close() await websocket.close()
except Exception as e: except Exception as e:
logger.error(f"An unexpected error occurred - breaking watch loop: {e}") logger.error(f"An unexpected error occurred - breaking watch loop: {e}")
@ -1236,22 +1237,7 @@ async def subscribe(websocket):
try: try:
await websocket.send(json.dumps(request)) await websocket.send(json.dumps(request))
logger.info("Subscription request sent") logger.info("Subscription request sent")
return await process_messages(websocket)
response = await websocket.recv()
response_data = json.loads(response)
if 'result' in response_data:
subscription_id = response_data['result']
logger.info(f"Subscription successful. Subscription id: {subscription_id}")
return subscription_id
else:
logger.warning(f"Unexpected response: {response_data}")
return None
except websockets.exceptions.ConnectionClosedError as e:
logger.error(f"Connection closed unexpectedly: {e}")
await send_telegram_message("Connection to Solana network was closed. Not listening for transactions right now. Attempting to reconnect...")
await websocket.close()
return None
except Exception as e: except Exception as e:
logger.error(f"An unexpected error occurred: {e}") logger.error(f"An unexpected error occurred: {e}")
return None return None
@ -1268,14 +1254,23 @@ async def unsubscribe(websocket, subscription_id):
logger.info(f"Unsubscribed from subscription id: {subscription_id}") logger.info(f"Unsubscribed from subscription id: {subscription_id}")
subscription_id = None subscription_id = None
async def process_messages(websocket, subscription_id): async def process_messages(websocket):
try: try:
while True: while True:
response = await websocket.recv() response = await websocket.recv()
response_data = json.loads(response) response_data = json.loads(response)
logger.debug(f"Received response: {response_data}") logger.debug(f"Received response: {response_data}")
if 'params' in response_data: if 'result' in response_data:
new_sub_id = response_data['result']
if int(new_sub_id) > 1:
subscription_id = new_sub_id
logger.info(f"Subscription successful. New id: {subscription_id}")
elif new_sub_id:
logger.info(f"Existing subscription confirmed: {subscription_id}")
else: return None
return subscription_id
elif 'params' in response_data:
log = response_data['params']['result'] log = response_data['params']['result']
logger.debug(f"Received transaction log: {log}") logger.debug(f"Received transaction log: {log}")
asyncio.create_task(process_log(log)) asyncio.create_task(process_log(log))

View File

@ -82,12 +82,12 @@
"price": 4.026e-06 "price": 4.026e-06
}, },
"EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v": { "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v": {
"price": 1.001, "price": 1.00028,
"decimals": 6, "decimals": 6,
"name": "USD Coin", "name": "USD Coin",
"symbol": "USDC", "symbol": "USDC",
"address": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v", "address": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
"holdedAmount": 160.755238, "holdedAmount": 51.117694,
"priice": 1.00073 "priice": 1.00073
}, },
"Akev8YDBQfuCv33M1tjDcaUFAsY4Q5izMSfhbozL1Q6j": { "Akev8YDBQfuCv33M1tjDcaUFAsY4Q5izMSfhbozL1Q6j": {
@ -97,7 +97,7 @@
"address": "Akev8YDBQfuCv33M1tjDcaUFAsY4Q5izMSfhbozL1Q6j", "address": "Akev8YDBQfuCv33M1tjDcaUFAsY4Q5izMSfhbozL1Q6j",
"holdedAmount": 511117.33566278, "holdedAmount": 511117.33566278,
"priice": 3.585e-06, "priice": 3.585e-06,
"price": 2.696e-06 "price": 1.714e-09
}, },
"BkVeSP2GsXV3AYoRJBSZTpFE8sXmcuGnRQcFgoWspump": { "BkVeSP2GsXV3AYoRJBSZTpFE8sXmcuGnRQcFgoWspump": {
"price": 0.001581, "price": 0.001581,
@ -146,12 +146,12 @@
"holdedAmount": 176920.153819 "holdedAmount": 176920.153819
}, },
"8Ki8DpuWNxu9VsS3kQbarsCWMcFGWkzzA8pUPto9zBd5": { "8Ki8DpuWNxu9VsS3kQbarsCWMcFGWkzzA8pUPto9zBd5": {
"price": 0.06036, "price": 0.0721,
"decimals": 9, "decimals": 9,
"name": "LOCK IN", "name": "LOCK IN",
"symbol": "LOCKIN", "symbol": "LOCKIN",
"address": "8Ki8DpuWNxu9VsS3kQbarsCWMcFGWkzzA8pUPto9zBd5", "address": "8Ki8DpuWNxu9VsS3kQbarsCWMcFGWkzzA8pUPto9zBd5",
"holdedAmount": 562.91513794 "holdedAmount": 3666.718751598
}, },
"fESbUKjuMY6jzDH9VP8cy4p3pu2q5W2rK2XghVfNseP": { "fESbUKjuMY6jzDH9VP8cy4p3pu2q5W2rK2XghVfNseP": {
"price": 0.0004163, "price": 0.0004163,
@ -220,7 +220,7 @@
"symbol": "SOL", "symbol": "SOL",
"address": "So11111111111111111111111111111111111111112", "address": "So11111111111111111111111111111111111111112",
"priice": 142.85, "priice": 142.85,
"price": 138.13 "price": 154.21
}, },
"4nfn86ssbv7wiqcsw7bpvn46k24jhe334fudtyxhp1og": { "4nfn86ssbv7wiqcsw7bpvn46k24jhe334fudtyxhp1og": {
"symbol": null, "symbol": null,
@ -291,8 +291,8 @@
"name": "Banana Tape Wall", "name": "Banana Tape Wall",
"symbol": "BTW", "symbol": "BTW",
"address": "4ytpZgVoNB66bFs6NRCUaAVsLdtYk2fHq4U92Jnjpump", "address": "4ytpZgVoNB66bFs6NRCUaAVsLdtYk2fHq4U92Jnjpump",
"holdedAmount": 54542.700895, "holdedAmount": 53869.113034,
"price": 0.002082 "price": 0.003814
}, },
"2JcXacFwt9mVAwBQ5nZkYwCyXQkRcdsYrDXn6hj22SbP": { "2JcXacFwt9mVAwBQ5nZkYwCyXQkRcdsYrDXn6hj22SbP": {
"decimals": 6, "decimals": 6,
@ -307,8 +307,8 @@
"name": "real fast", "name": "real fast",
"symbol": "speed", "symbol": "speed",
"address": "5Wd2ALxQfnpgQKCyH4WL9giBiiuuLuJs84CJxfQccvmN", "address": "5Wd2ALxQfnpgQKCyH4WL9giBiiuuLuJs84CJxfQccvmN",
"holdedAmount": 561240.789081, "holdedAmount": 59475.003778,
"price": 0.002958 "price": 0.005088
}, },
"BsTRFEVZhXbBuy5fhxbttuim8iwzXqMdRCfFftDAkkeu": { "BsTRFEVZhXbBuy5fhxbttuim8iwzXqMdRCfFftDAkkeu": {
"decimals": 6, "decimals": 6,
@ -331,8 +331,8 @@
"name": "Honk", "name": "Honk",
"symbol": "HONK", "symbol": "HONK",
"address": "3ag1Mj9AKz9FAkCQ6gAEhpLSX8B2pUbPdkb9iBsDLZNB", "address": "3ag1Mj9AKz9FAkCQ6gAEhpLSX8B2pUbPdkb9iBsDLZNB",
"holdedAmount": 70780.323867533, "holdedAmount": 51532.310973239,
"price": 0.00369 "price": 0.005597
}, },
"7M9KJcPNC65ShLDmJmTNhVFcuY95Y1VMeYngKgt67D1t": { "7M9KJcPNC65ShLDmJmTNhVFcuY95Y1VMeYngKgt67D1t": {
"decimals": 6, "decimals": 6,
@ -341,5 +341,117 @@
"address": "7M9KJcPNC65ShLDmJmTNhVFcuY95Y1VMeYngKgt67D1t", "address": "7M9KJcPNC65ShLDmJmTNhVFcuY95Y1VMeYngKgt67D1t",
"holdedAmount": 118734.201549, "holdedAmount": 118734.201549,
"price": 0.01307 "price": 0.01307
},
"9MBzpyMRkj2r5nTQZMMnxnCm5j1MAAFSYUtbSKjAF3WU": {
"decimals": 9,
"name": "Zoomer",
"symbol": "ZOOMER",
"address": "9MBzpyMRkj2r5nTQZMMnxnCm5j1MAAFSYUtbSKjAF3WU",
"holdedAmount": 14933.802262203,
"price": 0.01624
},
"7GCihgDB8fe6KNjn2MYtkzZcRjQy3t9GHdC8uHYmW2hr": {
"decimals": 9,
"name": "POPCAT",
"symbol": "POPCAT",
"address": "7GCihgDB8fe6KNjn2MYtkzZcRjQy3t9GHdC8uHYmW2hr",
"holdedAmount": 0.000847952,
"price": 1.35
},
"ENKS64JiF1zqUoDK8co94H56jyeSLk7reCL9JMgb9kvN": {
"decimals": 9,
"name": "KODOG",
"symbol": "KODOG",
"address": "ENKS64JiF1zqUoDK8co94H56jyeSLk7reCL9JMgb9kvN",
"holdedAmount": 99.0,
"price": 0.0
},
"8yJ15ee2AUQmwbWPxXLTTeBTzyMGn4MtSRKMqVHw1J1G": {
"decimals": 6,
"name": "KITTY AI",
"symbol": "KITTY",
"address": "8yJ15ee2AUQmwbWPxXLTTeBTzyMGn4MtSRKMqVHw1J1G",
"holdedAmount": 129276.709668,
"price": 0.0009348
},
"Fch1oixTPri8zxBnmdCEADoJW2toyFHxqDZacQkwdvSP": {
"decimals": 9,
"name": "HARAMBE",
"symbol": "HARAMBE",
"address": "Fch1oixTPri8zxBnmdCEADoJW2toyFHxqDZacQkwdvSP",
"holdedAmount": 64709.32823393,
"price": 0.04215
},
"5AnPDx9GposBi9jSW2dFfE5QQD3FmXbudoquMNDxpump": {
"decimals": 6,
"holdedAmount": 96454.077139,
"name": "Dollar",
"symbol": "DOLLAR",
"address": "5AnPDx9GposBi9jSW2dFfE5QQD3FmXbudoquMNDxpump",
"price": 0.001738
},
"6n7Janary9fqzxKaJVrhL9TG2F61VbAtwUMu1YZscaQS": {
"decimals": 6,
"holdedAmount": 165800.081237,
"name": "Ansem's Cat",
"symbol": "Hobbes",
"address": "6n7Janary9fqzxKaJVrhL9TG2F61VbAtwUMu1YZscaQS",
"price": 0.001806
},
"9jaZhJM6nMHTo4hY9DGabQ1HNuUWhJtm7js1fmKMVpkN": {
"decimals": 9,
"name": "AMC",
"symbol": "AMC",
"address": "9jaZhJM6nMHTo4hY9DGabQ1HNuUWhJtm7js1fmKMVpkN",
"holdedAmount": 151990.888522526,
"price": 0.001647
},
"Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB": {
"decimals": 6,
"name": "USDT",
"symbol": "USDT",
"address": "Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB",
"holdedAmount": 0.060209,
"price": 0.9998
},
"8vCAUbxejdtaxn6jnX5uaQTyTZLmXALg9u1bvFCAjtx7": {
"decimals": 6,
"name": "ZACK MORRIS",
"symbol": "ZACK",
"address": "8vCAUbxejdtaxn6jnX5uaQTyTZLmXALg9u1bvFCAjtx7",
"holdedAmount": 7313.78243,
"price": 0.02023
},
"EKEWAk7hfnwfR8DBb1cTayPPambqyC7pwNiYkaYQKQHp": {
"decimals": 6,
"name": "Roaring Kitty",
"symbol": "KITTY",
"address": "EKEWAk7hfnwfR8DBb1cTayPPambqyC7pwNiYkaYQKQHp",
"holdedAmount": 228658.544423,
"price": 0.003091
},
"FtHCi9cxJSSizrzMzsPjAfTfJi32V1CGRDM5Skqn4QBF": {
"decimals": 6,
"name": "pixi",
"symbol": "pixi",
"address": "FtHCi9cxJSSizrzMzsPjAfTfJi32V1CGRDM5Skqn4QBF",
"holdedAmount": 211191.26677,
"price": 0.001234
},
"BuxH23osRyFFLbWG3czrTsfBQYbxzVZ8f7QV4cjTHN5x": {
"decimals": 6,
"name": "John",
"symbol": "JOHN",
"address": "BuxH23osRyFFLbWG3czrTsfBQYbxzVZ8f7QV4cjTHN5x",
"holdedAmount": 69195.568536,
"price": 0.004173
},
"J7tYmq2JnQPvxyhcXpCDrvJnc9R5ts8rv7tgVHDPsw7U": {
"decimals": 6,
"name": "George Droyd",
"symbol": "FLOYDAI",
"address": "J7tYmq2JnQPvxyhcXpCDrvJnc9R5ts8rv7tgVHDPsw7U",
"holdedAmount": 22523.013616,
"price": 0.007335
} }
} }