@pear-protocol/hyperliquid-sdk 0.0.76 → 0.0.78

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.
Files changed (2) hide show
  1. package/dist/index.js +22 -11
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -114,7 +114,7 @@ const useMarketData = create((set) => ({
114
114
  * Convert a full/prefixed symbol (e.g., "xyz:XYZ100") to a display symbol (e.g., "XYZ100").
115
115
  */
116
116
  function toDisplaySymbol(symbol) {
117
- const parts = symbol.split(':');
117
+ const parts = symbol.split(":");
118
118
  return parts.length > 1 ? parts.slice(-1)[0] : symbol;
119
119
  }
120
120
  /**
@@ -125,6 +125,8 @@ function toDisplaySymbol(symbol) {
125
125
  * @param hip3Assets map of display -> all full market names (e.g., "TSLA" -> ["xyz:TSLA", "flx:TSLA"])
126
126
  */
127
127
  function toBackendSymbol(displaySymbol, hip3Assets) {
128
+ if (displaySymbol === "BTC")
129
+ return "BTC";
128
130
  const markets = hip3Assets.get(displaySymbol);
129
131
  // Return first market if available, otherwise return original symbol
130
132
  return markets && markets.length > 0 ? markets[0] : displaySymbol;
@@ -169,7 +171,7 @@ function getAvailableMarkets(displaySymbol, hip3Assets) {
169
171
  * @returns The prefix (e.g., "xyz") or undefined if no prefix
170
172
  */
171
173
  function getMarketPrefix(fullSymbol) {
172
- const parts = fullSymbol.split(':');
174
+ const parts = fullSymbol.split(":");
173
175
  return parts.length > 1 ? parts[0] : undefined;
174
176
  }
175
177
  /**
@@ -178,7 +180,7 @@ function getMarketPrefix(fullSymbol) {
178
180
  * @returns true if the symbol has a market prefix
179
181
  */
180
182
  function isHip3Market(symbol) {
181
- return symbol.includes(':');
183
+ return symbol.includes(":");
182
184
  }
183
185
 
184
186
  const useHyperliquidWebSocket = ({ wsUrl, address, enabled = true, }) => {
@@ -786,6 +788,7 @@ const useHyperliquidNativeWebSocket = ({ address, enabled = true, onUserFills, }
786
788
  const [subscribedAddress, setSubscribedAddress] = useState(null);
787
789
  const [subscribedTokens, setSubscribedTokens] = useState([]);
788
790
  const [subscribedCandleTokens, setSubscribedCandleTokens] = useState([]);
791
+ const [clearinghouseStateReceived, setClearinghouseStateReceived] = useState(false);
789
792
  const prevCandleIntervalRef = useRef(null);
790
793
  const pingIntervalRef = useRef(null);
791
794
  const wsRef = useRef(null);
@@ -879,6 +882,7 @@ const useHyperliquidNativeWebSocket = ({ address, enabled = true, onUserFills, }
879
882
  };
880
883
  setAggregatedClearingHouseState(aggregatedClearingHouseState);
881
884
  setRawClearinghouseStates(data.clearinghouseStates || null);
885
+ setClearinghouseStateReceived(true);
882
886
  }
883
887
  break;
884
888
  case 'allMids':
@@ -1115,18 +1119,10 @@ const useHyperliquidNativeWebSocket = ({ address, enabled = true, onUserFills, }
1115
1119
  type: "allDexsAssetCtxs",
1116
1120
  },
1117
1121
  };
1118
- const subscribeUserFills = {
1119
- method: 'subscribe',
1120
- subscription: {
1121
- type: 'userFills',
1122
- user: userAddress,
1123
- },
1124
- };
1125
1122
  sendJsonMessage(subscribeWebData3);
1126
1123
  sendJsonMessage(subscribeAllDexsClearinghouseState);
1127
1124
  sendJsonMessage(subscribeAllMids);
1128
1125
  sendJsonMessage(subscribeAllDexsAssetCtxs);
1129
- sendJsonMessage(subscribeUserFills);
1130
1126
  // Subscribe to spotState for real-time spot balances (USDH, USDC, etc.)
1131
1127
  // Only subscribe if we have a real user address (not the default)
1132
1128
  if (userAddress !== DEFAULT_ADDRESS) {
@@ -1147,6 +1143,8 @@ const useHyperliquidNativeWebSocket = ({ address, enabled = true, onUserFills, }
1147
1143
  setRawClearinghouseStates(null);
1148
1144
  // clear spotState
1149
1145
  setSpotState(null);
1146
+ // reset clearinghouseStateReceived to wait for new data before subscribing to userFills
1147
+ setClearinghouseStateReceived(false);
1150
1148
  }
1151
1149
  }, [
1152
1150
  isConnected,
@@ -1157,6 +1155,19 @@ const useHyperliquidNativeWebSocket = ({ address, enabled = true, onUserFills, }
1157
1155
  setRawClearinghouseStates,
1158
1156
  setSpotState,
1159
1157
  ]);
1158
+ // Subscribe to userFills only after allDexsClearinghouseState data is received
1159
+ useEffect(() => {
1160
+ if (!isConnected || !subscribedAddress || !clearinghouseStateReceived)
1161
+ return;
1162
+ const subscribeUserFills = {
1163
+ method: 'subscribe',
1164
+ subscription: {
1165
+ type: 'userFills',
1166
+ user: subscribedAddress,
1167
+ },
1168
+ };
1169
+ sendJsonMessage(subscribeUserFills);
1170
+ }, [isConnected, subscribedAddress, clearinghouseStateReceived, sendJsonMessage]);
1160
1171
  // Handle token subscriptions for activeAssetData
1161
1172
  useEffect(() => {
1162
1173
  if (!isConnected || !address)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pear-protocol/hyperliquid-sdk",
3
- "version": "0.0.76",
3
+ "version": "0.0.78",
4
4
  "description": "React SDK for Pear Protocol Hyperliquid API integration",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",