eliza
eliza copied to clipboard
wip: Auto Trader - Super Goat
Auto Trader works and trades tokens listed in /characters/tokens when placed in a JSON file.
See readme for configuration requirements.
Don't forget to update your client-auto:
import { Client, IAgentRuntime, elizaLogger } from "@ai16z/eliza";
import createGoatPlugin from "@ai16z/plugin-goat";
export class AutoClient {
interval: NodeJS.Timeout;
runtime: IAgentRuntime;
constructor(runtime: IAgentRuntime) {
this.runtime = runtime;
// Initialize plugin first
this.initializePlugin().then(() => {
// Start trading loop after plugin is initialized
this.interval = setInterval(
async () => {
await this.executeTradingCycle();
},
60 * 60 * 1000 // 1 hour in milliseconds
);
}).catch(error => {
elizaLogger.error("Failed to initialize auto client:", error);
throw error;
});
}
private async initializePlugin() {
try {
const plugin = await createGoatPlugin(
(key: string) => this.runtime.getSetting(key),
this.runtime
);
elizaLogger.log("GOAT plugin initialized successfully");
} catch (error) {
elizaLogger.error("Failed to initialize GOAT plugin:", error);
throw error;
}
}
private async executeTradingCycle() {
try {
elizaLogger.log("Running auto client trading cycle...");
// Trading logic is handled by the plugin itself
} catch (error) {
elizaLogger.error("Error in trading cycle:", error);
}
}
}
export const AutoClientInterface: Client = {
start: async (runtime: IAgentRuntime) => {
const client = new AutoClient(runtime);
return client;
},
stop: async (_runtime: IAgentRuntime) => {
console.warn("Direct client does not support stopping yet");
},
};
export default AutoClientInterface;