shoonya-sdk 1.2.0 → 1.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/dist/index.cjs CHANGED
@@ -120,7 +120,7 @@ var Tokens = class {
120
120
  }
121
121
  };
122
122
  var tokens = new Tokens();
123
- async function refreshAccessToken(retryCount = 3) {
123
+ async function refreshAccessToken(retryCount = 1) {
124
124
  let errorMsg = "";
125
125
  for (let i = 0; i < retryCount; i++) {
126
126
  try {
@@ -858,6 +858,14 @@ var WebsocketClient = class extends import_events.EventEmitter {
858
858
  this.emit("unsubscribed", result.ts);
859
859
  }
860
860
  if (result.t === "ok") {
861
+ this.logger.log("Subscribed to order update");
862
+ this.emit("subscribedOrderUpdate");
863
+ }
864
+ if (result.t === "uok") {
865
+ this.logger.log("Unsubscribed from order update");
866
+ this.emit("unsubscribedOrderUpdate");
867
+ }
868
+ if (result.t === "om") {
861
869
  this.emit("orderUpdate", result);
862
870
  }
863
871
  if (result.lp && result.t === "df") {
@@ -942,6 +950,18 @@ var WebsocketClient = class extends import_events.EventEmitter {
942
950
  this.subscribe(tokensToSub);
943
951
  }
944
952
  }
953
+ subscribeOrderUpdate() {
954
+ this.send({
955
+ t: "o",
956
+ actid: tokens.getCred().accountId
957
+ });
958
+ }
959
+ unsubscribeOrderUpdate() {
960
+ this.send({
961
+ t: "uo"
962
+ // t: "ud" if "uo" doesn't work since there is some issue in docs
963
+ });
964
+ }
945
965
  send(msg) {
946
966
  if (this.ws && this.ws.readyState === this.ws.OPEN) {
947
967
  this.ws.send(JSON.stringify(msg));
package/dist/index.d.cts CHANGED
@@ -898,6 +898,8 @@ interface Events {
898
898
  subscribed: (token: string) => void;
899
899
  /** sends token name of symbol, user unsubscribed. eg. Nifty Bank*/
900
900
  unsubscribed: (token: string) => void;
901
+ subscribedOrderUpdate: () => void;
902
+ unsubscribedOrderUpdate: () => void;
901
903
  /** access token refreshed */
902
904
  tokenRefresh: () => void;
903
905
  error: (err: Error) => void;
@@ -940,6 +942,8 @@ declare class WebsocketClient extends EventEmitter {
940
942
  close(): void;
941
943
  isWsOpen(): boolean;
942
944
  private resubscribe;
945
+ subscribeOrderUpdate(): void;
946
+ unsubscribeOrderUpdate(): void;
943
947
  private send;
944
948
  private refreshEveryMorning;
945
949
  private parseDailyRefreshTime;
package/dist/index.d.ts CHANGED
@@ -898,6 +898,8 @@ interface Events {
898
898
  subscribed: (token: string) => void;
899
899
  /** sends token name of symbol, user unsubscribed. eg. Nifty Bank*/
900
900
  unsubscribed: (token: string) => void;
901
+ subscribedOrderUpdate: () => void;
902
+ unsubscribedOrderUpdate: () => void;
901
903
  /** access token refreshed */
902
904
  tokenRefresh: () => void;
903
905
  error: (err: Error) => void;
@@ -940,6 +942,8 @@ declare class WebsocketClient extends EventEmitter {
940
942
  close(): void;
941
943
  isWsOpen(): boolean;
942
944
  private resubscribe;
945
+ subscribeOrderUpdate(): void;
946
+ unsubscribeOrderUpdate(): void;
943
947
  private send;
944
948
  private refreshEveryMorning;
945
949
  private parseDailyRefreshTime;
package/dist/index.js CHANGED
@@ -85,7 +85,7 @@ var Tokens = class {
85
85
  }
86
86
  };
87
87
  var tokens = new Tokens();
88
- async function refreshAccessToken(retryCount = 3) {
88
+ async function refreshAccessToken(retryCount = 1) {
89
89
  let errorMsg = "";
90
90
  for (let i = 0; i < retryCount; i++) {
91
91
  try {
@@ -830,6 +830,14 @@ var WebsocketClient = class extends EventEmitter {
830
830
  this.emit("unsubscribed", result.ts);
831
831
  }
832
832
  if (result.t === "ok") {
833
+ this.logger.log("Subscribed to order update");
834
+ this.emit("subscribedOrderUpdate");
835
+ }
836
+ if (result.t === "uok") {
837
+ this.logger.log("Unsubscribed from order update");
838
+ this.emit("unsubscribedOrderUpdate");
839
+ }
840
+ if (result.t === "om") {
833
841
  this.emit("orderUpdate", result);
834
842
  }
835
843
  if (result.lp && result.t === "df") {
@@ -914,6 +922,18 @@ var WebsocketClient = class extends EventEmitter {
914
922
  this.subscribe(tokensToSub);
915
923
  }
916
924
  }
925
+ subscribeOrderUpdate() {
926
+ this.send({
927
+ t: "o",
928
+ actid: tokens.getCred().accountId
929
+ });
930
+ }
931
+ unsubscribeOrderUpdate() {
932
+ this.send({
933
+ t: "uo"
934
+ // t: "ud" if "uo" doesn't work since there is some issue in docs
935
+ });
936
+ }
917
937
  send(msg) {
918
938
  if (this.ws && this.ws.readyState === this.ws.OPEN) {
919
939
  this.ws.send(JSON.stringify(msg));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shoonya-sdk",
3
- "version": "1.2.0",
3
+ "version": "1.3.1",
4
4
  "description": "Wrapper around Shoonya API",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.js",