@fxdaemon/talibjs

1.0.4 • Public • Published

talibjs

Port the TA-Lib C library to WebAssembly, including all indicators from the original TA-Lib.

Installation

npm install @fxdaemon/talibjs

Usage

const talib = require('@fxdaemon/talibjs');
// Or: import talib from '@fxdaemon/talibjs';

async function run() {
  await talib.load();
  // Call the API here.
}

run();
  • get a list of functions
const retFuncList = talib.funcList();
console.log(retFuncList);
["ADD","DIV","MAX","MAXINDEX","MIN","MININDEX", ...]
  • get function definition in json format
const retFuncDef = talib.funcDef("SMA");
console.log(retFuncDef);
{"name":"SMA","group":"Overlap Studies","hint":"Simple Moving Average","inputs":[{"name":"inReal","type":"real"}],"opt_inputs":[{"name":"optInTimePeriod","display_name":"Time Period","default_value":30.0,"hint":"Number of period","type":"integer","range":{"min":2,"max":100000,"suggested_start":4,"suggested_end":200,"suggested_increment":1}}],"outputs":[{"name":"outReal","type":"real","flags":["line"]}]}
  • calculate an indicator
const inReal = getPrices();
const {
  error,
  outReal,
  outBegIdx,
  outNBElement,
} = talib.TA('SMA', {
  startIdx: 0,
  endIdx: inReal.length - 1,
  inReal,
  optInTimePeriod: 14,
});
if (error) {
  console.log(error.message);
} else {
  console.log(outReal);
}
  • set unstable period
talib.setUnstablePeriod(funcId, 14);

# available values for funcId:

"ADX","ADXR","ATR","CMO","DX","EMA","HT_DCPERIOD","HT_DCPHASE","HT_PHASOR","HT_SINE","HT_TRENDLINE","HT_TRENDMODE","IMI","KAMA","MAMA","MFI","MINUS_DI","MINUS_DM","NATR","PLUS_DI","PLUS_DM","RSI","STOCHRSI","T3","ALL"

Building

emcc -O3 -sWASM=1 -sALLOW_MEMORY_GROWTH=1 -sMODULARIZE -sEXPORTED_FUNCTIONS=_malloc,_free,_main -sEXPORTED_RUNTIME_METHODS=UTF8ToString,stringToUTF8,lengthBytesUTF8 -I ../include talib.c yyjson.c ../lib/libta_lib.a -o ../dist/talib.js

License

Talibjs is licensed under a MIT License.

Package Sidebar

Install

npm i @fxdaemon/talibjs

Weekly Downloads

0

Version

1.0.4

License

MIT

Unpacked Size

3.53 MB

Total Files

15

Last publish

Collaborators

  • fxdaemon