|
| 1 | +# talib-binding |
| 2 | + |
| 3 | +The [TA-Lib](http://ta-lib.org/) sync bindings. |
| 4 | + |
| 5 | +## Install |
| 6 | + |
| 7 | +```bash |
| 8 | +yarn add talib-binding |
| 9 | +``` |
| 10 | + |
| 11 | +## Usage |
| 12 | + |
| 13 | +All the functions are exported, you can call it in the same form to [c api](https://ta-lib.org/d_api/d_api.html), but |
| 14 | +there are some difference: |
| 15 | + |
| 16 | +- the `startIdx` and `endIdx` is placed at the end of the function signature, and is optional. |
| 17 | +- the return value is the computed result, if result is one array, will be it, else will be a nested array to contains all output arrays. |
| 18 | +- if the ta-lib function returns a error code, will throw a error. |
| 19 | + |
| 20 | +Additionally, you can pass a `Record[]` to extract its fields rather than input double array such as `inHigh`, `inLow`, etc. |
| 21 | +And if the input field is a implicit field of the records, you need to input a string to specifying which one field will be extract |
| 22 | +as it. |
| 23 | + |
| 24 | +## Example |
| 25 | + |
| 26 | +```typescript |
| 27 | +import * as talib from './src/talib-binding.generated' |
| 28 | + |
| 29 | +// Input double array directly: |
| 30 | +let output = talib.SAR( |
| 31 | + [2, 3, 4, 5], /* inHigh */ |
| 32 | + [1, 2, 3, 4], /* inLow */ |
| 33 | + 0.02, /* optAcceleration_Factor, optional */ |
| 34 | + 0.2, /* optAF_Maximum, optional */ |
| 35 | + 0, /* startIdx, optional */ |
| 36 | + 3 /* endIdx, optional */ |
| 37 | +) |
| 38 | +console.log(output) |
| 39 | + |
| 40 | +// Input a records array: |
| 41 | +output = talib.SAR([ |
| 42 | + { |
| 43 | + Time: 0, |
| 44 | + Open: 1, |
| 45 | + High: 2, |
| 46 | + Low: 1, |
| 47 | + Close: 2, |
| 48 | + Volume: 1, |
| 49 | + }, |
| 50 | + { |
| 51 | + Time: 0, |
| 52 | + Open: 2, |
| 53 | + High: 3, |
| 54 | + Low: 2, |
| 55 | + Close: 3, |
| 56 | + Volume: 1, |
| 57 | + }, |
| 58 | +]) |
| 59 | + |
| 60 | +// Input implicit field name with Record[] |
| 61 | +output = talib.COS([ |
| 62 | + { |
| 63 | + Time: 0, |
| 64 | + Open: 1, |
| 65 | + High: 2, |
| 66 | + Low: 1, |
| 67 | + Close: 2, |
| 68 | + Volume: 1, |
| 69 | + }, |
| 70 | + { |
| 71 | + Time: 0, |
| 72 | + Open: 2, |
| 73 | + High: 3, |
| 74 | + Low: 2, |
| 75 | + Close: 3, |
| 76 | + Volume: 1, |
| 77 | + }, |
| 78 | +], 'Volume') |
| 79 | +``` |
| 80 | + |
| 81 | +## Notes |
| 82 | + |
| 83 | +- Some API need to use `TA_MAType`, which is exported as `MATypes` in the binding. For example: |
| 84 | + ```typescript |
| 85 | + import * as talib from './src/talib-binding.generated' |
| 86 | + talib.MA([1, 2, 3], void 0, talib.MATypes.SMA) |
| 87 | + ``` |
| 88 | + |
| 89 | +## Contributing |
| 90 | + |
| 91 | +Clone the repo at first: |
| 92 | + |
| 93 | +```bash |
| 94 | +git clone https://github.com/acrazing/talib-binding-node && cd talib-binding-node |
| 95 | +``` |
| 96 | + |
| 97 | +All the files end with `generated.*` is generated by [src/generate.ts](./src/generate.ts). Maybe you need to view it |
| 98 | +to get detailed information. |
| 99 | + |
| 100 | +## License |
| 101 | + |
| 102 | +- This project published under [MIT](./LICENSE) License. |
| 103 | +- The `TA-Lib` is published under [LICENSE](./ta-lib/LICENSE.TXT). |
0 commit comments