@orderly.network/hooks 0.0.8 → 0.0.10

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.js CHANGED
@@ -4,17 +4,16 @@ var React = require('react');
4
4
  var useSWR = require('swr');
5
5
  var net = require('@orderly.network/net');
6
6
  var useSWRMutation = require('swr/mutation');
7
- var core = require('@orderly.network/core');
8
7
  var useConstant = require('use-constant');
8
+ var core = require('@orderly.network/core');
9
9
  var rxjsHooks = require('rxjs-hooks');
10
10
  var types = require('@orderly.network/types');
11
11
  var rxjs = require('rxjs');
12
12
  var operators = require('rxjs/operators');
13
13
  var ramda = require('ramda');
14
+ var useSWRSubscription = require('swr/subscription');
14
15
  var utils = require('@orderly.network/utils');
15
- var formik = require('formik');
16
16
  var futures = require('@orderly.network/futures');
17
- var useSWRSubscription = require('swr/subscription');
18
17
  var useSWRInfinite = require('swr/infinite');
19
18
 
20
19
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
@@ -104,50 +103,81 @@ var useQuery = (query, options) => {
104
103
  swrOptions
105
104
  );
106
105
  };
106
+ var useAccountInstance = () => {
107
+ const { configStore, keyStore, walletAdapter } = React.useContext(OrderlyContext);
108
+ if (!configStore)
109
+ throw new Error("configStore is not defined, please use OrderlyProvider");
110
+ if (!keyStore) {
111
+ throw new Error(
112
+ "keyStore is not defined, please use OrderlyProvider and provide keyStore"
113
+ );
114
+ }
115
+ const account4 = useConstant__default.default(() => {
116
+ let account5 = core.SimpleDI.get("account");
117
+ if (!account5) {
118
+ account5 = new core.Account(configStore, keyStore, walletAdapter);
119
+ core.SimpleDI.registerByName("account", account5);
120
+ }
121
+ return account5;
122
+ });
123
+ return account4;
124
+ };
125
+
126
+ // src/useMutation.ts
107
127
  var fetcher2 = (url, options) => {
108
128
  return net.post(url, options.arg.data, {
109
- headers: __spreadProps(__spreadValues({}, options.arg.signature), {
110
- "orderly-account-id": "0x47ab075adca7dfe9dd206eb7c50a10f7b99f4f08fa6c3abd4c170d438e15093b"
111
- })
129
+ headers: __spreadValues({}, options.arg.signature)
130
+ });
131
+ };
132
+ var deleteFetcher = (url, options) => {
133
+ return net.del(url, options.arg.data, {
134
+ headers: __spreadValues({}, options.arg.signature)
112
135
  });
113
136
  };
