@orderly.network/hooks 0.0.16 → 0.0.18
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 +21 -9
- package/dist/index.d.ts +21 -9
- package/dist/index.js +133 -89
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +131 -86
- package/dist/index.mjs.map +1 -1
- package/package.json +7 -7
package/dist/index.d.mts
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
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, WSMessage } from '@orderly.network/core';
|
|
5
|
-
import { SystemStateEnum, ExchangeStatusEnum, OrderSide, OrderEntity, API } from '@orderly.network/types';
|
|
6
|
-
export { useEventCallback, useObservable } from 'rxjs-hooks';
|
|
4
|
+
import { Account, AccountState, EventEmitter, ConfigStore, OrderlyKeyStore, WalletAdapter, WSMessage } from '@orderly.network/core';
|
|
7
5
|
export { default as useConstant } from 'use-constant';
|
|
8
6
|
import * as react from 'react';
|
|
9
7
|
import { FC, PropsWithChildren } from 'react';
|
|
10
8
|
import { WS } from '@orderly.network/net';
|
|
9
|
+
import { OrderSide, OrderEntity, API } from '@orderly.network/types';
|
|
11
10
|
import * as swr__internal from 'swr/_internal';
|
|
12
11
|
import * as swr_subscription from 'swr/subscription';
|
|
13
12
|
|
|
@@ -54,10 +53,9 @@ declare const useAccount: () => {
|
|
|
54
53
|
connect: () => Promise<any>;
|
|
55
54
|
};
|
|
56
55
|
|
|
57
|
-
declare const useAppState: () => {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
};
|
|
56
|
+
declare const useAppState: () => {};
|
|
57
|
+
|
|
58
|
+
declare const useEventEmitter: (channel?: string) => EventEmitter<string | symbol, any>;
|
|
61
59
|
|
|
62
60
|
declare const DataSourceProvider: FC<PropsWithChildren>;
|
|
63
61
|
|
|
@@ -104,10 +102,12 @@ declare const useOrderbookStream: (symbol: string, initial?: OrderbookData, opti
|
|
|
104
102
|
onDepthChange?: undefined;
|
|
105
103
|
depth?: undefined;
|
|
106
104
|
isLoading?: undefined;
|
|
105
|
+
onItemClick?: undefined;
|
|
107
106
|
} | {
|
|
108
107
|
onDepthChange: (depth: number) => void;
|
|
109
108
|
depth: number;
|
|
110
109
|
isLoading: boolean;
|
|
110
|
+
onItemClick: (item: OrderBookItem) => void;
|
|
111
111
|
})[];
|
|
112
112
|
|
|
113
113
|
interface OrderEntryReturn {
|
|
@@ -158,6 +158,10 @@ declare const useMarkPricesStream: () => swr_subscription.SWRSubscriptionRespons
|
|
|
158
158
|
|
|
159
159
|
declare const useMarkPrice: (symbol: string) => swr_subscription.SWRSubscriptionResponse<any, any>;
|
|
160
160
|
|
|
161
|
+
declare const useLeverage: () => ({
|
|
162
|
+
update: (data: any) => any;
|
|
163
|
+
} | undefined)[];
|
|
164
|
+
|
|
161
165
|
declare const useTickerStream: (symbol: string) => any;
|
|
162
166
|
|
|
163
167
|
declare const useFundingRate$1: (symbol: string) => {
|
|
@@ -189,11 +193,13 @@ declare const useOrderStream: ({ status, symbol, }?: {
|
|
|
189
193
|
cancelOrder: (orderId: string, symbol?: string) => any;
|
|
190
194
|
} | null)[];
|
|
191
195
|
|
|
192
|
-
declare const
|
|
196
|
+
declare const useMarketTradeStream: (symbol: string) => {
|
|
193
197
|
data: API.Trade[] | undefined;
|
|
194
198
|
isLoading: boolean;
|
|
195
199
|
};
|
|
196
200
|
|
|
201
|
+
declare const useTradeStream: () => unknown[];
|
|
202
|
+
|
|
197
203
|
type CollateralOutputs = {
|
|
198
204
|
totalCollateral: number;
|
|
199
205
|
freeCollateral: number;
|
|
@@ -218,6 +224,12 @@ type inputOptions = {
|
|
|
218
224
|
};
|
|
219
225
|
declare const useChains: (networkId?: "testnet" | "mainnet", options?: inputOptions) => any[];
|
|
220
226
|
|
|
227
|
+
declare const useBalance: () => any;
|
|
228
|
+
|
|
229
|
+
declare const usePrivateDataObserver: () => void;
|
|
230
|
+
|
|
231
|
+
declare const useExecutionReport: () => any;
|
|
232
|
+
|
|
221
233
|
interface Info {
|
|
222
234
|
symbol: string;
|
|
223
235
|
quote_min: number;
|
|
@@ -283,4 +295,4 @@ declare namespace index {
|
|
|
283
295
|
};
|
|
284
296
|
}
|
|
285
297
|
|
|
286
|
-
export { DataSourceProvider, OrderStatus, OrderlyAppConfig, OrderlyContext, OrderlyContextState, OrderlyProvider, index as apis, useAccount, useAccountInfo, useAppState, useChains, useCollateral, useFetures, useFundingRate$1 as useFundingRate, useMarginRatio, useMarkPrice, useMarkPricesStream, useMarketsStream, useMaxQty, useMutation, useOrderEntry, useOrderStream, useOrderbookStream, usePositionStream, usePrivateObserve, usePrivateQuery, useQuery, useSymbolsInfo, useTickerStream, useTokenInfo, useTopicObserve, useTradeStream, useTradingView, useWS };
|
|
298
|
+
export { DataSourceProvider, OrderStatus, OrderlyAppConfig, OrderlyContext, OrderlyContextState, OrderlyProvider, index as apis, useAccount, useAccountInfo, useAppState, useBalance, useChains, useCollateral, useEventEmitter, useExecutionReport, useFetures, useFundingRate$1 as useFundingRate, useLeverage, useMarginRatio, useMarkPrice, useMarkPricesStream, useMarketTradeStream, useMarketsStream, useMaxQty, useMutation, useOrderEntry, useOrderStream, useOrderbookStream, usePositionStream, usePrivateDataObserver, usePrivateObserve, usePrivateQuery, useQuery, useSymbolsInfo, useTickerStream, useTokenInfo, useTopicObserve, useTradeStream, useTradingView, useWS };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
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, WSMessage } from '@orderly.network/core';
|
|
5
|
-
import { SystemStateEnum, ExchangeStatusEnum, OrderSide, OrderEntity, API } from '@orderly.network/types';
|
|
6
|
-
export { useEventCallback, useObservable } from 'rxjs-hooks';
|
|
4
|
+
import { Account, AccountState, EventEmitter, ConfigStore, OrderlyKeyStore, WalletAdapter, WSMessage } from '@orderly.network/core';
|
|
7
5
|
export { default as useConstant } from 'use-constant';
|
|
8
6
|
import * as react from 'react';
|
|
9
7
|
import { FC, PropsWithChildren } from 'react';
|
|
10
8
|
import { WS } from '@orderly.network/net';
|
|
9
|
+
import { OrderSide, OrderEntity, API } from '@orderly.network/types';
|
|
11
10
|
import * as swr__internal from 'swr/_internal';
|
|
12
11
|
import * as swr_subscription from 'swr/subscription';
|
|
13
12
|
|
|
@@ -54,10 +53,9 @@ declare const useAccount: () => {
|
|
|
54
53
|
connect: () => Promise<any>;
|
|
55
54
|
};
|
|
56
55
|
|
|
57
|
-
declare const useAppState: () => {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
};
|
|
56
|
+
declare const useAppState: () => {};
|
|
57
|
+
|
|
58
|
+
declare const useEventEmitter: (channel?: string) => EventEmitter<string | symbol, any>;
|
|
61
59
|
|
|
62
60
|
declare const DataSourceProvider: FC<PropsWithChildren>;
|
|
63
61
|
|
|
@@ -104,10 +102,12 @@ declare const useOrderbookStream: (symbol: string, initial?: OrderbookData, opti
|
|
|
104
102
|
onDepthChange?: undefined;
|
|
105
103
|
depth?: undefined;
|
|
106
104
|
isLoading?: undefined;
|
|
105
|
+
onItemClick?: undefined;
|
|
107
106
|
} | {
|
|
108
107
|
onDepthChange: (depth: number) => void;
|
|
109
108
|
depth: number;
|
|
110
109
|
isLoading: boolean;
|
|
110
|
+
onItemClick: (item: OrderBookItem) => void;
|
|
111
111
|
})[];
|
|
112
112
|
|
|
113
113
|
interface OrderEntryReturn {
|
|
@@ -158,6 +158,10 @@ declare const useMarkPricesStream: () => swr_subscription.SWRSubscriptionRespons
|
|
|
158
158
|
|
|
159
159
|
declare const useMarkPrice: (symbol: string) => swr_subscription.SWRSubscriptionResponse<any, any>;
|
|
160
160
|
|
|
161
|
+
declare const useLeverage: () => ({
|
|
162
|
+
update: (data: any) => any;
|
|
163
|
+
} | undefined)[];
|
|
164
|
+
|
|
161
165
|
declare const useTickerStream: (symbol: string) => any;
|
|
162
166
|
|
|
163
167
|
declare const useFundingRate$1: (symbol: string) => {
|
|
@@ -189,11 +193,13 @@ declare const useOrderStream: ({ status, symbol, }?: {
|
|
|
189
193
|
cancelOrder: (orderId: string, symbol?: string) => any;
|
|
190
194
|
} | null)[];
|
|
191
195
|
|
|
192
|
-
declare const
|
|
196
|
+
declare const useMarketTradeStream: (symbol: string) => {
|
|
193
197
|
data: API.Trade[] | undefined;
|
|
194
198
|
isLoading: boolean;
|
|
195
199
|
};
|
|
196
200
|
|
|
201
|
+
declare const useTradeStream: () => unknown[];
|
|
202
|
+
|
|
197
203
|
type CollateralOutputs = {
|
|
198
204
|
totalCollateral: number;
|
|
199
205
|
freeCollateral: number;
|
|
@@ -218,6 +224,12 @@ type inputOptions = {
|
|
|
218
224
|
};
|
|
219
225
|
declare const useChains: (networkId?: "testnet" | "mainnet", options?: inputOptions) => any[];
|
|
220
226
|
|
|
227
|
+
declare const useBalance: () => any;
|
|
228
|
+
|
|
229
|
+
declare const usePrivateDataObserver: () => void;
|
|
230
|
+
|
|
231
|
+
declare const useExecutionReport: () => any;
|
|
232
|
+
|
|
221
233
|
interface Info {
|
|
222
234
|
symbol: string;
|
|
223
235
|
quote_min: number;
|
|
@@ -283,4 +295,4 @@ declare namespace index {
|
|
|
283
295
|
};
|
|
284
296
|
}
|
|
285
297
|
|
|
286
|
-
export { DataSourceProvider, OrderStatus, OrderlyAppConfig, OrderlyContext, OrderlyContextState, OrderlyProvider, index as apis, useAccount, useAccountInfo, useAppState, useChains, useCollateral, useFetures, useFundingRate$1 as useFundingRate, useMarginRatio, useMarkPrice, useMarkPricesStream, useMarketsStream, useMaxQty, useMutation, useOrderEntry, useOrderStream, useOrderbookStream, usePositionStream, usePrivateObserve, usePrivateQuery, useQuery, useSymbolsInfo, useTickerStream, useTokenInfo, useTopicObserve, useTradeStream, useTradingView, useWS };
|
|
298
|
+
export { DataSourceProvider, OrderStatus, OrderlyAppConfig, OrderlyContext, OrderlyContextState, OrderlyProvider, index as apis, useAccount, useAccountInfo, useAppState, useBalance, useChains, useCollateral, useEventEmitter, useExecutionReport, useFetures, useFundingRate$1 as useFundingRate, useLeverage, useMarginRatio, useMarkPrice, useMarkPricesStream, useMarketTradeStream, useMarketsStream, useMaxQty, useMutation, useOrderEntry, useOrderStream, useOrderbookStream, usePositionStream, usePrivateDataObserver, usePrivateObserve, usePrivateQuery, useQuery, useSymbolsInfo, useTickerStream, useTokenInfo, useTopicObserve, useTradeStream, useTradingView, useWS };
|
package/dist/index.js
CHANGED
|
@@ -8,11 +8,9 @@ var useConstant = require('use-constant');
|
|
|
8
8
|
var core = require('@orderly.network/core');
|
|
9
9
|
var types = require('@orderly.network/types');
|
|
10
10
|
var rxjs = require('rxjs');
|
|
11
|
-
var operators = require('rxjs/operators');
|
|
12
|
-
var rxjsHooks = require('rxjs-hooks');
|
|
13
|
-
var ramda = require('ramda');
|
|
14
11
|
var useSWRSubscription = require('swr/subscription');
|
|
15
12
|
var utils = require('@orderly.network/utils');
|
|
13
|
+
var ramda = require('ramda');
|
|
16
14
|
var futures = require('@orderly.network/futures');
|
|
17
15
|
var useSWRInfinite = require('swr/infinite');
|
|
18
16
|
|
|
@@ -33,26 +31,26 @@ var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
|
33
31
|
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
34
32
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
35
33
|
var __spreadValues = (a, b) => {
|
|
36
|
-
for (var
|
|
37
|
-
if (__hasOwnProp.call(b,
|
|
38
|
-
__defNormalProp(a,
|
|
34
|
+
for (var prop2 in b || (b = {}))
|
|
35
|
+
if (__hasOwnProp.call(b, prop2))
|
|
36
|
+
__defNormalProp(a, prop2, b[prop2]);
|
|
39
37
|
if (__getOwnPropSymbols)
|
|
40
|
-
for (var
|
|
41
|
-
if (__propIsEnum.call(b,
|
|
42
|
-
__defNormalProp(a,
|
|
38
|
+
for (var prop2 of __getOwnPropSymbols(b)) {
|
|
39
|
+
if (__propIsEnum.call(b, prop2))
|
|
40
|
+
__defNormalProp(a, prop2, b[prop2]);
|
|
43
41
|
}
|
|
44
42
|
return a;
|
|
45
43
|
};
|
|
46
44
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
47
45
|
var __objRest = (source, exclude) => {
|
|
48
46
|
var target = {};
|
|
49
|
-
for (var
|
|
50
|
-
if (__hasOwnProp.call(source,
|
|
51
|
-
target[
|
|
47
|
+
for (var prop2 in source)
|
|
48
|
+
if (__hasOwnProp.call(source, prop2) && exclude.indexOf(prop2) < 0)
|
|
49
|
+
target[prop2] = source[prop2];
|
|
52
50
|
if (source != null && __getOwnPropSymbols)
|
|
53
|
-
for (var
|
|
54
|
-
if (exclude.indexOf(
|
|
55
|
-
target[
|
|
51
|
+
for (var prop2 of __getOwnPropSymbols(source)) {
|
|
52
|
+
if (exclude.indexOf(prop2) < 0 && __propIsEnum.call(source, prop2))
|
|
53
|
+
target[prop2] = source[prop2];
|
|
56
54
|
}
|
|
57
55
|
return target;
|
|
58
56
|
};
|
|
@@ -259,9 +257,9 @@ var useAccount = () => {
|
|
|
259
257
|
const connect = React.useCallback(() => __async(void 0, null, function* () {
|
|
260
258
|
return onWalletConnect == null ? void 0 : onWalletConnect();
|
|
261
259
|
}), [account4]);
|
|
262
|
-
const disconnect =
|
|
260
|
+
const disconnect = () => __async(void 0, null, function* () {
|
|
263
261
|
return onWalletDisconnect == null ? void 0 : onWalletDisconnect();
|
|
264
|
-
})
|
|
262
|
+
});
|
|
265
263
|
return {
|
|
266
264
|
// account: state!,
|
|
267
265
|
account: account4,
|
|
@@ -345,21 +343,18 @@ function getAppState() {
|
|
|
345
343
|
|
|
346
344
|
// src/useAppState.ts
|
|
347
345
|
var useAppState = () => {
|
|
348
|
-
|
|
349
|
-
return
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
),
|
|
358
|
-
{
|
|
359
|
-
systemState: appState.systemState$.value,
|
|
360
|
-
exchangeState: appState.exchangeState$.value
|
|
346
|
+
getAppState();
|
|
347
|
+
return {};
|
|
348
|
+
};
|
|
349
|
+
var useEventEmitter = (channel) => {
|
|
350
|
+
return useConstant__default.default(() => {
|
|
351
|
+
let ee = core.SimpleDI.get("EE");
|
|
352
|
+
if (!ee) {
|
|
353
|
+
ee = new core.EventEmitter();
|
|
354
|
+
core.SimpleDI.registerByName("EE", ee);
|
|
361
355
|
}
|
|
362
|
-
|
|
356
|
+
return ee;
|
|
357
|
+
});
|
|
363
358
|
};
|
|
364
359
|
var DataSourceContext = React.createContext({});
|
|
365
360
|
var DataSourceProvider = (props) => {
|
|
@@ -389,6 +384,11 @@ var useWS = () => {
|
|
|
389
384
|
return __spreadProps(__spreadValues({}, result), { timestamp });
|
|
390
385
|
})
|
|
391
386
|
});
|
|
387
|
+
account4.on("change:status", (nextState) => {
|
|
388
|
+
if (nextState.status === types.AccountStatusEnum.EnableTrading && nextState.accountId) {
|
|
389
|
+
websocketClient.openPrivate(nextState.accountId);
|
|
390
|
+
}
|
|
391
|
+
});
|
|
392
392
|
core.SimpleDI.registerByName(WS_NAME, websocketClient);
|
|
393
393
|
}
|
|
394
394
|
return websocketClient;
|
|
@@ -468,8 +468,6 @@ var useMarkPrice = (symbol) => {
|
|
|
468
468
|
};
|
|
469
469
|
|
|
470
470
|
// src/orderly/useOrderbookStream.ts
|
|
471
|
-
ramda.compose(ramda.defaultTo(0), ramda.head, ramda.last, ramda.pathOr([], ["asks"]));
|
|
472
|
-
ramda.pathOr(0, ["bids", 0, 0]);
|
|
473
471
|
var paddingFn = (len) => Array(len).fill([Number.NaN, Number.NaN, Number.NaN]);
|
|
474
472
|
var asksSortFn = (a, b) => a[0] - b[0];
|
|
475
473
|
var bidsSortFn = (a, b) => b[0] - a[0];
|
|
@@ -546,6 +544,7 @@ var useOrderbookStream = (symbol, initial = { asks: [], bids: [] }, options) =>
|
|
|
546
544
|
});
|
|
547
545
|
const ws = useWS();
|
|
548
546
|
const ticker = useTickerStream(symbol);
|
|
547
|
+
const eventEmitter = useEventEmitter();
|
|
549
548
|
React.useEffect(() => {
|
|
550
549
|
ws.onceSubscribe(
|
|
551
550
|
{
|
|
@@ -594,6 +593,9 @@ var useOrderbookStream = (symbol, initial = { asks: [], bids: [] }, options) =>
|
|
|
594
593
|
subscription == null ? void 0 : subscription();
|
|
595
594
|
};
|
|
596
595
|
}, [symbol, requestData]);
|
|
596
|
+
const onItemClick = React.useCallback((item) => {
|
|
597
|
+
eventEmitter.emit("orderbook:item:click", item);
|
|
598
|
+
}, []);
|
|
597
599
|
const onDepthChange = React.useCallback((depth2) => {
|
|
598
600
|
console.log("Orderbook depth has changed:", depth2);
|
|
599
601
|
}, []);
|
|
@@ -611,7 +613,7 @@ var useOrderbookStream = (symbol, initial = { asks: [], bids: [] }, options) =>
|
|
|
611
613
|
}, [ticker, data]);
|
|
612
614
|
return [
|
|
613
615
|
__spreadProps(__spreadValues({}, data), { markPrice, middlePrice }),
|
|
614
|
-
{ onDepthChange, depth, isLoading }
|
|
616
|
+
{ onDepthChange, depth, isLoading, onItemClick }
|
|
615
617
|
];
|
|
616
618
|
};
|
|
617
619
|
|
|
@@ -723,7 +725,6 @@ function priceInputHandle(inputs) {
|
|
|
723
725
|
}
|
|
724
726
|
const price = new utils.Decimal(value);
|
|
725
727
|
const priceDP = price.dp();
|
|
726
|
-
console.log("priceInputHandle", priceDP, config.quoteDP);
|
|
727
728
|
if (priceDP > config.quoteDP) {
|
|
728
729
|
values.order_price = price.toDecimalPlaces(config.quoteDP).toString();
|
|
729
730
|
}
|
|
@@ -874,7 +875,11 @@ var usePositionStream = (symbol, options) => {
|
|
|
874
875
|
const symbolInfo = useSymbolsInfo();
|
|
875
876
|
const { data: accountInfo } = usePrivateQuery("/v1/client/info");
|
|
876
877
|
const fundingRates = useFundingRates();
|
|
877
|
-
const { data, error } = usePrivateQuery(`/v1/positions`, __spreadProps(__spreadValues({
|
|
878
|
+
const { data, error } = usePrivateQuery(`/v1/positions`, __spreadProps(__spreadValues({
|
|
879
|
+
// revalidateOnFocus: false,
|
|
880
|
+
// revalidateOnReconnect: false,
|
|
881
|
+
dedupingInterval: 5e3
|
|
882
|
+
}, options), {
|
|
878
883
|
formatter: (data2) => data2,
|
|
879
884
|
onError: (err) => {
|
|
880
885
|
console.log("usePositionStream error", err);
|
|
@@ -1133,7 +1138,7 @@ var BaseOrderCreator = class {
|
|
|
1133
1138
|
// symbol: data.symbol,
|
|
1134
1139
|
order_type: data.order_type === types.OrderType.LIMIT ? !!data.order_type_ext ? data.order_type_ext : data.order_type : data.order_type,
|
|
1135
1140
|
side: data.side,
|
|
1136
|
-
|
|
1141
|
+
reduce_only: data.reduce_only,
|
|
1137
1142
|
order_quantity: data.order_quantity
|
|
1138
1143
|
};
|
|
1139
1144
|
if (data.visible_quantity === 0) {
|
|
@@ -1151,32 +1156,40 @@ var BaseOrderCreator = class {
|
|
|
1151
1156
|
message: "quantity is required"
|
|
1152
1157
|
};
|
|
1153
1158
|
} else {
|
|
1154
|
-
const {
|
|
1159
|
+
const { base_min, quote_dp, base_dp } = configs.symbol;
|
|
1155
1160
|
const qty = new utils.Decimal(order_quantity);
|
|
1156
1161
|
if (qty.lt(base_min)) {
|
|
1157
1162
|
errors.order_quantity = {
|
|
1158
1163
|
type: "min",
|
|
1159
|
-
message: `quantity must be greater than ${base_min
|
|
1164
|
+
message: `quantity must be greater than ${new utils.Decimal(base_min).todp(
|
|
1165
|
+
base_dp
|
|
1166
|
+
)}`
|
|
1160
1167
|
};
|
|
1161
1168
|
} else if (qty.gt(maxQty)) {
|
|
1162
1169
|
errors.order_quantity = {
|
|
1163
1170
|
type: "max",
|
|
1164
|
-
message: `quantity must be less than ${maxQty
|
|
1171
|
+
message: `quantity must be less than ${new utils.Decimal(maxQty).todp(
|
|
1172
|
+
base_dp
|
|
1173
|
+
)}`
|
|
1165
1174
|
};
|
|
1166
1175
|
}
|
|
1167
1176
|
}
|
|
1168
1177
|
if (!!total) {
|
|
1169
|
-
const { quote_max, quote_min } = configs.symbol;
|
|
1178
|
+
const { quote_max, quote_min, quote_dp } = configs.symbol;
|
|
1170
1179
|
const totalNumber = new utils.Decimal(total);
|
|
1171
1180
|
if (totalNumber.lt(quote_min)) {
|
|
1172
1181
|
errors.total = {
|
|
1173
1182
|
type: "min",
|
|
1174
|
-
message: `Quantity should be greater or equal than ${
|
|
1183
|
+
message: `Quantity should be greater or equal than ${new utils.Decimal(
|
|
1184
|
+
quote_min
|
|
1185
|
+
).todp(quote_dp)}`
|
|
1175
1186
|
};
|
|
1176
1187
|
} else if (totalNumber.gt(quote_max)) {
|
|
1177
1188
|
errors.total = {
|
|
1178
1189
|
type: "max",
|
|
1179
|
-
message: `Quantity should be less or equal than ${
|
|
1190
|
+
message: `Quantity should be less or equal than ${new utils.Decimal(
|
|
1191
|
+
quote_max
|
|
1192
|
+
).todp(quote_dp)}`
|
|
1180
1193
|
};
|
|
1181
1194
|
}
|
|
1182
1195
|
}
|
|
@@ -1352,29 +1365,6 @@ var useOrderEntry = (symbol, side, reduceOnly = false, options) => {
|
|
|
1352
1365
|
symbolConfig: symbolInfo[symbol]()
|
|
1353
1366
|
};
|
|
1354
1367
|
};
|
|
1355
|
-
var WS_NAME2 = "websocketClient";
|
|
1356
|
-
var useWebSocketClient = () => {
|
|
1357
|
-
const ws = useConstant__default.default(() => {
|
|
1358
|
-
let websocketClient = core.SimpleDI.get(WS_NAME2);
|
|
1359
|
-
if (!websocketClient) {
|
|
1360
|
-
websocketClient = new net.WebSocketClient({
|
|
1361
|
-
accountId: "OqdphuyCtYWxwzhxyLLjOWNdFP7sQt8RPWzmb5xY",
|
|
1362
|
-
networkId: "testnet",
|
|
1363
|
-
onSigntureRequest: (accountId) => __async(void 0, null, function* () {
|
|
1364
|
-
const signer = core.getMockSigner();
|
|
1365
|
-
const timestamp = (/* @__PURE__ */ new Date()).getTime();
|
|
1366
|
-
const result = yield signer.signText(timestamp.toString());
|
|
1367
|
-
return __spreadProps(__spreadValues({}, result), { timestamp });
|
|
1368
|
-
})
|
|
1369
|
-
});
|
|
1370
|
-
core.SimpleDI.registerByName(WS_NAME2, websocketClient);
|
|
1371
|
-
}
|
|
1372
|
-
return websocketClient;
|
|
1373
|
-
});
|
|
1374
|
-
return ws;
|
|
1375
|
-
};
|
|
1376
|
-
|
|
1377
|
-
// src/orderly/useFetures.ts
|
|
1378
1368
|
var useFetures = () => {
|
|
1379
1369
|
const { data, isLoading, error } = useQuery(
|
|
1380
1370
|
`/v1/public/futures`,
|
|
@@ -1383,14 +1373,8 @@ var useFetures = () => {
|
|
|
1383
1373
|
}
|
|
1384
1374
|
);
|
|
1385
1375
|
const [sortedData, setSortedData] = React.useState(data);
|
|
1386
|
-
|
|
1376
|
+
useWS();
|
|
1387
1377
|
React.useEffect(() => {
|
|
1388
|
-
const sub = ws.observe(`tickers`).subscribe((value) => {
|
|
1389
|
-
console.log("useTickers", value);
|
|
1390
|
-
});
|
|
1391
|
-
return () => {
|
|
1392
|
-
sub.unsubscribe();
|
|
1393
|
-
};
|
|
1394
1378
|
}, []);
|
|
1395
1379
|
React.useEffect(() => {
|
|
1396
1380
|
if (data) {
|
|
@@ -1466,6 +1450,16 @@ var useMarketsStream = () => {
|
|
|
1466
1450
|
}, [futures, tickers]);
|
|
1467
1451
|
return { data: value };
|
|
1468
1452
|
};
|
|
1453
|
+
var useLeverage = () => {
|
|
1454
|
+
const { data, mutate: mutate2 } = usePrivateQuery("/v1/client/info");
|
|
1455
|
+
const [update] = useMutation("/v1/client/leverage");
|
|
1456
|
+
const updateLeverage = React.useCallback((data2) => {
|
|
1457
|
+
return update(data2).then((res) => {
|
|
1458
|
+
return mutate2();
|
|
1459
|
+
});
|
|
1460
|
+
}, []);
|
|
1461
|
+
return [ramda.prop("max_leverage", data), { update: updateLeverage }];
|
|
1462
|
+
};
|
|
1469
1463
|
var useFundingRate = (symbol) => {
|
|
1470
1464
|
if (!symbol) {
|
|
1471
1465
|
throw new Error("useFuturesForSymbol requires a symbol");
|
|
@@ -1586,12 +1580,6 @@ var useOrderStream = ({
|
|
|
1586
1580
|
}, []);
|
|
1587
1581
|
return [
|
|
1588
1582
|
orders,
|
|
1589
|
-
// {
|
|
1590
|
-
// ...res,
|
|
1591
|
-
// data: res.data?.reduce((acc, cur) => {
|
|
1592
|
-
// return [...acc, ...cur];
|
|
1593
|
-
// }, []),
|
|
1594
|
-
// },
|
|
1595
1583
|
{
|
|
1596
1584
|
cancelAllOrders,
|
|
1597
1585
|
updateOrder,
|
|
@@ -1600,8 +1588,8 @@ var useOrderStream = ({
|
|
|
1600
1588
|
];
|
|
1601
1589
|
};
|
|
1602
1590
|
|
|
1603
|
-
// src/orderly/
|
|
1604
|
-
var
|
|
1591
|
+
// src/orderly/useMarketTradeStream.ts
|
|
1592
|
+
var useMarketTradeStream = (symbol) => {
|
|
1605
1593
|
if (!symbol) {
|
|
1606
1594
|
throw new Error("useTradeStream: symbol is required");
|
|
1607
1595
|
}
|
|
@@ -1610,6 +1598,12 @@ var useTradeStream = (symbol) => {
|
|
|
1610
1598
|
);
|
|
1611
1599
|
return { data, isLoading };
|
|
1612
1600
|
};
|
|
1601
|
+
|
|
1602
|
+
// src/orderly/useTrades.tsx
|
|
1603
|
+
var useTradeStream = () => {
|
|
1604
|
+
const { data, isLoading } = usePrivateQuery("/v1/trades");
|
|
1605
|
+
return [data, { isLoading }];
|
|
1606
|
+
};
|
|
1613
1607
|
var useMarginRatio = () => {
|
|
1614
1608
|
const [{ rows }] = usePositionStream();
|
|
1615
1609
|
const { data: markPrices } = useMarkPricesStream();
|
|
@@ -1670,6 +1664,58 @@ var useChains = (networkId, options) => {
|
|
|
1670
1664
|
);
|
|
1671
1665
|
return [chains, { findByChainId }];
|
|
1672
1666
|
};
|
|
1667
|
+
var useBalance = () => {
|
|
1668
|
+
const ws = useWS();
|
|
1669
|
+
const { data } = useSWRSubscription__default.default("balance", (_, { next }) => {
|
|
1670
|
+
const unsubscribe = ws.privateSubscribe("balance", {
|
|
1671
|
+
onMessage: (data2) => {
|
|
1672
|
+
console.log(data2);
|
|
1673
|
+
}
|
|
1674
|
+
});
|
|
1675
|
+
return () => unsubscribe();
|
|
1676
|
+
});
|
|
1677
|
+
return data;
|
|
1678
|
+
};
|
|
1679
|
+
var usePrivateDataObserver = () => {
|
|
1680
|
+
const ws = useWS();
|
|
1681
|
+
const { mutate: mutate2 } = useSWR.useSWRConfig();
|
|
1682
|
+
React.useEffect(() => {
|
|
1683
|
+
console.log("subscribe: executionreport");
|
|
1684
|
+
const unsubscribe = ws.privateSubscribe("executionreport", {
|
|
1685
|
+
onMessage: (data) => {
|
|
1686
|
+
console.info("refresh orders");
|
|
1687
|
+
mutate2("/v1/orders");
|
|
1688
|
+
}
|
|
1689
|
+
});
|
|
1690
|
+
return () => unsubscribe == null ? void 0 : unsubscribe();
|
|
1691
|
+
}, []);
|
|
1692
|
+
React.useEffect(() => {
|
|
1693
|
+
console.log("subscribe: position");
|
|
1694
|
+
const unsubscribe = ws.privateSubscribe("position", {
|
|
1695
|
+
onMessage: (data) => {
|
|
1696
|
+
const { positions: nextPostions } = data;
|
|
1697
|
+
console.info("refresh positions", nextPostions);
|
|
1698
|
+
mutate2("/v1/positions");
|
|
1699
|
+
}
|
|
1700
|
+
});
|
|
1701
|
+
return () => {
|
|
1702
|
+
console.log("unsubscribe: private subscription position");
|
|
1703
|
+
unsubscribe == null ? void 0 : unsubscribe();
|
|
1704
|
+
};
|
|
1705
|
+
}, []);
|
|
1706
|
+
};
|
|
1707
|
+
var useExecutionReport = () => {
|
|
1708
|
+
const ws = useWS();
|
|
1709
|
+
const { data } = useSWRSubscription__default.default("executionreport", (_, { next }) => {
|
|
1710
|
+
const unsubscribe = ws.privateSubscribe("executionreport", {
|
|
1711
|
+
onMessage: (data2) => {
|
|
1712
|
+
console.log(data2);
|
|
1713
|
+
}
|
|
1714
|
+
});
|
|
1715
|
+
return () => unsubscribe();
|
|
1716
|
+
});
|
|
1717
|
+
return data;
|
|
1718
|
+
};
|
|
1673
1719
|
|
|
1674
1720
|
// src/apis/index.ts
|
|
1675
1721
|
var apis_exports = {};
|
|
@@ -1713,14 +1759,6 @@ Object.defineProperty(exports, 'useConstant', {
|
|
|
1713
1759
|
enumerable: true,
|
|
1714
1760
|
get: function () { return useConstant__default.default; }
|
|
1715
1761
|
});
|
|
1716
|
-
Object.defineProperty(exports, 'useEventCallback', {
|
|
1717
|
-
enumerable: true,
|
|
1718
|
-
get: function () { return rxjsHooks.useEventCallback; }
|
|
1719
|
-
});
|
|
1720
|
-
Object.defineProperty(exports, 'useObservable', {
|
|
1721
|
-
enumerable: true,
|
|
1722
|
-
get: function () { return rxjsHooks.useObservable; }
|
|
1723
|
-
});
|
|
1724
1762
|
exports.DataSourceProvider = DataSourceProvider;
|
|
1725
1763
|
exports.OrderStatus = OrderStatus;
|
|
1726
1764
|
exports.OrderlyContext = OrderlyContext;
|
|
@@ -1729,13 +1767,18 @@ exports.apis = apis_exports;
|
|
|
1729
1767
|
exports.useAccount = useAccount;
|
|
1730
1768
|
exports.useAccountInfo = useAccountInfo;
|
|
1731
1769
|
exports.useAppState = useAppState;
|
|
1770
|
+
exports.useBalance = useBalance;
|
|
1732
1771
|
exports.useChains = useChains;
|
|
1733
1772
|
exports.useCollateral = useCollateral;
|
|
1773
|
+
exports.useEventEmitter = useEventEmitter;
|
|
1774
|
+
exports.useExecutionReport = useExecutionReport;
|
|
1734
1775
|
exports.useFetures = useFetures;
|
|
1735
1776
|
exports.useFundingRate = useFundingRate;
|
|
1777
|
+
exports.useLeverage = useLeverage;
|
|
1736
1778
|
exports.useMarginRatio = useMarginRatio;
|
|
1737
1779
|
exports.useMarkPrice = useMarkPrice;
|
|
1738
1780
|
exports.useMarkPricesStream = useMarkPricesStream;
|
|
1781
|
+
exports.useMarketTradeStream = useMarketTradeStream;
|
|
1739
1782
|
exports.useMarketsStream = useMarketsStream;
|
|
1740
1783
|
exports.useMaxQty = useMaxQty;
|
|
1741
1784
|
exports.useMutation = useMutation;
|
|
@@ -1743,6 +1786,7 @@ exports.useOrderEntry = useOrderEntry;
|
|
|
1743
1786
|
exports.useOrderStream = useOrderStream;
|
|
1744
1787
|
exports.useOrderbookStream = useOrderbookStream;
|
|
1745
1788
|
exports.usePositionStream = usePositionStream;
|
|
1789
|
+
exports.usePrivateDataObserver = usePrivateDataObserver;
|
|
1746
1790
|
exports.usePrivateObserve = usePrivateObserve;
|
|
1747
1791
|
exports.usePrivateQuery = usePrivateQuery;
|
|
1748
1792
|
exports.useQuery = useQuery;
|