@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.mjs CHANGED
@@ -1,21 +1,20 @@
1
- import React, { createContext, useContext, useCallback, useState, useEffect, useRef, useMemo } from 'react';
1
+ import React, { createContext, useContext, useCallback, useState, useEffect, useMemo } from 'react';
2
2
  import useSWR from 'swr';
3
3
  export { default as useSWR } from 'swr';
4
- import { WebSocketClient, WS, get, post } from '@orderly.network/net';
4
+ import { WebSocketClient, WS, get, post, del } from '@orderly.network/net';
5
5
  import useSWRMutation from 'swr/mutation';
6
- import { SimpleDI, Account, getMockSigner } from '@orderly.network/core';
7
6
  import useConstant from 'use-constant';
8
7
  export { default as useConstant } from 'use-constant';
9
- import { useObservable, useEventCallback } from 'rxjs-hooks';
8
+ import { SimpleDI, Account, getMockSigner } from '@orderly.network/core';
9
+ import { useObservable } from 'rxjs-hooks';
10
10
  export { useEventCallback, useObservable } from 'rxjs-hooks';
11
11
  import { AccountStatusEnum, SystemStateEnum, ExchangeStatusEnum, OrderSide, OrderType } from '@orderly.network/types';
12
12
  import { BehaviorSubject, merge } from 'rxjs';
13
- import { map, combineLatestWith, startWith, debounceTime, switchMap, scan, withLatestFrom } from 'rxjs/operators';
14
- import { compose, defaultTo, head, last, pathOr, pick, propOr } from 'ramda';
13
+ import { map } from 'rxjs/operators';
14
+ import { compose, defaultTo, head, last, pathOr, propOr } from 'ramda';
15
+ import useSWRSubscription from 'swr/subscription';
15
16
  import { Decimal, zero, getPrecisionByNumber, timeConvertString } from '@orderly.network/utils';
16
- import { useFormik } from 'formik';
17
17
  import { positions, account, order } from '@orderly.network/futures';
18
- import useSWRSubscription from 'swr/subscription';
19
18
  import useSWRInfinite from 'swr/infinite';
20
19
 
21
20
  var __defProp = Object.defineProperty;
@@ -96,50 +95,81 @@ var useQuery = (query, options) => {
96
95
  swrOptions
97
96
  );
98
97
  };
98
+ var useAccountInstance = () => {
99
+ const { configStore, keyStore, walletAdapter } = useContext(OrderlyContext);
100
+ if (!configStore)
101
+ throw new Error("configStore is not defined, please use OrderlyProvider");
102
+ if (!keyStore) {
103
+ throw new Error(
104
+ "keyStore is not defined, please use OrderlyProvider and provide keyStore"
105
+ );
106
+ }
107
+ const account4 = useConstant(() => {
108
+ let account5 = SimpleDI.get("account");
109
+ if (!account5) {
110
+ account5 = new Account(configStore, keyStore, walletAdapter);
111
+ SimpleDI.registerByName("account", account5);
112
+ }
113
+ return account5;
114
+ });
115
+ return account4;
116
+ };
117
+
118
+ // src/useMutation.ts
99
119
  var fetcher2 = (url, options) => {
100
120
  return post(url, options.arg.data, {
101
- headers: __spreadProps(__spreadValues({}, options.arg.signature), {
102
- "orderly-account-id": "0x47ab075adca7dfe9dd206eb7c50a10f7b99f4f08fa6c3abd4c170d438e15093b"
103
- })
121
+ headers: __spreadValues({}, options.arg.signature)
122
+ });
123
+ };
124
+ var deleteFetcher = (url, options) => {
125
+ return del(url, options.arg.data, {
126
+ headers: __spreadValues({}, options.arg.signature)
104
127
  });
105
128
  };
