Skip to content

In addition to using the built-in terminal commands of banbot, you can also register and execute your own terminal commands.

Registering Regular Functions

You can register terminal command functions using the entry.AddCmdJob method:

go
entry.AddCmdJob(&entry.CmdJob{
    Name:    "hello",
    Parent:  "",
    Run: func(args *config.CmdArgs) *errs.Error {
        fmt.Println("hello")
        return nil
    },
    Options: []string{},
    Help:    "show hello",
})

You can then trigger the execution of the showHello function by typing bot hello. This function will accept a *config.CmdArgs parameter, which stores the parsed command-line arguments. If you need to access specific arguments, please fill in the required field names in the Options section. All available field names can be found in the bindSubFlags function in entry/main.

Registering Functions with Arbitrary Arguments

Fixed Options and *config.CmdArgs might not meet your personalized needs. You can also use RunRaw to replace Run and parse the command-line arguments yourself:

go
entry.AddCmdJob(&entry.CmdJob{
    Name:   "hello",
    Parent: "",
    RunRaw: func(args []string) error {
        fmt.Println(strings.Join(args, " "))
        return nil
    },
    Help:    "show hello",
})

Example of Reading Data to Generate a Candlestick Chart

By using the custom terminal commands described above, you can freely call the relevant interfaces provided by banbot to implement various complex tasks, not just the built-in backtesting, trading, etc.

For example, you can read the K-line data of a specified instrument and generate a static HTML candlestick chart: demo