Skip to content

Commit 0e66d2c

Browse files
committed
feat(core): the initial feature support
1 parent c3ee298 commit 0e66d2c

File tree

10 files changed

+18866
-25
lines changed

10 files changed

+18866
-25
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ CMakeFiles/
1616
CMakeCache.txt
1717
Makefile
1818
cmake_install.cmake
19-
ta_config.h
19+
ta_config.h

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2017 acrazing
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
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).

build.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/usr/bin/env bash
2+
#
3+
# build.sh
4+
# @author acrazing
5+
# @since 2017-09-25 23:05:26
6+
# @desc build.sh
7+
#
8+
9+
set -xe
10+
cd ta-lib
11+
cmake ./
12+
make -j4
13+
ts-node ./src/generate.ts generate-bindings
14+
ts-node ./src/generate.ts generate-types
15+
node-gyp configure build -j 4

package.json

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,35 @@
11
{
2+
"name": "talib-binding",
3+
"main": "./build/Release/talib_binding.node",
4+
"types": "./src/talib-binding.generated.d.ts",
5+
"version": "0.0.1",
6+
"license": "MIT",
7+
"scripts": {
8+
"install": "cd ta-lib && cmake && make -j4 && cd .. && node-gyp configure build -j4"
9+
},
10+
"description": "The [TA-Lib](http://ta-lib.org/) sync bindings.",
211
"devDependencies": {
312
"@types/node": "^8.0.30",
413
"@types/xml2js": "^0.4.0",
514
"json2ts": "^0.0.7",
615
"nan": "^2.7.0",
16+
"known-types": "^1.0.1",
717
"piclick": "^1.0.4",
818
"xml2js": "^0.4.19"
9-
}
10-
}
19+
},
20+
"repository": {
21+
"type": "git",
22+
"url": "git+https://github.com/acrazing/talib-binding-node.git"
23+
},
24+
"keywords": [
25+
"talib",
26+
"binding",
27+
"node",
28+
"sync"
29+
],
30+
"author": "acrazing",
31+
"bugs": {
32+
"url": "https://github.com/acrazing/talib-binding-node/issues"
33+
},
34+
"homepage": "https://github.com/acrazing/talib-binding-node#readme"
35+
}

0 commit comments

Comments
 (0)