Your first strategy

Your first strategy

Here is the smallest useful Algolang strategy. It trades nothing; it just says hello to every bar it sees. It follows strategies/demo/go/hello/main.go, with build-stamp and error-formatting boilerplate removed.

Examples use short import notation such as import algolang. This is documentation shorthand: when compiling Go source, substitute the package import configured for your installation.

package main

import algolang

type Hello struct{}

func (h *Hello) Name() string        { return "Hello" }
func (h *Hello) Description() string { return "Logs every bar; the smallest possible strategy." }

func (h *Hello) OnBar(ctx *algolang.Context, bar algolang.Bar) ([]algolang.Order, error) {
    ctx.Logf("hello: %s closed at %g", bar.Symbol, bar.Close)
    return nil, nil
}

func main() {
    if err := algolang.Run(&Hello{}); err != nil {
        panic(err)
    }
}

Three things make a strategy: Name(), Description(), and OnBar, which receives one bar and returns the orders you want to place (here: none). Remove the ctx.Logf call and make the arguments anonymous and this is a pure no-op strategy; nothing else is required. algolang.Run hands your main over to the SDK, which speaks the wire protocol on your behalf. make build already compiled this to bin/hello; the equivalent single command is:

go build -o bin/hello ./strategies/demo/go/hello