106
- var useMutation = (url, options) => {
129
+ var useMutation = (url, options, method = "POST") => {
107
130
  const { apiBaseUrl } = useContext(OrderlyContext);
108
131
  if (!url.startsWith("http")) {
109
132
  url = `${apiBaseUrl}${url}`;
110
133
  }
111
- let account3 = SimpleDI.get("account");
112
- const signer = account3.signer;
134
+ const account4 = useAccountInstance();
135
+ const signer = account4.signer;
113
136
  const { trigger, data, error, reset, isMutating } = useSWRMutation(
114
137
  url,
115
- fetcher2,
138
+ method === "POST" ? fetcher2 : deleteFetcher,
116
139
  options
117
140
  );
118
141
  const mutation = (data2) => __async(void 0, null, function* () {
119
142
  const payload = {
120
- method: "POST",
143
+ method,
121
144
  url,
122
145
  data: data2
123
146
  };
124
147
  const signature = yield signer.sign(payload);
125
- return trigger({ data: data2, signature });
148
+ return trigger({
149
+ data: data2,
150
+ signature: __spreadProps(__spreadValues({}, signature), {
151
+ "orderly-account-id": account4.accountId
152
+ })
153
+ });
126
154
  });
127
- return {
155
+ return [
128
156
  mutation,
129
- data,
130
- error,
131
- reset,
132
- isMutating
133
- };
157
+ {
158
+ data,
159
+ error,
160
+ reset,
161
+ isMutating
162
+ }
163
+ ];
134
164
  };
135
165
  var signatureMiddleware = (useSWRNext) => {
136
166
  const { apiBaseUrl } = useContext(OrderlyContext);
137
167
  return (key, fetcher4, config) => {
138
168
  try {
139
169
  const extendedFetcher = (url) => __async(void 0, null, function* () {
140
- let account3 = SimpleDI.get("account");
170
+ let account4 = SimpleDI.get("account");
141
171
  let fullUrl = `${apiBaseUrl}${url}`;
142
- const signer = account3.signer;
172
+ const signer = account4.signer;
143
173
  const payload = {
144
174
  method: "GET",
145
175
  url: fullUrl
@@ -147,9 +177,7 @@ var signatureMiddleware = (useSWRNext) => {
147
177
  const signature = yield signer.sign(payload);
148
178
  return fetcher4(fullUrl, {
149
179
  headers: __spreadProps(__spreadValues({}, signature), {
150
- "orderly-account-id": account3.accountId
151
- // "orderly-account-id":
152
- // "0x47ab075adca7dfe9dd206eb7c50a10f7b99f4f08fa6c3abd4c170d438e15093b",
180
+ "orderly-account-id": account4.accountId
153
181
  })
154
182
  });
155
183
  });
@@ -161,7 +189,13 @@ var signatureMiddleware = (useSWRNext) => {
161
189
  };
162
190
  };
163
191
  var useAccount = () => {
164
- const { configStore, keyStore, walletAdapter } = useContext(OrderlyContext);
192
+ const {
193
+ configStore,
194
+ keyStore,
195
+ walletAdapter,
196
+ onWalletConnect,
197
+ onWalletDisconnect
198
+ } = useContext(OrderlyContext);
165
199
  if (!configStore)
166
200
  throw new Error("configStore is not defined, please use OrderlyProvider");
167
201
  if (!keyStore) {
@@ -169,39 +203,58 @@ var useAccount = () => {
169
203
  "keyStore is not defined, please use OrderlyProvider and provide keyStore"
170
204
  );
171
205
  }
172
- const account3 = useConstant(() => {
173
- let account4 = SimpleDI.get("account");
174
- if (!account4) {
175
- account4 = new Account(configStore, keyStore, walletAdapter);
176
- SimpleDI.registerByName("account", account4);
206
+ const account4 = useConstant(() => {
207
+ let account5 = SimpleDI.get("account");
208
+ if (!account5) {
209
+ account5 = new Account(configStore, keyStore, walletAdapter);
210
+ SimpleDI.registerByName("account", account5);
177
211
  }
178
- return account4;
212
+ return account5;
179
213
  });
180
214
  const state = useObservable(
181
- () => account3.state$,
182
- account3.stateValue
215
+ () => account4.state$,
216
+ account4.stateValue
183
217
  );
184
218
  const login = useCallback(
185
219
  (address) => {
186
- account3.login(address);
220
+ account4.login(address);
187
221
  },
188
- [account3]
222
+ [account4]
189
223
  );
224
+ const createOrderlyKey = useCallback(
225
+ (remember) => __async(void 0, null, function* () {
226
+ return account4.createOrderlyKey(remember ? 365 : 30);
227
+ }),
228
+ [account4]
229
+ );
230
+ const createAccount = useCallback(() => __async(void 0, null, function* () {
231
+ return account4.createAccount();
232
+ }), [account4]);
233
+ const connect = useCallback(() => __async(void 0, null, function* () {
234
+ return onWalletConnect == null ? void 0 : onWalletConnect();
235
+ }), [account4]);
236
+ const disconnect = useCallback(() => __async(void 0, null, function* () {
237
+ return onWalletDisconnect == null ? void 0 : onWalletDisconnect();
238
+ }), [account4]);
190
239
  return {
191
240
  // account: state!,
192
- account: account3,
241
+ account: account4,
193
242
  state,
194
243
  // info: {},
195
- login
244
+ login,
245
+ createOrderlyKey,
246
+ createAccount,
247
+ disconnect,
248
+ connect
196
249
  };
197
250
  };
198
251
  var usePrivateQuery = (query, options) => {
199
252
  var _b;
200
253
  const _a = options || {}, { formatter } = _a, swrOptions = __objRest(_a, ["formatter"]);
201
- const account3 = useAccount();
254
+ const account4 = useAccount();
202
255
  const middleware = Array.isArray(options == null ? void 0 : options.use) ? (_b = options == null ? void 0 : options.use) != null ? _b : [] : [];
203
256
  return useSWR(
204
- () => account3.state.status >= AccountStatusEnum.SignedIn ? query : null,
257
+ () => account4.state.status >= AccountStatusEnum.EnableTrading ? query : null,
205
258
  // query,
206
259
  (url, init) => {
207
260
  return fetcher(url, init, { formatter });
@@ -288,7 +341,7 @@ var useWebSocketClient = () => {
288
341
  let websocketClient = SimpleDI.get(WS_NAME);
289
342
  if (!websocketClient) {
290
343
  websocketClient = new WebSocketClient({
291
- accountId: "0x47ab075adca7dfe9dd206eb7c50a10f7b99f4f08fa6c3abd4c170d438e15093b",
344
+ accountId: "OqdphuyCtYWxwzhxyLLjOWNdFP7sQt8RPWzmb5xY",
292
345
  networkId: "testnet",
293
346
  onSigntureRequest: (accountId) => __async(void 0, null, function* () {
294
347
  const signer = getMockSigner();
@@ -303,28 +356,6 @@ var useWebSocketClient = () => {
303
356
  });
304
357
  return ws;
305
358
  };
306
- var useAccountInstance = () => {
307
- const { configStore, keyStore } = useContext(OrderlyContext);
308
- if (!configStore)
309
- throw new Error("configStore is not defined, please use OrderlyProvider");
310
- if (!keyStore) {
311
- throw new Error(
312
- "keyStore is not defined, please use OrderlyProvider and provide keyStore"
313
- );
314
- }
315
- const account3 = useConstant(() => {
316
- let account4 = SimpleDI.get("account");
317
- if (!account4) {
318
- account4 = new Account(configStore, keyStore);
319
- SimpleDI.registerByName("account", account4);
320
- }
321
- return account4;
322
- });
323
- console.log("account instance ======>>>>>", account3);
324
- return account3;
325
- };
326
-
327
- // src/provider/dataProvider.tsx
328
359
  var DataSourceContext = createContext({});
329
360
  var DataSourceProvider = (props) => {
330
361
  console.log("render DataSourceProvider");
@@ -337,12 +368,13 @@ var WS_NAME2 = "nativeWebsocketClient";
337
368
  var useWS = () => {
338
369
  const ws = useConstant(() => {
339
370
  let websocketClient = SimpleDI.get(WS_NAME2);
371
+ const account4 = SimpleDI.get(Account.instanceName);
340
372
  if (!websocketClient) {
341
373
  websocketClient = new WS({
342
- accountId: "0x47ab075adca7dfe9dd206eb7c50a10f7b99f4f08fa6c3abd4c170d438e15093b",
374
+ // accountId: "OqdphuyCtYWxwzhxyLLjOWNdFP7sQt8RPWzmb5xY",
343
375
  networkId: "testnet",
344
376
  onSigntureRequest: (accountId) => __async(void 0, null, function* () {
345
- const signer = getMockSigner();
377
+ const signer = account4.signer;
346
378
  const timestamp = (/* @__PURE__ */ new Date()).getTime();
347
379
  const result = yield signer.signText(timestamp.toString());
348
380
  return __spreadProps(__spreadValues({}, result), { timestamp });
@@ -359,34 +391,69 @@ var useTickerStream = (symbol) => {
359
391
  throw new Error("useFuturesForSymbol requires a symbol");
360
392
  }
361
393
  const { data: info } = useQuery(`/public/futures/${symbol}`);
362
- const ws = useWebSocketClient();
363
- const ticker = useObservable(
364
- (_, input$) => input$.pipe(
365
- map(([config]) => config),
366
- combineLatestWith(ws.observe(`${symbol}@ticker`).pipe(startWith({}))),
367
- map(([config, ticker2]) => {
368
- if (!config)
369
- return config;
370
- if (ticker2.close !== void 0) {
371
- config["24h_close"] = ticker2.close;
372
- }
373
- if (ticker2.open !== void 0) {
374
- config["24h_open"] = ticker2.open;
375
- }
376
- if (ticker2.volume !== void 0) {
377
- config["24h_volumn"] = ticker2.volume;
378
- }
379
- if (ticker2.close !== void 0 && ticker2.open !== void 0) {
380
- config["change"] = new Decimal(ticker2.close).minus(ticker2.open).div(ticker2.open).toNumber();
394
+ const ws = useWS();
395
+ const { data: ticker } = useSWRSubscription(
396
+ `${symbol}@ticker`,
397
+ (key, { next }) => {
398
+ const unsubscribe = ws.subscribe(
399
+ // { event: "subscribe", topic: "markprices" },
400
+ `${symbol}@ticker`,
401
+ {
402
+ onMessage: (message) => {
403
+ next(null, message);
404
+ }
405
+ // onUnsubscribe: () => {
406
+ // return "markprices";
407
+ // },
408
+ // onError: (error: any) => {
409
+ // console.log("error", error);
410
+ // },
381
411
  }
382
- return config;
383
- })
384
- ),
385
- null,
386
- [info]
412
+ );
413
+ return () => {
414
+ console.log("unsubscribe!!!!!!!");
415
+ unsubscribe == null ? void 0 : unsubscribe();
416
+ };
417
+ }
387
418
  );
388
- return ticker;
419
+ const value = useMemo(() => {
420
+ if (!info)
421
+ return null;
422
+ if (!ticker)
423
+ return info;
424
+ const config = __spreadValues({}, info);
425
+ if (ticker.close !== void 0) {
426
+ config["24h_close"] = ticker.close;
427
+ }
428
+ if (ticker.open !== void 0) {
429
+ config["24h_open"] = ticker.open;
430
+ }
431
+ if (ticker.volume !== void 0) {
432
+ config["24h_volumn"] = ticker.volume;
433
+ }
434
+ if (ticker.close !== void 0 && ticker.open !== void 0) {
435
+ config["change"] = new Decimal(ticker.close).minus(ticker.open).div(ticker.open).toNumber();
436
+ }
437
+ return config;
438
+ }, [info, ticker]);
439
+ return value;
440
+ };
441
+ var useMarkPrice = (symbol) => {
442
+ const ws = useWS();
443
+ return useSWRSubscription(`${symbol}@markprice`, (key, { next }) => {
444
+ const unsubscribe = ws.subscribe(`${symbol}@markprice`, {
445
+ onMessage: (message) => {
446
+ next(null, message.price);
447
+ }
448
+ });
449
+ return () => {
450
+ console.log("unsubscribe useMarkPrice !!!!!!!");
451
+ unsubscribe == null ? void 0 : unsubscribe();
452
+ };
453
+ });
389
454
  };
455
+
456
+ // src/orderly/useOrderbookStream.ts
390
457
  compose(defaultTo(0), head, last, pathOr([], ["asks"]));
391
458
  pathOr(0, ["bids", 0, 0]);
392
459
  var paddingFn = (len) => Array(len).fill([Number.NaN, Number.NaN, Number.NaN]);
@@ -399,7 +466,13 @@ var reduceItems = (depth, level, data) => {
399
466
  const result = [];
400
467
  for (let i = 0; i < data.length; i++) {
401
468
  const [price, quantity] = data[i];
402
- result.push([price, quantity, quantity + (i > 0 ? result[i - 1][2] : 0)]);
469
+ if (isNaN(price) || isNaN(quantity))
470
+ continue;
471
+ result.push([
472
+ price,
473
+ quantity,
474
+ quantity + (result.length > 0 ? result[result.length - 1][2] : 0)
475
+ ]);
403
476
  if (i + 1 >= level) {
404
477
  break;
405
478
  }
@@ -445,21 +518,22 @@ var mergeOrderbook = (data, update) => {
445
518
  bids: mergeItems(data.bids, update.bids).sort(bidsSortFn)
446
519
  };
447
520
  };
448
- var useOrderbook = (symbol, initial = { asks: [], bids: [] }, options) => {
521
+ var useOrderbookStream = (symbol, initial = { asks: [], bids: [] }, options) => {
449
522
  if (!symbol) {
450
- throw new Error("useOrderbook requires a symbol");
523
+ throw new Error("useOrderbookStream requires a symbol");
451
524
  }
525
+ const [requestData, setRequestData] = useState(null);
452
526
  const [data, setData] = useState(initial);
527
+ const [isLoading, setIsLoading] = useState(true);
453
528
  const [depth, setDepth] = useState(1e-3);
454
529
  const [level, setLevel] = useState(() => {
455
530
  var _a;
456
531
  return (_a = options == null ? void 0 : options.level) != null ? _a : 10;
457
532
  });
458
- const ws = useWebSocketClient();
459
- const orderbookSubscriberRef = useRef();
533
+ const ws = useWS();
460
534
  const ticker = useTickerStream(symbol);
461
- const orderbookRequest$ = useMemo(() => {
462
- return ws.observe(
535
+ useEffect(() => {
536
+ ws.onceSubscribe(
463
537
  {
464
538
  event: "request",
465
539
  params: {
@@ -467,66 +541,52 @@ var useOrderbook = (symbol, initial = { asks: [], bids: [] }, options) => {
467
541
  symbol
468
542
  }
469
543
  },
470
- void 0,
471
- (message) => message.event === "request"
472
- );
473
- }, [symbol]);
474
- const orderbookUpdate$ = useMemo(() => {
475
- return ws.observe(`${symbol}@orderbookupdate`, () => ({
476
- event: "subscribe",
477
- topic: `${symbol}@orderbookupdate`
478
- })).pipe(
479
- startWith({ asks: [], bids: [] })
480
- // filter((message: any) => !!message.success)
544
+ {
545
+ onMessage: (message) => {
546
+ console.log("orderbook request message", message);
547
+ if (!!message) {
548
+ const reduceOrderbookData = reduceOrderbook(depth, level, message);
549
+ setRequestData(reduceOrderbookData);
550
+ setData(reduceOrderbookData);
551
+ }
552
+ setIsLoading(false);
553
+ }
554
+ }
481
555
  );
556
+ return () => {
557
+ setRequestData(null);
558
+ };
482
559
  }, [symbol]);
483
- const orderbookOptions$ = useConstant(() => {
484
- return new BehaviorSubject({
485
- depth: 1e-3,
486
- level: 10
487
- });
488
- });
489
- const markPrice = useObservable(
490
- (_, input$) => input$.pipe(
491
- debounceTime(200),
492
- switchMap(([symbol2]) => {
493
- return ws.observe(`${symbol2}@markprice`).pipe(map((data2) => data2.price));
494
- })
495
- ),
496
- 0,
497
- [symbol]
498
- );
560
+ const { data: markPrice } = useMarkPrice(symbol);
499
561
  useEffect(() => {
500
- if (orderbookSubscriberRef.current) {
501
- orderbookSubscriberRef.current.unsubscribe();
502
- }
503
- orderbookSubscriberRef.current = merge(orderbookRequest$, orderbookUpdate$).pipe(
504
- // tap((data) => console.log(data)),
505
- map(
506
- (data2) => pick(["asks", "bids"], data2)
507
- ),
508
- scan((acc, curr) => {
509
- if (!acc.asks && !acc.bids) {
510
- return curr;
562
+ if (!requestData)
563
+ return;
564
+ const subscription = ws.subscribe(
565
+ {
566
+ event: "subscribe",
567
+ topic: `${symbol}@orderbookupdate`
568
+ },
569
+ {
570
+ onMessage: (message) => {
571
+ setData((data2) => {
572
+ const mergedData = !message.asks && !message.bids ? data2 : mergeOrderbook(data2, message);
573
+ const reducedData = reduceOrderbook(depth, level, mergedData);
574
+ return reducedData;
575
+ });
511
576
  }
512
- return mergeOrderbook(acc, curr);
513
- }),
514
- map((data2) => reduceOrderbook(depth, level, data2))
515
- ).subscribe((data2) => {
516
- setData(data2);
517
- });
518
- }, [orderbookRequest$, orderbookUpdate$]);
577
+ }
578
+ );
579
+ return () => {
580
+ subscription == null ? void 0 : subscription();
581
+ };
582
+ }, [symbol, requestData]);
519
583
  const onDepthChange = useCallback((depth2) => {
520
584
  console.log("Orderbook depth has changed:", depth2);
521
- orderbookOptions$.next(__spreadProps(__spreadValues({}, orderbookOptions$.value), {
522
- depth: depth2
523
- // level,
524
- }));
525
585
  }, []);
526
586
  const middlePrice = useMemo(() => {
527
587
  let asksFrist = 0, bidsFirst = 0;
528
588
  if (data.asks.length > 0) {
529
- asksFrist = data.asks[data.bids.length - 1][0];
589
+ asksFrist = data.asks[data.asks.length - 1][0];
530
590
  }
531
591
  if (data.bids.length > 0) {
532
592
  bidsFirst = data.bids[0][0];
@@ -537,7 +597,7 @@ var useOrderbook = (symbol, initial = { asks: [], bids: [] }, options) => {
537
597
  }, [ticker, data]);
538
598
  return [
539
599
  __spreadProps(__spreadValues({}, data), { markPrice, middlePrice }),
540
- { onDepthChange, depth }
600
+ { onDepthChange, depth, isLoading }
541
601
  ];
542
602
  };
543
603
 
@@ -641,14 +701,15 @@ function orderEntityFormatHandle(baseTick, quoteTick) {
641
701
  }
642
702
  function priceInputHandle(inputs) {
643
703
  const [values, input, value, markPrice, config] = inputs;
704
+ console.log("priceInputHandle", inputs);
644
705
  if (value === "") {
645
706
  return [__spreadProps(__spreadValues({}, values), { total: "" }), input, value, markPrice, config];
646
707
  }
647
708
  const price = new Decimal(value);
648
709
  const priceDP = price.dp();
710
+ console.log("priceInputHandle", priceDP, config.quoteDP);
649
711
  if (priceDP > config.quoteDP) {
650
- price.toDecimalPlaces(config.quoteDP);
651
- values.order_price = price.toNumber();
712
+ values.order_price = price.toDecimalPlaces(config.quoteDP).toString();
652
713
  }
653
714
  price.toDecimalPlaces(Math.min(priceDP, config.quoteDP));
654
715
  if (!values.order_quantity) {
@@ -656,9 +717,10 @@ function priceInputHandle(inputs) {
656
717
  }
657
718
  const total = price.mul(values.order_quantity);
658
719
  const quantityDP = total.dp();
659
- total.toDecimalPlaces(Math.min(quantityDP, config.baseDP));
660
720
  return [
661
- __spreadProps(__spreadValues({}, values), { total: total.toNumber() }),
721
+ __spreadProps(__spreadValues({}, values), {
722
+ total: total.toDecimalPlaces(Math.min(quantityDP, config.baseDP)).toString()
723
+ }),
662
724
  input,
663
725
  value,
664
726
  markPrice,
@@ -682,10 +744,9 @@ function quantityInputHandle(inputs) {
682
744
  }
683
745
  const total = quantity.mul(price);
684
746
  const totalDP = total.dp();
685
- total.todp(Math.min(config.quoteDP, totalDP));
686
747
  return [
687
748
  __spreadProps(__spreadValues({}, values), {
688
- total: total.toNumber()
749
+ total: total.todp(Math.min(config.quoteDP, totalDP)).toNumber()
689
750
  }),
690
751
  input,
691
752
  value,
@@ -761,25 +822,12 @@ var useFundingRates = () => {
761
822
  );
762
823
  return createGetter(data);
763
824
  };
764
- var useMarkPricesSubject = () => {
765
- const ws = useWebSocketClient();
766
- return useConstant(
767
- () => ws.observe("markprices").pipe(
768
- map((data) => {
769
- const prices = {};
770
- data.forEach((item) => {
771
- prices[item.symbol] = item.price;
772
- });
773
- return prices;
774
- })
775
- )
776
- );
777
- };
778
825
  var useMarkPricesStream = () => {
779
826
  const ws = useWS();
780
827
  return useSWRSubscription("markPrices", (key, { next }) => {
781
- const unsubscribe = ws.subscription(
782
- { event: "subscribe", topic: "markprices" },
828
+ const unsubscribe = ws.subscribe(
829
+ // { event: "subscribe", topic: "markprices" },
830
+ "markprices",
783
831
  {
784
832
  onMessage: (message) => {
785
833
  const data = /* @__PURE__ */ Object.create(null);
@@ -789,9 +837,9 @@ var useMarkPricesStream = () => {
789
837
  }
790
838
  next(null, data);
791
839
  },
792
- onUnsubscribe: () => {
793
- return "markprices";
794
- },
840
+ // onUnsubscribe: () => {
841
+ // return "markprices";
842
+ // },
795
843
  onError: (error) => {
796
844
  console.log("error", error);
797
845
  }
@@ -799,36 +847,34 @@ var useMarkPricesStream = () => {
799
847
  );
800
848
  return () => {
801
849
  console.log("unsubscribe!!!!!!!");
802
- console.log("unsubscribe", unsubscribe);
803
850
  unsubscribe == null ? void 0 : unsubscribe();
804
851
  };
805
852
  });
806
853
  };
807
854
  var usePositionStream = (symbol, options) => {
808
- useState(false);
809
855
  const [visibledSymbol, setVisibleSymbol] = useState(
810
856
  symbol
811
857
  );
812
858
  const symbolInfo = useSymbolsInfo();
813
859
  const { data: accountInfo } = usePrivateQuery("/client/info");
814
- const { mutation } = useMutation("/order");
815
860
  const fundingRates = useFundingRates();
816
- useMarkPricesSubject();
817
- const { data, error, isLoading } = usePrivateQuery(
818
- `/positions`,
819
- __spreadProps(__spreadValues({}, options), {
820
- formatter: (data2) => data2,
821
- onError: (err) => {
822
- console.log("usePositionStream error", err);
823
- }
824
- })
825
- );
861
+ const { data, error } = usePrivateQuery(`/positions`, __spreadProps(__spreadValues({}, options), {
862
+ formatter: (data2) => data2,
863
+ onError: (err) => {
864
+ console.log("usePositionStream error", err);
865
+ }
866
+ }));
826
867
  const { data: markPrices } = useMarkPricesStream();
827
868
  const formatedPositions = useMemo(() => {
828
869
  if (!(data == null ? void 0 : data.rows) || !symbolInfo || !accountInfo)
829
870
  return null;
830
871
  let totalCollateral = 0;
831
- return data.rows.map((item) => {
872
+ const filteredData = typeof symbol === "undefined" || symbol === "" ? data.rows.filter((item) => {
873
+ return item.position_qty !== 0;
874
+ }) : data.rows.filter((item) => {
875
+ return item.symbol === symbol && item.position_qty !== 0;
876
+ });
877
+ return filteredData.map((item) => {
832
878
  const price = propOr(
833
879
  item.mark_price,
834
880
  item.symbol,
@@ -864,7 +910,7 @@ var usePositionStream = (symbol, options) => {
864
910
  })
865
911
  });
866
912
  });
867
- }, [data == null ? void 0 : data.rows, symbolInfo, accountInfo, markPrices]);
913
+ }, [data == null ? void 0 : data.rows, symbolInfo, accountInfo, markPrices, symbol]);
868
914
  const aggregatedData = useMemo(() => {
869
915
  const aggregatedData2 = {
870
916
  unsettledPnL: NaN,
@@ -892,18 +938,11 @@ var usePositionStream = (symbol, options) => {
892
938
  const showSymbol = useCallback((symbol2) => {
893
939
  setVisibleSymbol(symbol2);
894
940
  }, []);
895
- const onClosePosition = useCallback(
896
- (order2) => {
897
- return mutation(order2).finally(() => {
898
- });
899
- },
900
- []
901
- );
902
941
  return [
903
942
  { rows: formatedPositions, aggregated: aggregatedData },
904
943
  createGetter(data, 1),
905
944
  {
906
- close: onClosePosition,
945
+ // close: onClosePosition,
907
946
  loading: false,
908
947
  showSymbol,
909
948
  error,
@@ -918,7 +957,8 @@ var usePositionStream = (symbol, options) => {
918
957
  };
919
958
  var totalUnsettlementPnLPath = pathOr(0, [0, "aggregated", "unsettledPnL"]);
920
959
  var positionsPath = pathOr([], [0, "rows"]);
921
- var useCollateral = (dp = 6) => {
960
+ var useCollateral = (options = { dp: 6 }) => {
961
+ const { dp } = options;
922
962
  const positions2 = usePositionStream();
923
963
  const { data: orders } = usePrivateQuery(`/orders`);
924
964
  const { data: accountInfo } = usePrivateQuery("/client/info");
@@ -1072,7 +1112,7 @@ var BaseOrderCreator = class {
1072
1112
  baseOrder(data) {
1073
1113
  const order2 = {
1074
1114
  // symbol: data.symbol,
1075
- order_type: !!data.order_type_ext ? data.order_type_ext : data.order_type,
1115
+ order_type: data.order_type === OrderType.LIMIT ? !!data.order_type_ext ? data.order_type_ext : data.order_type : data.order_type,
1076
1116
  side: data.side,
1077
1117
  // reduce_only: data.reduce_only,
1078
1118
  order_quantity: data.order_quantity
@@ -1085,25 +1125,41 @@ var BaseOrderCreator = class {
1085
1125
  baseValidate(values, configs) {
1086
1126
  const errors = {};
1087
1127
  const { maxQty } = configs;
1128
+ console.log("baseValidate", values, configs);
1088
1129
  const { order_quantity, total } = values;
1089
1130
  if (!order_quantity) {
1090
- errors.order_quantity = "quantity is required";
1131
+ errors.order_quantity = {
1132
+ type: "required",
1133
+ message: "quantity is required"
1134
+ };
1091
1135
  } else {
1092
1136
  const { base_max, base_min } = configs.symbol;
1093
1137
  const qty = new Decimal(order_quantity);
1094
1138
  if (qty.lt(base_min)) {
1095
- errors.order_quantity = `quantity must be greater than ${base_min}`;
1139
+ errors.order_quantity = {
1140
+ type: "min",
1141
+ message: `quantity must be greater than ${base_min}`
1142
+ };
1096
1143
  } else if (qty.gt(maxQty)) {
1097
- errors.order_quantity = `quantity must be less than ${base_max}`;
1144
+ errors.order_quantity = {
1145
+ type: "max",
1146
+ message: `quantity must be less than ${maxQty}`
1147
+ };
1098
1148
  }
1099
1149
  }
1100
1150
  if (!!total) {
1101
1151
  const { quote_max, quote_min } = configs.symbol;
1102
1152
  const totalNumber = new Decimal(total);
1103
1153
  if (totalNumber.lt(quote_min)) {
1104
- errors.total = `Quantity should be greater than ${quote_min}`;
1154
+ errors.total = {
1155
+ type: "min",
1156
+ message: `Quantity should be greater or equal than ${quote_min}`
1157
+ };
1105
1158
  } else if (totalNumber.gt(quote_max)) {
1106
- errors.total = `Quantity should be less or equal than ${quote_max}`;
1159
+ errors.total = {
1160
+ type: "max",
1161
+ message: `Quantity should be less or equal than ${quote_max}`
1162
+ };
1107
1163
  }
1108
1164
  }
1109
1165
  return Promise.resolve(errors);
@@ -1119,7 +1175,10 @@ var LimitOrderCreator = class extends BaseOrderCreator {
1119
1175
  return this.baseValidate(values, config).then((errors) => {
1120
1176
  const { order_price } = values;
1121
1177
  if (!order_price) {
1122
- errors.order_price = "price is required";
1178
+ errors.order_price = {
1179
+ type: "required",
1180
+ message: "price is required"
1181
+ };
1123
1182
  } else {
1124
1183
  const price = new Decimal(order_price);
1125
1184
  const { symbol } = config;
@@ -1127,9 +1186,15 @@ var LimitOrderCreator = class extends BaseOrderCreator {
1127
1186
  const maxPriceNumber = maxPrice(config.markPrice, price_range);
1128
1187
  const minPriceNumber = minPrice(config.markPrice, price_range);
1129
1188
  if (price.lt(minPriceNumber)) {
1130
- errors.order_price = `price must be greater than ${minPriceNumber}`;
1189
+ errors.order_price = {
1190
+ type: "min",
1191
+ message: `price must be greater than ${minPriceNumber}`
1192
+ };
1131
1193
  } else if (price.gt(maxPriceNumber)) {
1132
- errors.order_price = `price must be less than ${maxPriceNumber}`;
1194
+ errors.order_price = {
1195
+ type: "max",
1196
+ message: `price must be less than ${maxPriceNumber}`
1197
+ };
1133
1198
  }
1134
1199
  }
1135
1200
  return errors;
@@ -1138,7 +1203,9 @@ var LimitOrderCreator = class extends BaseOrderCreator {
1138
1203
  };
1139
1204
  var MarketOrderCreator = class extends BaseOrderCreator {
1140
1205
  create(values) {
1141
- return __spreadValues({}, this.baseOrder(values));
1206
+ const data = this.baseOrder(values);
1207
+ delete data["order_price"];
1208
+ return __spreadValues({}, data);
1142
1209
  }
1143
1210
  validate(values, configs) {
1144
1211
  return this.baseValidate(values, configs);
@@ -1162,8 +1229,8 @@ var GeneralOrderCreator = class extends BaseOrderCreator {
1162
1229
  }
1163
1230
  };
1164
1231
  var OrderFactory = class {
1165
- static create(type2) {
1166
- switch (type2) {
1232
+ static create(type) {
1233
+ switch (type) {
1167
1234
  case OrderType.LIMIT:
1168
1235
  return new LimitOrderCreator();
1169
1236
  case OrderType.MARKET:
@@ -1181,8 +1248,8 @@ var OrderFactory = class {
1181
1248
  };
1182
1249
 
1183
1250
  // src/orderly/useOrderEntry.ts
1184
- var useOrderEntry = (symbol, initialValue = {}, options) => {
1185
- const { mutation } = useMutation("/order");
1251
+ var useOrderEntry = (symbol, side, reduceOnly = false, options) => {
1252
+ const [mutation] = useMutation("/order");
1186
1253
  const { freeCollateral } = useCollateral();
1187
1254
  const symbolInfo = useSymbolsInfo();
1188
1255
  const tokenInfo = useTokenInfo();
@@ -1193,97 +1260,29 @@ var useOrderEntry = (symbol, initialValue = {}, options) => {
1193
1260
  const quoteDP = useMemo(() => {
1194
1261
  return tokenInfo.USDC("decimals", 0);
1195
1262
  }, [tokenInfo]);
1196
- const [valuesUpdate, [orderExtraValues]] = useEventCallback(
1197
- (event$, state$) => {
1198
- return event$.pipe(
1199
- withLatestFrom(state$),
1200
- map(([event, state]) => {
1201
- const { field, value } = event;
1202
- console.log("orderExtraValues", field, value);
1203
- return [__spreadProps(__spreadValues({}, state[0]), { [field]: value })];
1204
- })
1205
- );
1206
- },
1207
- [
1208
- {
1209
- order_type: OrderType.MARKET,
1210
- side: OrderSide.BUY,
1211
- reduce_only: false
1212
- }
1213
- ]
1214
- );
1215
- const ws = useWebSocketClient();
1216
- const markPrice = useObservable(
1217
- (_, input$) => input$.pipe(
1218
- switchMap(([symbol2]) => {
1219
- return ws.observe(`${symbol2}@markprice`).pipe(
1220
- map((data) => data.price)
1221
- // takeWhile(() => type === OrderType.MARKET)
1222
- );
1223
- })
1224
- ),
1225
- 0,
1226
- [symbol]
1227
- );
1228
- const formik = useFormik({
1229
- initialValues: __spreadValues({
1230
- // order_type: OrderType.MARKET,
1231
- // side: OrderSide.BUY,
1232
- order_quantity: "",
1233
- total: "",
1234
- order_price: "",
1235
- visible_quantity: 1
1236
- }, initialValue),
1237
- validate: (values) => {
1238
- const creator = OrderFactory.create(orderExtraValues.order_type);
1239
- return creator == null ? void 0 : creator.validate(values, {
1240
- symbol: symbolInfo[symbol](),
1241
- token: tokenInfo[symbol](),
1242
- maxQty,
1243
- markPrice
1244
- });
1245
- },
1246
- onSubmit: (values) => {
1247
- console.log(values);
1248
- }
1249
- });
1263
+ const { data: markPrice } = useMarkPrice(symbol);
1250
1264
  const maxQty = useMaxQty(
1251
1265
  symbol,
1252
- orderExtraValues.side,
1253
- orderExtraValues.reduce_only
1266
+ side,
1267
+ // orderExtraValues.reduce_only
1268
+ reduceOnly
1254
1269
  );
1255
- const formFieldds = useMemo(() => {
1256
- return ["order_quantity", "order_price", "total"];
1257
- }, []);
1258
- const setValue = (field, value) => {
1259
- if (formFieldds.indexOf(field) < 0) {
1260
- valuesUpdate({ field, value });
1261
- return;
1262
- }
1263
- const fieldHandler = getCalculateHandler(field);
1264
- const newValues = compose(
1265
- head,
1266
- orderEntityFormatHandle(),
1267
- fieldHandler,
1268
- baseInputHandle
1269
- )([
1270
- __spreadValues(__spreadValues({}, formik.values), orderExtraValues),
1271
- field,
1272
- value,
1273
- markPrice,
1274
- { baseDP, quoteDP }
1275
- ]);
1276
- formik.setValues(newValues, true);
1277
- };
1278
1270
  const onSubmit = (values) => {
1279
- values = values || formik.values;
1280
- if (typeof values.order_type === "undefined" || values.order_type !== OrderType.MARKET && values.order_type !== OrderType.LIMIT) {
1271
+ if (!values || typeof values.order_type === "undefined" || values.order_type !== OrderType.MARKET && values.order_type !== OrderType.LIMIT) {
1281
1272
  throw new Error("order_type is error");
1282
1273
  }
1283
- return Promise.resolve().then(() => {
1284
- const orderCreator = OrderFactory.create(
1285
- !!values.order_type_ext ? values.order_type_ext : values.order_type
1286
- );
1274
+ const orderCreator = OrderFactory.create(
1275
+ !!values.order_type_ext ? values.order_type_ext : values.order_type
1276
+ );
1277
+ if (!orderCreator) {
1278
+ return Promise.reject(new Error("orderCreator is null"));
1279
+ }
1280
+ return orderCreator == null ? void 0 : orderCreator.validate(values, {
1281
+ symbol: symbolInfo[symbol](),
1282
+ token: tokenInfo[symbol](),
1283
+ maxQty,
1284
+ markPrice
1285
+ }).then(() => {
1287
1286
  if (!orderCreator) {
1288
1287
  throw new Error("orderCreator is null");
1289
1288
  }
@@ -1291,31 +1290,43 @@ var useOrderEntry = (symbol, initialValue = {}, options) => {
1291
1290
  throw new Error("symbol is null");
1292
1291
  }
1293
1292
  const data = orderCreator.create(values);
1294
- console.log("orderentry data:::", data);
1295
- formik.setSubmitting(true);
1296
1293
  return mutation(__spreadProps(__spreadValues({}, data), {
1297
1294
  symbol
1298
- })).finally(() => {
1299
- formik.setSubmitting(false);
1300
- });
1295
+ }));
1296
+ });
1297
+ };
1298
+ const calculate = useCallback(
1299
+ (values, field, value) => {
1300
+ console.log("calculate", values, field, value, markPrice);
1301
+ const fieldHandler = getCalculateHandler(field);
1302
+ const newValues = compose(
1303
+ head,
1304
+ orderEntityFormatHandle(),
1305
+ fieldHandler,
1306
+ baseInputHandle
1307
+ )([values, field, value, markPrice, { baseDP, quoteDP }]);
1308
+ return newValues;
1309
+ },
1310
+ [markPrice]
1311
+ );
1312
+ const validator = (values) => {
1313
+ const creator = OrderFactory.create(values.order_type);
1314
+ return creator == null ? void 0 : creator.validate(values, {
1315
+ symbol: symbolInfo[symbol](),
1316
+ token: tokenInfo[symbol](),
1317
+ maxQty,
1318
+ markPrice
1301
1319
  });
1302
1320
  };
1303
- useEffect(() => {
1304
- formik.resetForm();
1305
- }, [symbol]);
1306
1321
  return {
1307
1322
  maxQty,
1308
- // formState,
1309
- values: __spreadValues(__spreadValues({}, formik.values), orderExtraValues),
1310
- errors: formik.errors,
1311
1323
  freeCollateral,
1312
1324
  markPrice,
1313
- setValue,
1314
1325
  onSubmit,
1315
- isSubmitting: formik.isSubmitting,
1316
- resetForm: formik.resetForm,
1317
- validateForm: formik.validateForm,
1318
- submitCount: formik.submitCount,
1326
+ helper: {
1327
+ calculate,
1328
+ validator
1329
+ },
1319
1330
  symbolConfig: symbolInfo[symbol]()
1320
1331
  };
1321
1332
  };
@@ -1358,35 +1369,49 @@ var useAccountInfo = () => {
1358
1369
  return usePrivateQuery("/client/info");
1359
1370
  };
1360
1371
  var useMarketsStream = () => {
1361
- const ws = useWebSocketClient();
1362
- const { data } = useQuery(`/public/futures`);
1363
- const value = useObservable(
1364
- (_, input$) => ws.observe("tickers").pipe(
1365
- startWith([]),
1366
- withLatestFrom(input$.pipe(map((args) => args[0]))),
1367
- map((args) => {
1368
- if (args[0].length === 0) {
1369
- return args[1];
1372
+ const ws = useWS();
1373
+ const { data: futures } = useQuery(`/public/futures`);
1374
+ const { data: tickers } = useSWRSubscription("tickers", (_, { next }) => {
1375
+ const unsubscribe = ws.subscribe(
1376
+ // { event: "subscribe", topic: "markprices" },
1377
+ "tickers",
1378
+ {
1379
+ onMessage: (message) => {
1380
+ next(null, message);
1370
1381
  }
1371
- return args[1].map((item) => {
1372
- const ticker = args[0].find(
1373
- (t) => t.symbol === item.symbol
1374
- );
1375
- if (ticker) {
1376
- return __spreadProps(__spreadValues({}, item), {
1377
- ["24h_close"]: ticker.close,
1378
- ["24h_open"]: ticker.open,
1379
- ["24h_volumn"]: ticker.volume,
1380
- change: 0
1381
- });
1382
- }
1383
- return item;
1382
+ // onUnsubscribe: () => {
1383
+ // return "markprices";
1384
+ // },
1385
+ // onError: (error: any) => {
1386
+ // console.log("error", error);
1387
+ // },
1388
+ }
1389
+ );
1390
+ return () => {
1391
+ console.log("unsubscribe!!!!!!!");
1392
+ unsubscribe == null ? void 0 : unsubscribe();
1393
+ };
1394
+ });
1395
+ const value = useMemo(() => {
1396
+ if (!futures)
1397
+ return null;
1398
+ if (!tickers)
1399
+ return futures;
1400
+ return futures.map((item) => {
1401
+ const ticker = tickers.find(
1402
+ (t) => t.symbol === item.symbol
1403
+ );
1404
+ if (ticker) {
1405
+ return __spreadProps(__spreadValues({}, item), {
1406
+ ["24h_close"]: ticker.close,
1407
+ ["24h_open"]: ticker.open,
1408
+ ["24h_volumn"]: ticker.volume,
1409
+ change: 0
1384
1410
  });
1385
- })
1386
- ),
1387
- null,
1388
- [data]
1389
- );
1411
+ }
1412
+ return item;
1413
+ });
1414
+ }, [futures, tickers]);
1390
1415
  return { data: value };
1391
1416
  };
1392
1417
  var useFundingRate = (symbol) => {
@@ -1427,10 +1452,10 @@ var useFundingRate = (symbol) => {
1427
1452
  var fetcher3 = (url, init) => get(url, init);
1428
1453
  var usePrivateInfiniteQuery = (getKey, options) => {
1429
1454
  var _a;
1430
- const account3 = useAccount();
1455
+ const account4 = useAccount();
1431
1456
  const middleware = Array.isArray(options == null ? void 0 : options.use) ? (_a = options == null ? void 0 : options.use) != null ? _a : [] : [];
1432
1457
  const result = useSWRInfinite(
1433
- (pageIndex, previousPageData) => account3.state.status >= AccountStatusEnum.SignedIn ? getKey(pageIndex, previousPageData) : null,
1458
+ (pageIndex, previousPageData) => account4.state.status >= AccountStatusEnum.EnableTrading ? getKey(pageIndex, previousPageData) : null,
1434
1459
  fetcher3,
1435
1460
  __spreadProps(__spreadValues({}, options), {
1436
1461
  use: [signatureMiddleware, ...middleware]
@@ -1475,7 +1500,6 @@ var useOrderStream = ({
1475
1500
  if (!res.data) {
1476
1501
  return null;
1477
1502
  }
1478
- console.log("orders:::", markPrices);
1479
1503
  return (_a = res.data) == null ? void 0 : _a.flat().map((item) => {
1480
1504
  var _a2;
1481
1505
  return __spreadProps(__spreadValues({}, item), {
@@ -1505,6 +1529,77 @@ var useOrderStream = ({
1505
1529
  ];
1506
1530
  };
1507
1531
 
1532
+ // src/orderly/useTradeStream.ts
1533
+ var useTradeStream = (symbol) => {
1534
+ if (!symbol) {
1535
+ throw new Error("useTradeStream: symbol is required");
1536
+ }
1537
+ const { data, isLoading } = useQuery(
1538
+ `/public/market_trades?symbol=${symbol}&limit=20`
1539
+ );
1540
+ return { data, isLoading };
1541
+ };
1542
+ var useMarginRatio = () => {
1543
+ const [{ rows }] = usePositionStream();
1544
+ const { data: markPrices } = useMarkPricesStream();
1545
+ const { totalCollateral } = useCollateral();
1546
+ const marginRatio = useMemo(() => {
1547
+ const ratio = account.totalMarginRatio({
1548
+ totalCollateral,
1549
+ markPrices,
1550
+ positions: rows != null ? rows : []
1551
+ });
1552
+ return ratio;
1553
+ }, [rows, markPrices, totalCollateral]);
1554
+ return marginRatio;
1555
+ };
1556
+ var useChains = (networkId, options) => {
1557
+ const field = options == null ? void 0 : options.pick;
1558
+ const { data } = useSWR(
1559
+ "https://fi-api.woo.org/swap_support",
1560
+ (url) => fetch(url).then((res) => res.json()),
1561
+ {
1562
+ revalidateOnFocus: false,
1563
+ revalidateOnReconnect: false
1564
+ }
1565
+ );
1566
+ const chains = useMemo(() => {
1567
+ if (!data || !data.data)
1568
+ return data;
1569
+ let arr = [];
1570
+ Object.keys(data.data).forEach((key) => {
1571
+ const item = data.data[key];
1572
+ arr.push(__spreadProps(__spreadValues({}, item), {
1573
+ name: key
1574
+ }));
1575
+ });
1576
+ if (networkId === "mainnet") {
1577
+ arr = arr.filter((item) => item.network_infos.mainnet);
1578
+ }
1579
+ if (networkId === "testnet") {
1580
+ arr = arr.filter((item) => !item.network_infos.mainnet);
1581
+ }
1582
+ if (typeof (options == null ? void 0 : options.filter) === "function") {
1583
+ arr = arr.filter(options.filter);
1584
+ }
1585
+ if (typeof field !== "undefined") {
1586
+ return arr.map((item) => {
1587
+ return item[field];
1588
+ });
1589
+ }
1590
+ return arr;
1591
+ }, [data, networkId, field, options]);
1592
+ const findByChainId = useCallback(
1593
+ (chainId) => {
1594
+ if (!data || !data.data)
1595
+ return void 0;
1596
+ return data.data[chainId];
1597
+ },
1598
+ [data]
1599
+ );
1600
+ return [chains, { findByChainId }];
1601
+ };
1602
+
1508
1603
  // src/apis/index.ts
1509
1604
  var apis_exports = {};
1510
1605
  __export(apis_exports, {
@@ -1539,6 +1634,6 @@ var useFundingRate2 = (symbol) => {
1539
1634
  return useQuery(`/public/funding_rate`);
1540
1635
  };
1541
1636
 
1542
- export { DataSourceProvider, OrderStatus, OrderlyContext, OrderlyProvider, apis_exports as apis, useAccount, useAccountInfo, useAppState, useCollateral, useFetures, useFundingRate, useMarkPricesStream, useMarketsStream, useMaxQty, useMutation, useOrderEntry, useOrderStream, useOrderbook, usePositionStream, usePrivateObserve, usePrivateQuery, useQuery, useSymbolsInfo, useTickerStream, useTokenInfo, useTopicObserve, useTradingView, useWS, useWebSocketClient };
1637
+ export { DataSourceProvider, OrderStatus, OrderlyContext, OrderlyProvider, apis_exports as apis, useAccount, useAccountInfo, useAppState, useChains, useCollateral, useFetures, useFundingRate, useMarginRatio, useMarkPrice, useMarkPricesStream, useMarketsStream, useMaxQty, useMutation, useOrderEntry, useOrderStream, useOrderbookStream, usePositionStream, usePrivateObserve, usePrivateQuery, useQuery, useSymbolsInfo, useTickerStream, useTokenInfo, useTopicObserve, useTradeStream, useTradingView, useWS, useWebSocketClient };
1543
1638
  //# sourceMappingURL=out.js.map
1544
1639
  //# sourceMappingURL=index.mjs.map