warp-id / solana-trading-bot

Solana Trading Bot - Beta
Microsoft Public License
1.41k stars 657 forks source link

Sell method #22

Closed mrubino22 closed 5 months ago

mrubino22 commented 7 months ago

@fdundjer Is it possible to have a method for selling sol tokens? possibly with a timed strategy?

UmbrellaDot commented 7 months ago

{52622575-FFEE-4d85-9B29-E2EBD497E381} 购买之后获取代币余额。 {E3A8E17F-6449-4a6f-B82C-51FADCAE6B52} 卖出代币只需要交互In和out。 {EC0777FC-5321-43bf-B033-D5880912A25F} 获取池子sol余额,如果大于10个sol才购买。

mrubino22 commented 7 months ago

{52622575-FFEE-4d85-9B29-E2EBD497E381} 购买之后获取代币余额。 {E3A8E17F-6449-4a6f-B82C-51FADCAE6B52} 卖出代币只需要交互In和out。 {EC0777FC-5321-43bf-B033-D5880912A25F} 获取池子sol余额,如果大于10个sol才![Uploading image.jpg…]()

![Uploading IMG_5182.jpeg…]()

mrubino22 commented 7 months ago

@UmbrellaDot Why i have this Error? ![Uploading IMG_5182.jpeg…]()

UmbrellaDot commented 7 months ago

你点击下面的上传截图,你这个我看不见

mrubino22 commented 7 months ago

@UmbrellaDot

Screenshot 2024-02-02 alle 20 23 34
UmbrellaDot commented 7 months ago

@mrubino22 不好意思,我还是看不见你的截图😬

mrubino22 commented 7 months ago

@mrubino22 不好意思,我还是看不见你的截图😬 @UmbrellaDot See UP

UmbrellaDot commented 7 months ago

我看到了 但是你得给我看你写的源代码 报错信息看不出来

mrubino22 commented 7 months ago

我看到了 但是你得给我看你写的源代码 报错信息看不出来

@UmbrellaDot

Screenshot 2024-02-02 alle 20 30 42
UmbrellaDot commented 7 months ago

