Skip to content

Commit 78fdcf5

Browse files
authored
feat: export types, fix timezone, enhance order interface, resolve security issues (#114)
1 parent 1950324 commit 78fdcf5

File tree

16 files changed

+907
-442
lines changed

16 files changed

+907
-442
lines changed

CHANGELOG.md

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,35 @@
11
# Kite v5 - TypeScript
22

3+
## [5.1.0] - 2025-07-21
4+
5+
### New Features
6+
7+
- **Enhanced Type Safety**: Improved TypeScript type definitions for ticker event callbacks
8+
- **Comprehensive Type Exports**: All type definitions are now properly exported from main entry point with direct imports: `{ KiteConnect, Order, KiteTickerParams, Exchanges } from 'kiteconnect'`
9+
- **Ticker Event Types**: Added proper exports for `Tick`, `LTPTick`, `QuoteTick`, and `FullTick` interfaces
10+
- **Historical Data Types**: Added `HistoricalData` type with `Promise<HistoricalData[]>` for `getHistoricalData()` method
11+
- **Order Interface Completeness**: Enhanced Order interface with all missing fields from orderbook API response
12+
- **Enhanced Ticker Events**: Added `KiteTickerEvents` and `KiteTickerEventCallbacks` for type safety and discovery
13+
14+
### Bug Fixes
15+
16+
- **Security Vulnerabilities**: Fixed all npm audit vulnerabilities
17+
- Upgraded axios from vulnerable version to 1.10.0 with proper TypeScript typing
18+
- Applied security patches across all dependencies
19+
- **Timezone Handling**: Fixed historical data timezone handling for Date objects [Issue #107](https://github.com/zerodha/kiteconnectjs/issues/107)
20+
- Date objects now correctly preserve local timezone instead of converting to UTC
21+
- **Missing Order Fields**: Added missing fields to Order interface including `instrument_token`, `placed_by`, `exchange_order_id`, and 15+ other fields [Issue #113](https://github.com/zerodha/kiteconnectjs/issues/113)
22+
- **Content-Type Detection**: Enhanced CSV and JSON content-type handling to support charset specifications using pattern matching instead of strict equality
23+
24+
### Breaking Changes
25+
26+
- **Date Object Timezone Handling**: If you were manually compensating for the timezone bug by adjusting Date objects, you'll need to update your code to use the actual intended time values
27+
28+
### Backward Compatibility
29+
30+
- String date inputs: No changes required
31+
- Ticker event callbacks: Existing `any[]` callbacks continue to work
32+
333
## [5.0.0] - 2024-06-13
434

535
### Breaking Changes
@@ -35,4 +65,5 @@ If you are upgrading from a previous version, please review the following change
3565

3666
- This release marks a significant update with the transition to TypeScript. Please report any issues or bugs to the repository's issue tracker.
3767

38-
[5.0.0]: https://github.com/your-repo/kiteconnect-ts/releases/tag/v5.0.0
68+
[5.1.0]: https://github.com/zerodha/kiteconnectjs/releases/tag/v5.1.0
69+
[5.0.0]: https://github.com/zerodha/kiteconnectjs/releases/tag/v5.0.0

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ ticker.on("disconnect", onDisconnect);
8787
ticker.on("error", onError);
8888
ticker.on("close", onClose);
8989
ticker.on("order_update", onTrade);
90+
ticker.on("message", onMessage);
9091

9192
function onTicks(ticks: any[]): void {
9293
console.log("Ticks", ticks);
@@ -113,6 +114,11 @@ function onClose(reason: string): void {
113114
function onTrade(order: any): void {
114115
console.log("Order update", order);
115116
}
117+
118+
function onMessage(binaryData: ArrayBuffer): void {
119+
console.log("Binary message received", binaryData);
120+
// Process raw WebSocket binary data if needed
121+
}
116122
```
117123

118124
## Auto re-connect WebSocket client

examples/kiteconnect.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ async function init() {
2424
await getOHLC(['NSE:RELIANCE', 'NSE:SBIN', 'BSE:ONGC']);
2525
await getLTP(['NSE:RELIANCE', 'NSE:SBIN', 'BSE:ONGC']);
2626
await getHistoricalData(16320514, "day", "2024-05-11 00:00:00", "2024-06-12 00:00:00", true, true);
27+
await getHistoricalData(16320514, "day", new Date('2024-05-11T09:15:00'), new Date('2024-06-12T15:30:00'), true, true);
2728
await placeRegularOrder();
2829
await placeIcebergOrder();
2930
await modifyRegularOrder(240611801793632);
@@ -176,7 +177,7 @@ async function getLTP(instruments: string[]) {
176177
}
177178
}
178179

179-
async function getHistoricalData(instrumentToken: number, interval: string, from: string, to: string, continuous: boolean, oi: boolean) {
180+
async function getHistoricalData(instrumentToken: number, interval: string, from: string | Date, to: string | Date, continuous: boolean, oi: boolean) {
180181
try {
181182
const historicalData = await kc.getHistoricalData(instrumentToken, interval, from, to, continuous, oi);
182183
console.log('Historical Data:', historicalData);

examples/kiteticker.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { KiteTicker } from "kiteconnect";
2+
import { Tick, LTPTick, QuoteTick, FullTick } from "kiteconnect";
23

34
const apiKey = 'your_api_key';
45
const accessToken = 'generated_access_token';
@@ -15,11 +16,31 @@ ticker.on('disconnect', onDisconnect);
1516
ticker.on('error', onError);
1617
ticker.on('close', onClose);
1718
ticker.on('order_update', onTrade);
19+
ticker.on('message', onMessage);
1820

21+
// OPTION 1: Backward compatible (existing code continues to work)
1922
function onTicks(ticks: any[]): void {
2023
console.log("Ticks", ticks);
2124
}
2225

26+
// OPTION 2: Type-safe approach (recommended)
27+
function onTicks(ticks: Tick[]): void {
28+
console.log("Ticks", ticks);
29+
30+
// With typed approach:
31+
ticks.forEach(tick => {
32+
console.log('Instrument:', tick.instrument_token);
33+
console.log('Last price:', tick.last_price);
34+
console.log('Mode:', tick.mode);
35+
36+
if (tick.mode === 'full') {
37+
const fullTick = tick as FullTick;
38+
console.log('Volume:', fullTick.volume_traded);
39+
console.log('OI:', fullTick.oi);
40+
}
41+
});
42+
}
43+
2344
function subscribe(): void {
2445
const tokens = [738561, 256265];
2546
ticker.subscribe(tokens);
@@ -41,3 +62,7 @@ function onClose(reason: string): void {
4162
function onTrade(order: any): void {
4263
console.log("Order update", order);
4364
}
65+
66+
function onMessage(binaryData: ArrayBuffer): void {
67+
console.log("Binary message received", binaryData);
68+
}

interfaces/connect.ts

Lines changed: 96 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -276,21 +276,53 @@ export interface ConvertPositionParams {
276276
*/
277277
export interface Order {
278278
/**
279-
* @type {?TransactionTypes}
279+
* @type {?string}
280280
*/
281-
transaction_type?: TransactionTypes;
281+
placed_by?: string;
282282
/**
283283
* @type {?(string | number)}
284284
*/
285-
quantity?: string | number;
285+
order_id?: string | number;
286286
/**
287-
* @type {?Products}
287+
* @type {?string}
288288
*/
289-
product?: Products;
289+
exchange_order_id?: string;
290290
/**
291-
* @type {?OrderTypes}
291+
* @type {?(string | number)}
292292
*/
293-
order_type?: OrderTypes;
293+
parent_order_id?: string | number;
294+
/**
295+
* @type {?string}
296+
*/
297+
status?: string;
298+
/**
299+
* @type {?string}
300+
*/
301+
status_message?: string;
302+
/**
303+
* @type {?string}
304+
*/
305+
status_message_raw?: string;
306+
/**
307+
* @type {?(string | Date)}
308+
*/
309+
order_timestamp?: string | Date;
310+
/**
311+
* @type {?(string | Date)}
312+
*/
313+
exchange_update_timestamp?: string | Date;
314+
/**
315+
* @type {?(string | Date)}
316+
*/
317+
exchange_timestamp?: string | Date;
318+
/**
319+
* @type {?Varieties}
320+
*/
321+
variety?: Varieties;
322+
/**
323+
* @type {?boolean}
324+
*/
325+
modified?: boolean;
294326
/**
295327
* @type {?Exchanges}
296328
*/
@@ -300,9 +332,33 @@ export interface Order {
300332
*/
301333
tradingsymbol?: string;
302334
/**
303-
* @type {?Varieties}
335+
* @type {?number}
304336
*/
305-
variety?: Varieties;
337+
instrument_token?: number;
338+
/**
339+
* @type {?OrderTypes}
340+
*/
341+
order_type?: OrderTypes;
342+
/**
343+
* @type {?TransactionTypes}
344+
*/
345+
transaction_type?: TransactionTypes;
346+
/**
347+
* @type {?Validities}
348+
*/
349+
validity?: Validities;
350+
/**
351+
* @type {?Products}
352+
*/
353+
product?: Products;
354+
/**
355+
* @type {?(string | number)}
356+
*/
357+
quantity?: string | number;
358+
/**
359+
* @type {?(string | number)}
360+
*/
361+
disclosed_quantity?: string | number;
306362
/**
307363
* @type {?(number | string)}
308364
*/
@@ -312,25 +368,43 @@ export interface Order {
312368
*/
313369
trigger_price?: number;
314370
/**
315-
* @type {?PositionTypes}
371+
* @type {?number}
316372
*/
317-
position_type?: PositionTypes;
373+
average_price?: number;
318374
/**
319-
* @type {?Products}
375+
* @type {?(string | number)}
320376
*/
321-
old_product?: Products;
377+
filled_quantity?: string | number;
322378
/**
323-
* @type {?Products}
379+
* @type {?(string | number)}
324380
*/
325-
new_product?: Products;
381+
pending_quantity?: string | number;
326382
/**
327383
* @type {?(string | number)}
328384
*/
329-
amount?: string | number;
385+
cancelled_quantity?: string | number;
386+
/**
387+
* @type {?(string | number)}
388+
*/
389+
market_protection?: string | number;
390+
/**
391+
* @type {?any}
392+
*/
393+
meta?: any;
330394
/**
331395
* @type {?string}
332396
*/
333397
tag?: string;
398+
/**
399+
* @type {?string}
400+
*/
401+
guid?: string;
402+
403+
// Additional fields for compatibility with other interfaces (MF SIP, GTT, etc.)
404+
/**
405+
* @type {?(string | number)}
406+
*/
407+
amount?: string | number;
334408
/**
335409
* @type {?(string | number)}
336410
*/
@@ -347,10 +421,6 @@ export interface Order {
347421
* @type {?(string | number)}
348422
*/
349423
instalment_day?: string | number;
350-
/**
351-
* @type {?(string | number)}
352-
*/
353-
status?: string | number;
354424
/**
355425
* @type {?(string | number)}
356426
*/
@@ -372,17 +442,17 @@ export interface Order {
372442
*/
373443
orders?: Order[];
374444
/**
375-
* @type {?(string | number)}
445+
* @type {?PositionTypes}
376446
*/
377-
order_id?: string | number;
447+
position_type?: PositionTypes;
378448
/**
379-
* @type {?(string | number)}
449+
* @type {?Products}
380450
*/
381-
parent_order_id?: string | number;
451+
old_product?: Products;
382452
/**
383-
* @type {number}
453+
* @type {?Products}
384454
*/
385-
average_price?: number;
455+
new_product?: Products;
386456
}
387457

388458
/**

interfaces/ticker.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,3 +136,32 @@ export interface Depth {
136136

137137
// Combined type for all tick modes
138138
export type Tick = LTPTick | QuoteTick | FullTick;
139+
140+
/**
141+
* Event types for KiteTicker
142+
*/
143+
export type KiteTickerEvents =
144+
| 'connect'
145+
| 'ticks'
146+
| 'disconnect'
147+
| 'error'
148+
| 'close'
149+
| 'reconnect'
150+
| 'noreconnect'
151+
| 'message'
152+
| 'order_update';
153+
154+
/**
155+
* Event callback types for KiteTicker
156+
*/
157+
export interface KiteTickerEventCallbacks {
158+
connect: () => void;
159+
ticks: (ticks: Tick[]) => void;
160+
disconnect: (error: Error) => void;
161+
error: (error: Error) => void;
162+
close: (reason: string) => void;
163+
reconnect: (reconnect_count: number, reconnect_interval: number) => void;
164+
noreconnect: () => void;
165+
message: (binaryData: ArrayBuffer) => void;
166+
order_update: (order: any) => void;
167+
}

0 commit comments

Comments
 (0)