Skip to content

Commit 3a57004

Browse files
authored
feat: refactor codebase for better TypeScript annotations and TSDoc documentation (#101)
* feat: refactor codebase for better TypeScript annotations and TSDoc comments * chore: update node-version for github workflow * feat: add TypeScript interfaces, types, examples, update README, and improve documentation and unit tests * feat: add deploy workflow and changelog
1 parent 9fceb6a commit 3a57004

26 files changed

+3551
-2715
lines changed

.eslintrc.js

+14-10
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
1-
module.exports = {
2-
env: {
3-
browser: true,
4-
es2021: true
5-
},
6-
overrides: [
1+
module.exports = {
2+
plugins: [
3+
"@typescript-eslint/eslint-plugin",
4+
"eslint-plugin-tsdoc"
5+
],
6+
extends: [
7+
'plugin:@typescript-eslint/recommended'
78
],
9+
parser: '@typescript-eslint/parser',
810
parserOptions: {
9-
ecmaVersion: "latest",
10-
sourceType: "module"
11+
project: "./tsconfig.json",
12+
tsconfigRootDir: __dirname,
13+
ecmaVersion: 2018,
14+
sourceType: "module"
1115
},
1216
rules: {
13-
'quote-props': ['error', 'as-needed'],
17+
"tsdoc/syntax": "warn"
1418
}
15-
}
19+
};

.github/workflows/deploy.yml

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: Release, npm publish and deploy gh-pages
2+
3+
on:
4+
push:
5+
tags:
6+
- "v*"
7+
8+
jobs:
9+
publish-npm:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v3
13+
- uses: actions/setup-node@v3
14+
with:
15+
node-version: 20
16+
registry-url: https://registry.npmjs.org/
17+
- run: npm ci
18+
- run: npm run build
19+
- run: npm publish
20+
env:
21+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
22+
23+
publish-doc:
24+
runs-on: ubuntu-latest
25+
permissions:
26+
contents: read
27+
pages: write
28+
id-token: write
29+
steps:
30+
- uses: actions/checkout@v3
31+
with:
32+
submodules: true
33+
- uses: actions/setup-node@v3
34+
with:
35+
node-version: 20
36+
- name: Install Dependencies
37+
run: |
38+
npm install
39+
npm install typedoc
40+
- name: Building documentation for GitHub Pages
41+
run: npx typedoc --out ./docs
42+
- name: Setup Pages
43+
uses: actions/configure-pages@v5
44+
- name: Upload artifacts
45+
uses: actions/upload-pages-artifact@v3
46+
with:
47+
path: docs/
48+
- name: Deploy to GitHub Pages
49+
id: deployment
50+
uses: actions/deploy-pages@v4

.github/workflows/node-test.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ jobs:
55
test:
66
strategy:
77
matrix:
8-
node-version: [12.x, 13.x, 14.x]
8+
node-version: [18.x, 20.x, 21.x]
99
os: [ubuntu-latest, macos-latest, windows-latest]
1010

1111
runs-on: ${{ matrix.os }}
@@ -22,5 +22,5 @@ jobs:
2222
- name: Install Dependencies
2323
run: npm install
2424

25-
- name: Run All Node.js Tests
25+
- name: Run All typescript Tests
2626
run: npm run test

.jsdoc.json

-27
This file was deleted.

CHANGELOG.md

+26-87
Original file line numberDiff line numberDiff line change
@@ -1,99 +1,38 @@
1-
# Kite v4
1+
# Kite v5 - TypeScript
22

3-
### Breaking changes
4-
- Upgrade deps and set minimum nodejs version to 8.0.0+
5-
- Return promise instead of throwing error on generateSession and renewAccessToken
6-
- Handle gtt payload validation and throw proper error
7-
- Change ticker response attributes naming as per [kite connect doc](https://kite.trade/docs/connect/v3/websocket/#quote-packet-structure)
3+
## [5.0.0] - 2024-06-13
84

9-
### New features
10-
- Order margin call : [orderMargins](https://github.com/zerodha/kiteconnectjs/blob/master/lib/connect.js#L704)
11-
- Basket order margin call : [orderBasketMargins](https://github.com/zerodha/kiteconnectjs/blob/master/lib/connect.js#L727)
12-
- Add OI param to `getHistoricalData`
13-
- Add global constant for postion types `POSITION_TYPE_DAY`, `POSITION_TYPE_OVERNIGHT` and `EXCHANGE_BCD`
5+
### Breaking Changes
146

15-
### Fixes
16-
- Remove `order_id` param from complete tradebook fetch `getTrades`
17-
- Fix `cancelMF` order_id param struct
18-
- Handle price conversion for BCD segment in ticker
19-
- Remove un-used `headers` param for `parseHistorical`
20-
- Update comment block for `getQuote, getOHLC, getLTP, placeOrder and placeMFOrder`
7+
- **TypeScript Conversion**: The entire codebase has been converted to TypeScript. This means type definitions are now included, and any custom integrations may need to be updated to match the new type definitions.
8+
- **Node.js Version Requirement**: The minimum required Node.js version is now 18.0.0. Please upgrade your Node.js installation if you are using an older version.
9+
- **API Changes**: Updated various function signatures and added explicit types for better TypeScript support.
2110

11+
### New Features
2212

23-
# Kite v3
13+
- **TypeScript Support**: The library is now fully written in TypeScript, providing better type safety.
14+
- **Documentation**: Added and updated documentation to reflect the new TypeScript codebase as per the [TSDOC standard](https://tsdoc.org/).
15+
- **Examples**: Added new examples for both REST API and WebSocket client in TypeScript.
2416

25-
### New features
26-
- method: `getProfile`
27-
- method: `getOHLC`
28-
- method: `getLTP`
29-
- method: `getInstrumentsMargins`
30-
- Added MF API calls
31-
- method: `getMFOrders`
32-
- method: `getMFHoldings`
33-
- method: `placeMFOrder`
34-
- method: `cancelMFOrder`
35-
- method: `getMFSIPS`
36-
- method: `placeMFSIP`
37-
- method: `modifyMFSIP`
38-
- method: `cancelMFSIP`
39-
- method: `getMFInstruments`
40-
- method: `exitOrder`
41-
- method: `renewAccessToken`
42-
- method: `invalidateRefreshToken`
43-
- constants for products, order type, transaction type, variety, validity, exchanges and margin segments
17+
### Improvements
4418

45-
### API method name changes
19+
- **Code Quality**: Refactored codebase to improve readability, maintainability, and performance.
20+
- **Error Handling**: Improved error handling and added more descriptive error messages.
4621

47-
| v2 | v3 |
48-
| ------------------------- | ------------------------- |
49-
| requestAccessToken | generateSession |
50-
| invalidateToken | invalidateAccessToken |
51-
| setSessionHook | setSessionExpiryHook |
52-
| loginUrl | getLoginURL |
53-
| margins | getMargins |
54-
| orderPlace | placeOrder |
55-
| orderModify | modifyOrder |
56-
| orderCancel | cancelOrder |
57-
| orders | getOrders |
58-
| orders(order_id) | getOrderHistory |
59-
| trades | getTrades |
60-
| trades(order_id) | getOrderTrades |
61-
| holdings | getHoldings |
62-
| positions | getPositions |
63-
| productModify | convertPosition |
64-
| instruments | getInstruments |
65-
| historical | getHistoricalData |
66-
| triggerRange | getTriggerRange |
22+
### Migration Guide
6723

68-
### Params and other changes
69-
- `KiteConnect` takes all the params as object including `api_key`
70-
- `convertPosition` method takes all the params as object
71-
- All success response returns only `data` field in response instead with envelope
72-
- All error thrown are in the format of `{"message": "Unknown error", "error_type": "GeneralException", "data": null}`
73-
- [Changes in `generateSession` response structure](https://kite.trade/docs/connect/v3/user/#response-attributes)
74-
- [Changes in `getPositions` response structure](https://kite.trade/docs/connect/v3/portfolio/#response-attributes_1)
75-
- [Changes in `getQuote` response structure](https://kite.trade/docs/connect/v3/market-quotes/#retrieving-full-market-quotes)
76-
- [Changes in `placeOrder` params](https://kite.trade/docs/connect/v3/orders/#bracket-order-bo-parameters)
77-
- Changes in `getHistoricalData` params
78-
- All datetime string fields has been converted to `Date` object.
79-
- `getOrders`, `getOrderHistory`, `getTrades`, `getOrderTrades`, `getMFOrders` responses fields `order_timestamp`, `exchange_timestamp`, `fill_timestamp`
80-
- `getMFSIPS` fields `created`, `last_instalment`
81-
- `generateSession` field `login_time`
82-
- `getQuote` fields `timestamp`, `last_trade_time`
83-
- `getInstruments` field `expiry`
84-
- `getMFInstruments` field `last_price_date`
24+
If you are upgrading from a previous version, please review the following changes and adjust your code accordingly:
8525

86-
### KiteTicker changes
87-
- `KiteTicker` receives param `access_token` instead of `public_token`
88-
- New params addedd to `KiteTicker` initializer
89-
- `reconnect` - Toggle auto reconnect on/off
90-
- `max_retry` - Max retry count for auto reconnect
91-
- `max_delay` - Max delay between subsequent retries
92-
- Auto reconnect is enabled by default
93-
- Renamed callback `reconnecting` to `reconnect`
94-
- Added new callbacks
95-
- `error` - when socket connection is closed with error. Error is received as a first param
96-
- `close` - when socket connection is closed cleanly
97-
- `order_update` - When order update (postback) is received for the connected user (Data object is received as first argument)
26+
- **Node.js Version**: Ensure your Node.js version is 18.0.0 or higher.
27+
- **TypeScript Integration**: Update your project to handle the new TypeScript types. This may involve adding or adjusting type definitions in your project.
28+
- **Function Signatures**: Review the updated function signatures in the documentation and adjust your usage of the library accordingly.
9829

30+
### Bug Fixes
9931

32+
- Fixed various minor bugs and performance issues reported in the previous version.
33+
34+
### Notes
35+
36+
- This release marks a significant update with the transition to TypeScript. Please report any issues or bugs to the repository's issue tracker.
37+
38+
[5.0.0]: https://github.com/your-repo/kiteconnect-ts/releases/tag/v5.0.0

LICENSE

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

0 commit comments

Comments
 (0)