Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wip: Auto Trader - Super Goat #1100

Closed
wants to merge 1 commit into from
Closed

Conversation

Freytes
Copy link
Contributor

@Freytes Freytes commented Dec 14, 2024

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;

@monilpat monilpat marked this pull request as draft December 14, 2024 17:20
@monilpat monilpat changed the base branch from main to develop December 14, 2024 17:20
@odilitime odilitime deleted the branch elizaOS:develop December 17, 2024 02:33
@odilitime odilitime closed this Dec 17, 2024
@odilitime odilitime reopened this Dec 17, 2024
@shakkernerd shakkernerd deleted the branch elizaOS:develop December 17, 2024 03:45
@odilitime odilitime reopened this Dec 17, 2024
@shakkernerd shakkernerd deleted the branch elizaOS:develop December 22, 2024 07:01
@odilitime odilitime reopened this Dec 22, 2024
@Freytes
Copy link
Contributor Author

Freytes commented Dec 25, 2024

Closing PR, will contribute a new PR for this build as needed.

@Freytes Freytes closed this Dec 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants