oransel / node-talib

A technical analysis library for node.js
GNU Lesser General Public License v3.0
904 stars 149 forks source link

Illegal instruction error running `execute`. #104

Closed arquadrado closed 1 year ago

arquadrado commented 1 year ago

Hi,

I am trying to use talib to get calculate some indicators but I am encountering problems with that. Both for:

 let rsiInput = {
      values: prices,
      period: 14,
    };

    let rsiResult = await talib.execute({
      name: 'RSI',
      startIdx: 0,
      endIdx: prices.length - 1,
      inReal: rsiInput,
    });

and:

 let macdInput = {
      fastPeriod: 12,
      slowPeriod: 26,
      signalPeriod: 9,
      values: prices,
    };
    let macdResult = await talib.execute({
      name: 'MACD',
      startIdx: 0,
      endIdx: prices.length - 1,
      inReal: macdInput,
    });

where prices is just an array of decimal numbers I am getting the following:

#
# Fatal error in , line 0
# Check failed: receiver.IsJSFunction().
#
#
#
#FailureMessage Object: 0x7ffda663ff50
 1: 0xa891f1  [node]
 2: 0x1a37e75 V8_Fatal(char const*, ...) [node]
 3: 0xefb3f2 v8::internal::JSReceiver::GetCreationContext() [node]
 4: 0xbac318 v8::Object::CreationContext() [node]
 5: 0x985569 node::MakeCallback(v8::Isolate*, v8::Local<v8::Object>, v8::Local<v8::Function>, int, v8::Local<v8::Value>*, node::async_context) [node]
 6: 0x7f81c459514c  [/home/godlash/dev/the_experiment/node_modules/talib/build/Release/talib.node]
 7: 0x7f81c459bec1 Execute(Nan::FunctionCallbackInfo<v8::Value> const&) [/home/godlash/dev/the_experiment/node_modules/talib/build/Release/talib.node]
 8: 0x7f81c4594cdc  [/home/godlash/dev/the_experiment/node_modules/talib/build/Release/talib.node]
 9: 0xc07179  [node]
10: 0xc08f67 v8::internal::Builtin_HandleApiCall(int, unsigned long*, v8::internal::Isolate*) [node]
11: 0x140e919  [node]
Illegal instruction

I have tried several versions of node and the only one where I could install the library (1.1.5) was with node 12.22.12 but even then I get the above mentioned errors.

Any clue what I might be missing?

Thanks

P.S.: I am running this code in Ubuntu 22.04 LTS.

g-gundam commented 1 year ago

@arquadrado - In case you haven't figured this out by now, you're calling talib.execute with slightly wrong parameters. inReal should just be prices in your case. You don't need to create rsiInput. MACD is a similar situation. The inReal key should just be given an Array of numbers.

If you want to customize periods, you pass it in like this:

let rsiResult = await talib.execute({
  name:            'RSI',
  startIdx:        0,
  endIdx:          prices.length - 1,
  inReal:          prices,
  optInTimePeriod: 14 // or whatever period you want
})

let macdResult = await talib.execute({
  name:              'MACD',
  startIdx:          0,
  endIdx:            prices.length - 1,
  inReal:            prices,
  optInFastPeriod:   12,
  optInSlowPeriod:   26,
  optInSignalPeriod: 9
})

You can query talib itself to see what parameters these indicators take.

talib.explain('RSI')
talib.explain('MACD')

This issue should be closed, because it's not a bug in talib. You were calling talib.execute incorrectly.