@pear-protocol/hyperliquid-sdk 0.0.75 → 0.0.77

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.
@@ -9,7 +9,7 @@ export interface PairAssetInput {
9
9
  }
10
10
  export interface TpSlThresholdInput {
11
11
  type: TpSlThresholdType;
12
- value: number;
12
+ value?: number;
13
13
  isTrailing?: boolean;
14
14
  trailingDeltaValue?: number;
15
15
  trailingActivationValue?: number;
package/dist/index.d.ts CHANGED
@@ -1100,7 +1100,7 @@ interface PairAssetInput {
1100
1100
  }
1101
1101
  interface TpSlThresholdInput {
1102
1102
  type: TpSlThresholdType;
1103
- value: number;
1103
+ value?: number;
1104
1104
  isTrailing?: boolean;
1105
1105
  trailingDeltaValue?: number;
1106
1106
  trailingActivationValue?: number;
package/dist/index.js CHANGED
@@ -786,6 +786,7 @@ const useHyperliquidNativeWebSocket = ({ address, enabled = true, onUserFills, }
786
786
  const [subscribedAddress, setSubscribedAddress] = useState(null);
787
787
  const [subscribedTokens, setSubscribedTokens] = useState([]);
788
788
  const [subscribedCandleTokens, setSubscribedCandleTokens] = useState([]);
789
+ const [clearinghouseStateReceived, setClearinghouseStateReceived] = useState(false);
789
790
  const prevCandleIntervalRef = useRef(null);
790
791
  const pingIntervalRef = useRef(null);
791
792
  const wsRef = useRef(null);
@@ -879,6 +880,7 @@ const useHyperliquidNativeWebSocket = ({ address, enabled = true, onUserFills, }
879
880
  };
880
881
  setAggregatedClearingHouseState(aggregatedClearingHouseState);
881
882
  setRawClearinghouseStates(data.clearinghouseStates || null);
883
+ setClearinghouseStateReceived(true);
882
884
  }
883
885
  break;
884
886
  case 'allMids':
@@ -1115,18 +1117,10 @@ const useHyperliquidNativeWebSocket = ({ address, enabled = true, onUserFills, }
1115
1117
  type: "allDexsAssetCtxs",
1116
1118
  },
1117
1119
  };
1118
- const subscribeUserFills = {
1119
- method: 'subscribe',
1120
- subscription: {
1121
- type: 'userFills',
1122
- user: userAddress,
1123
- },
1124
- };
1125
1120
  sendJsonMessage(subscribeWebData3);
1126
1121
  sendJsonMessage(subscribeAllDexsClearinghouseState);
1127
1122
  sendJsonMessage(subscribeAllMids);
1128
1123
  sendJsonMessage(subscribeAllDexsAssetCtxs);
1129
- sendJsonMessage(subscribeUserFills);
1130
1124
  // Subscribe to spotState for real-time spot balances (USDH, USDC, etc.)
1131
1125
  // Only subscribe if we have a real user address (not the default)
1132
1126
  if (userAddress !== DEFAULT_ADDRESS) {
@@ -1147,6 +1141,8 @@ const useHyperliquidNativeWebSocket = ({ address, enabled = true, onUserFills, }
1147
1141
  setRawClearinghouseStates(null);
1148
1142
  // clear spotState
1149
1143
  setSpotState(null);
1144
+ // reset clearinghouseStateReceived to wait for new data before subscribing to userFills
1145
+ setClearinghouseStateReceived(false);
1150
1146
  }
1151
1147
  }, [
1152
1148
  isConnected,
@@ -1157,6 +1153,19 @@ const useHyperliquidNativeWebSocket = ({ address, enabled = true, onUserFills, }
1157
1153
  setRawClearinghouseStates,
1158
1154
  setSpotState,
1159
1155
  ]);
1156
+ // Subscribe to userFills only after allDexsClearinghouseState data is received
1157
+ useEffect(() => {
1158
+ if (!isConnected || !subscribedAddress || !clearinghouseStateReceived)
1159
+ return;
1160
+ const subscribeUserFills = {
1161
+ method: 'subscribe',
1162
+ subscription: {
1163
+ type: 'userFills',
1164
+ user: subscribedAddress,
1165
+ },
1166
+ };
1167
+ sendJsonMessage(subscribeUserFills);
1168
+ }, [isConnected, subscribedAddress, clearinghouseStateReceived, sendJsonMessage]);
1160
1169
  // Handle token subscriptions for activeAssetData
1161
1170
  useEffect(() => {
1162
1171
  if (!isConnected || !address)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pear-protocol/hyperliquid-sdk",
3
- "version": "0.0.75",
3
+ "version": "0.0.77",
4
4
  "description": "React SDK for Pear Protocol Hyperliquid API integration",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",