@orderly.network/hooks 0.0.24 → 0.0.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +7 -6
- package/dist/index.d.ts +7 -6
- package/dist/index.js +128 -105
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +129 -105
- package/dist/index.mjs.map +1 -1
- package/package.json +7 -7
package/dist/index.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import useSWR, { SWRConfiguration, SWRResponse } from 'swr';
|
|
2
2
|
export { SWRConfiguration, default as useSWR } from 'swr';
|
|
3
3
|
import { SWRMutationConfiguration } from 'swr/mutation';
|
|
4
|
-
import { Account, AccountState, ConfigStore, OrderlyKeyStore, WalletAdapter, EventEmitter, WSMessage } from '@orderly.network/core';
|
|
4
|
+
import { Account, AccountState, ConfigStore, OrderlyKeyStore, WalletAdapter, IContract, EventEmitter, WSMessage } from '@orderly.network/core';
|
|
5
5
|
import * as react from 'react';
|
|
6
6
|
import react__default, { FC, PropsWithChildren } from 'react';
|
|
7
7
|
export { default as useConstant } from 'use-constant';
|
|
@@ -74,6 +74,7 @@ interface OrderlyContextState extends OrderlyAppConfig {
|
|
|
74
74
|
walletAdapter: {
|
|
75
75
|
new (options: any): WalletAdapter;
|
|
76
76
|
};
|
|
77
|
+
contractManager: IContract;
|
|
77
78
|
networkId: string;
|
|
78
79
|
onWalletConnect?: () => Promise<any>;
|
|
79
80
|
onWalletDisconnect?: () => Promise<any>;
|
|
@@ -125,11 +126,13 @@ declare const useOrderbookStream: (symbol: string, initial?: OrderbookData, opti
|
|
|
125
126
|
bids: OrderBookItem[];
|
|
126
127
|
onDepthChange?: undefined;
|
|
127
128
|
depth?: undefined;
|
|
129
|
+
allDepths?: undefined;
|
|
128
130
|
isLoading?: undefined;
|
|
129
131
|
onItemClick?: undefined;
|
|
130
132
|
} | {
|
|
131
133
|
onDepthChange: (depth: number) => void;
|
|
132
|
-
depth: number;
|
|
134
|
+
depth: number | undefined;
|
|
135
|
+
allDepths: any[];
|
|
133
136
|
isLoading: boolean;
|
|
134
137
|
onItemClick: (item: OrderBookItem) => void;
|
|
135
138
|
})[];
|
|
@@ -223,12 +226,10 @@ interface MarketTradeStreamOptions {
|
|
|
223
226
|
level?: number;
|
|
224
227
|
}
|
|
225
228
|
declare const useMarketTradeStream: (symbol: string, options?: MarketTradeStreamOptions) => {
|
|
226
|
-
data: API.Trade[]
|
|
229
|
+
data: API.Trade[];
|
|
227
230
|
isLoading: boolean;
|
|
228
231
|
};
|
|
229
232
|
|
|
230
|
-
declare const useTradeStream: () => unknown[];
|
|
231
|
-
|
|
232
233
|
type CollateralOutputs = {
|
|
233
234
|
totalCollateral: number;
|
|
234
235
|
freeCollateral: number;
|
|
@@ -323,4 +324,4 @@ declare namespace index {
|
|
|
323
324
|
};
|
|
324
325
|
}
|
|
325
326
|
|
|
326
|
-
export { AppStateErrors, DataSourceProvider, OrderStatus, OrderlyAppConfig, OrderlyContext, OrderlyContextState, OrderlyProvider, index as apis, useAccount, useAccountInfo, useAccountInstance, useAppState, useBalance, useChains, useCollateral, useEventEmitter, useExecutionReport, useFetures, useFundingRate, useHolding, useLeverage, useMarginRatio, useMarkPrice, useMarkPricesStream, useMarketTradeStream, useMarketsStream, useMaxQty, useMutation, useOrderEntry, useOrderStream, useOrderbookStream, usePositionStream, usePreLoadData, usePrivateDataObserver, usePrivateObserve, usePrivateQuery, useQuery, useRunOnce, useSessionStorage, useSymbolsInfo, useTickerStream, useTokenInfo, useTopicObserve,
|
|
327
|
+
export { AppStateErrors, DataSourceProvider, OrderStatus, OrderlyAppConfig, OrderlyContext, OrderlyContextState, OrderlyProvider, index as apis, useAccount, useAccountInfo, useAccountInstance, useAppState, useBalance, useChains, useCollateral, useEventEmitter, useExecutionReport, useFetures, useFundingRate, useHolding, useLeverage, useMarginRatio, useMarkPrice, useMarkPricesStream, useMarketTradeStream, useMarketsStream, useMaxQty, useMutation, useOrderEntry, useOrderStream, useOrderbookStream, usePositionStream, usePreLoadData, usePrivateDataObserver, usePrivateObserve, usePrivateQuery, useQuery, useRunOnce, useSessionStorage, useSymbolsInfo, useTickerStream, useTokenInfo, useTopicObserve, useTradingView, useWS };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import useSWR, { SWRConfiguration, SWRResponse } from 'swr';
|
|
2
2
|
export { SWRConfiguration, default as useSWR } from 'swr';
|
|
3
3
|
import { SWRMutationConfiguration } from 'swr/mutation';
|
|
4
|
-
import { Account, AccountState, ConfigStore, OrderlyKeyStore, WalletAdapter, EventEmitter, WSMessage } from '@orderly.network/core';
|
|
4
|
+
import { Account, AccountState, ConfigStore, OrderlyKeyStore, WalletAdapter, IContract, EventEmitter, WSMessage } from '@orderly.network/core';
|
|
5
5
|
import * as react from 'react';
|
|
6
6
|
import react__default, { FC, PropsWithChildren } from 'react';
|
|
7
7
|
export { default as useConstant } from 'use-constant';
|
|
@@ -74,6 +74,7 @@ interface OrderlyContextState extends OrderlyAppConfig {
|
|
|
74
74
|
walletAdapter: {
|
|
75
75
|
new (options: any): WalletAdapter;
|
|
76
76
|
};
|
|
77
|
+
contractManager: IContract;
|
|
77
78
|
networkId: string;
|
|
78
79
|
onWalletConnect?: () => Promise<any>;
|
|
79
80
|
onWalletDisconnect?: () => Promise<any>;
|
|
@@ -125,11 +126,13 @@ declare const useOrderbookStream: (symbol: string, initial?: OrderbookData, opti
|
|
|
125
126
|
bids: OrderBookItem[];
|
|
126
127
|
onDepthChange?: undefined;
|
|
127
128
|
depth?: undefined;
|
|
129
|
+
allDepths?: undefined;
|
|
128
130
|
isLoading?: undefined;
|
|
129
131
|
onItemClick?: undefined;
|
|
130
132
|
} | {
|
|
131
133
|
onDepthChange: (depth: number) => void;
|
|
132
|
-
depth: number;
|
|
134
|
+
depth: number | undefined;
|
|
135
|
+
allDepths: any[];
|
|
133
136
|
isLoading: boolean;
|
|
134
137
|
onItemClick: (item: OrderBookItem) => void;
|
|
135
138
|
})[];
|
|
@@ -223,12 +226,10 @@ interface MarketTradeStreamOptions {
|
|
|
223
226
|
level?: number;
|
|
224
227
|
}
|
|
225
228
|
declare const useMarketTradeStream: (symbol: string, options?: MarketTradeStreamOptions) => {
|
|
226
|
-
data: API.Trade[]
|
|
229
|
+
data: API.Trade[];
|
|
227
230
|
isLoading: boolean;
|
|
228
231
|
};
|
|
229
232
|
|
|
230
|
-
declare const useTradeStream: () => unknown[];
|
|
231
|
-
|
|
232
233
|
type CollateralOutputs = {
|
|
233
234
|
totalCollateral: number;
|
|
234
235
|
freeCollateral: number;
|
|
@@ -323,4 +324,4 @@ declare namespace index {
|
|
|
323
324
|
};
|
|
324
325
|
}
|
|
325
326
|
|
|
326
|
-
export { AppStateErrors, DataSourceProvider, OrderStatus, OrderlyAppConfig, OrderlyContext, OrderlyContextState, OrderlyProvider, index as apis, useAccount, useAccountInfo, useAccountInstance, useAppState, useBalance, useChains, useCollateral, useEventEmitter, useExecutionReport, useFetures, useFundingRate, useHolding, useLeverage, useMarginRatio, useMarkPrice, useMarkPricesStream, useMarketTradeStream, useMarketsStream, useMaxQty, useMutation, useOrderEntry, useOrderStream, useOrderbookStream, usePositionStream, usePreLoadData, usePrivateDataObserver, usePrivateObserve, usePrivateQuery, useQuery, useRunOnce, useSessionStorage, useSymbolsInfo, useTickerStream, useTokenInfo, useTopicObserve,
|
|
327
|
+
export { AppStateErrors, DataSourceProvider, OrderStatus, OrderlyAppConfig, OrderlyContext, OrderlyContextState, OrderlyProvider, index as apis, useAccount, useAccountInfo, useAccountInstance, useAppState, useBalance, useChains, useCollateral, useEventEmitter, useExecutionReport, useFetures, useFundingRate, useHolding, useLeverage, useMarginRatio, useMarkPrice, useMarkPricesStream, useMarketTradeStream, useMarketsStream, useMaxQty, useMutation, useOrderEntry, useOrderStream, useOrderbookStream, usePositionStream, usePreLoadData, usePrivateDataObserver, usePrivateObserve, usePrivateQuery, useQuery, useRunOnce, useSessionStorage, useSymbolsInfo, useTickerStream, useTokenInfo, useTopicObserve, useTradingView, useWS };
|
package/dist/index.js
CHANGED
|
@@ -98,7 +98,7 @@ var useQuery = (query, options) => {
|
|
|
98
98
|
);
|
|
99
99
|
};
|
|
100
100
|
var useAccountInstance = () => {
|
|
101
|
-
const { configStore, keyStore, walletAdapter } = React2.useContext(OrderlyContext);
|
|
101
|
+
const { configStore, keyStore, contractManager, walletAdapter } = React2.useContext(OrderlyContext);
|
|
102
102
|
if (!configStore)
|
|
103
103
|
throw new Error("configStore is not defined, please use OrderlyProvider");
|
|
104
104
|
if (!keyStore) {
|
|
@@ -109,7 +109,12 @@ var useAccountInstance = () => {
|
|
|
109
109
|
const account5 = useConstant__default.default(() => {
|
|
110
110
|
let account6 = core.SimpleDI.get("account");
|
|
111
111
|
if (!account6) {
|
|
112
|
-
account6 = new core.Account(
|
|
112
|
+
account6 = new core.Account(
|
|
113
|
+
configStore,
|
|
114
|
+
keyStore,
|
|
115
|
+
contractManager,
|
|
116
|
+
walletAdapter
|
|
117
|
+
);
|
|
113
118
|
core.SimpleDI.registerByName("account", account6);
|
|
114
119
|
}
|
|
115
120
|
return account6;
|
|
@@ -208,6 +213,7 @@ var useAccount = () => {
|
|
|
208
213
|
configStore,
|
|
209
214
|
keyStore,
|
|
210
215
|
walletAdapter,
|
|
216
|
+
contractManager,
|
|
211
217
|
onWalletConnect,
|
|
212
218
|
onWalletDisconnect,
|
|
213
219
|
onSetChain
|
|
@@ -219,14 +225,7 @@ var useAccount = () => {
|
|
|
219
225
|
"keyStore is not defined, please use OrderlyProvider and provide keyStore"
|
|
220
226
|
);
|
|
221
227
|
}
|
|
222
|
-
const account5 =
|
|
223
|
-
let account6 = core.SimpleDI.get("account");
|
|
224
|
-
if (!account6) {
|
|
225
|
-
account6 = new core.Account(configStore, keyStore, walletAdapter);
|
|
226
|
-
core.SimpleDI.registerByName("account", account6);
|
|
227
|
-
}
|
|
228
|
-
return account6;
|
|
229
|
-
});
|
|
228
|
+
const account5 = useAccountInstance();
|
|
230
229
|
const [state, setState] = React2.useState(account5.stateValue);
|
|
231
230
|
const statusChangeHandler = (nextState) => {
|
|
232
231
|
setState(() => nextState);
|
|
@@ -535,17 +534,93 @@ var useMarkPrice = (symbol) => {
|
|
|
535
534
|
});
|
|
536
535
|
};
|
|
537
536
|
|
|
537
|
+
// src/utils/createGetter.ts
|
|
538
|
+
function createGetter(data, depth = 2) {
|
|
539
|
+
return new Proxy(data || {}, {
|
|
540
|
+
get(target, property, receiver) {
|
|
541
|
+
if (depth === 1) {
|
|
542
|
+
return (defaultValue) => {
|
|
543
|
+
var _a;
|
|
544
|
+
if (!target)
|
|
545
|
+
return defaultValue;
|
|
546
|
+
return (_a = target[property]) != null ? _a : defaultValue;
|
|
547
|
+
};
|
|
548
|
+
}
|
|
549
|
+
return (key, defaultValue) => {
|
|
550
|
+
var _a, _b;
|
|
551
|
+
if (key) {
|
|
552
|
+
return (_b = (_a = target[property]) == null ? void 0 : _a[key]) != null ? _b : defaultValue;
|
|
553
|
+
} else {
|
|
554
|
+
return target[property];
|
|
555
|
+
}
|
|
556
|
+
};
|
|
557
|
+
}
|
|
558
|
+
});
|
|
559
|
+
}
|
|
560
|
+
var useSymbolsInfo = () => {
|
|
561
|
+
const { data = {} } = useQuery(`/v1/public/info`, {
|
|
562
|
+
focusThrottleInterval: 1e3 * 60 * 60 * 24,
|
|
563
|
+
revalidateOnFocus: false,
|
|
564
|
+
formatter(data2) {
|
|
565
|
+
var _a;
|
|
566
|
+
if (!(data2 == null ? void 0 : data2.rows) || !((_a = data2 == null ? void 0 : data2.rows) == null ? void 0 : _a.length)) {
|
|
567
|
+
return {};
|
|
568
|
+
}
|
|
569
|
+
const obj = /* @__PURE__ */ Object.create(null);
|
|
570
|
+
for (let index = 0; index < data2.rows.length; index++) {
|
|
571
|
+
const item = data2.rows[index];
|
|
572
|
+
const arr = item.symbol.split("_");
|
|
573
|
+
const base_dp = utils.getPrecisionByNumber(item.base_tick);
|
|
574
|
+
const quote_dp = utils.getPrecisionByNumber(item.quote_tick);
|
|
575
|
+
obj[item.symbol] = __spreadProps(__spreadValues({}, item), {
|
|
576
|
+
base_dp,
|
|
577
|
+
quote_dp,
|
|
578
|
+
base: arr[1],
|
|
579
|
+
quote: arr[2],
|
|
580
|
+
type: arr[0],
|
|
581
|
+
name: `${arr[1]}-${arr[0]}`
|
|
582
|
+
});
|
|
583
|
+
}
|
|
584
|
+
return obj;
|
|
585
|
+
}
|
|
586
|
+
});
|
|
587
|
+
return createGetter(data);
|
|
588
|
+
};
|
|
589
|
+
|
|
538
590
|
// src/orderly/useOrderbookStream.ts
|
|
539
591
|
var paddingFn = (len) => Array(len).fill([Number.NaN, Number.NaN, Number.NaN]);
|
|
540
592
|
var asksSortFn = (a, b) => a[0] - b[0];
|
|
541
593
|
var bidsSortFn = (a, b) => b[0] - a[0];
|
|
542
|
-
var reduceItems = (depth, level, data) => {
|
|
594
|
+
var reduceItems = (depth, level, data, asks = false) => {
|
|
543
595
|
if (!Array.isArray(data) || data.length === 0) {
|
|
544
596
|
return [];
|
|
545
597
|
}
|
|
598
|
+
let newData = [...data];
|
|
546
599
|
const result = [];
|
|
547
|
-
|
|
548
|
-
const
|
|
600
|
+
if (typeof depth !== "undefined") {
|
|
601
|
+
const prices = /* @__PURE__ */ new Map();
|
|
602
|
+
for (let i = 0; i < data.length; i++) {
|
|
603
|
+
const [price, quantity] = data[i];
|
|
604
|
+
if (isNaN(price) || isNaN(quantity))
|
|
605
|
+
continue;
|
|
606
|
+
let priceKey;
|
|
607
|
+
if (asks) {
|
|
608
|
+
priceKey = Math.ceil(price / depth) * depth;
|
|
609
|
+
} else {
|
|
610
|
+
priceKey = Math.floor(price / depth) * depth;
|
|
611
|
+
}
|
|
612
|
+
if (prices.has(priceKey)) {
|
|
613
|
+
const item = prices.get(priceKey);
|
|
614
|
+
const itemPrice = item[1] + quantity;
|
|
615
|
+
prices.set(priceKey, [priceKey, itemPrice]);
|
|
616
|
+
} else {
|
|
617
|
+
prices.set(priceKey, [priceKey, quantity]);
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
newData = Array.from(prices.values());
|
|
621
|
+
}
|
|
622
|
+
for (let i = 0; i < newData.length; i++) {
|
|
623
|
+
const [price, quantity] = newData[i];
|
|
549
624
|
if (isNaN(price) || isNaN(quantity))
|
|
550
625
|
continue;
|
|
551
626
|
result.push([
|
|
@@ -560,7 +635,7 @@ var reduceItems = (depth, level, data) => {
|
|
|
560
635
|
return result;
|
|
561
636
|
};
|
|
562
637
|
var reduceOrderbook = (depth, level, data) => {
|
|
563
|
-
const asks = reduceItems(depth, level, data.asks).reverse();
|
|
638
|
+
const asks = reduceItems(depth, level, data.asks, true).reverse();
|
|
564
639
|
const bids = reduceItems(depth, level, data.bids);
|
|
565
640
|
return {
|
|
566
641
|
asks: asks.length < level ? paddingFn(level - asks.length).concat(asks) : asks,
|
|
@@ -574,10 +649,6 @@ var mergeItems = (data, update) => {
|
|
|
574
649
|
const item = update.shift();
|
|
575
650
|
if (item) {
|
|
576
651
|
const [price, quantity] = item;
|
|
577
|
-
if (price < data[0][0] && quantity > 0) {
|
|
578
|
-
data.unshift(item);
|
|
579
|
-
continue;
|
|
580
|
-
}
|
|
581
652
|
const index = data.findIndex(([p], index2) => p === price);
|
|
582
653
|
if (index === -1) {
|
|
583
654
|
data.push(item);
|
|
@@ -585,8 +656,9 @@ var mergeItems = (data, update) => {
|
|
|
585
656
|
if (quantity === 0) {
|
|
586
657
|
data.splice(index, 1);
|
|
587
658
|
continue;
|
|
659
|
+
} else {
|
|
660
|
+
data[index] = item;
|
|
588
661
|
}
|
|
589
|
-
data[index] = item;
|
|
590
662
|
}
|
|
591
663
|
}
|
|
592
664
|
}
|
|
@@ -605,11 +677,19 @@ var useOrderbookStream = (symbol, initial = { asks: [], bids: [] }, options) =>
|
|
|
605
677
|
const [requestData, setRequestData] = React2.useState(null);
|
|
606
678
|
const [data, setData] = React2.useState(initial);
|
|
607
679
|
const [isLoading, setIsLoading] = React2.useState(true);
|
|
608
|
-
const [depth, setDepth] = React2.useState(1e-3);
|
|
609
680
|
const [level, setLevel] = React2.useState(() => {
|
|
610
681
|
var _a;
|
|
611
682
|
return (_a = options == null ? void 0 : options.level) != null ? _a : 10;
|
|
612
683
|
});
|
|
684
|
+
const config = useSymbolsInfo()[symbol];
|
|
685
|
+
const [depth, setDepth] = React2.useState();
|
|
686
|
+
const depths = React2.useMemo(() => {
|
|
687
|
+
const tick = config("quote_tick");
|
|
688
|
+
return [tick, tick * 10, tick * 100, tick * 1e3];
|
|
689
|
+
}, [config("quote_tick")]);
|
|
690
|
+
React2.useEffect(() => {
|
|
691
|
+
setDepth(config("quote_tick"));
|
|
692
|
+
}, [config("quote_tick")]);
|
|
613
693
|
const ws = useWS();
|
|
614
694
|
const ticker = useTickerStream(symbol);
|
|
615
695
|
const eventEmitter = useEventEmitter();
|
|
@@ -624,7 +704,6 @@ var useOrderbookStream = (symbol, initial = { asks: [], bids: [] }, options) =>
|
|
|
624
704
|
},
|
|
625
705
|
{
|
|
626
706
|
onMessage: (message) => {
|
|
627
|
-
console.log("orderbook request message", message);
|
|
628
707
|
if (!!message) {
|
|
629
708
|
const reduceOrderbookData = reduceOrderbook(depth, level, message);
|
|
630
709
|
setRequestData(reduceOrderbookData);
|
|
@@ -637,7 +716,7 @@ var useOrderbookStream = (symbol, initial = { asks: [], bids: [] }, options) =>
|
|
|
637
716
|
return () => {
|
|
638
717
|
setRequestData(null);
|
|
639
718
|
};
|
|
640
|
-
}, [symbol]);
|
|
719
|
+
}, [symbol, depth]);
|
|
641
720
|
const { data: markPrice } = useMarkPrice(symbol);
|
|
642
721
|
React2.useEffect(() => {
|
|
643
722
|
if (!requestData)
|
|
@@ -665,7 +744,7 @@ var useOrderbookStream = (symbol, initial = { asks: [], bids: [] }, options) =>
|
|
|
665
744
|
eventEmitter.emit("orderbook:item:click", item);
|
|
666
745
|
}, []);
|
|
667
746
|
const onDepthChange = React2.useCallback((depth2) => {
|
|
668
|
-
|
|
747
|
+
setDepth(() => depth2);
|
|
669
748
|
}, []);
|
|
670
749
|
const middlePrice = React2.useMemo(() => {
|
|
671
750
|
let asksFrist = 0, bidsFirst = 0;
|
|
@@ -681,63 +760,10 @@ var useOrderbookStream = (symbol, initial = { asks: [], bids: [] }, options) =>
|
|
|
681
760
|
}, [ticker, data]);
|
|
682
761
|
return [
|
|
683
762
|
__spreadProps(__spreadValues({}, data), { markPrice, middlePrice }),
|
|
684
|
-
{ onDepthChange, depth, isLoading, onItemClick }
|
|
763
|
+
{ onDepthChange, depth, allDepths: depths, isLoading, onItemClick }
|
|
685
764
|
];
|
|
686
765
|
};
|
|
687
766
|
|
|
688
|
-
// src/utils/createGetter.ts
|
|
689
|
-
function createGetter(data, depth = 2) {
|
|
690
|
-
return new Proxy(data || {}, {
|
|
691
|
-
get(target, property, receiver) {
|
|
692
|
-
if (depth === 1) {
|
|
693
|
-
return (defaultValue) => {
|
|
694
|
-
var _a;
|
|
695
|
-
if (!target)
|
|
696
|
-
return defaultValue;
|
|
697
|
-
return (_a = target[property]) != null ? _a : defaultValue;
|
|
698
|
-
};
|
|
699
|
-
}
|
|
700
|
-
return (key, defaultValue) => {
|
|
701
|
-
var _a, _b;
|
|
702
|
-
if (key) {
|
|
703
|
-
return (_b = (_a = target[property]) == null ? void 0 : _a[key]) != null ? _b : defaultValue;
|
|
704
|
-
} else {
|
|
705
|
-
return target[property];
|
|
706
|
-
}
|
|
707
|
-
};
|
|
708
|
-
}
|
|
709
|
-
});
|
|
710
|
-
}
|
|
711
|
-
var useSymbolsInfo = () => {
|
|
712
|
-
const { data = {} } = useQuery(`/v1/public/info`, {
|
|
713
|
-
focusThrottleInterval: 1e3 * 60 * 60 * 24,
|
|
714
|
-
revalidateOnFocus: false,
|
|
715
|
-
formatter(data2) {
|
|
716
|
-
var _a;
|
|
717
|
-
if (!(data2 == null ? void 0 : data2.rows) || !((_a = data2 == null ? void 0 : data2.rows) == null ? void 0 : _a.length)) {
|
|
718
|
-
return {};
|
|
719
|
-
}
|
|
720
|
-
const obj = /* @__PURE__ */ Object.create(null);
|
|
721
|
-
for (let index = 0; index < data2.rows.length; index++) {
|
|
722
|
-
const item = data2.rows[index];
|
|
723
|
-
const arr = item.symbol.split("_");
|
|
724
|
-
const base_dp = utils.getPrecisionByNumber(item.base_tick);
|
|
725
|
-
const quote_dp = utils.getPrecisionByNumber(item.quote_tick);
|
|
726
|
-
obj[item.symbol] = __spreadProps(__spreadValues({}, item), {
|
|
727
|
-
base_dp,
|
|
728
|
-
quote_dp,
|
|
729
|
-
base: arr[1],
|
|
730
|
-
quote: arr[2],
|
|
731
|
-
type: arr[0],
|
|
732
|
-
name: `${arr[1]}-${arr[0]}`
|
|
733
|
-
});
|
|
734
|
-
}
|
|
735
|
-
return obj;
|
|
736
|
-
}
|
|
737
|
-
});
|
|
738
|
-
return createGetter(data);
|
|
739
|
-
};
|
|
740
|
-
|
|
741
767
|
// src/orderly/useTokenInfo.ts
|
|
742
768
|
var useTokenInfo = () => {
|
|
743
769
|
const { data = {} } = useQuery(
|
|
@@ -995,10 +1021,7 @@ var usePositionStream = (symbol, options) => {
|
|
|
995
1021
|
item.symbol,
|
|
996
1022
|
markPrices
|
|
997
1023
|
);
|
|
998
|
-
const notional = futures.positions.notional(
|
|
999
|
-
item.position_qty,
|
|
1000
|
-
item.average_open_price
|
|
1001
|
-
);
|
|
1024
|
+
const notional = futures.positions.notional(item.position_qty, price);
|
|
1002
1025
|
const unrealPnl = futures.positions.unrealizedPnL({
|
|
1003
1026
|
qty: item.position_qty,
|
|
1004
1027
|
openPrice: item.average_open_price,
|
|
@@ -1668,6 +1691,7 @@ var useOrderStream = ({
|
|
|
1668
1691
|
side,
|
|
1669
1692
|
size = 100
|
|
1670
1693
|
} = {}) => {
|
|
1694
|
+
const ee = useEventEmitter();
|
|
1671
1695
|
const { data: markPrices = {} } = useMarkPricesStream();
|
|
1672
1696
|
const [doCancelOrder] = useMutation("/v1/order", "DELETE");
|
|
1673
1697
|
const [doUpdateOrder] = useMutation("/v1/order", "PUT");
|
|
@@ -1708,6 +1732,13 @@ var useOrderStream = ({
|
|
|
1708
1732
|
});
|
|
1709
1733
|
});
|
|
1710
1734
|
}, [ordersResponse.data, markPrices]);
|
|
1735
|
+
React2.useEffect(() => {
|
|
1736
|
+
const handler = () => ordersResponse.mutate();
|
|
1737
|
+
ee.on("orders:changed", handler);
|
|
1738
|
+
return () => {
|
|
1739
|
+
ee.off("orders:changed", handler);
|
|
1740
|
+
};
|
|
1741
|
+
}, []);
|
|
1711
1742
|
const cancelAllOrders = React2.useCallback(() => {
|
|
1712
1743
|
}, [ordersResponse.data]);
|
|
1713
1744
|
const updateOrder = React2.useCallback((orderId, order2) => {
|
|
@@ -1741,38 +1772,31 @@ var useMarketTradeStream = (symbol, options = {}) => {
|
|
|
1741
1772
|
if (!symbol) {
|
|
1742
1773
|
throw new Error("useTradeStream: symbol is required");
|
|
1743
1774
|
}
|
|
1744
|
-
React2.useState([]);
|
|
1775
|
+
const [trades, setTrades] = React2.useState([]);
|
|
1745
1776
|
const { level = 20 } = options;
|
|
1746
|
-
const {
|
|
1747
|
-
`/v1/public/market_trades?symbol=${symbol}&limit=${level}
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
// }
|
|
1777
|
+
const { isLoading } = useQuery(
|
|
1778
|
+
`/v1/public/market_trades?symbol=${symbol}&limit=${level}`,
|
|
1779
|
+
{
|
|
1780
|
+
onSuccess: (data) => {
|
|
1781
|
+
if (Array.isArray(data)) {
|
|
1782
|
+
setTrades(() => data);
|
|
1783
|
+
}
|
|
1784
|
+
return data;
|
|
1785
|
+
}
|
|
1786
|
+
}
|
|
1757
1787
|
);
|
|
1758
1788
|
const ws = useWS();
|
|
1759
1789
|
React2.useEffect(() => {
|
|
1760
1790
|
const unsubscript = ws.subscribe(`@${symbol}/@trade`, {
|
|
1761
|
-
onMessage: (
|
|
1762
|
-
console.log("trade",
|
|
1791
|
+
onMessage: (data) => {
|
|
1792
|
+
console.log("ws: trade", data);
|
|
1763
1793
|
}
|
|
1764
1794
|
});
|
|
1765
1795
|
return () => {
|
|
1766
1796
|
unsubscript == null ? void 0 : unsubscript();
|
|
1767
1797
|
};
|
|
1768
1798
|
}, []);
|
|
1769
|
-
return { data, isLoading };
|
|
1770
|
-
};
|
|
1771
|
-
|
|
1772
|
-
// src/orderly/useTrades.tsx
|
|
1773
|
-
var useTradeStream = () => {
|
|
1774
|
-
const { data, isLoading } = usePrivateQuery("/v1/trades");
|
|
1775
|
-
return [data, { isLoading }];
|
|
1799
|
+
return { data: trades, isLoading };
|
|
1776
1800
|
};
|
|
1777
1801
|
var useMarginRatio = () => {
|
|
1778
1802
|
const [{ rows }] = usePositionStream();
|
|
@@ -1853,12 +1877,12 @@ var useBalance = () => {
|
|
|
1853
1877
|
var usePrivateDataObserver = () => {
|
|
1854
1878
|
const ws = useWS();
|
|
1855
1879
|
const { mutate: mutate2 } = useSWR.useSWRConfig();
|
|
1880
|
+
const ee = useEventEmitter();
|
|
1856
1881
|
React2.useEffect(() => {
|
|
1857
1882
|
console.log("subscribe: executionreport");
|
|
1858
1883
|
const unsubscribe = ws.privateSubscribe("executionreport", {
|
|
1859
1884
|
onMessage: (data) => {
|
|
1860
|
-
|
|
1861
|
-
console.log(data);
|
|
1885
|
+
ee.emit("orders:changed");
|
|
1862
1886
|
}
|
|
1863
1887
|
});
|
|
1864
1888
|
return () => unsubscribe == null ? void 0 : unsubscribe();
|
|
@@ -1967,7 +1991,6 @@ exports.useSymbolsInfo = useSymbolsInfo;
|
|
|
1967
1991
|
exports.useTickerStream = useTickerStream;
|
|
1968
1992
|
exports.useTokenInfo = useTokenInfo;
|
|
1969
1993
|
exports.useTopicObserve = useTopicObserve;
|
|
1970
|
-
exports.useTradeStream = useTradeStream;
|
|
1971
1994
|
exports.useTradingView = useTradingView;
|
|
1972
1995
|
exports.useWS = useWS;
|
|
1973
1996
|
//# sourceMappingURL=out.js.map
|