shoonya-sdk 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -0
- package/dist/shoonya-sdk.d.mts +335 -0
- package/dist/shoonya-sdk.d.ts +335 -0
- package/dist/shoonya-sdk.js +595 -0
- package/dist/shoonya-sdk.mjs +570 -0
- package/package.json +33 -0
- package/tsup.config.ts +12 -0
package/README.md
ADDED
|
@@ -0,0 +1,335 @@
|
|
|
1
|
+
import { EventEmitter } from 'events';
|
|
2
|
+
|
|
3
|
+
declare const paths: {
|
|
4
|
+
readonly login: "QuickAuth";
|
|
5
|
+
readonly logout: "Logout";
|
|
6
|
+
readonly forgotPassword: "ForgotPassword";
|
|
7
|
+
readonly changePassword: "Changepwd";
|
|
8
|
+
readonly watchlist: "MWList";
|
|
9
|
+
readonly getWatchlist: "MarketWatch";
|
|
10
|
+
readonly searchScrip: "SearchScrip";
|
|
11
|
+
readonly userInfo: "UserDetails";
|
|
12
|
+
readonly clientInfo: "ClientDetails";
|
|
13
|
+
readonly quotes: "GetQuotes";
|
|
14
|
+
readonly addScripToWL: "AddMultiScripsToMW";
|
|
15
|
+
readonly removeScripFromWL: "DeleteMultiMWScrips";
|
|
16
|
+
readonly securityInfo: "GetSecurityInfo";
|
|
17
|
+
readonly placeOrder: "PlaceOrder";
|
|
18
|
+
readonly modifyOrder: "ModifyOrder";
|
|
19
|
+
readonly cancelOrder: "CancelOrder";
|
|
20
|
+
readonly exitSNOOrder: "ExitSNOOrder";
|
|
21
|
+
readonly historicData: "TPSeries";
|
|
22
|
+
readonly optionChain: "GetOptionChain";
|
|
23
|
+
readonly orderBook: "OrderBook";
|
|
24
|
+
};
|
|
25
|
+
type Path = keyof typeof paths;
|
|
26
|
+
|
|
27
|
+
type LogType = "INFO" | "WARN" | "ERROR";
|
|
28
|
+
declare class Logger {
|
|
29
|
+
private logPath;
|
|
30
|
+
private maxSize;
|
|
31
|
+
/**
|
|
32
|
+
*
|
|
33
|
+
* @param logPath path of the log file
|
|
34
|
+
* @param maxSize max size a log file should have (in bytes)
|
|
35
|
+
*/
|
|
36
|
+
constructor(logPath: string, maxSize: number);
|
|
37
|
+
private checkLogSize;
|
|
38
|
+
log(message: string, type?: LogType): void;
|
|
39
|
+
getRecentLog(): string;
|
|
40
|
+
private deleteOldestFile;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
type RequestDataType = {
|
|
44
|
+
[key: string]: string;
|
|
45
|
+
};
|
|
46
|
+
type MakeKeysRequired<T, K extends keyof T> = T & {
|
|
47
|
+
[P in K]-?: T[P];
|
|
48
|
+
};
|
|
49
|
+
interface UserCred {
|
|
50
|
+
userId: string;
|
|
51
|
+
password: string;
|
|
52
|
+
twoFa: string;
|
|
53
|
+
apiKey: string;
|
|
54
|
+
imei?: string;
|
|
55
|
+
vendorCode?: string;
|
|
56
|
+
}
|
|
57
|
+
interface OrderInput {
|
|
58
|
+
uid?: string;
|
|
59
|
+
/**
|
|
60
|
+
* Same as userId
|
|
61
|
+
*/
|
|
62
|
+
actid?: string;
|
|
63
|
+
exch: "NSE" | "NFO" | "CDS" | "MCX" | "BSE";
|
|
64
|
+
/**
|
|
65
|
+
* Unique id of contract on which order to be placed.
|
|
66
|
+
*
|
|
67
|
+
* (Use the Results from Search Script to get the trading symbol & use url encoding to avoid special char error for symbols like M&M)
|
|
68
|
+
*/
|
|
69
|
+
tsym: string;
|
|
70
|
+
/**
|
|
71
|
+
* Order Quantity
|
|
72
|
+
*/
|
|
73
|
+
qty: string;
|
|
74
|
+
/**
|
|
75
|
+
* Order Price
|
|
76
|
+
*/
|
|
77
|
+
prc: string;
|
|
78
|
+
/**
|
|
79
|
+
* Only to be sent in case of SL / SL-M order.
|
|
80
|
+
*/
|
|
81
|
+
trgprc?: string;
|
|
82
|
+
/**
|
|
83
|
+
* Disclosed quantity (Max 10% for NSE, and 50% for MCX)
|
|
84
|
+
*/
|
|
85
|
+
dscqty: string;
|
|
86
|
+
/**
|
|
87
|
+
* Product Name
|
|
88
|
+
* (Select from ‘prarr’ Array provided in User Details response, and if same is allowed for selected, exchange.
|
|
89
|
+
* Show product display name, for user to select, and send corresponding prd in API call)
|
|
90
|
+
*
|
|
91
|
+
* ```
|
|
92
|
+
* `C` : CNC
|
|
93
|
+
* `M` : NRML
|
|
94
|
+
* `I` : MIS
|
|
95
|
+
* `B` : Bracket Order
|
|
96
|
+
* `H` : Cover Order
|
|
97
|
+
* ```
|
|
98
|
+
*/
|
|
99
|
+
prd: "C" | "M" | "I" | "B" | "H";
|
|
100
|
+
/**
|
|
101
|
+
* Transaction Type
|
|
102
|
+
* ```
|
|
103
|
+
* `B` : "Buy"
|
|
104
|
+
* `S` : "Sell"
|
|
105
|
+
* ```
|
|
106
|
+
*/
|
|
107
|
+
trantype: "B" | "S";
|
|
108
|
+
prctyp: "LMT" | "MKT" | "SL-LMT" | "SL-MKT" | "DS" | "2L" | "3L";
|
|
109
|
+
/**
|
|
110
|
+
* Retention Type (Show options as per allowed exchanges)
|
|
111
|
+
*/
|
|
112
|
+
ret: "DAY" | "EOS" | "IOC";
|
|
113
|
+
/**
|
|
114
|
+
* Any tag by user to mark order
|
|
115
|
+
*/
|
|
116
|
+
remarks?: string;
|
|
117
|
+
/**
|
|
118
|
+
* Noren order number, which needs to be modified
|
|
119
|
+
*/
|
|
120
|
+
norenordno?: string;
|
|
121
|
+
}
|
|
122
|
+
interface BaseResponse<T> {
|
|
123
|
+
stat: "Ok" | "Not_Ok";
|
|
124
|
+
values: T[];
|
|
125
|
+
emsg?: string;
|
|
126
|
+
}
|
|
127
|
+
interface SearchScripValues {
|
|
128
|
+
exch: "NSE" | "BSE" | "NFO" | "MCX";
|
|
129
|
+
tsym: string;
|
|
130
|
+
token: string;
|
|
131
|
+
pp: string;
|
|
132
|
+
ti: string;
|
|
133
|
+
ls: string;
|
|
134
|
+
}
|
|
135
|
+
interface SearchScripResponse extends BaseResponse<SearchScripValues> {
|
|
136
|
+
request_time?: string;
|
|
137
|
+
}
|
|
138
|
+
interface OptionChainValue extends SearchScripValues {
|
|
139
|
+
/**
|
|
140
|
+
* Option Type
|
|
141
|
+
*/
|
|
142
|
+
optt: string;
|
|
143
|
+
/**
|
|
144
|
+
* Strike Price
|
|
145
|
+
*/
|
|
146
|
+
strprc: string;
|
|
147
|
+
}
|
|
148
|
+
interface OptionChainResponse extends BaseResponse<OptionChainValue> {
|
|
149
|
+
}
|
|
150
|
+
type PlaceOrder = {
|
|
151
|
+
stat: "Ok" | "Not_Ok";
|
|
152
|
+
request_time?: string;
|
|
153
|
+
norenordno?: string;
|
|
154
|
+
emsg?: string;
|
|
155
|
+
};
|
|
156
|
+
interface OrderBookSuccess {
|
|
157
|
+
stat: "Ok";
|
|
158
|
+
exch: "NSE" | "BSE" | "NFO" | "MCX";
|
|
159
|
+
/**
|
|
160
|
+
* Trading Symbol
|
|
161
|
+
*/
|
|
162
|
+
tsym: string;
|
|
163
|
+
norenordno: string;
|
|
164
|
+
/**
|
|
165
|
+
* Price
|
|
166
|
+
*/
|
|
167
|
+
prc: string;
|
|
168
|
+
qty: string;
|
|
169
|
+
/**
|
|
170
|
+
* Product Alias Name
|
|
171
|
+
*/
|
|
172
|
+
prd: string;
|
|
173
|
+
status: string;
|
|
174
|
+
trantype: "B" | "S";
|
|
175
|
+
/**
|
|
176
|
+
* Price Type
|
|
177
|
+
*/
|
|
178
|
+
prctyp: "LMT" | "MKT";
|
|
179
|
+
fillshares: string;
|
|
180
|
+
avgprc: string;
|
|
181
|
+
/**
|
|
182
|
+
* Exchange Order Number
|
|
183
|
+
*/
|
|
184
|
+
exchordid: string;
|
|
185
|
+
/**
|
|
186
|
+
* Reject Reason
|
|
187
|
+
*/
|
|
188
|
+
rejreason?: string;
|
|
189
|
+
cancelqty?: string;
|
|
190
|
+
remarks?: string;
|
|
191
|
+
dscqty?: string;
|
|
192
|
+
uid: string;
|
|
193
|
+
actid: string;
|
|
194
|
+
ret: "DAY" | "IOC" | "EOS";
|
|
195
|
+
amo: "Yes" | "No";
|
|
196
|
+
exch_tm: string;
|
|
197
|
+
norentm: string;
|
|
198
|
+
}
|
|
199
|
+
interface OrderBookFail {
|
|
200
|
+
stat: "Not_Ok";
|
|
201
|
+
request_time: string;
|
|
202
|
+
emsg: string;
|
|
203
|
+
}
|
|
204
|
+
type OrderBook = OrderBookSuccess[] | OrderBookFail;
|
|
205
|
+
|
|
206
|
+
declare class Shoonya extends EventEmitter {
|
|
207
|
+
accessToken: string;
|
|
208
|
+
userId: string;
|
|
209
|
+
logger: Logger;
|
|
210
|
+
private logging;
|
|
211
|
+
private readonly httpBaseUrl;
|
|
212
|
+
private readonly wsBaseUrl;
|
|
213
|
+
private ws;
|
|
214
|
+
private connectTimer;
|
|
215
|
+
private disconnectTimer;
|
|
216
|
+
private accountId;
|
|
217
|
+
private twoFa;
|
|
218
|
+
private password;
|
|
219
|
+
private apiKey;
|
|
220
|
+
private cronJobRunning;
|
|
221
|
+
private scripList;
|
|
222
|
+
constructor(options?: {
|
|
223
|
+
logging: boolean;
|
|
224
|
+
});
|
|
225
|
+
request<T>(path: Path, body: {
|
|
226
|
+
data: RequestDataType;
|
|
227
|
+
key?: string;
|
|
228
|
+
}): Promise<T>;
|
|
229
|
+
/**
|
|
230
|
+
*
|
|
231
|
+
* @param credentials User Credential (username, password, appkeys etc.)
|
|
232
|
+
* @returns user information and access token
|
|
233
|
+
*/
|
|
234
|
+
login(rawCred: UserCred): Promise<any>;
|
|
235
|
+
/**
|
|
236
|
+
* @param query scrip name (BankNifty, Sensex etc.)
|
|
237
|
+
* @param exchange exchange name (NSE, BSE etc.)
|
|
238
|
+
* @returns
|
|
239
|
+
*/
|
|
240
|
+
searchScrip(query: string, exchange: string): Promise<SearchScripResponse>;
|
|
241
|
+
getWatchlistsName(): Promise<unknown>;
|
|
242
|
+
getWatchlist(listName: string): Promise<unknown>;
|
|
243
|
+
forgetPassword(PAN: string, DOB: string): Promise<unknown>;
|
|
244
|
+
/**
|
|
245
|
+
*
|
|
246
|
+
* @param oldPass sha256 of old pass
|
|
247
|
+
* @param newPass new password in plain text
|
|
248
|
+
* @returns
|
|
249
|
+
*/
|
|
250
|
+
changePassword(oldPass: string, newPass: string): Promise<unknown>;
|
|
251
|
+
getUserDetails(): Promise<unknown>;
|
|
252
|
+
/**
|
|
253
|
+
* @param brokerId logged in user's brokers Name / Id
|
|
254
|
+
* @returns
|
|
255
|
+
*/
|
|
256
|
+
getClientDetails(brokerId: string): Promise<unknown>;
|
|
257
|
+
getQuotes(exchange: string, contractToken: string): Promise<unknown>;
|
|
258
|
+
/**
|
|
259
|
+
*
|
|
260
|
+
* @param listName name of watchlist in which user want to add script
|
|
261
|
+
* @param scrips list of the scrip
|
|
262
|
+
* @returns
|
|
263
|
+
*/
|
|
264
|
+
addScripToWatchList(listName: string, scrips: string[]): Promise<unknown>;
|
|
265
|
+
/**
|
|
266
|
+
*
|
|
267
|
+
* @param listName name of watchlist in which user want to add script
|
|
268
|
+
* @param scrips list of the scrip
|
|
269
|
+
* @returns
|
|
270
|
+
*/
|
|
271
|
+
removeScripFromWatchList(listName: string, scrips: string[]): Promise<unknown>;
|
|
272
|
+
getSecurityInfo(exchange: string, contractToken: string): Promise<unknown>;
|
|
273
|
+
placeOrder(details: OrderInput): Promise<PlaceOrder>;
|
|
274
|
+
modifyOrder(orderDetail: MakeKeysRequired<Partial<OrderInput>, "exch" | "norenordno" | "tsym">): Promise<unknown>;
|
|
275
|
+
cancelOrder(orderNo: string): Promise<unknown>;
|
|
276
|
+
/**
|
|
277
|
+
*
|
|
278
|
+
* @param orderNo Noren order number, which needs to be modified
|
|
279
|
+
* @param product Allowed for only H and B products (Cover order and bracket order)
|
|
280
|
+
* @returns
|
|
281
|
+
*/
|
|
282
|
+
exitSNOOrder(orderNo: string, product: "H" | "B"): Promise<unknown>;
|
|
283
|
+
getHistoricData(option: {
|
|
284
|
+
exch: string;
|
|
285
|
+
token: string;
|
|
286
|
+
st?: string;
|
|
287
|
+
et?: string;
|
|
288
|
+
}): Promise<unknown>;
|
|
289
|
+
getOptionChain(option: {
|
|
290
|
+
tradingSymbol: string;
|
|
291
|
+
exchange: string;
|
|
292
|
+
midPrice: string;
|
|
293
|
+
count: string;
|
|
294
|
+
}): Promise<OptionChainResponse>;
|
|
295
|
+
orderBook(prd: "C" | "M" | "I" | "B" | "H"): Promise<OrderBook>;
|
|
296
|
+
/**
|
|
297
|
+
* Its a custom method which will return token number of option
|
|
298
|
+
* it can be used to start websocket connection to that tokenƒ
|
|
299
|
+
*
|
|
300
|
+
* @param params info about symbol
|
|
301
|
+
* @returns
|
|
302
|
+
*/
|
|
303
|
+
getOptionToken(params: {
|
|
304
|
+
symbol: string;
|
|
305
|
+
strikePrice: number;
|
|
306
|
+
optionType: "CE" | "PE";
|
|
307
|
+
exchange?: "NFO" | "MCX";
|
|
308
|
+
/**
|
|
309
|
+
* Count of option in each side. default 5 on ITM and 5 OTM
|
|
310
|
+
* @default 5
|
|
311
|
+
*/
|
|
312
|
+
count?: string;
|
|
313
|
+
}): Promise<{
|
|
314
|
+
token: string;
|
|
315
|
+
exchange: "NFO" | "MCX";
|
|
316
|
+
tsym: string;
|
|
317
|
+
}>;
|
|
318
|
+
private getFormattedExpiry;
|
|
319
|
+
private getNext7FormattedDate;
|
|
320
|
+
connectWS(): void;
|
|
321
|
+
/**
|
|
322
|
+
*
|
|
323
|
+
* subscribes for list of scrip by which WS returns them every time their price changes.
|
|
324
|
+
*
|
|
325
|
+
* `searchScrip` method can be used to get scripToken from scripName
|
|
326
|
+
* @param scripList scrip list requires list of scrip name in format of `exchangeName|scripToken`
|
|
327
|
+
*/
|
|
328
|
+
subscribe(scripList: string[]): void;
|
|
329
|
+
unsubscribe(scripList: string[]): void;
|
|
330
|
+
subscribeOrderUpdate(): void;
|
|
331
|
+
unsubscribeOrderUpdate(): void;
|
|
332
|
+
disconnect(): void;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
export { Shoonya };
|
|
@@ -0,0 +1,335 @@
|
|
|
1
|
+
import { EventEmitter } from 'events';
|
|
2
|
+
|
|
3
|
+
declare const paths: {
|
|
4
|
+
readonly login: "QuickAuth";
|
|
5
|
+
readonly logout: "Logout";
|
|
6
|
+
readonly forgotPassword: "ForgotPassword";
|
|
7
|
+
readonly changePassword: "Changepwd";
|
|
8
|
+
readonly watchlist: "MWList";
|
|
9
|
+
readonly getWatchlist: "MarketWatch";
|
|
10
|
+
readonly searchScrip: "SearchScrip";
|
|
11
|
+
readonly userInfo: "UserDetails";
|
|
12
|
+
readonly clientInfo: "ClientDetails";
|
|
13
|
+
readonly quotes: "GetQuotes";
|
|
14
|
+
readonly addScripToWL: "AddMultiScripsToMW";
|
|
15
|
+
readonly removeScripFromWL: "DeleteMultiMWScrips";
|
|
16
|
+
readonly securityInfo: "GetSecurityInfo";
|
|
17
|
+
readonly placeOrder: "PlaceOrder";
|
|
18
|
+
readonly modifyOrder: "ModifyOrder";
|
|
19
|
+
readonly cancelOrder: "CancelOrder";
|
|
20
|
+
readonly exitSNOOrder: "ExitSNOOrder";
|
|
21
|
+
readonly historicData: "TPSeries";
|
|
22
|
+
readonly optionChain: "GetOptionChain";
|
|
23
|
+
readonly orderBook: "OrderBook";
|
|
24
|
+
};
|
|
25
|
+
type Path = keyof typeof paths;
|
|
26
|
+
|
|
27
|
+
type LogType = "INFO" | "WARN" | "ERROR";
|
|
28
|
+
declare class Logger {
|
|
29
|
+
private logPath;
|
|
30
|
+
private maxSize;
|
|
31
|
+
/**
|
|
32
|
+
*
|
|
33
|
+
* @param logPath path of the log file
|
|
34
|
+
* @param maxSize max size a log file should have (in bytes)
|
|
35
|
+
*/
|
|
36
|
+
constructor(logPath: string, maxSize: number);
|
|
37
|
+
private checkLogSize;
|
|
38
|
+
log(message: string, type?: LogType): void;
|
|
39
|
+
getRecentLog(): string;
|
|
40
|
+
private deleteOldestFile;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
type RequestDataType = {
|
|
44
|
+
[key: string]: string;
|
|
45
|
+
};
|
|
46
|
+
type MakeKeysRequired<T, K extends keyof T> = T & {
|
|
47
|
+
[P in K]-?: T[P];
|
|
48
|
+
};
|
|
49
|
+
interface UserCred {
|
|
50
|
+
userId: string;
|
|
51
|
+
password: string;
|
|
52
|
+
twoFa: string;
|
|
53
|
+
apiKey: string;
|
|
54
|
+
imei?: string;
|
|
55
|
+
vendorCode?: string;
|
|
56
|
+
}
|
|
57
|
+
interface OrderInput {
|
|
58
|
+
uid?: string;
|
|
59
|
+
/**
|
|
60
|
+
* Same as userId
|
|
61
|
+
*/
|
|
62
|
+
actid?: string;
|
|
63
|
+
exch: "NSE" | "NFO" | "CDS" | "MCX" | "BSE";
|
|
64
|
+
/**
|
|
65
|
+
* Unique id of contract on which order to be placed.
|
|
66
|
+
*
|
|
67
|
+
* (Use the Results from Search Script to get the trading symbol & use url encoding to avoid special char error for symbols like M&M)
|
|
68
|
+
*/
|
|
69
|
+
tsym: string;
|
|
70
|
+
/**
|
|
71
|
+
* Order Quantity
|
|
72
|
+
*/
|
|
73
|
+
qty: string;
|
|
74
|
+
/**
|
|
75
|
+
* Order Price
|
|
76
|
+
*/
|
|
77
|
+
prc: string;
|
|
78
|
+
/**
|
|
79
|
+
* Only to be sent in case of SL / SL-M order.
|
|
80
|
+
*/
|
|
81
|
+
trgprc?: string;
|
|
82
|
+
/**
|
|
83
|
+
* Disclosed quantity (Max 10% for NSE, and 50% for MCX)
|
|
84
|
+
*/
|
|
85
|
+
dscqty: string;
|
|
86
|
+
/**
|
|
87
|
+
* Product Name
|
|
88
|
+
* (Select from ‘prarr’ Array provided in User Details response, and if same is allowed for selected, exchange.
|
|
89
|
+
* Show product display name, for user to select, and send corresponding prd in API call)
|
|
90
|
+
*
|
|
91
|
+
* ```
|
|
92
|
+
* `C` : CNC
|
|
93
|
+
* `M` : NRML
|
|
94
|
+
* `I` : MIS
|
|
95
|
+
* `B` : Bracket Order
|
|
96
|
+
* `H` : Cover Order
|
|
97
|
+
* ```
|
|
98
|
+
*/
|
|
99
|
+
prd: "C" | "M" | "I" | "B" | "H";
|
|
100
|
+
/**
|
|
101
|
+
* Transaction Type
|
|
102
|
+
* ```
|
|
103
|
+
* `B` : "Buy"
|
|
104
|
+
* `S` : "Sell"
|
|
105
|
+
* ```
|
|
106
|
+
*/
|
|
107
|
+
trantype: "B" | "S";
|
|
108
|
+
prctyp: "LMT" | "MKT" | "SL-LMT" | "SL-MKT" | "DS" | "2L" | "3L";
|
|
109
|
+
/**
|
|
110
|
+
* Retention Type (Show options as per allowed exchanges)
|
|
111
|
+
*/
|
|
112
|
+
ret: "DAY" | "EOS" | "IOC";
|
|
113
|
+
/**
|
|
114
|
+
* Any tag by user to mark order
|
|
115
|
+
*/
|
|
116
|
+
remarks?: string;
|
|
117
|
+
/**
|
|
118
|
+
* Noren order number, which needs to be modified
|
|
119
|
+
*/
|
|
120
|
+
norenordno?: string;
|
|
121
|
+
}
|
|
122
|
+
interface BaseResponse<T> {
|
|
123
|
+
stat: "Ok" | "Not_Ok";
|
|
124
|
+
values: T[];
|
|
125
|
+
emsg?: string;
|
|
126
|
+
}
|
|
127
|
+
interface SearchScripValues {
|
|
128
|
+
exch: "NSE" | "BSE" | "NFO" | "MCX";
|
|
129
|
+
tsym: string;
|
|
130
|
+
token: string;
|
|
131
|
+
pp: string;
|
|
132
|
+
ti: string;
|
|
133
|
+
ls: string;
|
|
134
|
+
}
|
|
135
|
+
interface SearchScripResponse extends BaseResponse<SearchScripValues> {
|
|
136
|
+
request_time?: string;
|
|
137
|
+
}
|
|
138
|
+
interface OptionChainValue extends SearchScripValues {
|
|
139
|
+
/**
|
|
140
|
+
* Option Type
|
|
141
|
+
*/
|
|
142
|
+
optt: string;
|
|
143
|
+
/**
|
|
144
|
+
* Strike Price
|
|
145
|
+
*/
|
|
146
|
+
strprc: string;
|
|
147
|
+
}
|
|
148
|
+
interface OptionChainResponse extends BaseResponse<OptionChainValue> {
|
|
149
|
+
}
|
|
150
|
+
type PlaceOrder = {
|
|
151
|
+
stat: "Ok" | "Not_Ok";
|
|
152
|
+
request_time?: string;
|
|
153
|
+
norenordno?: string;
|
|
154
|
+
emsg?: string;
|
|
155
|
+
};
|
|
156
|
+
interface OrderBookSuccess {
|
|
157
|
+
stat: "Ok";
|
|
158
|
+
exch: "NSE" | "BSE" | "NFO" | "MCX";
|
|
159
|
+
/**
|
|
160
|
+
* Trading Symbol
|
|
161
|
+
*/
|
|
162
|
+
tsym: string;
|
|
163
|
+
norenordno: string;
|
|
164
|
+
/**
|
|
165
|
+
* Price
|
|
166
|
+
*/
|
|
167
|
+
prc: string;
|
|
168
|
+
qty: string;
|
|
169
|
+
/**
|
|
170
|
+
* Product Alias Name
|
|
171
|
+
*/
|
|
172
|
+
prd: string;
|
|
173
|
+
status: string;
|
|
174
|
+
trantype: "B" | "S";
|
|
175
|
+
/**
|
|
176
|
+
* Price Type
|
|
177
|
+
*/
|
|
178
|
+
prctyp: "LMT" | "MKT";
|
|
179
|
+
fillshares: string;
|
|
180
|
+
avgprc: string;
|
|
181
|
+
/**
|
|
182
|
+
* Exchange Order Number
|
|
183
|
+
*/
|
|
184
|
+
exchordid: string;
|
|
185
|
+
/**
|
|
186
|
+
* Reject Reason
|
|
187
|
+
*/
|
|
188
|
+
rejreason?: string;
|
|
189
|
+
cancelqty?: string;
|
|
190
|
+
remarks?: string;
|
|
191
|
+
dscqty?: string;
|
|
192
|
+
uid: string;
|
|
193
|
+
actid: string;
|
|
194
|
+
ret: "DAY" | "IOC" | "EOS";
|
|
195
|
+
amo: "Yes" | "No";
|
|
196
|
+
exch_tm: string;
|
|
197
|
+
norentm: string;
|
|
198
|
+
}
|
|
199
|
+
interface OrderBookFail {
|
|
200
|
+
stat: "Not_Ok";
|
|
201
|
+
request_time: string;
|
|
202
|
+
emsg: string;
|
|
203
|
+
}
|
|
204
|
+
type OrderBook = OrderBookSuccess[] | OrderBookFail;
|
|
205
|
+
|
|
206
|
+
declare class Shoonya extends EventEmitter {
|
|
207
|
+
accessToken: string;
|
|
208
|
+
userId: string;
|
|
209
|
+
logger: Logger;
|
|
210
|
+
private logging;
|
|
211
|
+
private readonly httpBaseUrl;
|
|
212
|
+
private readonly wsBaseUrl;
|
|
213
|
+
private ws;
|
|
214
|
+
private connectTimer;
|
|
215
|
+
private disconnectTimer;
|
|
216
|
+
private accountId;
|
|
217
|
+
private twoFa;
|
|
218
|
+
private password;
|
|
219
|
+
private apiKey;
|
|
220
|
+
private cronJobRunning;
|
|
221
|
+
private scripList;
|
|
222
|
+
constructor(options?: {
|
|
223
|
+
logging: boolean;
|
|
224
|
+
});
|
|
225
|
+
request<T>(path: Path, body: {
|
|
226
|
+
data: RequestDataType;
|
|
227
|
+
key?: string;
|
|
228
|
+
}): Promise<T>;
|
|
229
|
+
/**
|
|
230
|
+
*
|
|
231
|
+
* @param credentials User Credential (username, password, appkeys etc.)
|
|
232
|
+
* @returns user information and access token
|
|
233
|
+
*/
|
|
234
|
+
login(rawCred: UserCred): Promise<any>;
|
|
235
|
+
/**
|
|
236
|
+
* @param query scrip name (BankNifty, Sensex etc.)
|
|
237
|
+
* @param exchange exchange name (NSE, BSE etc.)
|
|
238
|
+
* @returns
|
|
239
|
+
*/
|
|
240
|
+
searchScrip(query: string, exchange: string): Promise<SearchScripResponse>;
|
|
241
|
+
getWatchlistsName(): Promise<unknown>;
|
|
242
|
+
getWatchlist(listName: string): Promise<unknown>;
|
|
243
|
+
forgetPassword(PAN: string, DOB: string): Promise<unknown>;
|
|
244
|
+
/**
|
|
245
|
+
*
|
|
246
|
+
* @param oldPass sha256 of old pass
|
|
247
|
+
* @param newPass new password in plain text
|
|
248
|
+
* @returns
|
|
249
|
+
*/
|
|
250
|
+
changePassword(oldPass: string, newPass: string): Promise<unknown>;
|
|
251
|
+
getUserDetails(): Promise<unknown>;
|
|
252
|
+
/**
|
|
253
|
+
* @param brokerId logged in user's brokers Name / Id
|
|
254
|
+
* @returns
|
|
255
|
+
*/
|
|
256
|
+
getClientDetails(brokerId: string): Promise<unknown>;
|
|
257
|
+
getQuotes(exchange: string, contractToken: string): Promise<unknown>;
|
|
258
|
+
/**
|
|
259
|
+
*
|
|
260
|
+
* @param listName name of watchlist in which user want to add script
|
|
261
|
+
* @param scrips list of the scrip
|
|
262
|
+
* @returns
|
|
263
|
+
*/
|
|
264
|
+
addScripToWatchList(listName: string, scrips: string[]): Promise<unknown>;
|
|
265
|
+
/**
|
|
266
|
+
*
|
|
267
|
+
* @param listName name of watchlist in which user want to add script
|
|
268
|
+
* @param scrips list of the scrip
|
|
269
|
+
* @returns
|
|
270
|
+
*/
|
|
271
|
+
removeScripFromWatchList(listName: string, scrips: string[]): Promise<unknown>;
|
|
272
|
+
getSecurityInfo(exchange: string, contractToken: string): Promise<unknown>;
|
|
273
|
+
placeOrder(details: OrderInput): Promise<PlaceOrder>;
|
|
274
|
+
modifyOrder(orderDetail: MakeKeysRequired<Partial<OrderInput>, "exch" | "norenordno" | "tsym">): Promise<unknown>;
|
|
275
|
+
cancelOrder(orderNo: string): Promise<unknown>;
|
|
276
|
+
/**
|
|
277
|
+
*
|
|
278
|
+
* @param orderNo Noren order number, which needs to be modified
|
|
279
|
+
* @param product Allowed for only H and B products (Cover order and bracket order)
|
|
280
|
+
* @returns
|
|
281
|
+
*/
|
|
282
|
+
exitSNOOrder(orderNo: string, product: "H" | "B"): Promise<unknown>;
|
|
283
|
+
getHistoricData(option: {
|
|
284
|
+
exch: string;
|
|
285
|
+
token: string;
|
|
286
|
+
st?: string;
|
|
287
|
+
et?: string;
|
|
288
|
+
}): Promise<unknown>;
|
|
289
|
+
getOptionChain(option: {
|
|
290
|
+
tradingSymbol: string;
|
|
291
|
+
exchange: string;
|
|
292
|
+
midPrice: string;
|
|
293
|
+
count: string;
|
|
294
|
+
}): Promise<OptionChainResponse>;
|
|
295
|
+
orderBook(prd: "C" | "M" | "I" | "B" | "H"): Promise<OrderBook>;
|
|
296
|
+
/**
|
|
297
|
+
* Its a custom method which will return token number of option
|
|
298
|
+
* it can be used to start websocket connection to that tokenƒ
|
|
299
|
+
*
|
|
300
|
+
* @param params info about symbol
|
|
301
|
+
* @returns
|
|
302
|
+
*/
|
|
303
|
+
getOptionToken(params: {
|
|
304
|
+
symbol: string;
|
|
305
|
+
strikePrice: number;
|
|
306
|
+
optionType: "CE" | "PE";
|
|
307
|
+
exchange?: "NFO" | "MCX";
|
|
308
|
+
/**
|
|
309
|
+
* Count of option in each side. default 5 on ITM and 5 OTM
|
|
310
|
+
* @default 5
|
|
311
|
+
*/
|
|
312
|
+
count?: string;
|
|
313
|
+
}): Promise<{
|
|
314
|
+
token: string;
|
|
315
|
+
exchange: "NFO" | "MCX";
|
|
316
|
+
tsym: string;
|
|
317
|
+
}>;
|
|
318
|
+
private getFormattedExpiry;
|
|
319
|
+
private getNext7FormattedDate;
|
|
320
|
+
connectWS(): void;
|
|
321
|
+
/**
|
|
322
|
+
*
|
|
323
|
+
* subscribes for list of scrip by which WS returns them every time their price changes.
|
|
324
|
+
*
|
|
325
|
+
* `searchScrip` method can be used to get scripToken from scripName
|
|
326
|
+
* @param scripList scrip list requires list of scrip name in format of `exchangeName|scripToken`
|
|
327
|
+
*/
|
|
328
|
+
subscribe(scripList: string[]): void;
|
|
329
|
+
unsubscribe(scripList: string[]): void;
|
|
330
|
+
subscribeOrderUpdate(): void;
|
|
331
|
+
unsubscribeOrderUpdate(): void;
|
|
332
|
+
disconnect(): void;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
export { Shoonya };
|