Skip to main content

python bindings for banta

Project description

BanTA Technical Analysis Library

中文文档
banta is a high-performance technical analysis indicator library that supports both state-caching and parallel computation modes. It aims to provide a highly flexible, high-performance, and user-friendly indicator framework.

DeepWiki Q&A

  • State-Caching Mode: Updates and caches on each candle, eliminating the need to recalculate historical data. Indicator results are globally reused, similar to TradingView.
  • Parallel Computation Mode: Computes all candles at once without caching. New candles require a full recalculation, similar to TA-Lib.
  • NaN Compatibility: Intelligently skips NaN values in input data, resuming calculations with the previous state.
  • Rigorous Testing: Each indicator is validated with unit tests under various conditions and compared against results from common indicator libraries.
  • Lightweight & Dependency-Free: Pure Go implementation with zero external dependencies.

Supported Indicators

Consistency Comparison with Common Indicator Platforms

banta MyTT TA-lib Class TA-lib Metastock Pandas-TA TradingView
AvgPrice
Sum
SMA T1
EMA T1 T1 T2
EMABy1 T1 T2 T2 T3
RMA -- -- -- T1 --
VWMA -- -- --
WMA
HMA -- -- --
TR -- --
ATR T1 T2 T3
MACD T1 T2 T1 T3
RSI T1 T2 T3
KDJ T1 T2 T1 T3
Stoch -- --
BBANDS
Aroon -- T1
ADX -- T1 T2
ADXBy1 -- T1 T1 T2
PluMinDI -- -- --
PluMinDM -- -- --
ROC --
TNR/ER -- -- -- -- --
CCI
CMF -- -- --
KAMA -- T1 ✔~
WillR --
StochRSI -- ✔~
MFI
RMI -- -- -- -- ✔~
CTI -- -- -- T1
LinReg -- -- -- ?
CMO -- T1
CMOBy1 -- T1 T1 T1
CHOP -- -- -- T1
ALMA -- -- -- T1
Stiffness -- -- -- --
PercentRank -- -- -- -- ✔~
CRSI -- -- -- -- ✔~
CRSIBy1 -- community -- -- --
DV -- -- -- -- --
UTBot -- -- -- --
STC -- -- -- --
--  This platform does not have the indicator  
✔  Consistent with this platform's results  
✔~ Mostly consistent with this platform's results (minor deviations)  
Ti Inconsistent with this platform's results  

How to Use (State-Caching Mode)

import (  
	"fmt"  
	ta "github.com/banbox/banta"  
)  

var envMap = make(map[string]*ta.BarEnv)  

func OnBar(symbol string, timeframe string, bar *ta.Kline) {  
	envKey := fmt.Sprintf("%s_%s", symbol, timeframe)  
	e, ok := envMap[envKey]  
	if !ok {  
		e = &ta.BarEnv{  
			TimeFrame: timeframe,  
			BarNum:    1,  
		}  
		envMap[envKey] = e  
	}  
	e.OnBar(bar)  
	ma5 := ta.SMA(e.Close, 5)  
	ma30 := ta.SMA(e.Close, 30)  
	atr := ta.ATR(e.High, e.Low, e.Close, 14).Get(0)  
	xnum := ta.Cross(ma5, ma30)  
	if xnum == 1 {  
		// ma5 cross up ma30  
		curPrice := e.Close.Get(0) // or bar.Close  
		stopLoss := curPrice - atr  
		fmt.Printf("open long at %f, stoploss: %f", curPrice, stopLoss)  
	} else if xnum == -1 {  
		// ma5 cross down ma30  
		curPrice := e.Close.Get(0)  
		fmt.Printf("close long at %f", curPrice)  
	}  
	kdjRes := ta.KDJ(e.High, e.Low, e.Close, 9, 3, 3).Cols  
	k, d := kdjRes[0], kdjRes[1]  
}  

Core Concept

Traditional technical analysis libraries like TA-Lib and Pandas-TA are widely used and highly optimized for performance, making them extremely fast when computing hundreds or thousands of candles at once.
However, when your trading bot uses these libraries in live trading, every new candle requires passing in hundreds of historical candles. If you're running multiple symbols or operating on 1-minute or even 1-second timeframes, the computational delay can become unbearable.
Many are familiar with TradingView, which uses Pine Script—an event-driven technical analysis engine. It doesn't recalculate historical candles upon receiving a new one but instead reuses cached results.
This is the philosophy behind BanTA: event-driven computation, processing each candle as it arrives while leveraging cached results.

How State Caching Works in BanTA

In BanTA, state caching revolves around the Series sequence type. Most return values are sequences, and the Series struct includes a Data []float64 field that records the indicator's values across candles.
For example, e.Close is the closing price sequence, and e.Close.Get(0) retrieves the current closing price as a float64.
Calculating a moving average is straightforward: ma5 := ta.SMA(e.Close, 5), which returns another sequence.
Some indicators like KDJ return multiple fields: kdjRes := ta.KDJ(e.High, e.Low, e.Close, 9, 3, 3).Cols, where Cols contains an array of sequences (e.g., K and D lines).

How to Use (Parallel Computation)

import (  
	"github.com/banbox/banta/tav"  
)  

func main(){  
	highArr := []float64{1.01, 1.01, 1.02, 0.996, 0.98, 0.993, 0.99, 1.0, 1.02}  
    lowArr := []float64{0.99, 1.0, 1.0, 0.98, 0.965, 0.98, 0.98, 0.984, 1.0}  
	closeArr := []float64{1.0, 1.01, 1.0, 0.99, 0.97, 0.981, 0.988, 0.992, 1.002}  
	sma := tav.SMA(closeArr, 5)  
    ma30 := tav.SMA(closeArr, 30)  
    atr := tav.ATR(highArr, lowArr, closeArr, 14)  
    xArr := tav.Cross(ma5, ma30)  
}  

