@limitless-exchange/sdk 0.0.3 → 1.0.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.d.ts CHANGED
@@ -1,34 +1,11 @@
1
+ import { AxiosRequestConfig } from 'axios';
1
2
  import { ethers } from 'ethers';
2
- import { AxiosRequestConfig, AxiosResponse } from 'axios';
3
3
 
4
- /**
5
- * Client type for authentication.
6
- * @public
7
- */
8
- type ClientType = 'eoa' | 'base' | 'etherspot';
9
4
  /**
10
5
  * Trading mode for user interface.
11
6
  * @public
12
7
  */
13
8
  type TradingMode = 'SIMPLE' | 'ADVANCED';
14
- /**
15
- * Authentication headers required for login.
16
- * @public
17
- */
18
- interface SignatureHeaders {
19
- /**
20
- * The Ethereum address of the user
21
- */
22
- 'x-account': string;
23
- /**
24
- * The signing message in hex format
25
- */
26
- 'x-signing-message': string;
27
- /**
28
- * The signature generated by signing the message with the user's wallet
29
- */
30
- 'x-signature': string;
31
- }
32
9
  /**
33
10
  * User rank information.
34
11
  * @public
@@ -74,7 +51,7 @@ interface ReferralData {
74
51
  displayName: string;
75
52
  }
76
53
  /**
77
- * User profile information returned after authentication (1:1 with API response).
54
+ * User profile information (1:1 with API response).
78
55
  * @public
79
56
  */
