import { ATM } from'atmai';// Replace these placeholders with your actual credentialsconstAPI_KEY='{your-api-key-here}';constAPI_SECRET='{your-api-secret-here}';constAPI_URL='https://api.atmai.fun';exportconstatm=newATM({ apiKey:API_KEY, apiSecret:API_SECRET, apiUrl:API_URL,});
import { atm } from'./atmConfig';// Trend Following Configurationconstconfig= { network:'Solana',// Blockchain network token:'',// Replace with your token of choice tradeAmount:10000,// Amount of tokens to trade per order pollingInterval:5000,// Check price every 50 seconds mevProtection:true,// Enable MEV protection};// Function to buy tokens with MEV protectionasyncfunctionbuyTokens(token:string, amount:number):Promise<void> {try {constresponse=awaitatm.buy({ token, amount, mevProtection:config.mevProtection, });console.log(`Successfully purchased ${amount} of ${token} with MEV protection:`, response); } catch (error) {console.error('Error purchasing tokens:', error); }}// Function to sell tokens with MEV protectionasyncfunctionsellTokens(token:string, amount:number):Promise<void> {try {constresponse=awaitatm.sell({ token, amount, mevProtection:config.mevProtection, });console.log(`Successfully sold ${amount} of ${token} with MEV protection:`, response); } catch (error) {console.error('Error selling tokens:', error); }}// Function to execute trend-following tradesasyncfunctiontrendFollowingStrategy():Promise<void> {try {if (lastPrice ===0) {// Set initial price lastPrice = currentPrice;console.log('Initialized last price:', lastPrice);return; }// Prepare prompt for AI agentconstprompt= { network:config.network, token:config.token, strategy:'follow_trend_atm_v1.0a', tradeAmount:config.tradeAmount, mevProtection:config.mevProtection, };console.log('Sending prompt to AI agent for trend analysis:', prompt);// Use AI agent to decide actionconstaiResponse=awaitatm.executeStrategy(prompt);if (aiResponse.action ==='BUY') {console.log('ATM identified an upward trend. Buying tokens...');awaitbuyTokens(config.token,config.tradeAmount,config.network); lastPrice = currentPrice; // Update the last price after buying } elseif (aiResponse.action ==='SELL') {console.log('ATM identified a downward trend. Selling tokens...');awaitsellTokens(config.token,config.tradeAmount,config.network); lastPrice = currentPrice; // Update the last price after selling } else {console.log('ATM recommended holding. No trade executed.'); } } catch (error) {console.error('Error in trend-following strategy:', error); }}// Main function to execute the strategyasyncfunctionmain():Promise<void> {console.log('Starting Trend Following Strategy on Solana...');setInterval(async () => {console.log('Executing trend-following strategy...');awaittrendFollowingStrategy(); },config.pollingInterval); // Run strategy at regular intervals}// Run the scriptmain().catch((error) => {console.error('Error in main function:', error);});