114
- var useMutation = (url, options) => {
137
+ var useMutation = (url, options, method = "POST") => {
115
138
  const { apiBaseUrl } = React.useContext(OrderlyContext);
116
139
  if (!url.startsWith("http")) {
117
140
  url = `${apiBaseUrl}${url}`;
118
141
  }
119
- let account3 = core.SimpleDI.get("account");
120
- const signer = account3.signer;
142
+ const account4 = useAccountInstance();
143
+ const signer = account4.signer;
121
144
  const { trigger, data, error, reset, isMutating } = useSWRMutation__default.default(
122
145
  url,
123
- fetcher2,
146
+ method === "POST" ? fetcher2 : deleteFetcher,
124
147
  options
125
148
  );
126
149
  const mutation = (data2) => __async(void 0, null, function* () {
127
150
  const payload = {
128
- method: "POST",
151
+ method,
129
152
  url,
130
153
  data: data2
131
154
  };
132
155
  const signature = yield signer.sign(payload);
133
- return trigger({ data: data2, signature });
156
+ return trigger({
157
+ data: data2,
158
+ signature: __spreadProps(__spreadValues({}, signature), {
159
+ "orderly-account-id": account4.accountId
160
+ })
161
+ });
134
162
  });
135
- return {
163
+ return [
136
164
  mutation,
137
- data,
138
- error,
139
- reset,
140
- isMutating
141
- };
165
+ {
166
+ data,
167
+ error,
168
+ reset,
169
+ isMutating
170
+ }
171
+ ];
142
172
  };
143
173
  var signatureMiddleware = (useSWRNext) => {
144
174
  const { apiBaseUrl } = React.useContext(OrderlyContext);
145
175
  return (key, fetcher4, config) => {
146
176
  try {
147
177
  const extendedFetcher = (url) => __async(void 0, null, function* () {
148
- let account3 = core.SimpleDI.get("account");
178
+ let account4 = core.SimpleDI.get("account");
149
179
  let fullUrl = `${apiBaseUrl}${url}`;
150
- const signer = account3.signer;
180
+ const signer = account4.signer;
151
181
  const payload = {
152
182
  method: "GET",
153
183
  url: fullUrl
@@ -155,9 +185,7 @@ var signatureMiddleware = (useSWRNext) => {
155
185
  const signature = yield signer.sign(payload);
156
186
  return fetcher4(fullUrl, {
157
187
  headers: __spreadProps(__spreadValues({}, signature), {
158
- "orderly-account-id": account3.accountId
159
- // "orderly-account-id":
160
- // "0x47ab075adca7dfe9dd206eb7c50a10f7b99f4f08fa6c3abd4c170d438e15093b",
188
+ "orderly-account-id": account4.accountId
161
189
  })
162
190
  });
163
191
  });
@@ -169,7 +197,13 @@ var signatureMiddleware = (useSWRNext) => {
169
197
  };
170
198
  };
171
199
  var useAccount = () => {
172
- const { configStore, keyStore, walletAdapter } = React.useContext(OrderlyContext);
200
+ const {
201
+ configStore,
202
+ keyStore,
203
+ walletAdapter,
204
+ onWalletConnect,
205
+ onWalletDisconnect
206
+ } = React.useContext(OrderlyContext);
173
207
  if (!configStore)
174
208
  throw new Error("configStore is not defined, please use OrderlyProvider");
175
209
  if (!keyStore) {
@@ -177,39 +211,58 @@ var useAccount = () => {
177
211
  "keyStore is not defined, please use OrderlyProvider and provide keyStore"
178
212
  );
179
213
  }
180
- const account3 = useConstant__default.default(() => {
181
- let account4 = core.SimpleDI.get("account");
182
- if (!account4) {
183
- account4 = new core.Account(configStore, keyStore, walletAdapter);
184
- core.SimpleDI.registerByName("account", account4);
214
+ const account4 = useConstant__default.default(() => {
215
+ let account5 = core.SimpleDI.get("account");
216
+ if (!account5) {
217
+ account5 = new core.Account(configStore, keyStore, walletAdapter);
218
+ core.SimpleDI.registerByName("account", account5);
185
219
  }
186
- return account4;
220
+ return account5;
187
221
  });
188
222
  const state = rxjsHooks.useObservable(
189
- () => account3.state$,
190
- account3.stateValue
223
+ () => account4.state$,
224
+ account4.stateValue
191
225
  );
192
226
  const login = React.useCallback(
193
227
  (address) => {
194
- account3.login(address);
228
+ account4.login(address);
195
229
  },
196
- [account3]
230
+ [account4]
197
231
  );
232
+ const createOrderlyKey = React.useCallback(
233
+ (remember) => __async(void 0, null, function* () {
234
+ return account4.createOrderlyKey(remember ? 365 : 30);
235
+ }),
236
+ [account4]
237
+ );
238
+ const createAccount = React.useCallback(() => __async(void 0, null, function* () {
239
+ return account4.createAccount();
240
+ }), [account4]);
241
+ const connect = React.useCallback(() => __async(void 0, null, function* () {
242
+ return onWalletConnect == null ? void 0 : onWalletConnect();
243
+ }), [account4]);
244
+ const disconnect = React.useCallback(() => __async(void 0, null, function* () {
245
+ return onWalletDisconnect == null ? void 0 : onWalletDisconnect();
246
+ }), [account4]);
198
247
  return {
199
248
  // account: state!,
200
- account: account3,
249
+ account: account4,
201
250
  state,
202
251
  // info: {},
203
- login
252
+ login,
253
+ createOrderlyKey,
254
+ createAccount,
255
+ disconnect,
256
+ connect
204
257
  };
205
258
  };
206
259
  var usePrivateQuery = (query, options) => {
207
260
  var _b;
208
261
  const _a = options || {}, { formatter } = _a, swrOptions = __objRest(_a, ["formatter"]);
209
- const account3 = useAccount();
262
+ const account4 = useAccount();
210
263
  const middleware = Array.isArray(options == null ? void 0 : options.use) ? (_b = options == null ? void 0 : options.use) != null ? _b : [] : [];
211
264
  return useSWR__default.default(
212
- () => account3.state.status >= types.AccountStatusEnum.SignedIn ? query : null,
265
+ () => account4.state.status >= types.AccountStatusEnum.EnableTrading ? query : null,
213
266
  // query,
214
267
  (url, init) => {
215
268
  return fetcher(url, init, { formatter });
@@ -296,7 +349,7 @@ var useWebSocketClient = () => {
296
349
  let websocketClient = core.SimpleDI.get(WS_NAME);
297
350
  if (!websocketClient) {
298
351
  websocketClient = new net.WebSocketClient({
299
- accountId: "0x47ab075adca7dfe9dd206eb7c50a10f7b99f4f08fa6c3abd4c170d438e15093b",
352
+ accountId: "OqdphuyCtYWxwzhxyLLjOWNdFP7sQt8RPWzmb5xY",
300
353
  networkId: "testnet",
301
354
  onSigntureRequest: (accountId) => __async(void 0, null, function* () {
302
355
  const signer = core.getMockSigner();
@@ -311,28 +364,6 @@ var useWebSocketClient = () => {
311
364
  });
312
365
  return ws;
313
366
  };
314
- var useAccountInstance = () => {
315
- const { configStore, keyStore } = React.useContext(OrderlyContext);
316
- if (!configStore)
317
- throw new Error("configStore is not defined, please use OrderlyProvider");
318
- if (!keyStore) {
319
- throw new Error(
320
- "keyStore is not defined, please use OrderlyProvider and provide keyStore"
321
- );
322
- }
323
- const account3 = useConstant__default.default(() => {
324
- let account4 = core.SimpleDI.get("account");
325
- if (!account4) {
326
- account4 = new core.Account(configStore, keyStore);
327
- core.SimpleDI.registerByName("account", account4);
328
- }
329
- return account4;
330
- });
331
- console.log("account instance ======>>>>>", account3);
332
- return account3;
333
- };
334
-
335
- // src/provider/dataProvider.tsx
336
367
  var DataSourceContext = React.createContext({});
337
368
  var DataSourceProvider = (props) => {
338
369
  console.log("render DataSourceProvider");
@@ -345,12 +376,13 @@ var WS_NAME2 = "nativeWebsocketClient";
345
376
  var useWS = () => {
346
377
  const ws = useConstant__default.default(() => {
347
378
  let websocketClient = core.SimpleDI.get(WS_NAME2);
379
+ const account4 = core.SimpleDI.get(core.Account.instanceName);
348
380
  if (!websocketClient) {
349
381
  websocketClient = new net.WS({
350
- accountId: "0x47ab075adca7dfe9dd206eb7c50a10f7b99f4f08fa6c3abd4c170d438e15093b",
382
+ // accountId: "OqdphuyCtYWxwzhxyLLjOWNdFP7sQt8RPWzmb5xY",
351
383
  networkId: "testnet",
352
384
  onSigntureRequest: (accountId) => __async(void 0, null, function* () {
353
- const signer = core.getMockSigner();
385
+ const signer = account4.signer;
354
386
  const timestamp = (/* @__PURE__ */ new Date()).getTime();
355
387
  const result = yield signer.signText(timestamp.toString());
356
388
  return __spreadProps(__spreadValues({}, result), { timestamp });
@@ -367,34 +399,69 @@ var useTickerStream = (symbol) => {
367
399
  throw new Error("useFuturesForSymbol requires a symbol");
368
400
  }
369
401
  const { data: info } = useQuery(`/public/futures/${symbol}`);
370
- const ws = useWebSocketClient();
371
- const ticker = rxjsHooks.useObservable(
372
- (_, input$) => input$.pipe(
373
- operators.map(([config]) => config),
374
- operators.combineLatestWith(ws.observe(`${symbol}@ticker`).pipe(operators.startWith({}))),
375
- operators.map(([config, ticker2]) => {
376
- if (!config)
377
- return config;
378
- if (ticker2.close !== void 0) {
379
- config["24h_close"] = ticker2.close;
380
- }
381
- if (ticker2.open !== void 0) {
382
- config["24h_open"] = ticker2.open;
383
- }
384
- if (ticker2.volume !== void 0) {
385
- config["24h_volumn"] = ticker2.volume;
386
- }
387
- if (ticker2.close !== void 0 && ticker2.open !== void 0) {
388
- config["change"] = new utils.Decimal(ticker2.close).minus(ticker2.open).div(ticker2.open).toNumber();
402
+ const ws = useWS();
403
+ const { data: ticker } = useSWRSubscription__default.default(
404
+ `${symbol}@ticker`,
405
+ (key, { next }) => {
406
+ const unsubscribe = ws.subscribe(
407
+ // { event: "subscribe", topic: "markprices" },
408
+ `${symbol}@ticker`,
409
+ {
410
+ onMessage: (message) => {
411
+ next(null, message);
412
+ }
413
+ // onUnsubscribe: () => {
414
+ // return "markprices";
415
+ // },
416
+ // onError: (error: any) => {
417
+ // console.log("error", error);
418
+ // },
389
419
  }
390
- return config;
391
- })
392
- ),
393
- null,
394
- [info]
420
+ );
421
+ return () => {
422
+ console.log("unsubscribe!!!!!!!");
423
+ unsubscribe == null ? void 0 : unsubscribe();
424
+ };
425
+ }
395
426
  );
396
- return ticker;
427
+ const value = React.useMemo(() => {
428
+ if (!info)
429
+ return null;
430
+ if (!ticker)
431
+ return info;
432
+ const config = __spreadValues({}, info);
433
+ if (ticker.close !== void 0) {
434
+ config["24h_close"] = ticker.close;
435
+ }
436
+ if (ticker.open !== void 0) {
437
+ config["24h_open"] = ticker.open;
438
+ }
439
+ if (ticker.volume !== void 0) {
440
+ config["24h_volumn"] = ticker.volume;
441
+ }
442
+ if (ticker.close !== void 0 && ticker.open !== void 0) {
443
+ config["change"] = new utils.Decimal(ticker.close).minus(ticker.open).div(ticker.open).toNumber();
444
+ }
445
+ return config;
446
+ }, [info, ticker]);
447
+ return value;
448
+ };
449
+ var useMarkPrice = (symbol) => {
450
+ const ws = useWS();
451
+ return useSWRSubscription__default.default(`${symbol}@markprice`, (key, { next }) => {
452
+ const unsubscribe = ws.subscribe(`${symbol}@markprice`, {
453
+ onMessage: (message) => {
454
+ next(null, message.price);
455
+ }
456
+ });
457
+ return () => {
458
+ console.log("unsubscribe useMarkPrice !!!!!!!");
459
+ unsubscribe == null ? void 0 : unsubscribe();
460
+ };
461
+ });
397
462
  };
463
+
464
+ // src/orderly/useOrderbookStream.ts
398
465
  ramda.compose(ramda.defaultTo(0), ramda.head, ramda.last, ramda.pathOr([], ["asks"]));
399
466
  ramda.pathOr(0, ["bids", 0, 0]);
400
467
  var paddingFn = (len) => Array(len).fill([Number.NaN, Number.NaN, Number.NaN]);
@@ -407,7 +474,13 @@ var reduceItems = (depth, level, data) => {
407
474
  const result = [];
408
475
  for (let i = 0; i < data.length; i++) {
409
476
  const [price, quantity] = data[i];
410
- result.push([price, quantity, quantity + (i > 0 ? result[i - 1][2] : 0)]);
477
+ if (isNaN(price) || isNaN(quantity))
478
+ continue;
479
+ result.push([
480
+ price,
481
+ quantity,
482
+ quantity + (result.length > 0 ? result[result.length - 1][2] : 0)
483
+ ]);
411
484
  if (i + 1 >= level) {
412
485
  break;
413
486
  }
@@ -453,21 +526,22 @@ var mergeOrderbook = (data, update) => {
453
526
  bids: mergeItems(data.bids, update.bids).sort(bidsSortFn)
454
527
  };
455
528
  };
456
- var useOrderbook = (symbol, initial = { asks: [], bids: [] }, options) => {
529
+ var useOrderbookStream = (symbol, initial = { asks: [], bids: [] }, options) => {
457
530
  if (!symbol) {
458
- throw new Error("useOrderbook requires a symbol");
531
+ throw new Error("useOrderbookStream requires a symbol");
459
532
  }
533
+ const [requestData, setRequestData] = React.useState(null);
460
534
  const [data, setData] = React.useState(initial);
535
+ const [isLoading, setIsLoading] = React.useState(true);
461
536
  const [depth, setDepth] = React.useState(1e-3);
462
537
  const [level, setLevel] = React.useState(() => {
463
538
  var _a;
464
539
  return (_a = options == null ? void 0 : options.level) != null ? _a : 10;
465
540
  });
466
- const ws = useWebSocketClient();
467
- const orderbookSubscriberRef = React.useRef();
541
+ const ws = useWS();
468
542
  const ticker = useTickerStream(symbol);
469
- const orderbookRequest$ = React.useMemo(() => {
470
- return ws.observe(
543
+ React.useEffect(() => {
544
+ ws.onceSubscribe(
471
545
  {
472
546
  event: "request",
473
547
  params: {
@@ -475,66 +549,52 @@ var useOrderbook = (symbol, initial = { asks: [], bids: [] }, options) => {
475
549
  symbol
476
550
  }
477
551
  },
478
- void 0,
479
- (message) => message.event === "request"
480
- );
481
- }, [symbol]);
482
- const orderbookUpdate$ = React.useMemo(() => {
483
- return ws.observe(`${symbol}@orderbookupdate`, () => ({
484
- event: "subscribe",
485
- topic: `${symbol}@orderbookupdate`
486
- })).pipe(
487
- operators.startWith({ asks: [], bids: [] })
488
- // filter((message: any) => !!message.success)
552
+ {
553
+ onMessage: (message) => {
554
+ console.log("orderbook request message", message);
555
+ if (!!message) {
556
+ const reduceOrderbookData = reduceOrderbook(depth, level, message);
557
+ setRequestData(reduceOrderbookData);
558
+ setData(reduceOrderbookData);
559
+ }
560
+ setIsLoading(false);
561
+ }
562
+ }
489
563
  );
564
+ return () => {
565
+ setRequestData(null);
566
+ };
490
567
  }, [symbol]);
491
- const orderbookOptions$ = useConstant__default.default(() => {
492
- return new rxjs.BehaviorSubject({
493
- depth: 1e-3,
494
- level: 10
495
- });
496
- });
497
- const markPrice = rxjsHooks.useObservable(
498
- (_, input$) => input$.pipe(
499
- operators.debounceTime(200),
500
- operators.switchMap(([symbol2]) => {
501
- return ws.observe(`${symbol2}@markprice`).pipe(operators.map((data2) => data2.price));
502
- })
503
- ),
504
- 0,
505
- [symbol]
506
- );
568
+ const { data: markPrice } = useMarkPrice(symbol);
507
569
  React.useEffect(() => {
508
- if (orderbookSubscriberRef.current) {
509
- orderbookSubscriberRef.current.unsubscribe();
510
- }
511
- orderbookSubscriberRef.current = rxjs.merge(orderbookRequest$, orderbookUpdate$).pipe(
512
- // tap((data) => console.log(data)),
513
- operators.map(
514
- (data2) => ramda.pick(["asks", "bids"], data2)
515
- ),
516
- operators.scan((acc, curr) => {
517
- if (!acc.asks && !acc.bids) {
518
- return curr;
570
+ if (!requestData)
571
+ return;
572
+ const subscription = ws.subscribe(
573
+ {
574
+ event: "subscribe",
575
+ topic: `${symbol}@orderbookupdate`
576
+ },
577
+ {
578
+ onMessage: (message) => {
579
+ setData((data2) => {
580
+ const mergedData = !message.asks && !message.bids ? data2 : mergeOrderbook(data2, message);
581
+ const reducedData = reduceOrderbook(depth, level, mergedData);
582
+ return reducedData;
583
+ });
519
584
  }
520
- return mergeOrderbook(acc, curr);
521
- }),
522
- operators.map((data2) => reduceOrderbook(depth, level, data2))
523
- ).subscribe((data2) => {
524
- setData(data2);
525
- });
526
- }, [orderbookRequest$, orderbookUpdate$]);
585
+ }
586
+ );
587
+ return () => {
588
+ subscription == null ? void 0 : subscription();
589
+ };
590
+ }, [symbol, requestData]);
527
591
  const onDepthChange = React.useCallback((depth2) => {
528
592
  console.log("Orderbook depth has changed:", depth2);
529
- orderbookOptions$.next(__spreadProps(__spreadValues({}, orderbookOptions$.value), {
530
- depth: depth2
531
- // level,
532
- }));
533
593
  }, []);
534
594
  const middlePrice = React.useMemo(() => {
535
595
  let asksFrist = 0, bidsFirst = 0;
536
596
  if (data.asks.length > 0) {
537
- asksFrist = data.asks[data.bids.length - 1][0];
597
+ asksFrist = data.asks[data.asks.length - 1][0];
538
598
  }
539
599
  if (data.bids.length > 0) {
540
600
  bidsFirst = data.bids[0][0];
@@ -545,7 +605,7 @@ var useOrderbook = (symbol, initial = { asks: [], bids: [] }, options) => {
545
605
  }, [ticker, data]);
546
606
  return [
547
607
  __spreadProps(__spreadValues({}, data), { markPrice, middlePrice }),
548
- { onDepthChange, depth }
608
+ { onDepthChange, depth, isLoading }
549
609
  ];
550
610
  };
551
611
 
@@ -649,14 +709,15 @@ function orderEntityFormatHandle(baseTick, quoteTick) {
649
709
  }
650
710
  function priceInputHandle(inputs) {
651
711
  const [values, input, value, markPrice, config] = inputs;
712
+ console.log("priceInputHandle", inputs);
652
713
  if (value === "") {
653
714
  return [__spreadProps(__spreadValues({}, values), { total: "" }), input, value, markPrice, config];
654
715
  }
655
716
  const price = new utils.Decimal(value);
656
717
  const priceDP = price.dp();
718
+ console.log("priceInputHandle", priceDP, config.quoteDP);
657
719
  if (priceDP > config.quoteDP) {
658
- price.toDecimalPlaces(config.quoteDP);
659
- values.order_price = price.toNumber();
720
+ values.order_price = price.toDecimalPlaces(config.quoteDP).toString();
660
721
  }
661
722
  price.toDecimalPlaces(Math.min(priceDP, config.quoteDP));
662
723
  if (!values.order_quantity) {
@@ -664,9 +725,10 @@ function priceInputHandle(inputs) {
664
725
  }
665
726
  const total = price.mul(values.order_quantity);
666
727
  const quantityDP = total.dp();
667
- total.toDecimalPlaces(Math.min(quantityDP, config.baseDP));
668
728
  return [
669
- __spreadProps(__spreadValues({}, values), { total: total.toNumber() }),
729
+ __spreadProps(__spreadValues({}, values), {
730
+ total: total.toDecimalPlaces(Math.min(quantityDP, config.baseDP)).toString()
731
+ }),
670
732
  input,
671
733
  value,
672
734
  markPrice,
@@ -690,10 +752,9 @@ function quantityInputHandle(inputs) {
690
752
  }
691
753
  const total = quantity.mul(price);
692
754
  const totalDP = total.dp();
693
- total.todp(Math.min(config.quoteDP, totalDP));
694
755
  return [
695
756
  __spreadProps(__spreadValues({}, values), {
696
- total: total.toNumber()
757
+ total: total.todp(Math.min(config.quoteDP, totalDP)).toNumber()
697
758
  }),
698
759
  input,
699
760
  value,
@@ -769,25 +830,12 @@ var useFundingRates = () => {
769
830
  );
770
831
  return createGetter(data);
771
832
  };
772
- var useMarkPricesSubject = () => {
773
- const ws = useWebSocketClient();
774
- return useConstant__default.default(
775
- () => ws.observe("markprices").pipe(
776
- operators.map((data) => {
777
- const prices = {};
778
- data.forEach((item) => {
779
- prices[item.symbol] = item.price;
780
- });
781
- return prices;
782
- })
783
- )
784
- );
785
- };
786
833
  var useMarkPricesStream = () => {
787
834
  const ws = useWS();
788
835
  return useSWRSubscription__default.default("markPrices", (key, { next }) => {
789
- const unsubscribe = ws.subscription(
790
- { event: "subscribe", topic: "markprices" },
836
+ const unsubscribe = ws.subscribe(
837
+ // { event: "subscribe", topic: "markprices" },
838
+ "markprices",
791
839
  {
792
840
  onMessage: (message) => {
793
841
  const data = /* @__PURE__ */ Object.create(null);
@@ -797,9 +845,9 @@ var useMarkPricesStream = () => {
797
845
  }
798
846
  next(null, data);
799
847
  },
800
- onUnsubscribe: () => {
801
- return "markprices";
802
- },
848
+ // onUnsubscribe: () => {
849
+ // return "markprices";
850
+ // },
803
851
  onError: (error) => {
804
852
  console.log("error", error);
805
853
  }
@@ -807,36 +855,34 @@ var useMarkPricesStream = () => {
807
855
  );
808
856
  return () => {
809
857
  console.log("unsubscribe!!!!!!!");
810
- console.log("unsubscribe", unsubscribe);
811
858
  unsubscribe == null ? void 0 : unsubscribe();
812
859
  };
813
860
  });
814
861
  };
815
862
  var usePositionStream = (symbol, options) => {
816
- React.useState(false);
817
863
  const [visibledSymbol, setVisibleSymbol] = React.useState(
818
864
  symbol
819
865
  );
820
866
  const symbolInfo = useSymbolsInfo();
821
867
  const { data: accountInfo } = usePrivateQuery("/client/info");
822
- const { mutation } = useMutation("/order");
823
868
  const fundingRates = useFundingRates();
824
- useMarkPricesSubject();
825
- const { data, error, isLoading } = usePrivateQuery(
826
- `/positions`,
827
- __spreadProps(__spreadValues({}, options), {
828
- formatter: (data2) => data2,
829
- onError: (err) => {
830
- console.log("usePositionStream error", err);
831
- }
832
- })
833
- );
869
+ const { data, error } = usePrivateQuery(`/positions`, __spreadProps(__spreadValues({}, options), {
870
+ formatter: (data2) => data2,
871
+ onError: (err) => {
872
+ console.log("usePositionStream error", err);
873
+ }
874
+ }));
834
875
  const { data: markPrices } = useMarkPricesStream();
835
876
  const formatedPositions = React.useMemo(() => {
836
877
  if (!(data == null ? void 0 : data.rows) || !symbolInfo || !accountInfo)
837
878
  return null;
838
879
  let totalCollateral = 0;
839
- return data.rows.map((item) => {
880
+ const filteredData = typeof symbol === "undefined" || symbol === "" ? data.rows.filter((item) => {
881
+ return item.position_qty !== 0;
882
+ }) : data.rows.filter((item) => {
883
+ return item.symbol === symbol && item.position_qty !== 0;
884
+ });
885
+ return filteredData.map((item) => {
840
886
  const price = ramda.propOr(
841
887
  item.mark_price,
842
888
  item.symbol,
@@ -872,7 +918,7 @@ var usePositionStream = (symbol, options) => {
872
918
  })
873
919
  });
874
920
  });
875
- }, [data == null ? void 0 : data.rows, symbolInfo, accountInfo, markPrices]);
921
+ }, [data == null ? void 0 : data.rows, symbolInfo, accountInfo, markPrices, symbol]);
876
922
  const aggregatedData = React.useMemo(() => {
877
923
  const aggregatedData2 = {
878
924
  unsettledPnL: NaN,
@@ -900,18 +946,11 @@ var usePositionStream = (symbol, options) => {
900
946
  const showSymbol = React.useCallback((symbol2) => {
901
947
  setVisibleSymbol(symbol2);
902
948
  }, []);
903
- const onClosePosition = React.useCallback(
904
- (order2) => {
905
- return mutation(order2).finally(() => {
906
- });
907
- },
908
- []
909
- );
910
949
  return [
911
950
  { rows: formatedPositions, aggregated: aggregatedData },
912
951
  createGetter(data, 1),
913
952
  {
914
- close: onClosePosition,
953
+ // close: onClosePosition,
915
954
  loading: false,
916
955
  showSymbol,
917
956
  error,
@@ -926,7 +965,8 @@ var usePositionStream = (symbol, options) => {
926
965
  };
927
966
  var totalUnsettlementPnLPath = ramda.pathOr(0, [0, "aggregated", "unsettledPnL"]);
928
967
  var positionsPath = ramda.pathOr([], [0, "rows"]);
929
- var useCollateral = (dp = 6) => {
968
+ var useCollateral = (options = { dp: 6 }) => {
969
+ const { dp } = options;
930
970
  const positions2 = usePositionStream();
931
971
  const { data: orders } = usePrivateQuery(`/orders`);
932
972
  const { data: accountInfo } = usePrivateQuery("/client/info");
@@ -1080,7 +1120,7 @@ var BaseOrderCreator = class {
1080
1120
  baseOrder(data) {
1081
1121
  const order2 = {
1082
1122
  // symbol: data.symbol,
1083
- order_type: !!data.order_type_ext ? data.order_type_ext : data.order_type,
1123
+ order_type: data.order_type === types.OrderType.LIMIT ? !!data.order_type_ext ? data.order_type_ext : data.order_type : data.order_type,
1084
1124
  side: data.side,
1085
1125
  // reduce_only: data.reduce_only,
1086
1126
  order_quantity: data.order_quantity
@@ -1093,25 +1133,41 @@ var BaseOrderCreator = class {
1093
1133
  baseValidate(values, configs) {
1094
1134
  const errors = {};
1095
1135
  const { maxQty } = configs;
1136
+ console.log("baseValidate", values, configs);
1096
1137
  const { order_quantity, total } = values;
1097
1138
  if (!order_quantity) {
1098
- errors.order_quantity = "quantity is required";
1139
+ errors.order_quantity = {
1140
+ type: "required",
1141
+ message: "quantity is required"
1142
+ };
1099
1143
  } else {
1100
1144
  const { base_max, base_min } = configs.symbol;
1101
1145
  const qty = new utils.Decimal(order_quantity);
1102
1146
  if (qty.lt(base_min)) {
1103
- errors.order_quantity = `quantity must be greater than ${base_min}`;
1147
+ errors.order_quantity = {
1148
+ type: "min",
1149
+ message: `quantity must be greater than ${base_min}`
1150
+ };
1104
1151
  } else if (qty.gt(maxQty)) {
1105
- errors.order_quantity = `quantity must be less than ${base_max}`;
1152
+ errors.order_quantity = {
1153
+ type: "max",
1154
+ message: `quantity must be less than ${maxQty}`
1155
+ };
1106
1156
  }
1107
1157
  }
1108
1158
  if (!!total) {
1109
1159
  const { quote_max, quote_min } = configs.symbol;
1110
1160
  const totalNumber = new utils.Decimal(total);
1111
1161
  if (totalNumber.lt(quote_min)) {
1112
- errors.total = `Quantity should be greater than ${quote_min}`;
1162
+ errors.total = {
1163
+ type: "min",
1164
+ message: `Quantity should be greater or equal than ${quote_min}`
1165
+ };
1113
1166
  } else if (totalNumber.gt(quote_max)) {
1114
- errors.total = `Quantity should be less or equal than ${quote_max}`;
1167
+ errors.total = {
1168
+ type: "max",
1169
+ message: `Quantity should be less or equal than ${quote_max}`
1170
+ };
1115
1171
  }
1116
1172
  }
1117
1173
  return Promise.resolve(errors);
@@ -1127,7 +1183,10 @@ var LimitOrderCreator = class extends BaseOrderCreator {
1127
1183
  return this.baseValidate(values, config).then((errors) => {
1128
1184
  const { order_price } = values;
1129
1185
  if (!order_price) {
1130
- errors.order_price = "price is required";
1186
+ errors.order_price = {
1187
+ type: "required",
1188
+ message: "price is required"
1189
+ };
1131
1190
  } else {
1132
1191
  const price = new utils.Decimal(order_price);
1133
1192
  const { symbol } = config;
@@ -1135,9 +1194,15 @@ var LimitOrderCreator = class extends BaseOrderCreator {
1135
1194
  const maxPriceNumber = maxPrice(config.markPrice, price_range);
1136
1195
  const minPriceNumber = minPrice(config.markPrice, price_range);
1137
1196
  if (price.lt(minPriceNumber)) {
1138
- errors.order_price = `price must be greater than ${minPriceNumber}`;
1197
+ errors.order_price = {
1198
+ type: "min",
1199
+ message: `price must be greater than ${minPriceNumber}`
1200
+ };
1139
1201
  } else if (price.gt(maxPriceNumber)) {
1140
- errors.order_price = `price must be less than ${maxPriceNumber}`;
1202
+ errors.order_price = {
1203
+ type: "max",
1204
+ message: `price must be less than ${maxPriceNumber}`
1205
+ };
1141
1206
  }
1142
1207
  }
1143
1208
  return errors;
@@ -1146,7 +1211,9 @@ var LimitOrderCreator = class extends BaseOrderCreator {
1146
1211
  };
1147
1212
  var MarketOrderCreator = class extends BaseOrderCreator {
1148
1213
  create(values) {
1149
- return __spreadValues({}, this.baseOrder(values));
1214
+ const data = this.baseOrder(values);
1215
+ delete data["order_price"];
1216
+ return __spreadValues({}, data);
1150
1217
  }
1151
1218
  validate(values, configs) {
1152
1219
  return this.baseValidate(values, configs);
@@ -1170,8 +1237,8 @@ var GeneralOrderCreator = class extends BaseOrderCreator {
1170
1237
  }
1171
1238
  };
1172
1239
  var OrderFactory = class {
1173
- static create(type2) {
1174
- switch (type2) {
1240
+ static create(type) {
1241
+ switch (type) {
1175
1242
  case types.OrderType.LIMIT:
1176
1243
  return new LimitOrderCreator();
1177
1244
  case types.OrderType.MARKET:
@@ -1189,8 +1256,8 @@ var OrderFactory = class {
1189
1256
  };
1190
1257
 
1191
1258
  // src/orderly/useOrderEntry.ts
1192
- var useOrderEntry = (symbol, initialValue = {}, options) => {
1193
- const { mutation } = useMutation("/order");
1259
+ var useOrderEntry = (symbol, side, reduceOnly = false, options) => {
1260
+ const [mutation] = useMutation("/order");
1194
1261
  const { freeCollateral } = useCollateral();
1195
1262
  const symbolInfo = useSymbolsInfo();
1196
1263
  const tokenInfo = useTokenInfo();
@@ -1201,97 +1268,29 @@ var useOrderEntry = (symbol, initialValue = {}, options) => {
1201
1268
  const quoteDP = React.useMemo(() => {
1202
1269
  return tokenInfo.USDC("decimals", 0);
1203
1270
  }, [tokenInfo]);
1204
- const [valuesUpdate, [orderExtraValues]] = rxjsHooks.useEventCallback(
1205
- (event$, state$) => {
1206
- return event$.pipe(
1207
- operators.withLatestFrom(state$),
1208
- operators.map(([event, state]) => {
1209
- const { field, value } = event;
1210
- console.log("orderExtraValues", field, value);
1211
- return [__spreadProps(__spreadValues({}, state[0]), { [field]: value })];
1212
- })
1213
- );
1214
- },
1215
- [
1216
- {
1217
- order_type: types.OrderType.MARKET,
1218
- side: types.OrderSide.BUY,
1219
- reduce_only: false
1220
- }
1221
- ]
1222
- );
1223
- const ws = useWebSocketClient();
1224
- const markPrice = rxjsHooks.useObservable(
1225
- (_, input$) => input$.pipe(
1226
- operators.switchMap(([symbol2]) => {
1227
- return ws.observe(`${symbol2}@markprice`).pipe(
1228
- operators.map((data) => data.price)
1229
- // takeWhile(() => type === OrderType.MARKET)
1230
- );
1231
- })
1232
- ),
1233
- 0,
1234
- [symbol]
1235
- );
1236
- const formik$1 = formik.useFormik({
1237
- initialValues: __spreadValues({
1238
- // order_type: OrderType.MARKET,
1239
- // side: OrderSide.BUY,
1240
- order_quantity: "",
1241
- total: "",
1242
- order_price: "",
1243
- visible_quantity: 1
1244
- }, initialValue),
1245
- validate: (values) => {
1246
- const creator = OrderFactory.create(orderExtraValues.order_type);
1247
- return creator == null ? void 0 : creator.validate(values, {
1248
- symbol: symbolInfo[symbol](),
1249
- token: tokenInfo[symbol](),
1250
- maxQty,
1251
- markPrice
1252
- });
1253
- },
1254
- onSubmit: (values) => {
1255
- console.log(values);
1256
- }
1257
- });
1271
+ const { data: markPrice } = useMarkPrice(symbol);
1258
1272
  const maxQty = useMaxQty(
1259
1273
  symbol,
1260
- orderExtraValues.side,
1261
- orderExtraValues.reduce_only
1274
+ side,
1275
+ // orderExtraValues.reduce_only
1276
+ reduceOnly
1262
1277
  );
1263
- const formFieldds = React.useMemo(() => {
1264
- return ["order_quantity", "order_price", "total"];
1265
- }, []);
1266
- const setValue = (field, value) => {
1267
- if (formFieldds.indexOf(field) < 0) {
1268
- valuesUpdate({ field, value });
1269
- return;
1270
- }
1271
- const fieldHandler = getCalculateHandler(field);
1272
- const newValues = ramda.compose(
1273
- ramda.head,
1274
- orderEntityFormatHandle(),
1275
- fieldHandler,
1276
- baseInputHandle
1277
- )([
1278
- __spreadValues(__spreadValues({}, formik$1.values), orderExtraValues),
1279
- field,
1280
- value,
1281
- markPrice,
1282
- { baseDP, quoteDP }
1283
- ]);
1284
- formik$1.setValues(newValues, true);
1285
- };
1286
1278
  const onSubmit = (values) => {
1287
- values = values || formik$1.values;
1288
- if (typeof values.order_type === "undefined" || values.order_type !== types.OrderType.MARKET && values.order_type !== types.OrderType.LIMIT) {
1279
+ if (!values || typeof values.order_type === "undefined" || values.order_type !== types.OrderType.MARKET && values.order_type !== types.OrderType.LIMIT) {
1289
1280
  throw new Error("order_type is error");
1290
1281
  }
1291
- return Promise.resolve().then(() => {
1292
- const orderCreator = OrderFactory.create(
1293
- !!values.order_type_ext ? values.order_type_ext : values.order_type
1294
- );
1282
+ const orderCreator = OrderFactory.create(
1283
+ !!values.order_type_ext ? values.order_type_ext : values.order_type
1284
+ );
1285
+ if (!orderCreator) {
1286
+ return Promise.reject(new Error("orderCreator is null"));
1287
+ }
1288
+ return orderCreator == null ? void 0 : orderCreator.validate(values, {
1289
+ symbol: symbolInfo[symbol](),
1290
+ token: tokenInfo[symbol](),
1291
+ maxQty,
1292
+ markPrice
1293
+ }).then(() => {
1295
1294
  if (!orderCreator) {
1296
1295
  throw new Error("orderCreator is null");
1297
1296
  }
@@ -1299,31 +1298,43 @@ var useOrderEntry = (symbol, initialValue = {}, options) => {
1299
1298
  throw new Error("symbol is null");
1300
1299
  }
1301
1300
  const data = orderCreator.create(values);
1302
- console.log("orderentry data:::", data);
1303
- formik$1.setSubmitting(true);
1304
1301
  return mutation(__spreadProps(__spreadValues({}, data), {
1305
1302
  symbol
1306
- })).finally(() => {
1307
- formik$1.setSubmitting(false);
1308
- });
1303
+ }));
1304
+ });
1305
+ };
1306
+ const calculate = React.useCallback(
1307
+ (values, field, value) => {
1308
+ console.log("calculate", values, field, value, markPrice);
1309
+ const fieldHandler = getCalculateHandler(field);
1310
+ const newValues = ramda.compose(
1311
+ ramda.head,
1312
+ orderEntityFormatHandle(),
1313
+ fieldHandler,
1314
+ baseInputHandle
1315
+ )([values, field, value, markPrice, { baseDP, quoteDP }]);
1316
+ return newValues;
1317
+ },
1318
+ [markPrice]
1319
+ );
1320
+ const validator = (values) => {
1321
+ const creator = OrderFactory.create(values.order_type);
1322
+ return creator == null ? void 0 : creator.validate(values, {
1323
+ symbol: symbolInfo[symbol](),
1324
+ token: tokenInfo[symbol](),
1325
+ maxQty,
1326
+ markPrice
1309
1327
  });
1310
1328
  };
1311
- React.useEffect(() => {
1312
- formik$1.resetForm();
1313
- }, [symbol]);
1314
1329
  return {
1315
1330
  maxQty,
1316
- // formState,
1317
- values: __spreadValues(__spreadValues({}, formik$1.values), orderExtraValues),
1318
- errors: formik$1.errors,
1319
1331
  freeCollateral,
1320
1332
  markPrice,
1321
- setValue,
1322
1333
  onSubmit,
1323
- isSubmitting: formik$1.isSubmitting,
1324
- resetForm: formik$1.resetForm,
1325
- validateForm: formik$1.validateForm,
1326
- submitCount: formik$1.submitCount,
1334
+ helper: {
1335
+ calculate,
1336
+ validator
1337
+ },
1327
1338
  symbolConfig: symbolInfo[symbol]()
1328
1339
  };
1329
1340
  };
@@ -1366,35 +1377,49 @@ var useAccountInfo = () => {
1366
1377
  return usePrivateQuery("/client/info");
1367
1378
  };
1368
1379
  var useMarketsStream = () => {
1369
- const ws = useWebSocketClient();
1370
- const { data } = useQuery(`/public/futures`);
1371
- const value = rxjsHooks.useObservable(
1372
- (_, input$) => ws.observe("tickers").pipe(
1373
- operators.startWith([]),
1374
- operators.withLatestFrom(input$.pipe(operators.map((args) => args[0]))),
1375
- operators.map((args) => {
1376
- if (args[0].length === 0) {
1377
- return args[1];
1380
+ const ws = useWS();
1381
+ const { data: futures } = useQuery(`/public/futures`);
1382
+ const { data: tickers } = useSWRSubscription__default.default("tickers", (_, { next }) => {
1383
+ const unsubscribe = ws.subscribe(
1384
+ // { event: "subscribe", topic: "markprices" },
1385
+ "tickers",
1386
+ {
1387
+ onMessage: (message) => {
1388
+ next(null, message);
1378
1389
  }
1379
- return args[1].map((item) => {
1380
- const ticker = args[0].find(
1381
- (t) => t.symbol === item.symbol
1382
- );
1383
- if (ticker) {
1384
- return __spreadProps(__spreadValues({}, item), {
1385
- ["24h_close"]: ticker.close,
1386
- ["24h_open"]: ticker.open,
1387
- ["24h_volumn"]: ticker.volume,
1388
- change: 0
1389
- });
1390
- }
1391
- return item;
1390
+ // onUnsubscribe: () => {
1391
+ // return "markprices";
1392
+ // },
1393
+ // onError: (error: any) => {
1394
+ // console.log("error", error);
1395
+ // },
1396
+ }
1397
+ );
1398
+ return () => {
1399
+ console.log("unsubscribe!!!!!!!");
1400
+ unsubscribe == null ? void 0 : unsubscribe();
1401
+ };
1402
+ });
1403
+ const value = React.useMemo(() => {
1404
+ if (!futures)
1405
+ return null;
1406
+ if (!tickers)
1407
+ return futures;
1408
+ return futures.map((item) => {
1409
+ const ticker = tickers.find(
1410
+ (t) => t.symbol === item.symbol
1411
+ );
1412
+ if (ticker) {
1413
+ return __spreadProps(__spreadValues({}, item), {
1414
+ ["24h_close"]: ticker.close,
1415
+ ["24h_open"]: ticker.open,
1416
+ ["24h_volumn"]: ticker.volume,
1417
+ change: 0
1392
1418
  });
1393
- })
1394
- ),
1395
- null,
1396
- [data]
1397
- );
1419
+ }
1420
+ return item;
1421
+ });
1422
+ }, [futures, tickers]);
1398
1423
  return { data: value };
1399
1424
  };
1400
1425
  var useFundingRate = (symbol) => {
@@ -1435,10 +1460,10 @@ var useFundingRate = (symbol) => {
1435
1460
  var fetcher3 = (url, init) => net.get(url, init);
1436
1461
  var usePrivateInfiniteQuery = (getKey, options) => {
1437
1462
  var _a;
1438
- const account3 = useAccount();
1463
+ const account4 = useAccount();
1439
1464
  const middleware = Array.isArray(options == null ? void 0 : options.use) ? (_a = options == null ? void 0 : options.use) != null ? _a : [] : [];
1440
1465
  const result = useSWRInfinite__default.default(
1441
- (pageIndex, previousPageData) => account3.state.status >= types.AccountStatusEnum.SignedIn ? getKey(pageIndex, previousPageData) : null,
1466
+ (pageIndex, previousPageData) => account4.state.status >= types.AccountStatusEnum.EnableTrading ? getKey(pageIndex, previousPageData) : null,
1442
1467
  fetcher3,
1443
1468
  __spreadProps(__spreadValues({}, options), {
1444
1469
  use: [signatureMiddleware, ...middleware]
@@ -1483,7 +1508,6 @@ var useOrderStream = ({
1483
1508
  if (!res.data) {
1484
1509
  return null;
1485
1510
  }
1486
- console.log("orders:::", markPrices);
1487
1511
  return (_a = res.data) == null ? void 0 : _a.flat().map((item) => {
1488
1512
  var _a2;
1489
1513
  return __spreadProps(__spreadValues({}, item), {
@@ -1513,6 +1537,77 @@ var useOrderStream = ({
1513
1537
  ];
1514
1538
  };
1515
1539
 
1540
+ // src/orderly/useTradeStream.ts
1541
+ var useTradeStream = (symbol) => {
1542
+ if (!symbol) {
1543
+ throw new Error("useTradeStream: symbol is required");
1544
+ }
1545
+ const { data, isLoading } = useQuery(
1546
+ `/public/market_trades?symbol=${symbol}&limit=20`
1547
+ );
1548
+ return { data, isLoading };
1549
+ };
1550
+ var useMarginRatio = () => {
1551
+ const [{ rows }] = usePositionStream();
1552
+ const { data: markPrices } = useMarkPricesStream();
1553
+ const { totalCollateral } = useCollateral();
1554
+ const marginRatio = React.useMemo(() => {
1555
+ const ratio = futures.account.totalMarginRatio({
1556
+ totalCollateral,
1557
+ markPrices,
1558
+ positions: rows != null ? rows : []
1559
+ });
1560
+ return ratio;
1561
+ }, [rows, markPrices, totalCollateral]);
1562
+ return marginRatio;
1563
+ };
1564
+ var useChains = (networkId, options) => {
1565
+ const field = options == null ? void 0 : options.pick;
1566
+ const { data } = useSWR__default.default(
1567
+ "https://fi-api.woo.org/swap_support",
1568
+ (url) => fetch(url).then((res) => res.json()),
1569
+ {
1570
+ revalidateOnFocus: false,
1571
+ revalidateOnReconnect: false
1572
+ }
1573
+ );
1574
+ const chains = React.useMemo(() => {
1575
+ if (!data || !data.data)
1576
+ return data;
1577
+ let arr = [];
1578
+ Object.keys(data.data).forEach((key) => {
1579
+ const item = data.data[key];
1580
+ arr.push(__spreadProps(__spreadValues({}, item), {
1581
+ name: key
1582
+ }));
1583
+ });
1584
+ if (networkId === "mainnet") {
1585
+ arr = arr.filter((item) => item.network_infos.mainnet);
1586
+ }
1587
+ if (networkId === "testnet") {
1588
+ arr = arr.filter((item) => !item.network_infos.mainnet);
1589
+ }
1590
+ if (typeof (options == null ? void 0 : options.filter) === "function") {
1591
+ arr = arr.filter(options.filter);
1592
+ }
1593
+ if (typeof field !== "undefined") {
1594
+ return arr.map((item) => {
1595
+ return item[field];
1596
+ });
1597
+ }
1598
+ return arr;
1599
+ }, [data, networkId, field, options]);
1600
+ const findByChainId = React.useCallback(
1601
+ (chainId) => {
1602
+ if (!data || !data.data)
1603
+ return void 0;
1604
+ return data.data[chainId];
1605
+ },
1606
+ [data]
1607
+ );
1608
+ return [chains, { findByChainId }];
1609
+ };
1610
+
1516
1611
  // src/apis/index.ts
1517
1612
  var apis_exports = {};
1518
1613
  __export(apis_exports, {
@@ -1571,16 +1666,19 @@ exports.apis = apis_exports;
1571
1666
  exports.useAccount = useAccount;
1572
1667
  exports.useAccountInfo = useAccountInfo;
1573
1668
  exports.useAppState = useAppState;
1669
+ exports.useChains = useChains;
1574
1670
  exports.useCollateral = useCollateral;
1575
1671
  exports.useFetures = useFetures;
1576
1672
  exports.useFundingRate = useFundingRate;
1673
+ exports.useMarginRatio = useMarginRatio;
1674
+ exports.useMarkPrice = useMarkPrice;
1577
1675
  exports.useMarkPricesStream = useMarkPricesStream;
1578
1676
  exports.useMarketsStream = useMarketsStream;
1579
1677
  exports.useMaxQty = useMaxQty;
1580
1678
  exports.useMutation = useMutation;
1581
1679
  exports.useOrderEntry = useOrderEntry;
1582
1680
  exports.useOrderStream = useOrderStream;
1583
- exports.useOrderbook = useOrderbook;
1681
+ exports.useOrderbookStream = useOrderbookStream;
1584
1682
  exports.usePositionStream = usePositionStream;
1585
1683
  exports.usePrivateObserve = usePrivateObserve;
1586
1684
  exports.usePrivateQuery = usePrivateQuery;
@@ -1589,6 +1687,7 @@ exports.useSymbolsInfo = useSymbolsInfo;
1589
1687
  exports.useTickerStream = useTickerStream;
1590
1688
  exports.useTokenInfo = useTokenInfo;
1591
1689
  exports.useTopicObserve = useTopicObserve;
1690
+ exports.useTradeStream = useTradeStream;
1592
1691
  exports.useTradingView = useTradingView;
1593
1692
  exports.useWS = useWS;
1594
1693
  exports.useWebSocketClient = useWebSocketClient;