Skip to content

krew-solutions/goflux

 
 

Repository files navigation

GoFlux

Go Reference Go Report Card License CodSpeed

GoFlux is a modern technical analysis library for Go, forked from techan by sdcoffey. This project aims to revitalize and expand the library with modern Go best practices, comprehensive testing, and additional technical analysis indicators.

Features

  • 35+ technical analysis indicators (trend, momentum, volume, moving averages)
  • Performance metrics (Sharpe, Sortino, Calmar, CAGR, drawdown, and more)
  • Candlestick pattern detection (20+ patterns)
  • Rule-based strategy engine (AND/OR/NOT, trailing stops, time-based exits)
  • Backtesting engine with trade & equity analytics
  • Time series utilities (resampling, Heikin Ashi, Renko)

Installation

$ go get github.com/irfndi/goflux@latest

Quickstart

package main

import (
	"fmt"
	"log"
	"strconv"
	"time"

	"github.com/irfndi/goflux/pkg"
)

func main() {
	if err := run(); err != nil {
		log.Fatal(err)
	}
}

func run() error {
	series := goflux.NewTimeSeries()

	// fetch this from your preferred exchange
	dataset := [][]string{
		// Timestamp, Open, Close, High, Low, volume
		{"1234567", "1", "2", "3", "5", "6"},
	}

	for _, datum := range dataset {
		start, _ := strconv.ParseInt(datum[0], 10, 64)
		period := goflux.NewTimePeriod(time.Unix(start, 0), time.Hour*24)

		candle := goflux.NewCandle(period)
		open, err := goflux.NewDecimalFromStringWithError(datum[1])
		if err != nil {
			return err
		}
		closePrice, err := goflux.NewDecimalFromStringWithError(datum[2])
		if err != nil {
			return err
		}
		maxPrice, err := goflux.NewDecimalFromStringWithError(datum[3])
		if err != nil {
			return err
		}
		minPrice, err := goflux.NewDecimalFromStringWithError(datum[4])
		if err != nil {
			return err
		}
		volume, err := goflux.NewDecimalFromStringWithError(datum[5])
		if err != nil {
			return err
		}

		candle.OpenPrice = open
		candle.ClosePrice = closePrice
		candle.MaxPrice = maxPrice
		candle.MinPrice = minPrice
		candle.Volume = volume

		series.AddCandle(candle)
	}

	closePrices := goflux.NewClosePriceIndicator(series)
	movingAverage := goflux.NewEMAIndicator(closePrices, 10)

	fmt.Println(movingAverage.Calculate(0).FormattedString(2))
	return nil
}

Creating trading strategies

indicator := goflux.NewClosePriceIndicator(series)

// record trades on this object
record := goflux.NewTradingRecord()

entryConstant := goflux.NewConstantIndicator(30)
exitConstant := goflux.NewConstantIndicator(10)

// Is satisfied when the price ema moves above 30 and the current position is new
entryRule := goflux.And(
	goflux.NewCrossUpIndicatorRule(entryConstant, indicator),
	goflux.PositionNewRule{})
	
// Is satisfied when the price ema moves below 10 and the current position is open
exitRule := goflux.And(
	goflux.NewCrossDownIndicatorRule(indicator, exitConstant),
	goflux.PositionOpenRule{})

strategy := goflux.RuleStrategy{
	UnstablePeriod: 10, // Index at or below which ShouldEnter and ShouldExit return false
	EntryRule:      entryRule,
	ExitRule:       exitRule,
}

strategy.ShouldEnter(0, record) // returns false

Issue Tracking

This project uses Beads for issue tracking - a modern, AI-native tool designed for live directly in your codebase alongside your code.

Learn more: github.com/steveyegge/beads

For Developers

# Find available work
bd ready

# View issue details
bd show <issue-id>

# Claim work
bd update <issue-id> --status in_progress

# Complete work
bd close <issue-id>

# Sync with git
bd sync

Multi-Developer Collaboration

This project uses Protected Branch Mode for team collaboration:

  • Issues are automatically committed to beads-sync branch
  • main branch stays protected
  • Team members review and merge metadata via PR
  • See CONTRIBUTING.md for setup instructions

Installation

# Install Beads
curl -sSL https://raw.githubusercontent.com/steveyegge/beads/main/scripts/install.sh | bash

# Initialize in this repo (already configured)
bd ready

Roadmap

Run bd ready or bd list to see current planned improvements and tasks in progress.

Past work includes:

  • Modern project structure
  • Additional indicators and utilities
  • Expanded trading and risk-management rules
  • Comprehensive testing suite
  • Improved documentation
  • CI/CD pipeline with GitHub Actions

Migration from Techan

GoFlux maintains backward compatibility with the original techan API. Simply update your imports:

// Old
import "github.com/sdcoffey/techan"

// New
import "github.com/irfndi/goflux/pkg"

The package name is goflux, so you can use it directly:

import "github.com/irfndi/goflux/pkg"

// Usage
series := goflux.NewTimeSeries()

Contributing

Contributions are welcome! Please see CONTRIBUTING.md for guidelines on how to contribute.

To contribute:

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes with tests
  4. Submit a pull request

Acknowledgments

GoFlux builds on the pioneering work of the technical analysis community:

  • techan (sdcoffey) – the original Go technical analysis library and direct foundation of this project.
  • ta4j – a mature Java TA framework whose strategy composition and indicator design patterns heavily influenced GoFlux's architecture.
  • TA‑Lib – the long-standing C/C++ technical analysis library (200+ indicators and candlestick patterns) that serves as a reference standard for indicator behavior and naming.
  • Pandas TA (Python) – for ideas around indicator catalogs, composition patterns, and declarative strategy definitions.
  • YATA (Rust) – for performance-oriented designs and trait-based indicator patterns.
  • Backtrader – the Python backtesting framework that inspired GoFlux's analyzer and observer patterns.
  • VectorBT – for vectorized operations and portfolio simulation approaches.

GoFlux aims to bring these proven ideas into a modern, idiomatic Go library focused on concurrent, cloud-native trading systems.

License

GoFlux is released under the MIT license. See LICENSE for details.

About

Technical Analysis Library for Golang

Resources

License

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • Go 98.7%
  • Other 1.3%