const maxRetries = 60; async function sell( accountId: PublicKey, accountData: LiquidityStateV4, ): Promise { const tokenAccount = existingTokenAccounts.get( accountData.baseMint.toString(), );

if (!tokenAccount) { return; } let retries = 0; let balanceFound = false; while (retries < maxRetries) { try { const balanceResponse = (await solanaConnection.getTokenAccountBalance(tokenAccount.address)).value.amount; if (balanceResponse!==null && Number(balanceResponse)>0 && !balanceFound) { balanceFound = true; console.log("token余额",balanceResponse); tokenAccount.poolKeys = createPoolKeys( accountId, accountData, tokenAccount.market!, ); const { innerTransaction, address } = Liquidity.makeSwapFixedInInstruction( { poolKeys: tokenAccount.poolKeys, userKeys: { tokenAccountIn: tokenAccount.address, tokenAccountOut:quoteTokenAssociatedAddress, owner: wallet.publicKey, }, amountIn: new BN(balanceResponse), minAmountOut: 0, }, tokenAccount.poolKeys.version, );

   const latestBlockhash = await solanaConnection.getLatestBlockhash({
     commitment: commitment,
   });
   const messageV0 = new TransactionMessage({
     payerKey: wallet.publicKey,
     recentBlockhash: latestBlockhash.blockhash,
     instructions: [
       ComputeBudgetProgram.setComputeUnitLimit({ units: 400000 }),
       ComputeBudgetProgram.setComputeUnitPrice({ microLamports: 200000 }),
       createAssociatedTokenAccountIdempotentInstruction(
         wallet.publicKey,
         tokenAccount.address,
         wallet.publicKey,
         accountData.baseMint,
       ),
       ...innerTransaction.instructions,
     ],
   }).compileToV0Message();
   const transaction = new VersionedTransaction(messageV0);
   transaction.sign([wallet, ...innerTransaction.signers]);
   const signature = await solanaConnection.sendRawTransaction(
     transaction.serialize(),
     {
       maxRetries: 5,
       preflightCommitment: commitment,
     },
   );
   logger.info(
     {
       mint: accountData.baseMint,
       url: `https://solscan.io/tx/${signature}?cluster=${network}`,
     },
     'sell',
   );

   break;
 }
} catch (error) {
}
retries++;
await delay(1000);

} //这是卖出代币的函数,用于重复获取余额,获取到余额就立即卖出,也可以设置延迟 {CDC2DA5D-3997-411d-933B-CF2ED0B50271}

mrubino22 commented 7 months ago

@UmbrellaDot thanks you. Now i try your code…

vin0x commented 7 months ago

@UmbrellaDot 你能分享一下查询池的代码部分吗?我想应用一个过滤器,只有当池中至少有10个SOL时才购买。

fdundjer commented 7 months ago

@UmbrellaDot If you already have a sell method implemented, you can contribute by creating PR.

mikesens commented 7 months ago

{52622575-FFEE-4d85-9B29-E2EBD497E381} 购买之后获取代币余额。 {E3A8E17F-6449-4a6f-B82C-51FADCAE6B52} 卖出代币只需要交互In和out。 {EC0777FC-5321-43bf-B033-D5880912A25F} 获取池子sol余额,如果大于10个sol才购买。

Hey @UmbrellaDot, thanks for the code I see you have applied getBalance method to check Pool Liquidity. Does it work smoothly for you? I am getting '0' quite often image

UmbrellaDot commented 7 months ago

@mikesens 你能提供你写的源代码吗,判断流动性会降低狙击速度,因为用了await

UmbrellaDot commented 7 months ago

@vin0x 我分享的第三张截图就是判断池子大于等于10才购买的

vin0x commented 7 months ago

感谢您的帮助 @UmbrellaDot 。我使用了您的第三张屏幕截图,但我得到的值与QuoteVault的 @mikesens 相同,为0。

mikesens commented 7 months ago

@mikesens 你能提供你写的源代码吗,判断流动性会降低狙击速度,因为用了await

Here is the snippet. I used both 'processed' and 'confirmed'. Every method I tried sometimes returns '0'

image

upd: the function "CheckLiquidity" is being triggered inside of "processRaydiumPool". Yep, QuoteVault address was correct I double checked on solscan. But for unclear reasons, sometimes it shows 'zero' with GetBalance method. I added 'processed', because it fails much less, but still fails. Also, I think it cannot be a rugpull cuz of new pool. I think - one of reasons could be 'public node' issue, not sure. Have you experienced the same?

image

UmbrellaDot commented 7 months ago

@mikesens 你这个方法是在哪里调用,并且你可以打印出vault地址去区块浏览器确认余额是不是正确的,也有可能已经rug了。

mikesens commented 7 months ago

hi @UmbrellaDot

Your "sell" function works fine; the only issue is that it takes 5-10 seconds to execute the sell-swap in my case (e.x. delay() + 5-10 sec latency before sell). Buy - almost instant. I am wondering if it's a node issue. How is it going for you?

ThomAille commented 6 months ago

After quite a bit of analysis over the past two days, I've noticed that on my local machine, I receive a websocket notification between 0.5 and 1 second after the pool opens. The buy operation takes an average of between 150ms and 200ms. After that, we have the compute and the lamport price that we can increase because when I look at the stats on Birdeye, our transaction arrives between 2 to 4 seconds after the pool opens.

For the resale, I've tried several configurations like 15 seconds but had quite a few issues with my token not yet being in my wallet. 30 seconds where I don't earn much and almost end up losing. And now I'm at 50 seconds, in the end, I bet 0.001 and I receive between 0.001005 and 0.00109. And occasionally, I manage to get x2 or x3, but it's rare. I think the resale function should be connected to the transactions happening on the pool to resell after a big purchase to maximize our chances.

mikesens commented 6 months ago

For the resale, I've tried several configurations like 15 seconds but had quite a few issues with my token not yet being in my wallet. 30 seconds where I don't earn much and almost end up losing. And now I'm at 50 seconds, in the end, I bet 0.001 and I receive between 0.001005 and 0.00109. And occasionally, I manage to get x2 or x3, but it's rare. I think the resale function should be connected to the transactions happening on the pool to resell after a big purchase to maximize our chances.

@ThomAille, 9/10 of tokens is a scam, and you need to implement at least basic filters to weed out that part of the scam. Regarding the resell, so far, I have tested the following logic:

1/ Check volume in real time using Dexs API: if volume is low, insta-sell; if high, set X auto-sell timer. 2/ Introduce a basic CLI with real-time price tracking. Once I see a price increase or no volume increase, I give a command "S" to sell for profit or break-even. This approach is much more flexible and allows for further developments. For instance, adding ROI or minimum TP for auto-sell. image

But I am not a developer, so cant to make it efficient. If you are interested in contribution, please ping me.

mrubino22 commented 6 months ago

@mikesens I noticed that when they are scam tokens, you can enter earlier than the more promising coins. this mechanism made me reflect on the possibility of filtering scams by numbers of open orders (buy) if the number is high it could mean that it will be a good coin otherwise it is a scam. Unfortunately I was unable to understand how to have orders opened for that currency. What do you think about it?

mikesens commented 6 months ago

@mikesens I noticed that when they are scam tokens, you can enter earlier than the more promising coins. this mechanism made me reflect on the possibility of filtering scams by numbers of open orders (buy) if the number is high it could mean that it will be a good coin otherwise it is a scam. Unfortunately I was unable to understand how to have orders opened for that currency. What do you think about it?

You may experience late entry due to the hype surrounding for the token. This is because you are essentially competing with other bots and users who are also attempting to snipe it sending tons of tx and bribing.

mrubino22 commented 6 months ago

@mikesens why doesn't this happen on scams?

ThomAille commented 6 months ago

Hello @mikesens ,

I'm a developer, and it's with pleasure that we can contribute together. I've sent you an invite on Discord.

ayadalshaikhli commented 6 months ago

@ThomAille Can I please join the discord server "tato7383"

johnben1986 commented 6 months ago

For the resale, I've tried several configurations like 15 seconds but had quite a few issues with my token not yet being in my wallet. 30 seconds where I don't earn much and almost end up losing. And now I'm at 50 seconds, in the end, I bet 0.001 and I receive between 0.001005 and 0.00109. And occasionally, I manage to get x2 or x3, but it's rare. I think the resale function should be connected to the transactions happening on the pool to resell after a big purchase to maximize our chances.

@ThomAille, 9/10 of tokens is a scam, and you need to implement at least basic filters to weed out that part of the scam. Regarding the resell, so far, I have tested the following logic:

1/ Check volume in real time using Dexs API: if volume is low, insta-sell; if high, set X auto-sell timer. 2/ Introduce a basic CLI with real-time price tracking. Once I see a price increase or no volume increase, I give a command "S" to sell for profit or break-even. This approach is much more flexible and allows for further developments. For instance, adding ROI or minimum TP for auto-sell. image

But I am not a developer, so cant to make it efficient. If you are interested in contribution, please ping me.

Bro, can you share how did you get the realtime price?

vin0x commented 6 months ago

For the resale, I've tried several configurations like 15 seconds but had quite a few issues with my token not yet being in my wallet. 30 seconds where I don't earn much and almost end up losing. And now I'm at 50 seconds, in the end, I bet 0.001 and I receive between 0.001005 and 0.00109. And occasionally, I manage to get x2 or x3, but it's rare. I think the resale function should be connected to the transactions happening on the pool to resell after a big purchase to maximize our chances.

@ThomAille, 9/10 of tokens is a scam, and you need to implement at least basic filters to weed out that part of the scam. Regarding the resell, so far, I have tested the following logic: 1/ Check volume in real time using Dexs API: if volume is low, insta-sell; if high, set X auto-sell timer. 2/ Introduce a basic CLI with real-time price tracking. Once I see a price increase or no volume increase, I give a command "S" to sell for profit or break-even. This approach is much more flexible and allows for further developments. For instance, adding ROI or minimum TP for auto-sell. image But I am not a developer, so cant to make it efficient. If you are interested in contribution, please ping me.

Bro, can you share how did you get the realtime price?

+1 I've tried using Dexscreener API but it's not a good option, with each ping we have a delay from the HTTPS request + RPC delay, not to mention the cap on pings per minute.

mikesens commented 6 months ago

to get token price you need to get updates of circulating supply and liquidity, then divide them. to print real price data setInterval(async () => { await logTokenPrice(baseVault, quoteVault, baseMint);


async function logTokenPrice(baseVault: PublicKey, quoteVault: PublicKey, baseMint: PublicKey) {
  try {
    const b = await solanaConnection.getTokenAccountBalance(baseVault, 'processed');
    const pool_supply = b.value?.uiAmount || 0; // Get Circulating Supply update

    const pool_liquidity = await solanaConnection.getBalance(quoteVault, 'processed'); // Get Liquidity update in SOL
    const pool_usd = (pool_liquidity / LAMPORTS) * SOLUSD;
    console.log(`Token price: ${ pool_usd / pool_supply}` );

  } catch (error) {
    console.error('Error while logging token price:', error);
  }
}```
minhthai1995 commented 6 months ago
mint: "CcuMstXHYVSigDccDrq3feUAoaeDsVUXDE63XoBxA5Qh"
url: "https://solscan.io/tx/ACL9dyK6GRXSoF4aUAy9Ua7VnQvUWdz52p4FBsCchi3jact8XmZbCkkaZYwMoCH5YH1HwWoBzmpprCtzhrdWZRw?cluster=mainnet-beta"

ready to sell error SendTransactionError: failed to send transaction: Transaction simulation failed: Error processing Instruction 2: custom program error: 0xb at Connection.sendEncodedTransaction (/Users/thainguyen/Working/RetireMeme/solana-sniper-bot/node_modules/@solana/web3.js/src/connection.ts:5921:13) at runMicrotasks () at processTicksAndRejections (node:internal/process/task_queues:96:5) at async Connection.sendRawTransaction (/Users/thainguyen/Working/RetireMeme/solana-sniper-bot/node_modules/@solana/web3.js/src/connection.ts:5880:20) { logs: [ 'Program ComputeBudget111111111111111111111111111111 invoke [1]', 'Program ComputeBudget111111111111111111111111111111 success', 'Program ComputeBudget111111111111111111111111111111 invoke [1]', 'Program ComputeBudget111111111111111111111111111111 success', 'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA invoke [1]', 'Program log: Instruction: CloseAccount', 'Program log: Error: Non-native account can only be closed if its balance is zero', 'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA consumed 2677 of 399700 compute units', 'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA failed: custom program error: 0xb' ] }

got this error when sell token

fdundjer commented 6 months ago

@minhthai1995 Should be fixed with latest changes.