80
57
  interface UserProfile {
@@ -83,13 +60,9 @@ interface UserProfile {
83
60
  */
84
61
  id: number;
85
62
  /**
86
- * User's Ethereum address (EOA)
63
+ * User's Ethereum address
87
64
  */
88
65
  account: string;
89
- /**
90
- * Client type used for authentication
91
- */
92
- client: ClientType;
93
66
  /**
94
67
  * User rank information containing feeRateBps
95
68
  */
@@ -118,10 +91,6 @@ interface UserProfile {
118
91
  * Social media URL
119
92
  */
120
93
  socialUrl?: string;
121
- /**
122
- * Smart wallet address (optional, required for ETHERSPOT client)
123
- */
124
- smartWallet?: string;
125
94
  /**
126
95
  * Trade wallet option
127
96
  */
@@ -182,7 +151,6 @@ interface ModeInfo {
182
151
  *
183
152
  * @remarks
184
153
  * Contains user-specific information needed for creating orders.
185
- * Typically extracted from authentication result.
186
154
  *
187
155
  * @public
188
156
  */
@@ -197,35 +165,6 @@ interface UserData {
197
165
  */
198
166
  feeRateBps: number;
199
167
  }
200
- /**
201
- * Complete authentication result including session and profile.
202
- * @public
203
- */
204
- interface AuthResult {
205
- /**
206
- * Session cookie value (JWT token)
207
- */
208
- sessionCookie: string;
209
- /**
210
- * User profile information
211
- */
212
- profile: UserProfile;
213
- }
214
- /**
215
- * Options for login authentication.
216
- * @public
217
- */
218
- interface LoginOptions {
219
- /**
220
- * Client type to use for authentication
221
- * @defaultValue 'eoa'
222
- */
223
- client?: ClientType;
224
- /**
225
- * Smart wallet address (required when client is 'etherspot')
226
- */
227
- smartWallet?: string;
228
- }
229
168
 
230
169
  /**
231
170
  * Logger interface for SDK integration.
@@ -677,875 +616,909 @@ interface OrderSigningConfig {
677
616
  }
678
617
 
679
618
  /**
680
- * Market-related types for Limitless Exchange.
681
- * @module types/markets
619
+ * Portfolio and position types for Limitless Exchange.
620
+ * @module types/portfolio
682
621
  */
683
622
  /**
684
- * Collateral token information.
623
+ * Market information for a position.
624
+ *
685
625
  * @public
686
626
  */
687
- interface CollateralToken {
688
- /**
689
- * Token contract address
690
- */
691
- address: string;
692
- /**
693
- * Token decimals
694
- */
695
- decimals: number;
627
+ interface PositionMarket {
696
628
  /**
697
- * Token symbol (e.g., "USDC")
629
+ * Market ID
698
630
  */
699
- symbol: string;
700
- }
701
- /**
702
- * Market creator information.
703
- * @public
704
- */
705
- interface MarketCreator {
631
+ id: number | string;
706
632
  /**
707
- * Creator name
633
+ * Market slug
708
634
  */
709
- name: string;
635
+ slug: string;
710
636
  /**
711
- * Creator image URL
637
+ * Market title
712
638
  */
713
- imageURI?: string;
639
+ title: string;
714
640
  /**
715
- * Creator link URL
641
+ * Market status
716
642
  */
717
- link?: string;
718
- }
719
- /**
720
- * Market metadata.
721
- * @public
722
- */
723
- interface MarketMetadata {
643
+ status?: string;
724
644
  /**
725
- * Fee enabled flag
645
+ * Whether market is closed
726
646
  */
727
- fee: boolean;
647
+ closed: boolean;
728
648
  /**
729
- * Banner flag
649
+ * Market deadline
730
650
  */
731
- isBannered?: boolean;
651
+ deadline: string;
732
652
  /**
733
- * Polymarket arbitrage flag
653
+ * Condition ID
734
654
  */
735
- isPolyArbitrage?: boolean;
655
+ conditionId?: string;
736
656
  /**
737
- * Market making flag
657
+ * Winning outcome index (null if unresolved)
738
658
  */
739
- shouldMarketMake?: boolean;
659
+ winningOutcomeIndex?: number | null;
740
660
  /**
741
- * Opening price for oracle markets
661
+ * Market group information
742
662
  */
743
- openPrice?: string;
663
+ group?: {
664
+ slug?: string;
665
+ title?: string;
666
+ };
744
667
  }
745
668
  /**
746
- * Market settings for CLOB markets.
669
+ * Position details for YES or NO side.
670
+ *
747
671
  * @public
748
672
  */
749
- interface MarketSettings {
673
+ interface PositionSide {
750
674
  /**
751
- * Minimum order size
675
+ * Cost basis (6 decimals)
752
676
  */
753
- minSize: string;
677
+ cost: string;
754
678
  /**
755
- * Maximum spread allowed
679
+ * Fill price (6 decimals for CLOB, decimal string for AMM)
756
680
  */
757
- maxSpread: number;
681
+ fillPrice: string;
758
682
  /**
759
- * Daily reward amount
683
+ * Current market value (6 decimals)
760
684
  */
761
- dailyReward: string;
685
+ marketValue: string;
762
686
  /**
763
- * Rewards epoch duration
687
+ * Realized P&L (6 decimals)
764
688
  */
765
- rewardsEpoch: string;
689
+ realisedPnl: string;
766
690
  /**
767
- * Constant parameter
691
+ * Unrealized P&L (6 decimals)
768
692
  */
769
- c: string;
693
+ unrealizedPnl: string;
770
694
  }
771
695
  /**
772
- * Trade prices for different order types.
696
+ * Token balance for YES or NO side.
697
+ *
773
698
  * @public
774
699
  */
775
- interface TradePrices {
700
+ interface TokenBalance {
776
701
  /**
777
- * Buy prices (market and limit) for yes/no tokens
702
+ * YES token balance (6 decimals)
778
703
  */
779
- buy: {
780
- market: [number, number];
781
- limit: [number, number];
782
- };
704
+ yes: string;
783
705
  /**
784
- * Sell prices (market and limit) for yes/no tokens
706
+ * NO token balance (6 decimals)
785
707
  */
786
- sell: {
787
- market: [number, number];
788
- limit: [number, number];
789
- };
708
+ no: string;
790
709
  }
791
710
  /**
792
- * Price oracle metadata for oracle-based markets.
711
+ * Latest trade information.
712
+ *
793
713
  * @public
794
714
  */
795
- interface PriceOracleMetadata {
715
+ interface LatestTrade {
796
716
  /**
797
- * Asset ticker symbol
717
+ * Latest YES price (0.0 to 1.0)
798
718
  */
799
- ticker: string;
719
+ latestYesPrice: number;
800
720
  /**
801
- * Asset type (e.g., "CRYPTO")
721
+ * Latest NO price (0.0 to 1.0)
802
722
  */
803
- assetType: string;
723
+ latestNoPrice: number;
804
724
  /**
805
- * Pyth Network price feed address
725
+ * Outcome token price (0.0 to 1.0)
806
726
  */
807
- pythAddress: string;
727
+ outcomeTokenPrice: number;
728
+ }
729
+ /**
730
+ * CLOB (Central Limit Order Book) position.
731
+ *
732
+ * @public
733
+ */
734
+ interface CLOBPosition {
808
735
  /**
809
- * Price feed symbol
736
+ * Market information
810
737
  */
811
- symbol: string;
738
+ market: PositionMarket;
812
739
  /**
813
- * Asset name
740
+ * User's wallet address
814
741
  */
815
- name: string;
742
+ makerAddress: string;
816
743
  /**
817
- * Logo URL
744
+ * Position details for YES and NO sides
818
745
  */
819
- logo: string;
820
- }
821
- /**
822
- * Orderbook entry (bid or ask).
823
- * Matches API response format exactly (1:1 parity).
824
- *
825
- * @public
826
- */
827
- interface OrderbookEntry {
746
+ positions: {
747
+ yes: PositionSide;
748
+ no: PositionSide;
749
+ };
828
750
  /**
829
- * Price per share (0-1 range)
751
+ * Token balances
830
752
  */
831
- price: number;
753
+ tokensBalance: TokenBalance;
832
754
  /**
833
- * Size in shares
755
+ * Latest trade information
834
756
  */
835
- size: number;
757
+ latestTrade: LatestTrade;
836
758
  /**
837
- * Order side ("BUY" or "SELL")
759
+ * Active orders information
838
760
  */
839
- side: string;
761
+ orders?: {
762
+ liveOrders: any[];
763
+ totalCollateralLocked: string;
764
+ };
765
+ /**
766
+ * Rewards information
767
+ */
768
+ rewards?: {
769
+ epochs: any[];
770
+ isEarning: boolean;
771
+ };
840
772
  }
841
773
  /**
842
- * Complete orderbook for a market.
843
- * Matches API response format exactly (1:1 parity).
774
+ * AMM (Automated Market Maker) position.
844
775
  *
845
776
  * @public
846
777
  */
847
- interface OrderBook {
778
+ interface AMMPosition {
848
779
  /**
849
- * Bid orders (buy orders) sorted by price descending
780
+ * Market information
850
781
  */
851
- bids: OrderbookEntry[];
782
+ market: PositionMarket;
852
783
  /**
853
- * Ask orders (sell orders) sorted by price ascending
784
+ * User's wallet address
854
785
  */
855
- asks: OrderbookEntry[];
786
+ account: string;
856
787
  /**
857
- * Token ID for the orderbook (YES token)
788
+ * Outcome index (0 for YES, 1 for NO)
858
789
  */
859
- tokenId: string;
790
+ outcomeIndex: number;
860
791
  /**
861
- * Adjusted midpoint price between best bid and ask
792
+ * Collateral amount (decimal string)
862
793
  */
863
- adjustedMidpoint: number;
794
+ collateralAmount: string;
864
795
  /**
865
- * Maximum allowed spread for the market
796
+ * Outcome token amount (decimal string)
866
797
  */
867
- maxSpread: string;
798
+ outcomeTokenAmount: string;
868
799
  /**
869
- * Minimum order size allowed
800
+ * Average fill price (decimal string)
870
801
  */
871
- minSize: string;
802
+ averageFillPrice: string;
872
803
  /**
873
- * Last trade price for the market
804
+ * Total buys cost (decimal string)
874
805
  */
875
- lastTradePrice: number;
876
- }
877
- /**
878
- * Market price information.
879
- * @public
880
- */
881
- interface MarketPrice {
806
+ totalBuysCost: string;
882
807
  /**
883
- * Token ID
808
+ * Total sells cost (decimal string)
884
809
  */
885
- tokenId: string;
810
+ totalSellsCost: string;
886
811
  /**
887
- * Current price
812
+ * Realized P&L (decimal string)
888
813
  */
889
- price: number;
814
+ realizedPnl: string;
890
815
  /**
891
- * Last update timestamp
816
+ * Unrealized P&L (decimal string)
817
+ */
818
+ unrealizedPnl: string;
819
+ /**
820
+ * Latest trade information
892
821
  */
893
- updatedAt?: string;
822
+ latestTrade?: {
823
+ outcomeTokenPrice: string;
824
+ };
894
825
  }
895
826
  /**
896
- * Market outcome information.
827
+ * API response for /portfolio/positions endpoint.
828
+ *
897
829
  * @public
898
830
  */
899
- interface MarketOutcome {
831
+ interface PortfolioPositionsResponse {
900
832
  /**
901
- * Outcome ID
833
+ * AMM positions
902
834
  */
903
- id: number;
835
+ amm: AMMPosition[];
904
836
  /**
905
- * Outcome title
837
+ * CLOB positions
906
838
  */
907
- title: string;
839
+ clob: CLOBPosition[];
908
840
  /**
909
- * Token ID for this outcome
841
+ * Group positions
910
842
  */
911
- tokenId: string;
843
+ group: any[];
912
844
  /**
913
- * Current price
845
+ * User points
914
846
  */
915
- price?: number;
916
- }
917
- /**
918
- * Venue information for CLOB markets.
919
- *
920
- * @remarks
921
- * Contains contract addresses required for trading:
922
- * - exchange: Used as verifyingContract for EIP-712 order signing
923
- * - adapter: Required for NegRisk/Grouped market SELL approvals
924
- *
925
- * @public
926
- */
927
- interface Venue {
847
+ points?: string;
928
848
  /**
929
- * Exchange contract address.
930
- *
931
- * @remarks
932
- * This address is used as the verifyingContract in EIP-712 order signing.
933
- * All BUY orders require USDC approval to this address.
934
- * Simple CLOB SELL orders require CT approval to this address.
849
+ * Accumulative points
935
850
  */
936
- exchange: string;
851
+ accumulativePoints?: string;
937
852
  /**
938
- * Adapter contract address.
939
- *
940
- * @remarks
941
- * Required for NegRisk/Grouped markets only.
942
- * SELL orders on NegRisk markets require CT approval to both exchange AND adapter.
853
+ * Rewards information
943
854
  */
944
- adapter: string;
945
- }
946
- /**
947
- * Market token IDs for CLOB markets.
948
- * @public
949
- */
950
- interface MarketTokens {
951
- yes: string;
952
- no: string;
855
+ rewards?: {
856
+ todaysRewards: string;
857
+ rewardsByEpoch: any[];
858
+ rewardsChartData: any[];
859
+ totalUnpaidRewards: string;
860
+ totalUserRewardsLastEpoch: string;
861
+ };
953
862
  }
954
863
  /**
955
- * Complete market information (1:1 with API response).
956
- * Handles both CLOB single markets and NegRisk group markets.
864
+ * Simplified position for unified view.
957
865
  *
958
866
  * @public
959
867
  */
960
- interface Market {
868
+ interface Position {
961
869
  /**
962
- * Market database ID
870
+ * Position type
963
871
  */
964
- id: number;
872
+ type: 'CLOB' | 'AMM';
965
873
  /**
966
- * Market slug identifier
874
+ * Market information
967
875
  */
968
- slug: string;
876
+ market: PositionMarket;
969
877
  /**
970
- * Market title
878
+ * Position side (YES or NO)
971
879
  */
972
- title: string;
880
+ side: 'YES' | 'NO';
973
881
  /**
974
- * Market proxy title
882
+ * Cost basis in USDC (6 decimals)
975
883
  */
976
- proxyTitle: string | null;
884
+ costBasis: number;
977
885
  /**
978
- * Market description
886
+ * Current market value in USDC (6 decimals)
979
887
  */
980
- description?: string;
888
+ marketValue: number;
981
889
  /**
982
- * Collateral token information
890
+ * Unrealized P&L in USDC (6 decimals)
983
891
  */
984
- collateralToken: CollateralToken;
892
+ unrealizedPnl: number;
985
893
  /**
986
- * Human-readable expiration date
894
+ * Realized P&L in USDC (6 decimals)
987
895
  */
988
- expirationDate: string;
896
+ realizedPnl: number;
989
897
  /**
990
- * Expiration timestamp in milliseconds
898
+ * Current price (0.0 to 1.0)
991
899
  */
992
- expirationTimestamp: number;
900
+ currentPrice: number;
993
901
  /**
994
- * Whether market is expired
902
+ * Average entry price (0.0 to 1.0)
995
903
  */
996
- expired?: boolean;
904
+ avgPrice: number;
997
905
  /**
998
- * Creation timestamp
906
+ * Token balance (6 decimals)
999
907
  */
1000
- createdAt: string;
908
+ tokenBalance: number;
909
+ }
910
+ /**
911
+ * Portfolio summary statistics.
912
+ *
913
+ * @public
914
+ */
915
+ interface PortfolioSummary {
1001
916
  /**
1002
- * Last update timestamp
917
+ * Total portfolio value in USDC (6 decimals)
1003
918
  */
1004
- updatedAt: string;
919
+ totalValue: number;
1005
920
  /**
1006
- * Market categories
921
+ * Total cost basis in USDC (6 decimals)
1007
922
  */
1008
- categories: string[];
923
+ totalCostBasis: number;
1009
924
  /**
1010
- * Market status
925
+ * Total unrealized P&L in USDC (6 decimals)
1011
926
  */
1012
- status: string;
927
+ totalUnrealizedPnl: number;
1013
928
  /**
1014
- * Creator information
929
+ * Total realized P&L in USDC (6 decimals)
1015
930
  */
1016
- creator: MarketCreator;
931
+ totalRealizedPnl: number;
1017
932
  /**
1018
- * Market tags
933
+ * Total unrealized P&L percentage
1019
934
  */
1020
- tags: string[];
935
+ totalUnrealizedPnlPercent: number;
1021
936
  /**
1022
- * Trade type (clob or amm)
937
+ * Number of open positions
1023
938
  */
1024
- tradeType: string;
939
+ positionCount: number;
1025
940
  /**
1026
- * Market type (single or group)
941
+ * Number of markets with positions
1027
942
  */
1028
- marketType: string;
943
+ marketCount: number;
1029
944
  /**
1030
- * Priority index for sorting
945
+ * Breakdown by position type
1031
946
  */
1032
- priorityIndex: number;
947
+ breakdown: {
948
+ clob: {
949
+ positions: number;
950
+ value: number;
951
+ pnl: number;
952
+ };
953
+ amm: {
954
+ positions: number;
955
+ value: number;
956
+ pnl: number;
957
+ };
958
+ };
959
+ }
960
+ /**
961
+ * User history entry.
962
+ *
963
+ * Represents various types of user actions:
964
+ * - AMM trades
965
+ * - CLOB trades
966
+ * - Token splits/merges
967
+ * - NegRisk conversions
968
+ *
969
+ * @public
970
+ */
971
+ interface HistoryEntry {
1033
972
  /**
1034
- * Market metadata
973
+ * Entry ID
1035
974
  */
1036
- metadata: MarketMetadata;
975
+ id: string;
1037
976
  /**
1038
- * Trading volume
977
+ * Entry type (trade, split, merge, conversion, etc.)
1039
978
  */
1040
- volume?: string;
979
+ type: string;
1041
980
  /**
1042
- * Formatted trading volume
981
+ * Entry creation timestamp
1043
982
  */
1044
- volumeFormatted?: string;
983
+ createdAt: string;
1045
984
  /**
1046
- * Condition ID (CLOB only)
985
+ * Associated market slug
1047
986
  */
1048
- conditionId?: string;
987
+ marketSlug?: string;
1049
988
  /**
1050
- * NegRisk request ID (CLOB only)
989
+ * Transaction amount
1051
990
  */
1052
- negRiskRequestId?: string | null;
991
+ amount?: string;
1053
992
  /**
1054
- * Token IDs for yes/no outcomes (CLOB only)
1055
- * @example
1056
- * {
1057
- * yes: "27687694610130623013351012526567944730242898906227824547270172934678693687246",
1058
- * no: "9288900480010863316984252765488448624297561656655547117581633191173128271467"
1059
- * }
993
+ * Additional entry details
1060
994
  */
1061
- tokens?: MarketTokens;
995
+ details?: Record<string, any>;
996
+ }
997
+ /**
998
+ * Paginated user history response from /portfolio/history endpoint.
999
+ *
1000
+ * @public
1001
+ */
1002
+ interface HistoryResponse {
1062
1003
  /**
1063
- * Current prices [yes, no] (CLOB only)
1004
+ * List of history entries
1064
1005
  */
1065
- prices?: number[];
1006
+ data: HistoryEntry[];
1066
1007
  /**
1067
- * Trade prices for buy/sell market/limit orders (CLOB only)
1008
+ * Total number of entries
1068
1009
  */
1069
- tradePrices?: TradePrices;
1010
+ totalCount: number;
1011
+ }
1012
+
1013
+ /**
1014
+ * Market-related types for Limitless Exchange.
1015
+ * @module types/markets
1016
+ */
1017
+ /**
1018
+ * Collateral token information.
1019
+ * @public
1020
+ */
1021
+ interface CollateralToken {
1070
1022
  /**
1071
- * Whether market is rewardable (CLOB only)
1023
+ * Token contract address
1072
1024
  */
1073
- isRewardable?: boolean;
1025
+ address: string;
1074
1026
  /**
1075
- * Market settings (CLOB only)
1027
+ * Token decimals
1076
1028
  */
1077
- settings?: MarketSettings;
1029
+ decimals: number;
1078
1030
  /**
1079
- * Venue information for CLOB markets.
1080
- *
1081
- * @remarks
1082
- * Contains exchange and adapter contract addresses for order signing and approvals.
1083
- * The exchange address is used as verifyingContract in EIP-712 signatures.
1084
- *
1085
- * Performance tip: Call getMarket() before createOrder() to cache venue data
1086
- * and avoid additional API requests during order creation.
1031
+ * Token symbol (e.g., "USDC")
1087
1032
  */
1088
- venue?: Venue;
1033
+ symbol: string;
1034
+ }
1035
+ /**
1036
+ * Market creator information.
1037
+ * @public
1038
+ */
1039
+ interface MarketCreator {
1089
1040
  /**
1090
- * Market logo URL
1041
+ * Creator name
1091
1042
  */
1092
- logo?: string | null;
1043
+ name: string;
1093
1044
  /**
1094
- * Price oracle metadata (oracle markets only)
1045
+ * Creator image URL
1095
1046
  */
1096
- priceOracleMetadata?: PriceOracleMetadata;
1047
+ imageURI?: string;
1097
1048
  /**
1098
- * Order within group (group markets only)
1049
+ * Creator link URL
1099
1050
  */
1100
- orderInGroup?: number;
1051
+ link?: string;
1052
+ }
1053
+ /**
1054
+ * Market metadata.
1055
+ * @public
1056
+ */
1057
+ interface MarketMetadata {
1101
1058
  /**
1102
- * Winning outcome index
1059
+ * Fee enabled flag
1103
1060
  */
1104
- winningOutcomeIndex?: number | null;
1061
+ fee: boolean;
1105
1062
  /**
1106
- * Outcome token names (group only)
1063
+ * Banner flag
1107
1064
  */
1108
- outcomeTokens?: string[];
1065
+ isBannered?: boolean;
1109
1066
  /**
1110
- * OG image URI (group only)
1067
+ * Polymarket arbitrage flag
1111
1068
  */
1112
- ogImageURI?: string;
1069
+ isPolyArbitrage?: boolean;
1113
1070
  /**
1114
- * NegRisk market ID (group only)
1071
+ * Market making flag
1115
1072
  */
1116
- negRiskMarketId?: string;
1073
+ shouldMarketMake?: boolean;
1117
1074
  /**
1118
- * Child markets in group (group only)
1075
+ * Opening price for oracle markets
1119
1076
  */
1120
- markets?: Market[];
1077
+ openPrice?: string;
1078
+ }
1079
+ /**
1080
+ * Market settings for CLOB markets.
1081
+ * @public
1082
+ */
1083
+ interface MarketSettings {
1121
1084
  /**
1122
- * Daily reward for group (group only)
1085
+ * Minimum order size
1123
1086
  */
1124
- dailyReward?: string;
1087
+ minSize: string;
1125
1088
  /**
1126
- * Market contract address
1127
- * @deprecated Use conditionId instead
1089
+ * Maximum spread allowed
1128
1090
  */
1129
- address?: string | null;
1091
+ maxSpread: number;
1130
1092
  /**
1131
- * Market type (CLOB or AMM)
1132
- * @deprecated Use tradeType instead
1093
+ * Daily reward amount
1133
1094
  */
1134
- type?: string;
1095
+ dailyReward: string;
1135
1096
  /**
1136
- * Market outcomes
1137
- * @deprecated Use tokens for CLOB markets
1097
+ * Rewards epoch duration
1138
1098
  */
1139
- outcomes?: MarketOutcome[];
1099
+ rewardsEpoch: string;
1140
1100
  /**
1141
- * Resolution timestamp
1142
- * @deprecated Use expirationTimestamp instead
1101
+ * Constant parameter
1143
1102
  */
1144
- resolutionDate?: string;
1103
+ c: string;
1145
1104
  }
1146
1105
  /**
1147
- * Markets list response.
1106
+ * Trade prices for different order types.
1148
1107
  * @public
1149
1108
  */
1150
- interface MarketsResponse {
1151
- /**
1152
- * Array of markets
1153
- */
1154
- markets: Market[];
1155
- /**
1156
- * Total count
1157
- */
1158
- total?: number;
1109
+ interface TradePrices {
1159
1110
  /**
1160
- * Pagination offset
1111
+ * Buy prices (market and limit) for yes/no tokens
1161
1112
  */
1162
- offset?: number;
1113
+ buy: {
1114
+ market: [number, number];
1115
+ limit: [number, number];
1116
+ };
1163
1117
  /**
1164
- * Pagination limit
1118
+ * Sell prices (market and limit) for yes/no tokens
1165
1119
  */
1166
- limit?: number;
1120
+ sell: {
1121
+ market: [number, number];
1122
+ limit: [number, number];
1123
+ };
1167
1124
  }
1168
1125
  /**
1169
- * Sort options for active markets.
1170
- * @public
1171
- */
1172
- type ActiveMarketsSortBy = 'lp_rewards' | 'ending_soon' | 'newest' | 'high_value' | 'liquidity';
1173
- /**
1174
- * Query parameters for active markets endpoint.
1126
+ * Price oracle metadata for oracle-based markets.
1175
1127
  * @public
1176
1128
  */
1177
- interface ActiveMarketsParams {
1129
+ interface PriceOracleMetadata {
1178
1130
  /**
1179
- * Maximum number of markets to return (max 25)
1180
- * @defaultValue 25
1131
+ * Asset ticker symbol
1181
1132
  */
1182
- limit?: number;
1133
+ ticker: string;
1183
1134
  /**
1184
- * Page number for pagination (starts at 1)
1185
- * @defaultValue 1
1135
+ * Asset type (e.g., "CRYPTO")
1186
1136
  */
1187
- page?: number;
1137
+ assetType: string;
1188
1138
  /**
1189
- * Sort order for markets
1139
+ * Pyth Network price feed address
1190
1140
  */
1191
- sortBy?: ActiveMarketsSortBy;
1192
- }
1193
- /**
1194
- * Active markets response from API.
1195
- * @public
1196
- */
1197
- interface ActiveMarketsResponse {
1141
+ pythAddress: string;
1198
1142
  /**
1199
- * Array of active markets
1143
+ * Price feed symbol
1200
1144
  */
1201
- data: Market[];
1145
+ symbol: string;
1202
1146
  /**
1203
- * Total count of active markets
1147
+ * Asset name
1204
1148
  */
1205
- totalMarketsCount: number;
1149
+ name: string;
1150
+ /**
1151
+ * Logo URL
1152
+ */
1153
+ logo: string;
1206
1154
  }
1207
-
1208
1155
  /**
1209
- * Portfolio and position types for Limitless Exchange.
1210
- * @module types/portfolio
1211
- */
1212
- /**
1213
- * Market information for a position.
1156
+ * Orderbook entry (bid or ask).
1157
+ * Matches API response format exactly (1:1 parity).
1214
1158
  *
1215
1159
  * @public
1216
1160
  */
1217
- interface PositionMarket {
1161
+ interface OrderbookEntry {
1218
1162
  /**
1219
- * Market ID
1163
+ * Price per share (0-1 range)
1220
1164
  */
1221
- id: number | string;
1165
+ price: number;
1222
1166
  /**
1223
- * Market slug
1167
+ * Size in shares
1224
1168
  */
1225
- slug: string;
1169
+ size: number;
1226
1170
  /**
1227
- * Market title
1171
+ * Order side ("BUY" or "SELL")
1228
1172
  */
1229
- title: string;
1173
+ side: string;
1174
+ }
1175
+ /**
1176
+ * Complete orderbook for a market.
1177
+ * Matches API response format exactly (1:1 parity).
1178
+ *
1179
+ * @public
1180
+ */
1181
+ interface OrderBook {
1230
1182
  /**
1231
- * Market status
1183
+ * Bid orders (buy orders) sorted by price descending
1232
1184
  */
1233
- status?: string;
1185
+ bids: OrderbookEntry[];
1234
1186
  /**
1235
- * Whether market is closed
1187
+ * Ask orders (sell orders) sorted by price ascending
1236
1188
  */
1237
- closed: boolean;
1189
+ asks: OrderbookEntry[];
1238
1190
  /**
1239
- * Market deadline
1191
+ * Token ID for the orderbook (YES token)
1240
1192
  */
1241
- deadline: string;
1193
+ tokenId: string;
1242
1194
  /**
1243
- * Condition ID
1195
+ * Adjusted midpoint price between best bid and ask
1244
1196
  */
1245
- conditionId?: string;
1197
+ adjustedMidpoint: number;
1246
1198
  /**
1247
- * Winning outcome index (null if unresolved)
1199
+ * Maximum allowed spread for the market
1248
1200
  */
1249
- winningOutcomeIndex?: number | null;
1201
+ maxSpread: string;
1250
1202
  /**
1251
- * Market group information
1203
+ * Minimum order size allowed
1252
1204
  */
1253
- group?: {
1254
- slug?: string;
1255
- title?: string;
1256
- };
1205
+ minSize: string;
1206
+ /**
1207
+ * Last trade price for the market
1208
+ */
1209
+ lastTradePrice: number;
1257
1210
  }
1258
1211
  /**
1259
- * Position details for YES or NO side.
1260
- *
1212
+ * Market outcome information.
1261
1213
  * @public
1262
1214
  */
1263
- interface PositionSide {
1264
- /**
1265
- * Cost basis (6 decimals)
1266
- */
1267
- cost: string;
1215
+ interface MarketOutcome {
1268
1216
  /**
1269
- * Fill price (6 decimals for CLOB, decimal string for AMM)
1217
+ * Outcome ID
1270
1218
  */
1271
- fillPrice: string;
1219
+ id: number;
1272
1220
  /**
1273
- * Current market value (6 decimals)
1221
+ * Outcome title
1274
1222
  */
1275
- marketValue: string;
1223
+ title: string;
1276
1224
  /**
1277
- * Realized P&L (6 decimals)
1225
+ * Token ID for this outcome
1278
1226
  */
1279
- realisedPnl: string;
1227
+ tokenId: string;
1280
1228
  /**
1281
- * Unrealized P&L (6 decimals)
1229
+ * Current price
1282
1230
  */
1283
- unrealizedPnl: string;
1231
+ price?: number;
1284
1232
  }
1285
1233
  /**
1286
- * Token balance for YES or NO side.
1234
+ * Venue information for CLOB markets.
1235
+ *
1236
+ * @remarks
1237
+ * Contains contract addresses required for trading:
1238
+ * - exchange: Used as verifyingContract for EIP-712 order signing
1239
+ * - adapter: Required for NegRisk/Grouped market SELL approvals
1287
1240
  *
1288
1241
  * @public
1289
1242
  */
1290
- interface TokenBalance {
1243
+ interface Venue {
1291
1244
  /**
1292
- * YES token balance (6 decimals)
1245
+ * Exchange contract address.
1246
+ *
1247
+ * @remarks
1248
+ * This address is used as the verifyingContract in EIP-712 order signing.
1249
+ * All BUY orders require USDC approval to this address.
1250
+ * Simple CLOB SELL orders require CT approval to this address.
1293
1251
  */
1294
- yes: string;
1252
+ exchange: string;
1295
1253
  /**
1296
- * NO token balance (6 decimals)
1254
+ * Adapter contract address.
1255
+ *
1256
+ * @remarks
1257
+ * Required for NegRisk/Grouped markets only.
1258
+ * SELL orders on NegRisk markets require CT approval to both exchange AND adapter.
1297
1259
  */
1260
+ adapter: string;
1261
+ }
1262
+ /**
1263
+ * Market token IDs for CLOB markets.
1264
+ * @public
1265
+ */
1266
+ interface MarketTokens {
1267
+ yes: string;
1298
1268
  no: string;
1299
1269
  }
1300
1270
  /**
1301
- * Latest trade information.
1271
+ * Complete market information (1:1 with API response).
1272
+ * Handles both CLOB single markets and NegRisk group markets.
1302
1273
  *
1303
1274
  * @public
1304
1275
  */
1305
- interface LatestTrade {
1276
+ interface Market$1 {
1306
1277
  /**
1307
- * Latest YES price (0.0 to 1.0)
1278
+ * Market database ID
1308
1279
  */
1309
- latestYesPrice: number;
1280
+ id: number;
1310
1281
  /**
1311
- * Latest NO price (0.0 to 1.0)
1282
+ * Market slug identifier
1312
1283
  */
1313
- latestNoPrice: number;
1284
+ slug: string;
1314
1285
  /**
1315
- * Outcome token price (0.0 to 1.0)
1286
+ * Market title
1316
1287
  */
1317
- outcomeTokenPrice: number;
1318
- }
1319
- /**
1320
- * CLOB (Central Limit Order Book) position.
1321
- *
1322
- * @public
1323
- */
1324
- interface CLOBPosition {
1288
+ title: string;
1325
1289
  /**
1326
- * Market information
1290
+ * Market proxy title
1327
1291
  */
1328
- market: PositionMarket;
1292
+ proxyTitle: string | null;
1329
1293
  /**
1330
- * User's wallet address
1294
+ * Market description
1331
1295
  */
1332
- makerAddress: string;
1296
+ description?: string;
1333
1297
  /**
1334
- * Position details for YES and NO sides
1298
+ * Collateral token information
1335
1299
  */
1336
- positions: {
1337
- yes: PositionSide;
1338
- no: PositionSide;
1339
- };
1300
+ collateralToken: CollateralToken;
1340
1301
  /**
1341
- * Token balances
1302
+ * Human-readable expiration date
1342
1303
  */
1343
- tokensBalance: TokenBalance;
1304
+ expirationDate: string;
1344
1305
  /**
1345
- * Latest trade information
1306
+ * Expiration timestamp in milliseconds
1346
1307
  */
1347
- latestTrade: LatestTrade;
1308
+ expirationTimestamp: number;
1348
1309
  /**
1349
- * Active orders information
1310
+ * Whether market is expired
1350
1311
  */
1351
- orders?: {
1352
- liveOrders: any[];
1353
- totalCollateralLocked: string;
1354
- };
1312
+ expired?: boolean;
1355
1313
  /**
1356
- * Rewards information
1314
+ * Creation timestamp
1357
1315
  */
1358
- rewards?: {
1359
- epochs: any[];
1360
- isEarning: boolean;
1361
- };
1362
- }
1363
- /**
1364
- * AMM (Automated Market Maker) position.
1365
- *
1366
- * @public
1367
- */
1368
- interface AMMPosition {
1316
+ createdAt: string;
1369
1317
  /**
1370
- * Market information
1318
+ * Last update timestamp
1371
1319
  */
1372
- market: PositionMarket;
1320
+ updatedAt: string;
1373
1321
  /**
1374
- * User's wallet address
1322
+ * Market categories
1375
1323
  */
1376
- account: string;
1324
+ categories: string[];
1377
1325
  /**
1378
- * Outcome index (0 for YES, 1 for NO)
1326
+ * Market status
1379
1327
  */
1380
- outcomeIndex: number;
1328
+ status: string;
1381
1329
  /**
1382
- * Collateral amount (decimal string)
1330
+ * Creator information
1383
1331
  */
1384
- collateralAmount: string;
1332
+ creator: MarketCreator;
1385
1333
  /**
1386
- * Outcome token amount (decimal string)
1334
+ * Market tags
1387
1335
  */
1388
- outcomeTokenAmount: string;
1336
+ tags: string[];
1389
1337
  /**
1390
- * Average fill price (decimal string)
1338
+ * Trade type (clob or amm)
1391
1339
  */
1392
- averageFillPrice: string;
1340
+ tradeType: string;
1393
1341
  /**
1394
- * Total buys cost (decimal string)
1342
+ * Market type (single or group)
1395
1343
  */
1396
- totalBuysCost: string;
1344
+ marketType: string;
1397
1345
  /**
1398
- * Total sells cost (decimal string)
1346
+ * Priority index for sorting
1399
1347
  */
1400
- totalSellsCost: string;
1348
+ priorityIndex: number;
1401
1349
  /**
1402
- * Realized P&L (decimal string)
1350
+ * Market metadata
1403
1351
  */
1404
- realizedPnl: string;
1352
+ metadata: MarketMetadata;
1405
1353
  /**
1406
- * Unrealized P&L (decimal string)
1354
+ * Trading volume
1407
1355
  */
1408
- unrealizedPnl: string;
1356
+ volume?: string;
1409
1357
  /**
1410
- * Latest trade information
1358
+ * Formatted trading volume
1411
1359
  */
1412
- latestTrade?: {
1413
- outcomeTokenPrice: string;
1414
- };
1415
- }
1416
- /**
1417
- * API response for /portfolio/positions endpoint.
1418
- *
1419
- * @public
1420
- */
1421
- interface PortfolioPositionsResponse {
1360
+ volumeFormatted?: string;
1422
1361
  /**
1423
- * AMM positions
1362
+ * Condition ID (CLOB only)
1424
1363
  */
1425
- amm: AMMPosition[];
1364
+ conditionId?: string;
1426
1365
  /**
1427
- * CLOB positions
1366
+ * NegRisk request ID (CLOB only)
1428
1367
  */
1429
- clob: CLOBPosition[];
1368
+ negRiskRequestId?: string | null;
1430
1369
  /**
1431
- * Group positions
1370
+ * Token IDs for yes/no outcomes (CLOB only)
1371
+ * @example
1372
+ * {
1373
+ * yes: "27687694610130623013351012526567944730242898906227824547270172934678693687246",
1374
+ * no: "9288900480010863316984252765488448624297561656655547117581633191173128271467"
1375
+ * }
1432
1376
  */
1433
- group: any[];
1377
+ tokens?: MarketTokens;
1434
1378
  /**
1435
- * User points
1379
+ * Current prices [yes, no] (CLOB only)
1436
1380
  */
1437
- points?: string;
1381
+ prices?: number[];
1438
1382
  /**
1439
- * Accumulative points
1383
+ * Trade prices for buy/sell market/limit orders (CLOB only)
1440
1384
  */
1441
- accumulativePoints?: string;
1385
+ tradePrices?: TradePrices;
1442
1386
  /**
1443
- * Rewards information
1387
+ * Whether market is rewardable (CLOB only)
1444
1388
  */
1445
- rewards?: {
1446
- todaysRewards: string;
1447
- rewardsByEpoch: any[];
1448
- rewardsChartData: any[];
1449
- totalUnpaidRewards: string;
1450
- totalUserRewardsLastEpoch: string;
1451
- };
1452
- }
1453
- /**
1454
- * Simplified position for unified view.
1455
- *
1456
- * @public
1457
- */
1458
- interface Position {
1389
+ isRewardable?: boolean;
1459
1390
  /**
1460
- * Position type
1391
+ * Market settings (CLOB only)
1461
1392
  */
1462
- type: 'CLOB' | 'AMM';
1393
+ settings?: MarketSettings;
1463
1394
  /**
1464
- * Market information
1395
+ * Venue information for CLOB markets.
1396
+ *
1397
+ * @remarks
1398
+ * Contains exchange and adapter contract addresses for order signing and approvals.
1399
+ * The exchange address is used as verifyingContract in EIP-712 signatures.
1400
+ *
1401
+ * Performance tip: Call getMarket() before createOrder() to cache venue data
1402
+ * and avoid additional API requests during order creation.
1465
1403
  */
1466
- market: PositionMarket;
1404
+ venue?: Venue;
1467
1405
  /**
1468
- * Position side (YES or NO)
1406
+ * Market logo URL
1469
1407
  */
1470
- side: 'YES' | 'NO';
1408
+ logo?: string | null;
1471
1409
  /**
1472
- * Cost basis in USDC (6 decimals)
1410
+ * Price oracle metadata (oracle markets only)
1473
1411
  */
1474
- costBasis: number;
1412
+ priceOracleMetadata?: PriceOracleMetadata;
1475
1413
  /**
1476
- * Current market value in USDC (6 decimals)
1414
+ * Order within group (group markets only)
1477
1415
  */
1478
- marketValue: number;
1416
+ orderInGroup?: number;
1417
+ /**
1418
+ * Winning outcome index
1419
+ */
1420
+ winningOutcomeIndex?: number | null;
1421
+ /**
1422
+ * Outcome token names (group only)
1423
+ */
1424
+ outcomeTokens?: string[];
1425
+ /**
1426
+ * OG image URI (group only)
1427
+ */
1428
+ ogImageURI?: string;
1429
+ /**
1430
+ * NegRisk market ID (group only)
1431
+ */
1432
+ negRiskMarketId?: string;
1433
+ /**
1434
+ * Child markets in group (group only)
1435
+ */
1436
+ markets?: Market$1[];
1479
1437
  /**
1480
- * Unrealized P&L in USDC (6 decimals)
1438
+ * Daily reward for group (group only)
1481
1439
  */
1482
- unrealizedPnl: number;
1440
+ dailyReward?: string;
1483
1441
  /**
1484
- * Realized P&L in USDC (6 decimals)
1442
+ * Market contract address
1443
+ * @deprecated Use conditionId instead
1485
1444
  */
1486
- realizedPnl: number;
1445
+ address?: string | null;
1487
1446
  /**
1488
- * Current price (0.0 to 1.0)
1447
+ * Market type (CLOB or AMM)
1448
+ * @deprecated Use tradeType instead
1489
1449
  */
1490
- currentPrice: number;
1450
+ type?: string;
1491
1451
  /**
1492
- * Average entry price (0.0 to 1.0)
1452
+ * Market outcomes
1453
+ * @deprecated Use tokens for CLOB markets
1493
1454
  */
1494
- avgPrice: number;
1455
+ outcomes?: MarketOutcome[];
1495
1456
  /**
1496
- * Token balance (6 decimals)
1457
+ * Resolution timestamp
1458
+ * @deprecated Use expirationTimestamp instead
1497
1459
  */
1498
- tokenBalance: number;
1460
+ resolutionDate?: string;
1499
1461
  }
1500
1462
  /**
1501
- * Portfolio summary statistics.
1502
- *
1463
+ * Markets list response.
1503
1464
  * @public
1504
1465
  */
1505
- interface PortfolioSummary {
1466
+ interface MarketsResponse {
1506
1467
  /**
1507
- * Total portfolio value in USDC (6 decimals)
1468
+ * Array of markets
1508
1469
  */
1509
- totalValue: number;
1470
+ markets: Market$1[];
1510
1471
  /**
1511
- * Total cost basis in USDC (6 decimals)
1472
+ * Total count
1512
1473
  */
1513
- totalCostBasis: number;
1474
+ total?: number;
1514
1475
  /**
1515
- * Total unrealized P&L in USDC (6 decimals)
1476
+ * Pagination offset
1516
1477
  */
1517
- totalUnrealizedPnl: number;
1478
+ offset?: number;
1518
1479
  /**
1519
- * Total realized P&L in USDC (6 decimals)
1480
+ * Pagination limit
1520
1481
  */
1521
- totalRealizedPnl: number;
1482
+ limit?: number;
1483
+ }
1484
+ /**
1485
+ * Sort options for active markets.
1486
+ * @public
1487
+ */
1488
+ type ActiveMarketsSortBy = 'lp_rewards' | 'ending_soon' | 'newest' | 'high_value' | 'liquidity';
1489
+ /**
1490
+ * Query parameters for active markets endpoint.
1491
+ * @public
1492
+ */
1493
+ interface ActiveMarketsParams {
1522
1494
  /**
1523
- * Total unrealized P&L percentage
1495
+ * Maximum number of markets to return (max 25)
1496
+ * @defaultValue 25
1524
1497
  */
1525
- totalUnrealizedPnlPercent: number;
1498
+ limit?: number;
1526
1499
  /**
1527
- * Number of open positions
1500
+ * Page number for pagination (starts at 1)
1501
+ * @defaultValue 1
1528
1502
  */
1529
- positionCount: number;
1503
+ page?: number;
1530
1504
  /**
1531
- * Number of markets with positions
1505
+ * Sort order for markets
1532
1506
  */
1533
- marketCount: number;
1507
+ sortBy?: ActiveMarketsSortBy;
1508
+ }
1509
+ /**
1510
+ * Active markets response from API.
1511
+ * @public
1512
+ */
1513
+ interface ActiveMarketsResponse {
1534
1514
  /**
1535
- * Breakdown by position type
1515
+ * Array of active markets
1536
1516
  */
1537
- breakdown: {
1538
- clob: {
1539
- positions: number;
1540
- value: number;
1541
- pnl: number;
1542
- };
1543
- amm: {
1544
- positions: number;
1545
- value: number;
1546
- pnl: number;
1547
- };
1548
- };
1517
+ data: Market$1[];
1518
+ /**
1519
+ * Total count of active markets
1520
+ */
1521
+ totalMarketsCount: number;
1549
1522
  }
1550
1523
 
1551
1524
  /**
@@ -1563,9 +1536,16 @@ interface WebSocketConfig {
1563
1536
  */
1564
1537
  url?: string;
1565
1538
  /**
1566
- * Session cookie for authentication
1539
+ * API key for authentication
1540
+ *
1541
+ * @remarks
1542
+ * **Required** for authenticated subscriptions (positions, transactions).
1543
+ * Not required for public subscriptions (market prices, orderbook).
1544
+ *
1545
+ * You can generate an API key at https://limitless.exchange
1546
+ * and the LIMITLESS_API_KEY environment variable.
1567
1547
  */
1568
- sessionCookie?: string;
1548
+ apiKey?: string;
1569
1549
  /**
1570
1550
  * Auto-reconnect on connection loss (default: true)
1571
1551
  */
@@ -1819,76 +1799,26 @@ interface WebSocketEvents {
1819
1799
  interface SubscriptionOptions {
1820
1800
  /**
1821
1801
  * Market slug to subscribe to (required for market-specific channels)
1802
+ * @deprecated Use marketSlugs (array) instead - server expects array format
1822
1803
  */
1823
1804
  marketSlug?: string;
1824
1805
  /**
1825
- * Market address to subscribe to (for AMM markets)
1826
- */
1827
- marketAddress?: string;
1828
- /**
1829
- * Additional filters
1830
- */
1831
- filters?: Record<string, any>;
1832
- }
1833
-
1834
- /**
1835
- * Message signer for authentication.
1836
- *
1837
- * @remarks
1838
- * This class handles signing messages with an Ethereum wallet and
1839
- * creating authentication headers required by the Limitless Exchange API.
1840
- *
1841
- * @public
1842
- */
1843
- declare class MessageSigner {
1844
- private wallet;
1845
- /**
1846
- * Creates a new message signer instance.
1847
- *
1848
- * @param wallet - Ethers wallet instance for signing
1849
- */
1850
- constructor(wallet: ethers.Wallet);
1851
- /**
1852
- * Creates authentication headers for API requests.
1853
- *
1854
- * @param signingMessage - Message to sign from the API
1855
- * @returns Promise resolving to signature headers
1856
- *
1857
- * @example
1858
- * ```typescript
1859
- * const signer = new MessageSigner(wallet);
1860
- * const headers = await signer.createAuthHeaders(message);
1861
- * ```
1806
+ * Market slugs to subscribe to (array format - required by server)
1862
1807
  */
1863
- createAuthHeaders(signingMessage: string): Promise<SignatureHeaders>;
1808
+ marketSlugs?: string[];
1864
1809
  /**
1865
- * Signs EIP-712 typed data.
1866
- *
1867
- * @param domain - EIP-712 domain
1868
- * @param types - EIP-712 types
1869
- * @param value - Value to sign
1870
- * @returns Promise resolving to signature string
1871
- *
1872
- * @example
1873
- * ```typescript
1874
- * const signature = await signer.signTypedData(domain, types, order);
1875
- * ```
1810
+ * Market address to subscribe to (for AMM markets)
1811
+ * @deprecated Use marketAddresses (array) instead - server expects array format
1876
1812
  */
1877
- signTypedData(domain: ethers.TypedDataDomain, types: Record<string, ethers.TypedDataField[]>, value: Record<string, any>): Promise<string>;
1813
+ marketAddress?: string;
1878
1814
  /**
1879
- * Gets the wallet address.
1880
- *
1881
- * @returns Ethereum address
1815
+ * Market addresses to subscribe to (array format - required by server)
1882
1816
  */
1883
- getAddress(): string;
1817
+ marketAddresses?: string[];
1884
1818
  /**
1885
- * Converts a string to hex format.
1886
- *
1887
- * @param text - String to convert
1888
- * @returns Hex string with 0x prefix
1889
- * @internal
1819
+ * Additional filters
1890
1820
  */
1891
- private stringToHex;
1821
+ filters?: Record<string, any>;
1892
1822
  }
1893
1823
 
1894
1824
  /**
@@ -1907,9 +1837,12 @@ interface HttpClientConfig {
1907
1837
  */
1908
1838
  timeout?: number;
1909
1839
  /**
1910
- * Session cookie for authenticated requests
1840
+ * API key for authenticated requests
1841
+ * @remarks
1842
+ * If not provided, will attempt to load from LIMITLESS_API_KEY environment variable.
1843
+ * Required for authenticated endpoints (portfolio, orders, etc.)
1911
1844
  */
1912
- sessionCookie?: string;
1845
+ apiKey?: string;
1913
1846
  /**
1914
1847
  * Optional logger for debugging
1915
1848
  * @defaultValue NoOpLogger (no logging)
@@ -1966,285 +1899,153 @@ interface HttpClientConfig {
1966
1899
  }
1967
1900
  /**
1968
1901
  * HTTP client wrapper for Limitless Exchange API.
1969
- *
1970
- * @remarks
1971
- * This class provides a centralized HTTP client with cookie management,
1972
- * error handling, and request/response interceptors.
1973
- *
1974
- * @public
1975
- */
1976
- declare class HttpClient {
1977
- private client;
1978
- private sessionCookie?;
1979
- private logger;
1980
- /**
1981
- * Creates a new HTTP client instance.
1982
- *
1983
- * @param config - Configuration options for the HTTP client
1984
- */
1985
- constructor(config?: HttpClientConfig);
1986
- /**
1987
- * Sets up request and response interceptors.
1988
- * @internal
1989
- */
1990
- private setupInterceptors;
1991
- /**
1992
- * Sets the session cookie for authenticated requests.
1993
- *
1994
- * @param cookie - Session cookie value
1995
- */
1996
- setSessionCookie(cookie: string): void;
1997
- /**
1998
- * Clears the session cookie.
1999
- */
2000
- clearSessionCookie(): void;
2001
- /**
2002
- * Performs a GET request.
2003
- *
2004
- * @param url - Request URL
2005
- * @param config - Additional request configuration
2006
- * @returns Promise resolving to the response data
2007
- */
2008
- get<T = any>(url: string, config?: AxiosRequestConfig): Promise<T>;
2009
- /**
2010
- * Performs a POST request.
2011
- *
2012
- * @param url - Request URL
2013
- * @param data - Request body data
2014
- * @param config - Additional request configuration
2015
- * @returns Promise resolving to the response data
2016
- */
2017
- post<T = any>(url: string, data?: any, config?: AxiosRequestConfig): Promise<T>;
2018
- /**
2019
- * Performs a POST request and returns the full response object.
2020
- * Useful when you need access to response headers (e.g., for cookie extraction).
2021
- *
2022
- * @param url - Request URL
2023
- * @param data - Request body data
2024
- * @param config - Additional request configuration
2025
- * @returns Promise resolving to the full AxiosResponse object
2026
- * @internal
2027
- */
2028
- postWithResponse<T = any>(url: string, data?: any, config?: AxiosRequestConfig): Promise<AxiosResponse<T>>;
2029
- /**
2030
- * Performs a DELETE request.
2031
- *
2032
- * @remarks
2033
- * DELETE requests typically don't have a body, so we remove the Content-Type header
2034
- * to avoid "Body cannot be empty" errors from the API.
2035
- *
2036
- * @param url - Request URL
2037
- * @param config - Additional request configuration
2038
- * @returns Promise resolving to the response data
2039
- */
2040
- delete<T = any>(url: string, config?: AxiosRequestConfig): Promise<T>;
2041
- /**
2042
- * Extracts cookies from response headers.
2043
- *
2044
- * @param response - Axios response object
2045
- * @returns Object containing parsed cookies
2046
- * @internal
2047
- */
2048
- extractCookies(response: AxiosResponse): Record<string, string>;
2049
- }
2050
-
2051
- /**
2052
- * Authenticator for Limitless Exchange API.
2053
- *
2054
- * @remarks
2055
- * This class handles the complete authentication flow:
2056
- * 1. Get signing message from API
2057
- * 2. Sign message with wallet
2058
- * 3. Login and obtain session cookie
2059
- * 4. Verify authentication status
2060
- *
2061
- * @public
2062
- */
2063
- declare class Authenticator {
2064
- private httpClient;
2065
- private signer;
2066
- private logger;
2067
- /**
2068
- * Creates a new authenticator instance.
2069
- *
2070
- * @param httpClient - HTTP client for API requests
2071
- * @param signer - Message signer for wallet operations
2072
- * @param logger - Optional logger for debugging and monitoring (default: no logging)
2073
- *
2074
- * @example
2075
- * ```typescript
2076
- * // Without logging (default)
2077
- * const authenticator = new Authenticator(httpClient, signer);
2078
- *
2079
- * // With logging
2080
- * import { ConsoleLogger } from '@limitless-exchange/sdk';
2081
- * const logger = new ConsoleLogger('debug');
2082
- * const authenticator = new Authenticator(httpClient, signer, logger);
2083
- * ```
2084
- */
2085
- constructor(httpClient: HttpClient, signer: MessageSigner, logger?: ILogger);
2086
- /**
2087
- * Gets a signing message from the API.
2088
- *
2089
- * @returns Promise resolving to signing message string
2090
- * @throws Error if API request fails
2091
- *
2092
- * @example
2093
- * ```typescript
2094
- * const message = await authenticator.getSigningMessage();
2095
- * console.log(message);
2096
- * ```
2097
- */
2098
- getSigningMessage(): Promise<string>;
2099
- /**
2100
- * Authenticates with the API and obtains session cookie.
2101
- *
2102
- * @param options - Login options including client type and smart wallet
2103
- * @returns Promise resolving to authentication result
2104
- * @throws Error if authentication fails or smart wallet is required but not provided
2105
- *
2106
- * @example
2107
- * ```typescript
2108
- * // EOA authentication
2109
- * const result = await authenticator.authenticate({ client: 'eoa' });
2110
- *
2111
- * // ETHERSPOT with smart wallet
2112
- * const result = await authenticator.authenticate({
2113
- * client: 'etherspot',
2114
- * smartWallet: '0x...'
2115
- * });
2116
- * ```
2117
- */
2118
- authenticate(options?: LoginOptions): Promise<AuthResult>;
2119
- /**
2120
- * Verifies the current authentication status.
2121
- *
2122
- * @param sessionCookie - Session cookie to verify
2123
- * @returns Promise resolving to user's Ethereum address
2124
- * @throws Error if session is invalid
2125
- *
2126
- * @example
2127
- * ```typescript
2128
- * const address = await authenticator.verifyAuth(sessionCookie);
2129
- * console.log(`Authenticated as: ${address}`);
2130
- * ```
2131
- */
2132
- verifyAuth(sessionCookie: string): Promise<string>;
2133
- /**
2134
- * Logs out and clears the session.
2135
- *
2136
- * @param sessionCookie - Session cookie to invalidate
2137
- * @throws Error if logout request fails
2138
- *
2139
- * @example
2140
- * ```typescript
2141
- * await authenticator.logout(sessionCookie);
2142
- * console.log('Logged out successfully');
2143
- * ```
2144
- */
2145
- logout(sessionCookie: string): Promise<void>;
2146
- }
2147
-
2148
- /**
2149
- * Optional helper for automatic authentication retry on token expiration.
2150
- * @module auth/authenticated-client
2151
- */
2152
-
2153
- /**
2154
- * Configuration for authenticated client with auto-retry.
1902
+ *
1903
+ * @remarks
1904
+ * This class provides a centralized HTTP client with API key authentication,
1905
+ * error handling, and request/response interceptors.
1906
+ *
2155
1907
  * @public
2156
1908
  */
2157
- interface AuthenticatedClientConfig {
1909
+ declare class HttpClient {
1910
+ private client;
1911
+ private apiKey?;
1912
+ private logger;
2158
1913
  /**
2159
- * HTTP client instance
1914
+ * Creates a new HTTP client instance.
1915
+ *
1916
+ * @param config - Configuration options for the HTTP client
2160
1917
  */
2161
- httpClient: HttpClient;
1918
+ constructor(config?: HttpClientConfig);
2162
1919
  /**
2163
- * Authenticator instance
1920
+ * Sets up request and response interceptors.
1921
+ * @internal
2164
1922
  */
2165
- authenticator: Authenticator;
1923
+ private setupInterceptors;
2166
1924
  /**
2167
- * Authentication client type ('eoa' or 'etherspot')
1925
+ * Sets the API key for authenticated requests.
1926
+ *
1927
+ * @param apiKey - API key value
2168
1928
  */
2169
- client: 'eoa' | 'etherspot';
1929
+ setApiKey(apiKey: string): void;
2170
1930
  /**
2171
- * Optional smart wallet address (required for 'etherspot')
1931
+ * Clears the API key.
2172
1932
  */
2173
- smartWallet?: string;
1933
+ clearApiKey(): void;
2174
1934
  /**
2175
- * Optional logger for debugging
1935
+ * Performs a GET request.
1936
+ *
1937
+ * @param url - Request URL
1938
+ * @param config - Additional request configuration
1939
+ * @returns Promise resolving to the response data
2176
1940
  */
2177
- logger?: ILogger;
1941
+ get<T = any>(url: string, config?: AxiosRequestConfig): Promise<T>;
2178
1942
  /**
2179
- * Maximum retry attempts for auth errors (default: 1)
1943
+ * Performs a POST request.
1944
+ *
1945
+ * @param url - Request URL
1946
+ * @param data - Request body data
1947
+ * @param config - Additional request configuration
1948
+ * @returns Promise resolving to the response data
2180
1949
  */
2181
- maxRetries?: number;
1950
+ post<T = any>(url: string, data?: any, config?: AxiosRequestConfig): Promise<T>;
1951
+ /**
1952
+ * Performs a DELETE request.
1953
+ *
1954
+ * @remarks
1955
+ * DELETE requests typically don't have a body, so we remove the Content-Type header
1956
+ * to avoid "Body cannot be empty" errors from the API.
1957
+ *
1958
+ * @param url - Request URL
1959
+ * @param config - Additional request configuration
1960
+ * @returns Promise resolving to the response data
1961
+ */
1962
+ delete<T = any>(url: string, config?: AxiosRequestConfig): Promise<T>;
2182
1963
  }
1964
+
1965
+ /**
1966
+ * Market class with fluent API methods.
1967
+ * @module types/market-class
1968
+ */
1969
+
2183
1970
  /**
2184
- * Optional helper class that automatically re-authenticates on token expiration.
1971
+ * Market class with fluent API support.
2185
1972
  *
2186
1973
  * @remarks
2187
- * This is an optional convenience wrapper. Users can choose to handle
2188
- * authentication retry manually or use this helper for automatic retry logic.
2189
- *
2190
- * @example
2191
- * ```typescript
2192
- * // Create authenticated client with auto-retry
2193
- * const authClient = new AuthenticatedClient({
2194
- * httpClient,
2195
- * authenticator,
2196
- * client: 'eoa'
2197
- * });
2198
- *
2199
- * // Use withRetry for automatic re-authentication
2200
- * const portfolioFetcher = new PortfolioFetcher(httpClient);
2201
- * const positions = await authClient.withRetry(() =>
2202
- * portfolioFetcher.getPositions()
2203
- * );
2204
- * ```
1974
+ * This class represents a market with methods for fetching related data.
1975
+ * Instances are created by MarketFetcher and have http_client attached.
2205
1976
  *
2206
1977
  * @public
2207
1978
  */
2208
- declare class AuthenticatedClient {
2209
- private httpClient;
2210
- private authenticator;
2211
- private client;
2212
- private smartWallet?;
2213
- private logger;
2214
- private maxRetries;
1979
+ declare class Market {
1980
+ id: number;
1981
+ slug: string;
1982
+ title: string;
1983
+ proxyTitle: string | null;
1984
+ description?: string;
1985
+ collateralToken: CollateralToken;
1986
+ expirationDate: string;
1987
+ expirationTimestamp: number;
1988
+ expired?: boolean;
1989
+ createdAt: string;
1990
+ updatedAt: string;
1991
+ categories: string[];
1992
+ status: string;
1993
+ creator: MarketCreator;
1994
+ tags: string[];
1995
+ tradeType: string;
1996
+ marketType: string;
1997
+ priorityIndex: number;
1998
+ metadata: MarketMetadata;
1999
+ volume?: string;
2000
+ volumeFormatted?: string;
2001
+ conditionId?: string;
2002
+ negRiskRequestId?: string | null;
2003
+ tokens?: MarketTokens;
2004
+ prices?: number[];
2005
+ tradePrices?: TradePrices;
2006
+ isRewardable?: boolean;
2007
+ settings?: MarketSettings;
2008
+ venue?: Venue;
2009
+ logo?: string | null;
2010
+ priceOracleMetadata?: PriceOracleMetadata;
2011
+ orderInGroup?: number;
2012
+ winningOutcomeIndex?: number | null;
2013
+ outcomeTokens?: string[];
2014
+ ogImageURI?: string;
2015
+ negRiskMarketId?: string;
2016
+ markets?: Market[];
2017
+ dailyReward?: string;
2018
+ address?: string | null;
2019
+ type?: string;
2020
+ outcomes?: MarketOutcome[];
2021
+ resolutionDate?: string;
2022
+ private httpClient?;
2215
2023
  /**
2216
- * Creates a new authenticated client with auto-retry capability.
2024
+ * Creates a Market instance.
2217
2025
  *
2218
- * @param config - Configuration for authenticated client
2026
+ * @param data - Market data from API
2027
+ * @param httpClient - HTTP client for making requests
2219
2028
  */
2220
- constructor(config: AuthenticatedClientConfig);
2029
+ constructor(data: any, httpClient?: HttpClient);
2221
2030
  /**
2222
- * Executes a function with automatic retry on authentication errors.
2031
+ * Get user's orders for this market.
2223
2032
  *
2224
- * @param fn - Function to execute with auth retry
2225
- * @returns Promise resolving to the function result
2226
- * @throws Error if max retries exceeded or non-auth error occurs
2033
+ * @remarks
2034
+ * Fetches all orders placed by the authenticated user for this specific market.
2035
+ * Uses the http_client from the MarketFetcher that created this Market instance.
2036
+ *
2037
+ * @returns Promise resolving to array of user orders
2038
+ * @throws Error if market wasn't fetched via MarketFetcher
2227
2039
  *
2228
2040
  * @example
2229
2041
  * ```typescript
2230
- * // Automatic retry on 401/403
2231
- * const positions = await authClient.withRetry(() =>
2232
- * portfolioFetcher.getPositions()
2233
- * );
2234
- *
2235
- * // Works with any async operation
2236
- * const order = await authClient.withRetry(() =>
2237
- * orderClient.createOrder({ ... })
2238
- * );
2042
+ * // Clean fluent API
2043
+ * const market = await marketFetcher.getMarket("bitcoin-2024");
2044
+ * const orders = await market.getUserOrders();
2045
+ * console.log(`You have ${orders.length} orders in ${market.title}`);
2239
2046
  * ```
2240
2047
  */
2241
- withRetry<T>(fn: () => Promise<T>): Promise<T>;
2242
- /**
2243
- * Re-authenticates with the API.
2244
- *
2245
- * @internal
2246
- */
2247
- private reauthenticate;
2048
+ getUserOrders(): Promise<any[]>;
2248
2049
  }
2249
2050
 
2250
2051
  /**
@@ -2319,6 +2120,72 @@ declare class APIError extends Error {
2319
2120
  */
2320
2121
  isAuthError(): boolean;
2321
2122
  }
2123
+ /**
2124
+ * Rate limit error (HTTP 429).
2125
+ *
2126
+ * @remarks
2127
+ * Thrown when API rate limits are exceeded. The request should be retried after a delay.
2128
+ *
2129
+ * @example
2130
+ * ```typescript
2131
+ * try {
2132
+ * await marketFetcher.getActiveMarkets();
2133
+ * } catch (error) {
2134
+ * if (error instanceof RateLimitError) {
2135
+ * console.log('Rate limit exceeded, retry after delay');
2136
+ * }
2137
+ * }
2138
+ * ```
2139
+ *
2140
+ * @public
2141
+ */
2142
+ declare class RateLimitError extends APIError {
2143
+ constructor(message?: string, status?: number, data?: any, url?: string, method?: string);
2144
+ }
2145
+ /**
2146
+ * Authentication error (HTTP 401, 403).
2147
+ *
2148
+ * @remarks
2149
+ * Thrown when authentication fails or API key is invalid/missing.
2150
+ *
2151
+ * @example
2152
+ * ```typescript
2153
+ * try {
2154
+ * await portfolioFetcher.getPositions();
2155
+ * } catch (error) {
2156
+ * if (error instanceof AuthenticationError) {
2157
+ * console.log('Authentication failed - check API key');
2158
+ * }
2159
+ * }
2160
+ * ```
2161
+ *
2162
+ * @public
2163
+ */
2164
+ declare class AuthenticationError extends APIError {
2165
+ constructor(message?: string, status?: number, data?: any, url?: string, method?: string);
2166
+ }
2167
+ /**
2168
+ * Validation error (HTTP 400).
2169
+ *
2170
+ * @remarks
2171
+ * Thrown when request validation fails (invalid parameters, missing required fields, etc.).
2172
+ *
2173
+ * @example
2174
+ * ```typescript
2175
+ * try {
2176
+ * await orderClient.createOrder({ ... });
2177
+ * } catch (error) {
2178
+ * if (error instanceof ValidationError) {
2179
+ * console.log('Validation failed:', error.message);
2180
+ * }
2181
+ * }
2182
+ * ```
2183
+ *
2184
+ * @public
2185
+ */
2186
+ declare class ValidationError extends APIError {
2187
+ constructor(message: string, status?: number, data?: any, url?: string, method?: string);
2188
+ }
2322
2189
 
2323
2190
  /**
2324
2191
  * Retry mechanism for handling transient API failures.
@@ -2870,17 +2737,17 @@ declare class OrderSigner {
2870
2737
  */
2871
2738
 
2872
2739
  /**
2873
- * Validation error class.
2740
+ * Order validation error class for client-side validation.
2874
2741
  * @public
2875
2742
  */
2876
- declare class ValidationError extends Error {
2743
+ declare class OrderValidationError extends Error {
2877
2744
  constructor(message: string);
2878
2745
  }
2879
2746
  /**
2880
2747
  * Validates order arguments before building.
2881
2748
  *
2882
2749
  * @param args - Order arguments to validate (FOK or GTC)
2883
- * @throws ValidationError if validation fails
2750
+ * @throws OrderValidationError if validation fails
2884
2751
  *
2885
2752
  * @public
2886
2753
  *
@@ -2898,7 +2765,7 @@ declare function validateOrderArgs(args: OrderArgs): void;
2898
2765
  * Validates an unsigned order.
2899
2766
  *
2900
2767
  * @param order - Unsigned order to validate
2901
- * @throws ValidationError if validation fails
2768
+ * @throws OrderValidationError if validation fails
2902
2769
  *
2903
2770
  * @public
2904
2771
  *
@@ -2912,7 +2779,7 @@ declare function validateUnsignedOrder(order: UnsignedOrder): void;
2912
2779
  * Validates a signed order.
2913
2780
  *
2914
2781
  * @param order - Signed order to validate
2915
- * @throws ValidationError if validation fails
2782
+ * @throws OrderValidationError if validation fails
2916
2783
  *
2917
2784
  * @public
2918
2785
  *
@@ -2996,9 +2863,14 @@ declare class MarketFetcher {
2996
2863
  *
2997
2864
  * @example
2998
2865
  * ```typescript
2866
+ * // Get market
2999
2867
  * const market = await fetcher.getMarket('bitcoin-price-2024');
3000
2868
  * console.log(`Market: ${market.title}`);
3001
2869
  *
2870
+ * // Fluent API - get user orders for this market (clean!)
2871
+ * const orders = await market.getUserOrders();
2872
+ * console.log(`You have ${orders.length} orders`);
2873
+ *
3002
2874
  * // Venue is now cached for order signing
3003
2875
  * await orderClient.createOrder({
3004
2876
  * marketSlug: 'bitcoin-price-2024',
@@ -3040,20 +2912,6 @@ declare class MarketFetcher {
3040
2912
  * ```
3041
2913
  */
3042
2914
  getOrderBook(slug: string): Promise<OrderBook>;
3043
- /**
3044
- * Gets the current price for a token.
3045
- *
3046
- * @param tokenId - Token ID
3047
- * @returns Promise resolving to price information
3048
- * @throws Error if API request fails
3049
- *
3050
- * @example
3051
- * ```typescript
3052
- * const price = await fetcher.getPrice('123456');
3053
- * console.log(`Current price: ${price.price}`);
3054
- * ```
3055
- */
3056
- getPrice(tokenId: string): Promise<MarketPrice>;
3057
2915
  }
3058
2916
 
3059
2917
  /**
@@ -3066,7 +2924,8 @@ declare class MarketFetcher {
3066
2924
  *
3067
2925
  * @remarks
3068
2926
  * The order client auto-configures signing based on venue data from the API.
3069
- * Custom signingConfig is optional for advanced use cases.
2927
+ * User data (userId, feeRateBps) is automatically fetched from the profile API
2928
+ * on first order creation and cached for subsequent orders.
3070
2929
  *
3071
2930
  * Performance tip: Provide a shared marketFetcher instance to enable venue caching
3072
2931
  * across market fetches and order creation, avoiding redundant API calls.
@@ -3075,25 +2934,13 @@ declare class MarketFetcher {
3075
2934
  */
3076
2935
  interface OrderClientConfig {
3077
2936
  /**
3078
- * HTTP client for API requests
2937
+ * HTTP client for API requests (must have API key configured)
3079
2938
  */
3080
2939
  httpClient: HttpClient;
3081
2940
  /**
3082
- * Wallet for signing orders
2941
+ * Wallet for signing orders with EIP-712
3083
2942
  */
3084
2943
  wallet: ethers.Wallet;
3085
- /**
3086
- * User data containing userId and feeRateBps
3087
- *
3088
- * @example
3089
- * ```typescript
3090
- * {
3091
- * userId: 123, // From auth result
3092
- * feeRateBps: 300 // User's fee rate (3%)
3093
- * }
3094
- * ```
3095
- */
3096
- userData: UserData;
3097
2944
  /**
3098
2945
  * Custom signing configuration (optional)
3099
2946
  *
@@ -3118,7 +2965,6 @@ interface OrderClientConfig {
3118
2965
  * const orderClient = new OrderClient({
3119
2966
  * httpClient,
3120
2967
  * wallet,
3121
- * userData,
3122
2968
  * marketFetcher // Shared instance
3123
2969
  * });
3124
2970
  *
@@ -3142,24 +2988,23 @@ interface OrderClientConfig {
3142
2988
  * This class provides high-level methods for order operations,
3143
2989
  * abstracting away HTTP details and order signing complexity.
3144
2990
  *
2991
+ * User data (userId, feeRateBps) is automatically fetched from profile API
2992
+ * on first order creation and cached for subsequent orders.
2993
+ *
3145
2994
  * Uses dynamic venue addressing for EIP-712 order signing. For best performance,
3146
2995
  * always call marketFetcher.getMarket() before creating orders to cache venue data.
3147
2996
  *
3148
2997
  * @example
3149
2998
  * ```typescript
2999
+ * import { ethers } from 'ethers';
3000
+ *
3001
+ * const wallet = new ethers.Wallet(process.env.PRIVATE_KEY!);
3150
3002
  * const orderClient = new OrderClient({
3151
- * httpClient,
3152
- * wallet,
3153
- * userData: {
3154
- * userId: 123,
3155
- * feeRateBps: 100
3156
- * },
3157
- * signingConfig: {
3158
- * chainId: 8453,
3159
- * contractAddress: '0x...'
3160
- * }
3003
+ * httpClient, // Must have API key configured
3004
+ * wallet, // For EIP-712 signing
3161
3005
  * });
3162
3006
  *
3007
+ * // User data automatically fetched on first order
3163
3008
  * const order = await orderClient.createOrder({
3164
3009
  * tokenId: '123...',
3165
3010
  * price: 0.65,
@@ -3174,10 +3019,11 @@ interface OrderClientConfig {
3174
3019
  */
3175
3020
  declare class OrderClient {
3176
3021
  private httpClient;
3177
- private orderBuilder;
3022
+ private wallet;
3023
+ private orderBuilder?;
3178
3024
  private orderSigner;
3179
3025
  private marketFetcher;
3180
- private ownerId;
3026
+ private cachedUserData?;
3181
3027
  private signingConfig;
3182
3028
  private logger;
3183
3029
  /**
@@ -3186,6 +3032,14 @@ declare class OrderClient {
3186
3032
  * @param config - Order client configuration
3187
3033
  */
3188
3034
  constructor(config: OrderClientConfig);
3035
+ /**
3036
+ * Ensures user data is loaded and cached.
3037
+ * Fetches from profile API on first call, then caches for subsequent calls.
3038
+ *
3039
+ * @returns Promise resolving to cached user data
3040
+ * @internal
3041
+ */
3042
+ private ensureUserData;
3189
3043
  /**
3190
3044
  * Creates and submits a new order.
3191
3045
  *
@@ -3268,25 +3122,6 @@ declare class OrderClient {
3268
3122
  cancelAll(marketSlug: string): Promise<{
3269
3123
  message: string;
3270
3124
  }>;
3271
- /**
3272
- * @deprecated Use `cancel()` instead
3273
- */
3274
- cancelOrder(orderId: string): Promise<void>;
3275
- /**
3276
- * Gets an order by ID.
3277
- *
3278
- * @param orderId - Order ID to fetch
3279
- * @returns Promise resolving to order details
3280
- *
3281
- * @throws Error if order not found
3282
- *
3283
- * @example
3284
- * ```typescript
3285
- * const order = await orderClient.getOrder('order-id-123');
3286
- * console.log(order.order.side);
3287
- * ```
3288
- */
3289
- getOrder(orderId: string): Promise<OrderResponse>;
3290
3125
  /**
3291
3126
  * Builds an unsigned order without submitting.
3292
3127
  *
@@ -3295,11 +3130,11 @@ declare class OrderClient {
3295
3130
  * before signing and submission.
3296
3131
  *
3297
3132
  * @param params - Order parameters
3298
- * @returns Unsigned order
3133
+ * @returns Promise resolving to unsigned order
3299
3134
  *
3300
3135
  * @example
3301
3136
  * ```typescript
3302
- * const unsignedOrder = orderClient.buildUnsignedOrder({
3137
+ * const unsignedOrder = await orderClient.buildUnsignedOrder({
3303
3138
  * tokenId: '123456',
3304
3139
  * price: 0.65,
3305
3140
  * size: 100,
@@ -3307,7 +3142,7 @@ declare class OrderClient {
3307
3142
  * });
3308
3143
  * ```
3309
3144
  */
3310
- buildUnsignedOrder(params: OrderArgs): UnsignedOrder;
3145
+ buildUnsignedOrder(params: OrderArgs): Promise<UnsignedOrder>;
3311
3146
  /**
3312
3147
  * Signs an unsigned order without submitting.
3313
3148
  *
@@ -3324,6 +3159,32 @@ declare class OrderClient {
3324
3159
  * ```
3325
3160
  */
3326
3161
  signOrder(order: UnsignedOrder): Promise<string>;
3162
+ /**
3163
+ * Gets the wallet address.
3164
+ *
3165
+ * @returns Ethereum address of the wallet
3166
+ *
3167
+ * @example
3168
+ * ```typescript
3169
+ * const address = orderClient.walletAddress;
3170
+ * console.log(`Wallet: ${address}`);
3171
+ * ```
3172
+ */
3173
+ get walletAddress(): string;
3174
+ /**
3175
+ * Gets the owner ID (user ID from profile).
3176
+ *
3177
+ * @returns Owner ID from user profile, or undefined if not yet loaded
3178
+ *
3179
+ * @example
3180
+ * ```typescript
3181
+ * const ownerId = orderClient.ownerId;
3182
+ * if (ownerId) {
3183
+ * console.log(`Owner ID: ${ownerId}`);
3184
+ * }
3185
+ * ```
3186
+ */
3187
+ get ownerId(): number | undefined;
3327
3188
  }
3328
3189
 
3329
3190
  /**
@@ -3360,6 +3221,26 @@ declare class PortfolioFetcher {
3360
3221
  * ```
3361
3222
  */
3362
3223
  constructor(httpClient: HttpClient, logger?: ILogger);
3224
+ /**
3225
+ * Gets user profile for a specific wallet address.
3226
+ *
3227
+ * @remarks
3228
+ * Returns user profile data including user ID and fee rate.
3229
+ * Used internally by OrderClient to fetch user data.
3230
+ *
3231
+ * @param address - Wallet address to fetch profile for
3232
+ * @returns Promise resolving to user profile data
3233
+ * @throws Error if API request fails or user is not authenticated
3234
+ *
3235
+ * @example
3236
+ * ```typescript
3237
+ * const profile = await portfolioFetcher.getProfile('0x1234...');
3238
+ * console.log(`User ID: ${profile.id}`);
3239
+ * console.log(`Account: ${profile.account}`);
3240
+ * console.log(`Fee Rate: ${profile.rank?.feeRateBps}`);
3241
+ * ```
3242
+ */
3243
+ getProfile(address: string): Promise<any>;
3363
3244
  /**
3364
3245
  * Gets raw portfolio positions response from API.
3365
3246
  *
@@ -3406,65 +3287,32 @@ declare class PortfolioFetcher {
3406
3287
  */
3407
3288
  getAMMPositions(): Promise<AMMPosition[]>;
3408
3289
  /**
3409
- * Flattens positions into a unified format for easier consumption.
3410
- *
3411
- * @remarks
3412
- * Converts CLOB positions (which have YES/NO sides) and AMM positions
3413
- * into a unified Position array. Only includes positions with non-zero values.
3414
- *
3415
- * @returns Promise resolving to array of flattened positions
3416
- * @throws Error if API request fails
3417
- *
3418
- * @example
3419
- * ```typescript
3420
- * const positions = await portfolioFetcher.getFlattenedPositions();
3421
- * positions.forEach(pos => {
3422
- * const pnlPercent = (pos.unrealizedPnl / pos.costBasis) * 100;
3423
- * console.log(`${pos.market.title} (${pos.side}): ${pnlPercent.toFixed(2)}% P&L`);
3424
- * });
3425
- * ```
3426
- */
3427
- getFlattenedPositions(): Promise<Position[]>;
3428
- /**
3429
- * Calculates portfolio summary statistics from raw API response.
3430
- *
3431
- * @param response - Portfolio positions response from API
3432
- * @returns Portfolio summary with totals and statistics
3433
- *
3434
- * @example
3435
- * ```typescript
3436
- * const response = await portfolioFetcher.getPositions();
3437
- * const summary = portfolioFetcher.calculateSummary(response);
3290
+ * Gets paginated history of user actions.
3438
3291
  *
3439
- * console.log(`Total Portfolio Value: $${(summary.totalValue / 1e6).toFixed(2)}`);
3440
- * console.log(`Total P&L: ${summary.totalUnrealizedPnlPercent.toFixed(2)}%`);
3441
- * console.log(`CLOB Positions: ${summary.breakdown.clob.positions}`);
3442
- * console.log(`AMM Positions: ${summary.breakdown.amm.positions}`);
3443
- * ```
3444
- */
3445
- calculateSummary(response: PortfolioPositionsResponse): PortfolioSummary;
3446
- /**
3447
- * Gets positions and calculates summary in a single call.
3292
+ * Includes AMM trades, CLOB trades, Negrisk trades & conversions.
3448
3293
  *
3449
- * @returns Promise resolving to response and summary
3294
+ * @param page - Page number (starts at 1)
3295
+ * @param limit - Number of items per page
3296
+ * @returns Promise resolving to paginated history response
3450
3297
  * @throws Error if API request fails or user is not authenticated
3451
3298
  *
3452
3299
  * @example
3453
3300
  * ```typescript
3454
- * const { response, summary } = await portfolioFetcher.getPortfolio();
3455
- *
3456
- * console.log('Portfolio Summary:');
3457
- * console.log(` Total Value: $${(summary.totalValue / 1e6).toFixed(2)}`);
3458
- * console.log(` Total P&L: $${(summary.totalUnrealizedPnl / 1e6).toFixed(2)}`);
3459
- * console.log(` P&L %: ${summary.totalUnrealizedPnlPercent.toFixed(2)}%`);
3460
- * console.log(`\nCLOB Positions: ${response.clob.length}`);
3461
- * console.log(`AMM Positions: ${response.amm.length}`);
3301
+ * // Get first page
3302
+ * const response = await portfolioFetcher.getUserHistory(1, 20);
3303
+ * console.log(`Found ${response.data.length} of ${response.totalCount} entries`);
3304
+ *
3305
+ * // Process history entries
3306
+ * for (const entry of response.data) {
3307
+ * console.log(`Type: ${entry.type}`);
3308
+ * console.log(`Market: ${entry.marketSlug}`);
3309
+ * }
3310
+ *
3311
+ * // Get next page
3312
+ * const page2 = await portfolioFetcher.getUserHistory(2, 20);
3462
3313
  * ```
3463
3314
  */
3464
- getPortfolio(): Promise<{
3465
- response: PortfolioPositionsResponse;
3466
- summary: PortfolioSummary;
3467
- }>;
3315
+ getUserHistory(page?: number, limit?: number): Promise<HistoryResponse>;
3468
3316
  }
3469
3317
 
3470
3318
  /**
@@ -3479,22 +3327,36 @@ declare class PortfolioFetcher {
3479
3327
  * This client uses Socket.IO to connect to the WebSocket server and provides
3480
3328
  * typed event subscriptions for orderbook, trades, orders, and market data.
3481
3329
  *
3330
+ * **Public Subscriptions** (no authentication required):
3331
+ * - Market prices (AMM)
3332
+ * - Orderbook updates (CLOB)
3333
+ *
3334
+ * **Authenticated Subscriptions** (require API key):
3335
+ * - User positions
3336
+ * - User transactions
3337
+ *
3482
3338
  * @example
3483
3339
  * ```typescript
3484
- * // Create client
3340
+ * // Public subscription (no API key needed)
3485
3341
  * const wsClient = new WebSocketClient({
3486
- * sessionCookie: 'your-session-cookie',
3487
3342
  * autoReconnect: true,
3488
3343
  * });
3489
3344
  *
3490
- * // Subscribe to orderbook updates
3491
- * wsClient.on('orderbook', (data) => {
3492
- * console.log('Orderbook update:', data);
3345
+ * await wsClient.connect();
3346
+ * await wsClient.subscribe('subscribe_market_prices', {
3347
+ * marketSlugs: ['market-123']
3348
+ * });
3349
+ *
3350
+ * // Authenticated subscription (API key required)
3351
+ * const wsClientAuth = new WebSocketClient({
3352
+ * apiKey: process.env.LIMITLESS_API_KEY,
3353
+ * autoReconnect: true,
3493
3354
  * });
3494
3355
  *
3495
- * // Connect and subscribe
3496
- * await wsClient.connect();
3497
- * await wsClient.subscribe('orderbook', { marketSlug: 'market-123' });
3356
+ * await wsClientAuth.connect();
3357
+ * await wsClientAuth.subscribe('subscribe_positions', {
3358
+ * marketSlugs: ['market-123']
3359
+ * });
3498
3360
  * ```
3499
3361
  *
3500
3362
  * @public
@@ -3527,11 +3389,20 @@ declare class WebSocketClient {
3527
3389
  */
3528
3390
  isConnected(): boolean;
3529
3391
  /**
3530
- * Sets the session cookie for authentication.
3392
+ * Sets the API key for authentication.
3393
+ *
3394
+ * @param apiKey - API key value
3531
3395
  *
3532
- * @param sessionCookie - Session cookie value
3396
+ * @remarks
3397
+ * API key is required for authenticated subscriptions (positions, transactions).
3398
+ * If already connected, this will trigger a reconnection with the new API key.
3399
+ */
3400
+ setApiKey(apiKey: string): void;
3401
+ /**
3402
+ * Reconnects with new authentication credentials.
3403
+ * @internal
3533
3404
  */
3534
- setSessionCookie(sessionCookie: string): void;
3405
+ private reconnectWithNewAuth;
3535
3406
  /**
3536
3407
  * Connects to the WebSocket server.
3537
3408
  *
@@ -3548,24 +3419,26 @@ declare class WebSocketClient {
3548
3419
  /**
3549
3420
  * Disconnects from the WebSocket server.
3550
3421
  *
3422
+ * @returns Promise that resolves when disconnected
3423
+ *
3551
3424
  * @example
3552
3425
  * ```typescript
3553
- * wsClient.disconnect();
3426
+ * await wsClient.disconnect();
3554
3427
  * ```
3555
3428
  */
3556
- disconnect(): void;
3429
+ disconnect(): Promise<void>;
3557
3430
  /**
3558
3431
  * Subscribes to a channel.
3559
3432
  *
3560
3433
  * @param channel - Channel to subscribe to
3561
3434
  * @param options - Subscription options
3562
- * @returns Promise that resolves when subscribed
3435
+ * @returns Promise that resolves immediately (kept async for API compatibility)
3563
3436
  * @throws Error if not connected
3564
3437
  *
3565
3438
  * @example
3566
3439
  * ```typescript
3567
3440
  * // Subscribe to orderbook for a specific market
3568
- * await wsClient.subscribe('orderbook', { marketSlug: 'market-123' });
3441
+ * await wsClient.subscribe('orderbook', { marketSlugs: ['market-123'] });
3569
3442
  *
3570
3443
  * // Subscribe to all trades
3571
3444
  * await wsClient.subscribe('trades');
@@ -3581,10 +3454,11 @@ declare class WebSocketClient {
3581
3454
  * @param channel - Channel to unsubscribe from
3582
3455
  * @param options - Subscription options (must match subscribe call)
3583
3456
  * @returns Promise that resolves when unsubscribed
3457
+ * @throws Error if not connected or unsubscribe fails
3584
3458
  *
3585
3459
  * @example
3586
3460
  * ```typescript
3587
- * await wsClient.unsubscribe('orderbook', { marketSlug: 'market-123' });
3461
+ * await wsClient.unsubscribe('orderbook', { marketSlugs: ['market-123'] });
3588
3462
  * ```
3589
3463
  */
3590
3464
  unsubscribe(channel: SubscriptionChannel, options?: SubscriptionOptions): Promise<void>;
@@ -3616,10 +3490,19 @@ declare class WebSocketClient {
3616
3490
  * Removes an event listener.
3617
3491
  *
3618
3492
  * @param event - Event name
3619
- * @param handler - Event handler to remove
3493
+ * @param handler - Event handler to remove (if undefined, removes all handlers for event)
3620
3494
  * @returns This client for chaining
3495
+ *
3496
+ * @example
3497
+ * ```typescript
3498
+ * // Remove specific handler
3499
+ * wsClient.off('orderbookUpdate', myHandler);
3500
+ *
3501
+ * // Remove all handlers for event
3502
+ * wsClient.off('orderbookUpdate');
3503
+ * ```
3621
3504
  */
3622
- off<K extends keyof WebSocketEvents>(event: K, handler: WebSocketEvents[K]): this;
3505
+ off<K extends keyof WebSocketEvents>(event: K, handler?: WebSocketEvents[K]): this;
3623
3506
  /**
3624
3507
  * Attach any pending event listeners that were added before connect().
3625
3508
  * @internal
@@ -3647,4 +3530,4 @@ declare class WebSocketClient {
3647
3530
  private getChannelFromKey;
3648
3531
  }
3649
3532
 
3650
- export { type AMMPosition, APIError, type ActiveMarketsParams, type ActiveMarketsResponse, type ActiveMarketsSortBy, type AmmPriceEntry, type AuthResult, AuthenticatedClient, type AuthenticatedClientConfig, Authenticator, BASE_SEPOLIA_CHAIN_ID, type BaseOrderArgs, type CLOBPosition, CONTRACT_ADDRESSES, type ClientType, type CollateralToken, ConsoleLogger, type CreatedOrder, DEFAULT_API_URL, DEFAULT_CHAIN_ID, DEFAULT_WS_URL, type FOKOrderArgs, type FillEvent, type GTCOrderArgs, HttpClient, type HttpClientConfig, type ILogger, type LatestTrade, type LoginOptions, type Market, type MarketCreator, MarketFetcher, type MarketMetadata, type MarketOutcome, type MarketPrice, type MarketSettings, type MarketTokens, type MarketUpdate, type MarketsResponse, MessageSigner, type ModeInfo, type NewOrderPayload, type NewPriceData, NoOpLogger, type OrderArgs, type OrderBook, OrderBuilder, OrderClient, type OrderClientConfig, type OrderMatch, type OrderResponse, OrderSigner, type OrderSigningConfig, OrderType, type OrderUpdate, type OrderbookData, type OrderbookEntry, type OrderbookUpdate, PortfolioFetcher, type PortfolioPositionsResponse, type PortfolioSummary, type Position, type PositionMarket, type PositionSide, type PriceOracleMetadata, type PriceUpdate, type ReferralData, RetryConfig, type RetryConfigOptions, RetryableClient, SIGNING_MESSAGE_TEMPLATE, Side, type SignatureHeaders, SignatureType, type SignedOrder, type SubscriptionChannel, type SubscriptionOptions, type TokenBalance, type TradeEvent, type TradePrices, type TradingMode, type TransactionEvent, type UnsignedOrder, type UserData, type UserProfile, type UserRank, ValidationError, type Venue, WebSocketClient, type WebSocketConfig, type WebSocketEvents, WebSocketState, ZERO_ADDRESS, getContractAddress, retryOnErrors, validateOrderArgs, validateSignedOrder, validateUnsignedOrder, withRetry };
3533
+ export { type AMMPosition, APIError, type ActiveMarketsParams, type ActiveMarketsResponse, type ActiveMarketsSortBy, type AmmPriceEntry, AuthenticationError, BASE_SEPOLIA_CHAIN_ID, type BaseOrderArgs, type CLOBPosition, CONTRACT_ADDRESSES, type CollateralToken, ConsoleLogger, type CreatedOrder, DEFAULT_API_URL, DEFAULT_CHAIN_ID, DEFAULT_WS_URL, type FOKOrderArgs, type FillEvent, type GTCOrderArgs, type HistoryEntry, type HistoryResponse, HttpClient, type HttpClientConfig, type ILogger, type LatestTrade, Market, type MarketCreator, MarketFetcher, type Market$1 as MarketInterface, type MarketMetadata, type MarketOutcome, type MarketSettings, type MarketTokens, type MarketUpdate, type MarketsResponse, type ModeInfo, type NewOrderPayload, type NewPriceData, NoOpLogger, type OrderArgs, type OrderBook, OrderBuilder, OrderClient, type OrderClientConfig, type OrderMatch, type OrderResponse, OrderSigner, type OrderSigningConfig, OrderType, type OrderUpdate, OrderValidationError, type OrderbookData, type OrderbookEntry, type OrderbookUpdate, PortfolioFetcher, type PortfolioPositionsResponse, type PortfolioSummary, type Position, type PositionMarket, type PositionSide, type PriceOracleMetadata, type PriceUpdate, RateLimitError, type ReferralData, RetryConfig, type RetryConfigOptions, RetryableClient, SIGNING_MESSAGE_TEMPLATE, Side, SignatureType, type SignedOrder, type SubscriptionChannel, type SubscriptionOptions, type TokenBalance, type TradeEvent, type TradePrices, type TradingMode, type TransactionEvent, type UnsignedOrder, type UserData, type UserProfile, type UserRank, ValidationError, type Venue, WebSocketClient, type WebSocketConfig, type WebSocketEvents, WebSocketState, ZERO_ADDRESS, getContractAddress, retryOnErrors, validateOrderArgs, validateSignedOrder, validateUnsignedOrder, withRetry };