Note

For research purposes, we recommend using parallel computation to compute indicators in bulk. For live trading or event-driven backtesting, state-cached indicators offer higher efficiency.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

bbta-0.3.0-cp311-cp311-win_amd64.whl (2.0 MB view details)

Uploaded CPython 3.11Windows x86-64

bbta-0.3.0-cp311-cp311-musllinux_1_2_x86_64.whl (2.0 MB view details)

Uploaded CPython 3.11musllinux: musl 1.2+ x86-64

bbta-0.3.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.9 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ ARM64

bbta-0.3.0-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.0 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64manylinux: glibc 2.5+ x86-64

bbta-0.3.0-cp310-cp310-musllinux_1_2_x86_64.whl (1.8 MB view details)

Uploaded CPython 3.10musllinux: musl 1.2+ x86-64

bbta-0.3.0-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.8 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64manylinux: glibc 2.5+ x86-64

bbta-0.3.0-cp310-cp310-macosx_11_0_arm64.whl (1.0 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

bbta-0.3.0-cp310-cp310-macosx_10_9_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.10macOS 10.9+ x86-64

File details

Details for the file bbta-0.3.0-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: bbta-0.3.0-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 2.0 MB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for bbta-0.3.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 f43cbe4d68661d2276ead2ce7b667814fc0edae8fa3cca35d474b634d65decb6
MD5 a65ef6b411701c57cb0a45e989935d96
BLAKE2b-256 81e28b0617378f8efb14b527702e1617c7eccead11e55b5ed69dae8ad47a3b96

See more details on using hashes here.

Provenance

The following attestation bundles were made for bbta-0.3.0-cp311-cp311-win_amd64.whl:

Publisher: build_wheels.yml on banbox/banta

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file bbta-0.3.0-cp311-cp311-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for bbta-0.3.0-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 778d5c6cc939a2d2fbb420be4eb42d944eaaa5f49662c8aeb9b52416099f90ba
MD5 569bdda661d4ff70214157839318807f
BLAKE2b-256 3c557e4af310b96a253944877284bbf12b1f6f0ee1c88d31395d88a736a55aeb

See more details on using hashes here.

Provenance

The following attestation bundles were made for bbta-0.3.0-cp311-cp311-musllinux_1_2_x86_64.whl:

Publisher: build_wheels.yml on banbox/banta

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file bbta-0.3.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for bbta-0.3.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 f96ca5f1c8f0ce52e2873b3f436d4255c4b14e43620a0b3e9a4bfe92272af6cf
MD5 dec29862c50a23a662a002c3c84f7c55
BLAKE2b-256 d3d729900eae01f959a808bdc8149425aa41193383e2dd5736610441dddf36f8

See more details on using hashes here.

Provenance

The following attestation bundles were made for bbta-0.3.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: build_wheels.yml on banbox/banta

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file bbta-0.3.0-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for bbta-0.3.0-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2520f4096ed78383961e8be7f150103ae876c7f0626fbb5b4445db24fd856046
MD5 ce9c72adcf1c50698858637bb37ca84c
BLAKE2b-256 df715451918f9f2c6f08bed5af12a1474fdfe9d9128753ab3e0ab088550656df

See more details on using hashes here.

Provenance

The following attestation bundles were made for bbta-0.3.0-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: build_wheels.yml on banbox/banta

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file bbta-0.3.0-cp310-cp310-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for bbta-0.3.0-cp310-cp310-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 2074af11b3e1e0d48ec64d868a3741d20c33f62bf35283024dfe371d9483dbb0
MD5 e2aafa42db33d6309c5a795b1429ff55
BLAKE2b-256 73296eb3a6a74c82909a1ad34532bb9be4cf16c46fa18a3d0faa932031a0a095

See more details on using hashes here.

Provenance

The following attestation bundles were made for bbta-0.3.0-cp310-cp310-musllinux_1_2_x86_64.whl:

Publisher: build_wheels.yml on banbox/banta

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file bbta-0.3.0-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for bbta-0.3.0-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 960f613c336a39bccdc0bec64a15ef55f7872c42ee42413ae590b2476315712a
MD5 de831215e9ebd80fd71cd9dca84afcfd
BLAKE2b-256 16d920db73a8a992f2ee7000b33b7f3a1a7244e8684a963da27fb10f23c0cce7

See more details on using hashes here.

Provenance

The following attestation bundles were made for bbta-0.3.0-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: build_wheels.yml on banbox/banta

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file bbta-0.3.0-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for bbta-0.3.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 fe7bb78027b3d418354f7cbb3ba1fe26d8f90cfe1a78dc99620665be1c61a31b
MD5 917650386f9957be7f7349d561615d51
BLAKE2b-256 d3df4904c335119e0747aa6a5a967334cf713ea5d452b51913fc3554f001593a

See more details on using hashes here.

Provenance

The following attestation bundles were made for bbta-0.3.0-cp310-cp310-macosx_11_0_arm64.whl:

Publisher: build_wheels.yml on banbox/banta

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file bbta-0.3.0-cp310-cp310-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for bbta-0.3.0-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 137e7ae595e09e0fd8d4860a8385ad44008f2a1add78e0c031057dcdb7e3444f
MD5 62faa8bf332ce80d626284dff6286268
BLAKE2b-256 574483d374bf36577a8640fb07ddaa056650a323c855ddac87bcd5bf9566d676

See more details on using hashes here.

Provenance

The following attestation bundles were made for bbta-0.3.0-cp310-cp310-macosx_10_9_x86_64.whl:

Publisher: build_wheels.yml on banbox/banta

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page