Using node talib gives an unexpected error

77 views Asked by At

I'm trying to use a couple functions from the talib library in my node backend, but getting an error, which I don't understand. This also happens when using the BBANDS indicator, but ADX seems to succeed. I'm sending the parameters to the function according to the result of the talib.explain("MACD") result.

import { createRequire } from "module";
const require = createRequire(import.meta.url);
const talib = require('talib');

const stockData = [ { open: 50, close: 100 }, { open: 40, close: 20 } ];
const taRes = await talib.execute({
  name: "MACD",
  startIdx: 0,
  endIdx: stockData.length - 1,
  inReal: stockData.map(h => h.close),
})

The error I'm getting from the execute call is:

FATAL ERROR: v8::ToLocalChecked Empty MaybeLocal.
 1: 00007FF77ADC1C7F node_api_throw_syntax_error+175855
 2: 00007FF77AD46476 EVP_MD_meth_get_input_blocksize+59654
 3: 00007FF77AD4826C node::OnFatalError+252
 4: 00007FF77B7F8EB5 v8::api_internal::ToLocalEmpty+53
 5: 00007FF77ADF154D node::MakeCallback+61
 6: 00007FFCC46D1943 Nan::Callback::Call+387 [c:\stock\stock-backend\node_modules\nan\nan.h]:L1754
 7: 00007FFCC46D22A7 REPORT_INTERNAL_ERROR+295 [c:\stock\stock-backend\node_modules\talib\src\talib.cpp]:L96
 8: 00007FFCC46D82F9 Execute+6057 [c:\stock\stock-backend\node_modules\talib\src\talib.cpp]:L953
 9: 00007FFCC46D1118 Nan::imp::FunctionCallbackWrapper+200 [c:\stock\stock-backend\node_modules\nan\nan_callbacks_12_inl.h]:L178
10: 00007FF77B7A8FED v8::internal::Builtins::code+248221
11: 00007FF77B7A8BF9 v8::internal::Builtins::code+247209
12: 00007FF77B7A8EBC v8::internal::Builtins::code+247916
13: 00007FF77B7A8D20 v8::internal::Builtins::code+247504
14: 00007FF77B88DA61 v8::internal::SetupIsolateDelegate::SetupHeap+558449
15: 00007FF77B811374 v8::internal::SetupIsolateDelegate::SetupHeap+48772
16: 00007FF77B8454A3 v8::internal::SetupIsolateDelegate::SetupHeap+262067
17: 00007FF77B8DE295 v8::internal::SetupIsolateDelegate::SetupHeap+888229
18: 00007FF77B836BAC v8::internal::SetupIsolateDelegate::SetupHeap+202428
19: 00007FF77B80F87B v8::internal::SetupIsolateDelegate::SetupHeap+41867
20: 00007FF77B6D9ECA v8::internal::Execution::CallWasm+1562
21: 00007FF77B6D9FEB v8::internal::Execution::CallWasm+1851
22: 00007FF77B6DAD9A v8::internal::Execution::TryCallScript+346
23: 00007FF77B6B388A v8::internal::MicrotaskQueue::RunMicrotasks+410
24: 00007FF77B6B362A v8::internal::MicrotaskQueue::PerformCheckpointInternal+74
25: 00007FF77B7A8FED v8::internal::Builtins::code+248221
26: 00007FF77B7A8BF9 v8::internal::Builtins::code+247209
27: 00007FF77B7A8EBC v8::internal::Builtins::code+247916
28: 00007FF77B7A8D20 v8::internal::Builtins::code+247504
29: 00007FF77B88DA61 v8::internal::SetupIsolateDelegate::SetupHeap+558449
30: 00007FF6FBBD61A1

Any idea?

1

There are 1 answers

0
Metheny On BEST ANSWER

Ok, I found the problem. It seems the parameters which I thought of as optional as they're described in the talib.explain("MACD") as optInputs aren't actually optional in the input object. If I add them as below, the calls succeeds.

 const taRes = await talib.execute({
            name: "MACD",
            startIdx: 0,
            endIdx: stockData.length - 1,
            inReal: stockData.map(h => h.close),
            optInFastPeriod: 12,
            optInSlowPeriod: 26,
            optInSignalPeriod: 9,
          });