@nightlylabs/dex-sdk 0.0.16 → 0.0.18

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
@@ -848,8 +848,9 @@ var Client = class _Client {
848
848
  await this.sendWsMessage(command);
849
849
  const topic = getTopicFromCommand(command);
850
850
  this._subscriptions.set(topic, callback);
851
+ return this.unsubscribeIndexPricesUpdates;
851
852
  }
852
- async unsubscribeIndexPricesUpdates(userId) {
853
+ async unsubscribeIndexPricesUpdates() {
853
854
  const command = {
854
855
  type: "SubscribeOracle",
855
856
  content: { id: getRandomId() }
@@ -866,6 +867,7 @@ var Client = class _Client {
866
867
  await this.sendWsMessage(command);
867
868
  const topic = getTopicFromCommand(command);
868
869
  this._subscriptions.set(topic, callback);
870
+ return () => this.unsubscribeUserUpdates(userId);
869
871
  }
870
872
  async unsubscribeUserUpdates(userId) {
871
873
  const command = {
@@ -876,6 +878,25 @@ var Client = class _Client {
876
878
  const topic = getTopicFromCommand(command);
877
879
  this._subscriptions.delete(topic);
878
880
  }
881
+ async subscribePerpMarketUpdates(market, callback) {
882
+ const command = {
883
+ type: "SubscribeMarket",
884
+ content: { id: getRandomId(), market }
885
+ };
886
+ await this.sendWsMessage(command);
887
+ const topic = getTopicFromCommand(command);
888
+ this._subscriptions.set(topic, callback);
889
+ return () => this.unsubscribePerpMarketUpdates(market);
890
+ }
891
+ async unsubscribePerpMarketUpdates(market) {
892
+ const command = {
893
+ type: "UnsubscribeMarket",
894
+ content: { id: getRandomId(), market }
895
+ };
896
+ await this.sendWsMessage(command);
897
+ const topic = getTopicFromCommand(command);
898
+ this._subscriptions.delete(topic);
899
+ }
879
900
  // needs to be signed by user and sent to blockchain
880
901
  async addApiKey(params) {
881
902
  return (0, import_surf.createEntryPayload)(addApiKey_default, {
package/dist/index.d.cts CHANGED
@@ -608,10 +608,12 @@ declare class Client {
608
608
  signature: AccountAuthenticator;
609
609
  apiKey: _aptos_labs_ts_sdk.Ed25519Account;
610
610
  }>;
611
- subscribeIndexPricesUpdates(callback: (data: WsMessage) => void): Promise<void>;
612
- unsubscribeIndexPricesUpdates(userId: string): Promise<void>;
613
- subscribeUserUpdates(userId: string, callback: (data: WsMessage) => void): Promise<void>;
611
+ subscribeIndexPricesUpdates(callback: (data: WsOracleUpdates) => void): Promise<() => Promise<void>>;
612
+ unsubscribeIndexPricesUpdates(): Promise<void>;
613
+ subscribeUserUpdates(userId: string, callback: (data: WsUserUpdates) => void): Promise<() => Promise<void>>;
614
614
  unsubscribeUserUpdates(userId: string): Promise<void>;
615
+ subscribePerpMarketUpdates(market: string, callback: (data: WsPerpMarketUpdates) => void): Promise<() => Promise<void>>;
616
+ unsubscribePerpMarketUpdates(market: string): Promise<void>;
615
617
  addApiKey(params: AddApiKeyParams): Promise<_thalalabs_surf.EntryPayload>;
616
618
  removeApiKey(params: RemoveApiKeyParams): Promise<SubmitSponsoredTransactionResponse>;
617
619
  setAliasName(params: SetAliasNameParams): Promise<SubmitSponsoredTransactionResponse>;
@@ -724,6 +726,15 @@ interface IGetChartCandlesInRange {
724
726
  endTime?: number;
725
727
  cursor?: PaginationCursor;
726
728
  }
729
+ type WsOracleUpdates = Extract<WsMessage, {
730
+ type: 'OracleUpdates';
731
+ }>;
732
+ type WsUserUpdates = Extract<WsMessage, {
733
+ type: 'BalanceChange' | 'Deposit' | 'Withdraw' | 'WithdrawLend' | 'Lend' | 'Borrow' | 'RepayBorrow' | 'PlacePerpLimitOrder' | 'PlacePerpMarketOrder' | 'CancelPerpOrders' | 'SetAutolend' | 'SetAliasName' | 'AddApiKey' | 'RemoveApiKey';
734
+ }>;
735
+ type WsPerpMarketUpdates = Extract<WsMessage, {
736
+ type: 'OrderbookUpdate' | 'TradesUpdate';
737
+ }>;
727
738
 
728
739
  declare const ExchangeProxies: {
729
740
  [key in Network]: string[];
@@ -746,4 +757,4 @@ declare const generateApiKey: () => _aptos_labs_ts_sdk.Ed25519Account;
746
757
  declare const getTopicFromCommand: (data: WsCommand) => string;
747
758
  declare const getTopicFromMessage: (data: WsMessage) => string;
748
759
 
749
- export { type AddApiKey, type AddApiKeyParams, type Address, AdminEndpoints, type BalanceChange, BaseEndpoints, type Borrow, type BorrowLending, type CancelAllPerpOrdersParams, type CancelPerpOrdersParams, type CanceledPerpOrders, type ChartCandle, ChartInterval, Client, type Content, type CreateUserParams, type Deposit, type DepositToVaultParams, type DepositTokenParams, EndpointsV1, type ErrorResponse, type ExchangeConfig, ExchangeProxies, type Fees, type FundingCheckpoint, type FundingRate, GLOBAL_DENOMINATOR, type GetBorrowLendingDataResponse, type GetChartCandlesInRangeRequest, type GetChartCandlesInRangeResponse, type GetPerpMarketsDataRequest, type GetPerpMarketsDataResponse, type GetPerpOrderBookDataRequest, type GetPerpOrderBookDataResponse, type GetPerpRecentTradesRequest, type GetPerpRecentTradesResponse, type GetPerpUserFillsRequest, type GetPerpUserFillsResponse, type GetPerpUserOrdersRequest, type GetPerpUserOrdersResponse, type GetPerpetualMarketsConfigResponse, type GetPriceIndexesResponse, type GetTokensConfigResponse, type GetUserDataRequest, type GetUserDataResponse, type GetUsersByAddressRequest, type GetUsersByAddressResponse, type IGetChartCandlesInRange, type Lend, type LendTokenParams, type MarginStep, Network, type OracleUpdate, type OracleUpdates, type Order, type OrderFills, OrderSide, OrderStatus, OrderType, type OrderbookUpdate, type PaginationCursor, type PerpFill, type PerpMarketData, type PerpOrder, type PerpOrderBookData, type PerpPosition, type PerpTrade, type PerpetualMarketConfigEntry, PerpetualMarketStatus, type PlacePerpLimitOrder, type PlacePerpLimitOrderParams, type PlacePerpMarketOrder, type PlacePerpMarketOrderParams, type PriceIndex, type RedeemTokenParams, type Referral, type RemoveApiKey, type RemoveApiKeyParams, type RepayBorrow, type SetAlias, type SetAliasNameParams, type SetAutolend, type SetAutolendParams, Status, type StatusResponse, type SubmitSponsoredTransactionRequest, type SubmitSponsoredTransactionResponse, TestFaucet, type TimeResponse, type TokenConfigEntry, type Topic, type Trade, TradeRole, type TradesUpdate, type User, UserStatus, type UtilizationCurve, type VaultInvestment, type Withdraw, type WithdrawFromVaultParams, type WithdrawLend, type WsCommand, type WsFill, type WsMessage, generateApiKey, getRandomId, getTopicFromCommand, getTopicFromMessage, sleep, toSystemValue };
760
+ export { type AddApiKey, type AddApiKeyParams, type Address, AdminEndpoints, type BalanceChange, BaseEndpoints, type Borrow, type BorrowLending, type CancelAllPerpOrdersParams, type CancelPerpOrdersParams, type CanceledPerpOrders, type ChartCandle, ChartInterval, Client, type Content, type CreateUserParams, type Deposit, type DepositToVaultParams, type DepositTokenParams, EndpointsV1, type ErrorResponse, type ExchangeConfig, ExchangeProxies, type Fees, type FundingCheckpoint, type FundingRate, GLOBAL_DENOMINATOR, type GetBorrowLendingDataResponse, type GetChartCandlesInRangeRequest, type GetChartCandlesInRangeResponse, type GetPerpMarketsDataRequest, type GetPerpMarketsDataResponse, type GetPerpOrderBookDataRequest, type GetPerpOrderBookDataResponse, type GetPerpRecentTradesRequest, type GetPerpRecentTradesResponse, type GetPerpUserFillsRequest, type GetPerpUserFillsResponse, type GetPerpUserOrdersRequest, type GetPerpUserOrdersResponse, type GetPerpetualMarketsConfigResponse, type GetPriceIndexesResponse, type GetTokensConfigResponse, type GetUserDataRequest, type GetUserDataResponse, type GetUsersByAddressRequest, type GetUsersByAddressResponse, type IGetChartCandlesInRange, type Lend, type LendTokenParams, type MarginStep, Network, type OracleUpdate, type OracleUpdates, type Order, type OrderFills, OrderSide, OrderStatus, OrderType, type OrderbookUpdate, type PaginationCursor, type PerpFill, type PerpMarketData, type PerpOrder, type PerpOrderBookData, type PerpPosition, type PerpTrade, type PerpetualMarketConfigEntry, PerpetualMarketStatus, type PlacePerpLimitOrder, type PlacePerpLimitOrderParams, type PlacePerpMarketOrder, type PlacePerpMarketOrderParams, type PriceIndex, type RedeemTokenParams, type Referral, type RemoveApiKey, type RemoveApiKeyParams, type RepayBorrow, type SetAlias, type SetAliasNameParams, type SetAutolend, type SetAutolendParams, Status, type StatusResponse, type SubmitSponsoredTransactionRequest, type SubmitSponsoredTransactionResponse, TestFaucet, type TimeResponse, type TokenConfigEntry, type Topic, type Trade, TradeRole, type TradesUpdate, type User, UserStatus, type UtilizationCurve, type VaultInvestment, type Withdraw, type WithdrawFromVaultParams, type WithdrawLend, type WsCommand, type WsFill, type WsMessage, type WsOracleUpdates, type WsPerpMarketUpdates, type WsUserUpdates, generateApiKey, getRandomId, getTopicFromCommand, getTopicFromMessage, sleep, toSystemValue };
package/dist/index.d.ts CHANGED
@@ -608,10 +608,12 @@ declare class Client {
608
608
  signature: AccountAuthenticator;
609
609
  apiKey: _aptos_labs_ts_sdk.Ed25519Account;
610
610
  }>;
611
- subscribeIndexPricesUpdates(callback: (data: WsMessage) => void): Promise<void>;
612
- unsubscribeIndexPricesUpdates(userId: string): Promise<void>;
613
- subscribeUserUpdates(userId: string, callback: (data: WsMessage) => void): Promise<void>;
611
+ subscribeIndexPricesUpdates(callback: (data: WsOracleUpdates) => void): Promise<() => Promise<void>>;
612
+ unsubscribeIndexPricesUpdates(): Promise<void>;
613
+ subscribeUserUpdates(userId: string, callback: (data: WsUserUpdates) => void): Promise<() => Promise<void>>;
614
614
  unsubscribeUserUpdates(userId: string): Promise<void>;
615
+ subscribePerpMarketUpdates(market: string, callback: (data: WsPerpMarketUpdates) => void): Promise<() => Promise<void>>;
616
+ unsubscribePerpMarketUpdates(market: string): Promise<void>;
615
617
  addApiKey(params: AddApiKeyParams): Promise<_thalalabs_surf.EntryPayload>;
616
618
  removeApiKey(params: RemoveApiKeyParams): Promise<SubmitSponsoredTransactionResponse>;
617
619
  setAliasName(params: SetAliasNameParams): Promise<SubmitSponsoredTransactionResponse>;
@@ -724,6 +726,15 @@ interface IGetChartCandlesInRange {
724
726
  endTime?: number;
725
727
  cursor?: PaginationCursor;
726
728
  }
729
+ type WsOracleUpdates = Extract<WsMessage, {
730
+ type: 'OracleUpdates';
731
+ }>;
732
+ type WsUserUpdates = Extract<WsMessage, {
733
+ type: 'BalanceChange' | 'Deposit' | 'Withdraw' | 'WithdrawLend' | 'Lend' | 'Borrow' | 'RepayBorrow' | 'PlacePerpLimitOrder' | 'PlacePerpMarketOrder' | 'CancelPerpOrders' | 'SetAutolend' | 'SetAliasName' | 'AddApiKey' | 'RemoveApiKey';
734
+ }>;
735
+ type WsPerpMarketUpdates = Extract<WsMessage, {
736
+ type: 'OrderbookUpdate' | 'TradesUpdate';
737
+ }>;
727
738
 
728
739
  declare const ExchangeProxies: {
729
740
  [key in Network]: string[];
@@ -746,4 +757,4 @@ declare const generateApiKey: () => _aptos_labs_ts_sdk.Ed25519Account;
746
757
  declare const getTopicFromCommand: (data: WsCommand) => string;
747
758
  declare const getTopicFromMessage: (data: WsMessage) => string;
748
759
 
749
- export { type AddApiKey, type AddApiKeyParams, type Address, AdminEndpoints, type BalanceChange, BaseEndpoints, type Borrow, type BorrowLending, type CancelAllPerpOrdersParams, type CancelPerpOrdersParams, type CanceledPerpOrders, type ChartCandle, ChartInterval, Client, type Content, type CreateUserParams, type Deposit, type DepositToVaultParams, type DepositTokenParams, EndpointsV1, type ErrorResponse, type ExchangeConfig, ExchangeProxies, type Fees, type FundingCheckpoint, type FundingRate, GLOBAL_DENOMINATOR, type GetBorrowLendingDataResponse, type GetChartCandlesInRangeRequest, type GetChartCandlesInRangeResponse, type GetPerpMarketsDataRequest, type GetPerpMarketsDataResponse, type GetPerpOrderBookDataRequest, type GetPerpOrderBookDataResponse, type GetPerpRecentTradesRequest, type GetPerpRecentTradesResponse, type GetPerpUserFillsRequest, type GetPerpUserFillsResponse, type GetPerpUserOrdersRequest, type GetPerpUserOrdersResponse, type GetPerpetualMarketsConfigResponse, type GetPriceIndexesResponse, type GetTokensConfigResponse, type GetUserDataRequest, type GetUserDataResponse, type GetUsersByAddressRequest, type GetUsersByAddressResponse, type IGetChartCandlesInRange, type Lend, type LendTokenParams, type MarginStep, Network, type OracleUpdate, type OracleUpdates, type Order, type OrderFills, OrderSide, OrderStatus, OrderType, type OrderbookUpdate, type PaginationCursor, type PerpFill, type PerpMarketData, type PerpOrder, type PerpOrderBookData, type PerpPosition, type PerpTrade, type PerpetualMarketConfigEntry, PerpetualMarketStatus, type PlacePerpLimitOrder, type PlacePerpLimitOrderParams, type PlacePerpMarketOrder, type PlacePerpMarketOrderParams, type PriceIndex, type RedeemTokenParams, type Referral, type RemoveApiKey, type RemoveApiKeyParams, type RepayBorrow, type SetAlias, type SetAliasNameParams, type SetAutolend, type SetAutolendParams, Status, type StatusResponse, type SubmitSponsoredTransactionRequest, type SubmitSponsoredTransactionResponse, TestFaucet, type TimeResponse, type TokenConfigEntry, type Topic, type Trade, TradeRole, type TradesUpdate, type User, UserStatus, type UtilizationCurve, type VaultInvestment, type Withdraw, type WithdrawFromVaultParams, type WithdrawLend, type WsCommand, type WsFill, type WsMessage, generateApiKey, getRandomId, getTopicFromCommand, getTopicFromMessage, sleep, toSystemValue };
760
+ export { type AddApiKey, type AddApiKeyParams, type Address, AdminEndpoints, type BalanceChange, BaseEndpoints, type Borrow, type BorrowLending, type CancelAllPerpOrdersParams, type CancelPerpOrdersParams, type CanceledPerpOrders, type ChartCandle, ChartInterval, Client, type Content, type CreateUserParams, type Deposit, type DepositToVaultParams, type DepositTokenParams, EndpointsV1, type ErrorResponse, type ExchangeConfig, ExchangeProxies, type Fees, type FundingCheckpoint, type FundingRate, GLOBAL_DENOMINATOR, type GetBorrowLendingDataResponse, type GetChartCandlesInRangeRequest, type GetChartCandlesInRangeResponse, type GetPerpMarketsDataRequest, type GetPerpMarketsDataResponse, type GetPerpOrderBookDataRequest, type GetPerpOrderBookDataResponse, type GetPerpRecentTradesRequest, type GetPerpRecentTradesResponse, type GetPerpUserFillsRequest, type GetPerpUserFillsResponse, type GetPerpUserOrdersRequest, type GetPerpUserOrdersResponse, type GetPerpetualMarketsConfigResponse, type GetPriceIndexesResponse, type GetTokensConfigResponse, type GetUserDataRequest, type GetUserDataResponse, type GetUsersByAddressRequest, type GetUsersByAddressResponse, type IGetChartCandlesInRange, type Lend, type LendTokenParams, type MarginStep, Network, type OracleUpdate, type OracleUpdates, type Order, type OrderFills, OrderSide, OrderStatus, OrderType, type OrderbookUpdate, type PaginationCursor, type PerpFill, type PerpMarketData, type PerpOrder, type PerpOrderBookData, type PerpPosition, type PerpTrade, type PerpetualMarketConfigEntry, PerpetualMarketStatus, type PlacePerpLimitOrder, type PlacePerpLimitOrderParams, type PlacePerpMarketOrder, type PlacePerpMarketOrderParams, type PriceIndex, type RedeemTokenParams, type Referral, type RemoveApiKey, type RemoveApiKeyParams, type RepayBorrow, type SetAlias, type SetAliasNameParams, type SetAutolend, type SetAutolendParams, Status, type StatusResponse, type SubmitSponsoredTransactionRequest, type SubmitSponsoredTransactionResponse, TestFaucet, type TimeResponse, type TokenConfigEntry, type Topic, type Trade, TradeRole, type TradesUpdate, type User, UserStatus, type UtilizationCurve, type VaultInvestment, type Withdraw, type WithdrawFromVaultParams, type WithdrawLend, type WsCommand, type WsFill, type WsMessage, type WsOracleUpdates, type WsPerpMarketUpdates, type WsUserUpdates, generateApiKey, getRandomId, getTopicFromCommand, getTopicFromMessage, sleep, toSystemValue };
package/dist/index.js CHANGED
@@ -791,8 +791,9 @@ var Client = class _Client {
791
791
  await this.sendWsMessage(command);
792
792
  const topic = getTopicFromCommand(command);
793
793
  this._subscriptions.set(topic, callback);
794
+ return this.unsubscribeIndexPricesUpdates;
794
795
  }
795
- async unsubscribeIndexPricesUpdates(userId) {
796
+ async unsubscribeIndexPricesUpdates() {
796
797
  const command = {
797
798
  type: "SubscribeOracle",
798
799
  content: { id: getRandomId() }
@@ -809,6 +810,7 @@ var Client = class _Client {
809
810
  await this.sendWsMessage(command);
810
811
  const topic = getTopicFromCommand(command);
811
812
  this._subscriptions.set(topic, callback);
813
+ return () => this.unsubscribeUserUpdates(userId);
812
814
  }
813
815
  async unsubscribeUserUpdates(userId) {
814
816
  const command = {
@@ -819,6 +821,25 @@ var Client = class _Client {
819
821
  const topic = getTopicFromCommand(command);
820
822
  this._subscriptions.delete(topic);
821
823
  }
824
+ async subscribePerpMarketUpdates(market, callback) {
825
+ const command = {
826
+ type: "SubscribeMarket",
827
+ content: { id: getRandomId(), market }
828
+ };
829
+ await this.sendWsMessage(command);
830
+ const topic = getTopicFromCommand(command);
831
+ this._subscriptions.set(topic, callback);
832
+ return () => this.unsubscribePerpMarketUpdates(market);
833
+ }
834
+ async unsubscribePerpMarketUpdates(market) {
835
+ const command = {
836
+ type: "UnsubscribeMarket",
837
+ content: { id: getRandomId(), market }
838
+ };
839
+ await this.sendWsMessage(command);
840
+ const topic = getTopicFromCommand(command);
841
+ this._subscriptions.delete(topic);
842
+ }
822
843
  // needs to be signed by user and sent to blockchain
823
844
  async addApiKey(params) {
824
845
  return createEntryPayload(addApiKey_default, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nightlylabs/dex-sdk",
3
- "version": "0.0.16",
3
+ "version": "0.0.18",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {