@orderly.network/hooks 1.1.4-rc.4 → 1.1.4

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.
Files changed (475) hide show
  1. package/esm/configProvider.d.ts +17 -0
  2. package/esm/configProvider.d.ts.map +1 -0
  3. package/esm/configProvider.js +54 -0
  4. package/esm/dataProvider.d.ts +10 -0
  5. package/esm/dataProvider.d.ts.map +1 -0
  6. package/esm/dataProvider.js +29 -0
  7. package/esm/index.d.ts +33 -0
  8. package/esm/index.d.ts.map +1 -0
  9. package/esm/index.js +30 -0
  10. package/esm/middleware/signatureMiddleware.d.ts +3 -0
  11. package/esm/middleware/signatureMiddleware.d.ts.map +1 -0
  12. package/esm/middleware/signatureMiddleware.js +32 -0
  13. package/esm/orderly/orderlyHooks.d.ts +30 -0
  14. package/esm/orderly/orderlyHooks.d.ts.map +1 -0
  15. package/esm/orderly/orderlyHooks.js +27 -0
  16. package/esm/orderly/useAccountInfo.d.ts +3 -0
  17. package/esm/orderly/useAccountInfo.d.ts.map +1 -0
  18. package/esm/orderly/useAccountInfo.js +4 -0
  19. package/esm/orderly/useChain.d.ts +6 -0
  20. package/esm/orderly/useChain.d.ts.map +1 -0
  21. package/esm/orderly/useChain.js +22 -0
  22. package/esm/orderly/useChains.d.ts +34 -0
  23. package/esm/orderly/useChains.d.ts.map +1 -0
  24. package/esm/orderly/useChains.js +159 -0
  25. package/esm/orderly/useCollateral.d.ts +16 -0
  26. package/esm/orderly/useCollateral.d.ts.map +1 -0
  27. package/esm/orderly/useCollateral.js +72 -0
  28. package/esm/orderly/useDeposit.d.ts +38 -0
  29. package/esm/orderly/useDeposit.d.ts.map +1 -0
  30. package/esm/orderly/useDeposit.js +270 -0
  31. package/esm/orderly/useFundingRate.d.ts +11 -0
  32. package/esm/orderly/useFundingRate.d.ts.map +1 -0
  33. package/esm/orderly/useFundingRate.js +40 -0
  34. package/esm/orderly/useFundingRates.d.ts +2 -0
  35. package/esm/orderly/useFundingRates.d.ts.map +1 -0
  36. package/esm/orderly/useFundingRates.js +21 -0
  37. package/esm/orderly/useHoldingStream.d.ts +7 -0
  38. package/esm/orderly/useHoldingStream.d.ts.map +1 -0
  39. package/esm/orderly/useHoldingStream.js +47 -0
  40. package/esm/orderly/useIndexPrice.d.ts +2 -0
  41. package/esm/orderly/useIndexPrice.d.ts.map +1 -0
  42. package/esm/orderly/useIndexPrice.js +17 -0
  43. package/esm/orderly/useLeverage.d.ts +2 -0
  44. package/esm/orderly/useLeverage.d.ts.map +1 -0
  45. package/esm/orderly/useLeverage.js +34 -0
  46. package/esm/orderly/useMarginRatio.d.ts +7 -0
  47. package/esm/orderly/useMarginRatio.d.ts.map +1 -0
  48. package/esm/orderly/useMarginRatio.js +41 -0
  49. package/esm/orderly/useMarkPrice.d.ts +4 -0
  50. package/esm/orderly/useMarkPrice.d.ts.map +1 -0
  51. package/esm/orderly/useMarkPrice.js +29 -0
  52. package/esm/orderly/useMarkPricesStream.d.ts +2 -0
  53. package/esm/orderly/useMarkPricesStream.d.ts.map +1 -0
  54. package/esm/orderly/useMarkPricesStream.js +26 -0
  55. package/esm/orderly/useMarketTradeStream.d.ts +9 -0
  56. package/esm/orderly/useMarketTradeStream.d.ts.map +1 -0
  57. package/esm/orderly/useMarketTradeStream.js +51 -0
  58. package/esm/orderly/useMarkets.d.ts +36 -0
  59. package/esm/orderly/useMarkets.d.ts.map +1 -0
  60. package/esm/orderly/useMarkets.js +240 -0
  61. package/esm/orderly/useMarketsStream.d.ts +5 -0
  62. package/esm/orderly/useMarketsStream.d.ts.map +1 -0
  63. package/esm/orderly/useMarketsStream.js +57 -0
  64. package/esm/orderly/useMaxQty.d.ts +3 -0
  65. package/esm/orderly/useMaxQty.d.ts.map +1 -0
  66. package/esm/orderly/useMaxQty.js +114 -0
  67. package/esm/orderly/useOpenInterest.d.ts +2 -0
  68. package/esm/orderly/useOpenInterest.d.ts.map +1 -0
  69. package/esm/orderly/useOpenInterest.js +15 -0
  70. package/esm/orderly/useOrderEntry.d.ts +63 -0
  71. package/esm/orderly/useOrderEntry.d.ts.map +1 -0
  72. package/esm/orderly/useOrderEntry.js +504 -0
  73. package/esm/orderly/useOrderStream.d.ts +38 -0
  74. package/esm/orderly/useOrderStream.d.ts.map +1 -0
  75. package/esm/orderly/useOrderStream.js +180 -0
  76. package/esm/orderly/useOrderbookStream.d.ts +53 -0
  77. package/esm/orderly/useOrderbookStream.d.ts.map +1 -0
  78. package/esm/orderly/useOrderbookStream.js +309 -0
  79. package/esm/orderly/usePositionStream.d.ts +25 -0
  80. package/esm/orderly/usePositionStream.d.ts.map +1 -0
  81. package/esm/orderly/usePositionStream.js +232 -0
  82. package/esm/orderly/usePrivateDataObserver.d.ts +5 -0
  83. package/esm/orderly/usePrivateDataObserver.d.ts.map +1 -0
  84. package/esm/orderly/usePrivateDataObserver.js +126 -0
  85. package/esm/orderly/useSettleSubscription.d.ts +4 -0
  86. package/esm/orderly/useSettleSubscription.d.ts.map +1 -0
  87. package/esm/orderly/useSettleSubscription.js +20 -0
  88. package/esm/orderly/useSymbolPriceRange.d.ts +13 -0
  89. package/esm/orderly/useSymbolPriceRange.d.ts.map +1 -0
  90. package/esm/orderly/useSymbolPriceRange.js +39 -0
  91. package/esm/orderly/useSymbolsInfo.d.ts +2 -0
  92. package/esm/orderly/useSymbolsInfo.d.ts.map +1 -0
  93. package/esm/orderly/useSymbolsInfo.js +33 -0
  94. package/esm/orderly/useTickerStream.d.ts +3 -0
  95. package/esm/orderly/useTickerStream.d.ts.map +1 -0
  96. package/esm/orderly/useTickerStream.js +86 -0
  97. package/esm/orderly/useWalletSubscription.d.ts +4 -0
  98. package/esm/orderly/useWalletSubscription.d.ts.map +1 -0
  99. package/esm/orderly/useWalletSubscription.js +20 -0
  100. package/esm/orderly/useWithdraw.d.ts +14 -0
  101. package/esm/orderly/useWithdraw.d.ts.map +1 -0
  102. package/esm/orderly/useWithdraw.js +64 -0
  103. package/esm/orderlyContext.d.ts +17 -0
  104. package/esm/orderlyContext.d.ts.map +1 -0
  105. package/esm/orderlyContext.js +5 -0
  106. package/esm/services/dataCenter.d.ts +2 -0
  107. package/esm/services/dataCenter.d.ts.map +1 -0
  108. package/esm/services/dataCenter.js +13 -0
  109. package/esm/services/painter/backgroundPaint.d.ts +9 -0
  110. package/esm/services/painter/backgroundPaint.d.ts.map +1 -0
  111. package/esm/services/painter/backgroundPaint.js +41 -0
  112. package/esm/services/painter/basePaint.d.ts +90 -0
  113. package/esm/services/painter/basePaint.d.ts.map +1 -0
  114. package/esm/services/painter/basePaint.js +6 -0
  115. package/esm/services/painter/dataPaint.d.ts +16 -0
  116. package/esm/services/painter/dataPaint.d.ts.map +1 -0
  117. package/esm/services/painter/dataPaint.js +195 -0
  118. package/esm/services/painter/layout.config.d.ts +3 -0
  119. package/esm/services/painter/layout.config.d.ts.map +1 -0
  120. package/esm/services/painter/layout.config.js +52 -0
  121. package/esm/services/painter/painter.d.ts +12 -0
  122. package/esm/services/painter/painter.d.ts.map +1 -0
  123. package/esm/services/painter/painter.js +37 -0
  124. package/esm/services/painter/resource.d.ts +7 -0
  125. package/esm/services/painter/resource.d.ts.map +1 -0
  126. package/esm/services/painter/resource.js +15 -0
  127. package/esm/statusProvider.d.ts +8 -0
  128. package/esm/statusProvider.d.ts.map +1 -0
  129. package/esm/statusProvider.js +8 -0
  130. package/esm/unuse/apiPrefixMiddleware.d.ts +3 -0
  131. package/esm/unuse/apiPrefixMiddleware.d.ts.map +1 -0
  132. package/esm/unuse/apiPrefixMiddleware.js +29 -0
  133. package/esm/unuse/fn.d.ts +2 -0
  134. package/esm/unuse/fn.d.ts.map +1 -0
  135. package/esm/unuse/fn.js +6 -0
  136. package/esm/unuse/useBalance.d.ts +2 -0
  137. package/esm/unuse/useBalance.d.ts.map +1 -0
  138. package/esm/unuse/useBalance.js +12 -0
  139. package/esm/unuse/useFetures.d.ts +11 -0
  140. package/esm/unuse/useFetures.d.ts.map +1 -0
  141. package/esm/unuse/useFetures.js +39 -0
  142. package/esm/unuse/useRunOnce.d.ts +7 -0
  143. package/esm/unuse/useRunOnce.d.ts.map +1 -0
  144. package/esm/unuse/useRunOnce.js +17 -0
  145. package/esm/unuse/useSyncEnd.d.ts +2 -0
  146. package/esm/unuse/useSyncEnd.d.ts.map +1 -0
  147. package/esm/unuse/useSyncEnd.js +10 -0
  148. package/esm/unuse/useTokenInfo.d.ts +2 -0
  149. package/esm/unuse/useTokenInfo.d.ts.map +1 -0
  150. package/esm/unuse/useTokenInfo.js +20 -0
  151. package/esm/unuse/useUnsettlementPnL.d.ts +2 -0
  152. package/esm/unuse/useUnsettlementPnL.d.ts.map +1 -0
  153. package/esm/unuse/useUnsettlementPnL.js +20 -0
  154. package/esm/useAccount.d.ts +8 -0
  155. package/esm/useAccount.d.ts.map +1 -0
  156. package/esm/useAccount.js +59 -0
  157. package/esm/useAccountInstance.d.ts +3 -0
  158. package/esm/useAccountInstance.d.ts.map +1 -0
  159. package/esm/useAccountInstance.js +23 -0
  160. package/esm/useBoolean.d.ts +6 -0
  161. package/esm/useBoolean.d.ts.map +1 -0
  162. package/esm/useBoolean.js +8 -0
  163. package/esm/useConfig.d.ts +3 -0
  164. package/esm/useConfig.d.ts.map +1 -0
  165. package/esm/useConfig.js +12 -0
  166. package/esm/useEventEmitter.d.ts +3 -0
  167. package/esm/useEventEmitter.d.ts.map +1 -0
  168. package/esm/useEventEmitter.js +12 -0
  169. package/esm/useLazyQuery.d.ts +13 -0
  170. package/esm/useLazyQuery.d.ts.map +1 -0
  171. package/esm/useLazyQuery.js +35 -0
  172. package/esm/useLocalStorage.d.ts +2 -0
  173. package/esm/useLocalStorage.d.ts.map +1 -0
  174. package/esm/useLocalStorage.js +74 -0
  175. package/esm/useMediaQuery.d.ts +2 -0
  176. package/esm/useMediaQuery.d.ts.map +1 -0
  177. package/esm/useMediaQuery.js +36 -0
  178. package/esm/useMutation.d.ts +10 -0
  179. package/esm/useMutation.d.ts.map +1 -0
  180. package/esm/useMutation.js +64 -0
  181. package/esm/useObserve.d.ts +6 -0
  182. package/esm/useObserve.d.ts.map +1 -0
  183. package/esm/useObserve.js +8 -0
  184. package/esm/useParamsCheck.d.ts +4 -0
  185. package/esm/useParamsCheck.d.ts.map +1 -0
  186. package/esm/useParamsCheck.js +14 -0
  187. package/esm/usePoster.d.ts +14 -0
  188. package/esm/usePoster.d.ts.map +1 -0
  189. package/esm/usePoster.js +52 -0
  190. package/esm/usePreloadData.d.ts +5 -0
  191. package/esm/usePreloadData.d.ts.map +1 -0
  192. package/esm/usePreloadData.js +14 -0
  193. package/esm/usePrivateInfiniteQuery.d.ts +5 -0
  194. package/esm/usePrivateInfiniteQuery.d.ts.map +1 -0
  195. package/esm/usePrivateInfiniteQuery.js +25 -0
  196. package/esm/usePrivateQuery.d.ts +10 -0
  197. package/esm/usePrivateQuery.d.ts.map +1 -0
  198. package/esm/usePrivateQuery.js +26 -0
  199. package/esm/useQuery.d.ts +10 -0
  200. package/esm/useQuery.d.ts.map +1 -0
  201. package/esm/useQuery.js +20 -0
  202. package/esm/useSessionStorage.d.ts +2 -0
  203. package/esm/useSessionStorage.d.ts.map +1 -0
  204. package/esm/useSessionStorage.js +60 -0
  205. package/esm/useWS.d.ts +3 -0
  206. package/esm/useWS.d.ts.map +1 -0
  207. package/esm/useWS.js +51 -0
  208. package/esm/useWsStatus.d.ts +7 -0
  209. package/esm/useWsStatus.d.ts.map +1 -0
  210. package/esm/useWsStatus.js +41 -0
  211. package/esm/utils/createGetter.d.ts +4 -0
  212. package/esm/utils/createGetter.d.ts.map +1 -0
  213. package/esm/utils/createGetter.js +21 -0
  214. package/esm/utils/createOrder.d.ts +56 -0
  215. package/esm/utils/createOrder.d.ts.map +1 -0
  216. package/esm/utils/createOrder.js +324 -0
  217. package/esm/utils/fetcher.d.ts +6 -0
  218. package/esm/utils/fetcher.d.ts.map +1 -0
  219. package/esm/utils/fetcher.js +2 -0
  220. package/esm/utils/json.d.ts +2 -0
  221. package/esm/utils/json.d.ts.map +1 -0
  222. package/esm/utils/json.js +8 -0
  223. package/esm/utils/orderEntryHelper.d.ts +25 -0
  224. package/esm/utils/orderEntryHelper.d.ts.map +1 -0
  225. package/esm/utils/orderEntryHelper.js +242 -0
  226. package/esm/utils/parseHolding.d.ts +9 -0
  227. package/esm/utils/parseHolding.d.ts.map +1 -0
  228. package/esm/utils/parseHolding.js +21 -0
  229. package/esm/version.d.ts +10 -0
  230. package/esm/version.d.ts.map +1 -0
  231. package/esm/version.js +6 -0
  232. package/esm/walletConnectorContext.d.ts +30 -0
  233. package/esm/walletConnectorContext.d.ts.map +1 -0
  234. package/esm/walletConnectorContext.js +5 -0
  235. package/lib/configProvider.d.ts +17 -0
  236. package/lib/configProvider.d.ts.map +1 -0
  237. package/lib/configProvider.js +82 -0
  238. package/lib/dataProvider.d.ts +10 -0
  239. package/lib/dataProvider.d.ts.map +1 -0
  240. package/lib/dataProvider.js +34 -0
  241. package/lib/index.d.ts +33 -0
  242. package/lib/index.d.ts.map +1 -0
  243. package/lib/index.js +88 -0
  244. package/lib/middleware/signatureMiddleware.d.ts +3 -0
  245. package/lib/middleware/signatureMiddleware.d.ts.map +1 -0
  246. package/lib/middleware/signatureMiddleware.js +36 -0
  247. package/lib/orderly/orderlyHooks.d.ts +30 -0
  248. package/lib/orderly/orderlyHooks.d.ts.map +1 -0
  249. package/lib/orderly/orderlyHooks.js +58 -0
  250. package/lib/orderly/useAccountInfo.d.ts +3 -0
  251. package/lib/orderly/useAccountInfo.d.ts.map +1 -0
  252. package/lib/orderly/useAccountInfo.js +8 -0
  253. package/lib/orderly/useChain.d.ts +6 -0
  254. package/lib/orderly/useChain.d.ts.map +1 -0
  255. package/lib/orderly/useChain.js +26 -0
  256. package/lib/orderly/useChains.d.ts +34 -0
  257. package/lib/orderly/useChains.d.ts.map +1 -0
  258. package/lib/orderly/useChains.js +166 -0
  259. package/lib/orderly/useCollateral.d.ts +16 -0
  260. package/lib/orderly/useCollateral.d.ts.map +1 -0
  261. package/lib/orderly/useCollateral.js +76 -0
  262. package/lib/orderly/useDeposit.d.ts +38 -0
  263. package/lib/orderly/useDeposit.d.ts.map +1 -0
  264. package/lib/orderly/useDeposit.js +274 -0
  265. package/lib/orderly/useFundingRate.d.ts +11 -0
  266. package/lib/orderly/useFundingRate.d.ts.map +1 -0
  267. package/lib/orderly/useFundingRate.js +44 -0
  268. package/lib/orderly/useFundingRates.d.ts +2 -0
  269. package/lib/orderly/useFundingRates.d.ts.map +1 -0
  270. package/lib/orderly/useFundingRates.js +25 -0
  271. package/lib/orderly/useHoldingStream.d.ts +7 -0
  272. package/lib/orderly/useHoldingStream.d.ts.map +1 -0
  273. package/lib/orderly/useHoldingStream.js +54 -0
  274. package/lib/orderly/useIndexPrice.d.ts +2 -0
  275. package/lib/orderly/useIndexPrice.d.ts.map +1 -0
  276. package/lib/orderly/useIndexPrice.js +24 -0
  277. package/lib/orderly/useLeverage.d.ts +2 -0
  278. package/lib/orderly/useLeverage.d.ts.map +1 -0
  279. package/lib/orderly/useLeverage.js +38 -0
  280. package/lib/orderly/useMarginRatio.d.ts +7 -0
  281. package/lib/orderly/useMarginRatio.d.ts.map +1 -0
  282. package/lib/orderly/useMarginRatio.js +45 -0
  283. package/lib/orderly/useMarkPrice.d.ts +4 -0
  284. package/lib/orderly/useMarkPrice.d.ts.map +1 -0
  285. package/lib/orderly/useMarkPrice.js +33 -0
  286. package/lib/orderly/useMarkPricesStream.d.ts +2 -0
  287. package/lib/orderly/useMarkPricesStream.d.ts.map +1 -0
  288. package/lib/orderly/useMarkPricesStream.js +33 -0
  289. package/lib/orderly/useMarketTradeStream.d.ts +9 -0
  290. package/lib/orderly/useMarketTradeStream.d.ts.map +1 -0
  291. package/lib/orderly/useMarketTradeStream.js +55 -0
  292. package/lib/orderly/useMarkets.d.ts +36 -0
  293. package/lib/orderly/useMarkets.d.ts.map +1 -0
  294. package/lib/orderly/useMarkets.js +244 -0
  295. package/lib/orderly/useMarketsStream.d.ts +5 -0
  296. package/lib/orderly/useMarketsStream.d.ts.map +1 -0
  297. package/lib/orderly/useMarketsStream.js +64 -0
  298. package/lib/orderly/useMaxQty.d.ts +3 -0
  299. package/lib/orderly/useMaxQty.d.ts.map +1 -0
  300. package/lib/orderly/useMaxQty.js +118 -0
  301. package/lib/orderly/useOpenInterest.d.ts +2 -0
  302. package/lib/orderly/useOpenInterest.d.ts.map +1 -0
  303. package/lib/orderly/useOpenInterest.js +22 -0
  304. package/lib/orderly/useOrderEntry.d.ts +63 -0
  305. package/lib/orderly/useOrderEntry.d.ts.map +1 -0
  306. package/lib/orderly/useOrderEntry.js +508 -0
  307. package/lib/orderly/useOrderStream.d.ts +38 -0
  308. package/lib/orderly/useOrderStream.d.ts.map +1 -0
  309. package/lib/orderly/useOrderStream.js +187 -0
  310. package/lib/orderly/useOrderbookStream.d.ts +53 -0
  311. package/lib/orderly/useOrderbookStream.d.ts.map +1 -0
  312. package/lib/orderly/useOrderbookStream.js +315 -0
  313. package/lib/orderly/usePositionStream.d.ts +25 -0
  314. package/lib/orderly/usePositionStream.d.ts.map +1 -0
  315. package/lib/orderly/usePositionStream.js +236 -0
  316. package/lib/orderly/usePrivateDataObserver.d.ts +5 -0
  317. package/lib/orderly/usePrivateDataObserver.d.ts.map +1 -0
  318. package/lib/orderly/usePrivateDataObserver.js +130 -0
  319. package/lib/orderly/useSettleSubscription.d.ts +4 -0
  320. package/lib/orderly/useSettleSubscription.d.ts.map +1 -0
  321. package/lib/orderly/useSettleSubscription.js +27 -0
  322. package/lib/orderly/useSymbolPriceRange.d.ts +13 -0
  323. package/lib/orderly/useSymbolPriceRange.d.ts.map +1 -0
  324. package/lib/orderly/useSymbolPriceRange.js +43 -0
  325. package/lib/orderly/useSymbolsInfo.d.ts +2 -0
  326. package/lib/orderly/useSymbolsInfo.d.ts.map +1 -0
  327. package/lib/orderly/useSymbolsInfo.js +37 -0
  328. package/lib/orderly/useTickerStream.d.ts +3 -0
  329. package/lib/orderly/useTickerStream.d.ts.map +1 -0
  330. package/lib/orderly/useTickerStream.js +90 -0
  331. package/lib/orderly/useWalletSubscription.d.ts +4 -0
  332. package/lib/orderly/useWalletSubscription.d.ts.map +1 -0
  333. package/lib/orderly/useWalletSubscription.js +27 -0
  334. package/lib/orderly/useWithdraw.d.ts +14 -0
  335. package/lib/orderly/useWithdraw.d.ts.map +1 -0
  336. package/lib/orderly/useWithdraw.js +68 -0
  337. package/lib/orderlyContext.d.ts +17 -0
  338. package/lib/orderlyContext.d.ts.map +1 -0
  339. package/lib/orderlyContext.js +8 -0
  340. package/lib/services/dataCenter.d.ts +2 -0
  341. package/lib/services/dataCenter.d.ts.map +1 -0
  342. package/lib/services/dataCenter.js +15 -0
  343. package/lib/services/painter/backgroundPaint.d.ts +9 -0
  344. package/lib/services/painter/backgroundPaint.d.ts.map +1 -0
  345. package/lib/services/painter/backgroundPaint.js +45 -0
  346. package/lib/services/painter/basePaint.d.ts +90 -0
  347. package/lib/services/painter/basePaint.d.ts.map +1 -0
  348. package/lib/services/painter/basePaint.js +10 -0
  349. package/lib/services/painter/dataPaint.d.ts +16 -0
  350. package/lib/services/painter/dataPaint.d.ts.map +1 -0
  351. package/lib/services/painter/dataPaint.js +199 -0
  352. package/lib/services/painter/layout.config.d.ts +3 -0
  353. package/lib/services/painter/layout.config.d.ts.map +1 -0
  354. package/lib/services/painter/layout.config.js +55 -0
  355. package/lib/services/painter/painter.d.ts +12 -0
  356. package/lib/services/painter/painter.d.ts.map +1 -0
  357. package/lib/services/painter/painter.js +41 -0
  358. package/lib/services/painter/resource.d.ts +7 -0
  359. package/lib/services/painter/resource.d.ts.map +1 -0
  360. package/lib/services/painter/resource.js +19 -0
  361. package/lib/statusProvider.d.ts +8 -0
  362. package/lib/statusProvider.d.ts.map +1 -0
  363. package/lib/statusProvider.js +12 -0
  364. package/lib/unuse/apiPrefixMiddleware.d.ts +3 -0
  365. package/lib/unuse/apiPrefixMiddleware.d.ts.map +1 -0
  366. package/lib/unuse/apiPrefixMiddleware.js +33 -0
  367. package/lib/unuse/fn.d.ts +2 -0
  368. package/lib/unuse/fn.d.ts.map +1 -0
  369. package/lib/unuse/fn.js +9 -0
  370. package/lib/unuse/useBalance.d.ts +2 -0
  371. package/lib/unuse/useBalance.d.ts.map +1 -0
  372. package/lib/unuse/useBalance.js +19 -0
  373. package/lib/unuse/useFetures.d.ts +11 -0
  374. package/lib/unuse/useFetures.d.ts.map +1 -0
  375. package/lib/unuse/useFetures.js +43 -0
  376. package/lib/unuse/useRunOnce.d.ts +7 -0
  377. package/lib/unuse/useRunOnce.d.ts.map +1 -0
  378. package/lib/unuse/useRunOnce.js +21 -0
  379. package/lib/unuse/useSyncEnd.d.ts +2 -0
  380. package/lib/unuse/useSyncEnd.d.ts.map +1 -0
  381. package/lib/unuse/useSyncEnd.js +14 -0
  382. package/lib/unuse/useTokenInfo.d.ts +2 -0
  383. package/lib/unuse/useTokenInfo.d.ts.map +1 -0
  384. package/lib/unuse/useTokenInfo.js +24 -0
  385. package/lib/unuse/useUnsettlementPnL.d.ts +2 -0
  386. package/lib/unuse/useUnsettlementPnL.d.ts.map +1 -0
  387. package/lib/unuse/useUnsettlementPnL.js +24 -0
  388. package/lib/useAccount.d.ts +8 -0
  389. package/lib/useAccount.d.ts.map +1 -0
  390. package/lib/useAccount.js +63 -0
  391. package/lib/useAccountInstance.d.ts +3 -0
  392. package/lib/useAccountInstance.d.ts.map +1 -0
  393. package/lib/useAccountInstance.js +30 -0
  394. package/lib/useBoolean.d.ts +6 -0
  395. package/lib/useBoolean.d.ts.map +1 -0
  396. package/lib/useBoolean.js +12 -0
  397. package/lib/useConfig.d.ts +3 -0
  398. package/lib/useConfig.d.ts.map +1 -0
  399. package/lib/useConfig.js +16 -0
  400. package/lib/useEventEmitter.d.ts +3 -0
  401. package/lib/useEventEmitter.d.ts.map +1 -0
  402. package/lib/useEventEmitter.js +19 -0
  403. package/lib/useLazyQuery.d.ts +13 -0
  404. package/lib/useLazyQuery.d.ts.map +1 -0
  405. package/lib/useLazyQuery.js +42 -0
  406. package/lib/useLocalStorage.d.ts +2 -0
  407. package/lib/useLocalStorage.d.ts.map +1 -0
  408. package/lib/useLocalStorage.js +78 -0
  409. package/lib/useMediaQuery.d.ts +2 -0
  410. package/lib/useMediaQuery.d.ts.map +1 -0
  411. package/lib/useMediaQuery.js +40 -0
  412. package/lib/useMutation.d.ts +10 -0
  413. package/lib/useMutation.d.ts.map +1 -0
  414. package/lib/useMutation.js +71 -0
  415. package/lib/useObserve.d.ts +6 -0
  416. package/lib/useObserve.d.ts.map +1 -0
  417. package/lib/useObserve.js +12 -0
  418. package/lib/useParamsCheck.d.ts +4 -0
  419. package/lib/useParamsCheck.d.ts.map +1 -0
  420. package/lib/useParamsCheck.js +18 -0
  421. package/lib/usePoster.d.ts +14 -0
  422. package/lib/usePoster.d.ts.map +1 -0
  423. package/lib/usePoster.js +56 -0
  424. package/lib/usePreloadData.d.ts +5 -0
  425. package/lib/usePreloadData.d.ts.map +1 -0
  426. package/lib/usePreloadData.js +18 -0
  427. package/lib/usePrivateInfiniteQuery.d.ts +5 -0
  428. package/lib/usePrivateInfiniteQuery.d.ts.map +1 -0
  429. package/lib/usePrivateInfiniteQuery.js +32 -0
  430. package/lib/usePrivateQuery.d.ts +10 -0
  431. package/lib/usePrivateQuery.d.ts.map +1 -0
  432. package/lib/usePrivateQuery.js +33 -0
  433. package/lib/useQuery.d.ts +10 -0
  434. package/lib/useQuery.d.ts.map +1 -0
  435. package/lib/useQuery.js +27 -0
  436. package/lib/useSessionStorage.d.ts +2 -0
  437. package/lib/useSessionStorage.d.ts.map +1 -0
  438. package/lib/useSessionStorage.js +64 -0
  439. package/lib/useWS.d.ts +3 -0
  440. package/lib/useWS.d.ts.map +1 -0
  441. package/lib/useWS.js +58 -0
  442. package/lib/useWsStatus.d.ts +7 -0
  443. package/lib/useWsStatus.d.ts.map +1 -0
  444. package/lib/useWsStatus.js +45 -0
  445. package/lib/utils/createGetter.d.ts +4 -0
  446. package/lib/utils/createGetter.d.ts.map +1 -0
  447. package/lib/utils/createGetter.js +25 -0
  448. package/lib/utils/createOrder.d.ts +56 -0
  449. package/lib/utils/createOrder.d.ts.map +1 -0
  450. package/lib/utils/createOrder.js +337 -0
  451. package/lib/utils/fetcher.d.ts +6 -0
  452. package/lib/utils/fetcher.d.ts.map +1 -0
  453. package/lib/utils/fetcher.js +6 -0
  454. package/lib/utils/json.d.ts +2 -0
  455. package/lib/utils/json.d.ts.map +1 -0
  456. package/lib/utils/json.js +12 -0
  457. package/lib/utils/orderEntryHelper.d.ts +25 -0
  458. package/lib/utils/orderEntryHelper.d.ts.map +1 -0
  459. package/lib/utils/orderEntryHelper.js +250 -0
  460. package/lib/utils/parseHolding.d.ts +9 -0
  461. package/lib/utils/parseHolding.d.ts.map +1 -0
  462. package/lib/utils/parseHolding.js +25 -0
  463. package/lib/version.d.ts +10 -0
  464. package/lib/version.d.ts.map +1 -0
  465. package/lib/version.js +8 -0
  466. package/lib/walletConnectorContext.d.ts +30 -0
  467. package/lib/walletConnectorContext.d.ts.map +1 -0
  468. package/lib/walletConnectorContext.js +9 -0
  469. package/package.json +18 -13
  470. package/dist/index.d.mts +0 -548
  471. package/dist/index.d.ts +0 -548
  472. package/dist/index.js +0 -5412
  473. package/dist/index.js.map +0 -1
  474. package/dist/index.mjs +0 -5329
  475. package/dist/index.mjs.map +0 -1
@@ -0,0 +1,17 @@
1
+ import type { PropsWithChildren } from "react";
2
+ import { ConfigStore, OrderlyKeyStore, getWalletAdapterFunc, IContract } from "@orderly.network/core";
3
+ import { NetworkId } from "@orderly.network/types";
4
+ type RequireAtLeastOne<T, R extends keyof T = keyof T> = Omit<T, R> & {
5
+ [K in R]-?: Required<Pick<T, K>> & Partial<Pick<T, Exclude<R, K>>>;
6
+ }[R];
7
+ export interface ConfigProviderProps {
8
+ configStore?: ConfigStore;
9
+ keyStore?: OrderlyKeyStore;
10
+ contracts?: IContract;
11
+ getWalletAdapter?: getWalletAdapterFunc;
12
+ brokerId: string;
13
+ networkId: NetworkId;
14
+ }
15
+ export declare const OrderlyConfigProvider: (props: PropsWithChildren<RequireAtLeastOne<ConfigProviderProps, "brokerId" | "configStore">>) => import("react/jsx-runtime").JSX.Element | null;
16
+ export {};
17
+ //# sourceMappingURL=configProvider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"configProvider.d.ts","sourceRoot":"","sources":["../src/configProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAM,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAGnD,OAAO,EACL,WAAW,EAGX,eAAe,EACf,oBAAoB,EAMpB,SAAS,EACV,MAAM,uBAAuB,CAAC;AAG/B,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAYnD,KAAK,iBAAiB,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,CAAC,GAAG,MAAM,CAAC,IAAI,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,GACjE;KACG,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;CACnE,CAAC,CAAC,CAAC,CAAC;AAEP,MAAM,WAAW,mBAAmB;IAClC,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,QAAQ,CAAC,EAAE,eAAe,CAAC;IAC3B,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,gBAAgB,CAAC,EAAE,oBAAoB,CAAC;IACxC,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,SAAS,CAAC;CACtB;AAED,eAAO,MAAM,qBAAqB,UACzB,kBACL,kBAAkB,mBAAmB,EAAE,UAAU,GAAG,aAAa,CAAC,CACnE,mDA+EF,CAAC"}
@@ -0,0 +1,54 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import React, { useEffect } from "react";
3
+ import { OrderlyProvider } from "./orderlyContext";
4
+ import {
5
+ // MemoryConfigStore,
6
+ DefaultConfigStore, LocalStorageStore, EtherAdapter, SimpleDI, Account, } from "@orderly.network/core";
7
+ import useConstant from "use-constant";
8
+ // import { usePreLoadData } from "./usePreloadData";
9
+ import { DataCenterProvider } from "./dataProvider";
10
+ import { StatusProvider } from "./statusProvider";
11
+ import { SDKError } from "@orderly.network/types";
12
+ export const OrderlyConfigProvider = (props) => {
13
+ const [account, setAccount] = React.useState(null);
14
+ const { configStore, keyStore, getWalletAdapter, brokerId, networkId, contracts, } = props;
15
+ if (!brokerId && typeof configStore === "undefined") {
16
+ console.error("[OrderlyConfigProvider]: brokerId is required");
17
+ }
18
+ if (typeof configStore !== "undefined" && !configStore.get("brokerId")) {
19
+ // console.error("[OrderlyConfigProvider]: brokerId is required");
20
+ throw new SDKError("if configStore is provided, brokerId is required in configStore");
21
+ }
22
+ const innerConfigStore = useConstant(() => {
23
+ return configStore || new DefaultConfigStore({ brokerId, networkId });
24
+ });
25
+ const innerKeyStore = useConstant(() => {
26
+ return keyStore || new LocalStorageStore(networkId);
27
+ });
28
+ const innerGetWalletAdapter = useConstant(() => {
29
+ return (getWalletAdapter ||
30
+ ((options) => new EtherAdapter(options)));
31
+ });
32
+ // check params, if has mismatch, throw warning message to console
33
+ // useParamsCheck({ brokerId: innerConfigStore.get("brokerId") });
34
+ useEffect(() => {
35
+ let account = SimpleDI.get(Account.instanceName);
36
+ if (!account) {
37
+ account = new Account(innerConfigStore, innerKeyStore, innerGetWalletAdapter, {
38
+ contracts,
39
+ });
40
+ SimpleDI.registerByName(Account.instanceName, account);
41
+ }
42
+ setAccount(account);
43
+ }, []);
44
+ if (!account) {
45
+ return null;
46
+ }
47
+ return (_jsx(OrderlyProvider, { value: {
48
+ configStore: innerConfigStore,
49
+ keyStore: innerKeyStore,
50
+ getWalletAdapter: innerGetWalletAdapter,
51
+ networkId: networkId,
52
+ // apiBaseUrl,
53
+ }, children: _jsx(StatusProvider, { children: _jsx(DataCenterProvider, { children: props.children }) }) }));
54
+ };
@@ -0,0 +1,10 @@
1
+ import { PropsWithChildren } from "react";
2
+ export type getKeyFunction = (index: number, prevData: any) => string | null;
3
+ interface DataCenterContextValue {
4
+ regesterKeyHandler: (key: string, handler: getKeyFunction) => void;
5
+ }
6
+ export declare const DataCenterContext: import("react").Context<DataCenterContextValue>;
7
+ export declare const useDataCenterContext: () => DataCenterContextValue;
8
+ export declare const DataCenterProvider: ({ children }: PropsWithChildren) => import("react/jsx-runtime").JSX.Element | null;
9
+ export {};
10
+ //# sourceMappingURL=dataProvider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dataProvider.d.ts","sourceRoot":"","sources":["../src/dataProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAqC,MAAM,OAAO,CAAC;AAI7E,MAAM,MAAM,cAAc,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,KAAK,MAAM,GAAG,IAAI,CAAC;AAE7E,UAAU,sBAAsB;IAK9B,kBAAkB,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,cAAc,KAAK,IAAI,CAAC;CACpE;AAED,eAAO,MAAM,iBAAiB,iDAE7B,CAAC;AAEF,eAAO,MAAM,oBAAoB,8BAAsC,CAAC;AAExE,eAAO,MAAM,kBAAkB,iBAAkB,iBAAiB,mDAgCjE,CAAC"}
@@ -0,0 +1,29 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { createContext, useContext, useRef } from "react";
3
+ import { usePrivateDataObserver } from "./orderly/usePrivateDataObserver";
4
+ import { usePreLoadData } from "./usePreloadData";
5
+ export const DataCenterContext = createContext({});
6
+ export const useDataCenterContext = () => useContext(DataCenterContext);
7
+ export const DataCenterProvider = ({ children }) => {
8
+ /**
9
+ * preload the required data for the app
10
+ * hidden view while the required data is not ready
11
+ */
12
+ const { error, done } = usePreLoadData();
13
+ const getKeyHandlerMapRef = useRef(new Map());
14
+ usePrivateDataObserver({
15
+ getKeysMap(type) {
16
+ return getKeyHandlerMapRef.current;
17
+ },
18
+ });
19
+ if (error) {
20
+ return _jsx("div", { children: "Data load failed" });
21
+ }
22
+ if (!done)
23
+ return null;
24
+ return (_jsx(DataCenterContext.Provider, { value: {
25
+ regesterKeyHandler: (key, fun) => {
26
+ getKeyHandlerMapRef.current.set(key, fun);
27
+ },
28
+ }, children: children }));
29
+ };
package/esm/index.d.ts ADDED
@@ -0,0 +1,33 @@
1
+ export { default as version } from "./version";
2
+ export { useQuery } from "./useQuery";
3
+ export { useLazyQuery } from "./useLazyQuery";
4
+ export { useMutation } from "./useMutation";
5
+ export { usePrivateQuery } from "./usePrivateQuery";
6
+ export { usePrivateInfiniteQuery } from "./usePrivateInfiniteQuery";
7
+ export { useBoolean } from "./useBoolean";
8
+ export { useAccount } from "./useAccount";
9
+ export { useAccountInstance } from "./useAccountInstance";
10
+ export { usePreLoadData } from "./usePreloadData";
11
+ export { useEventEmitter } from "./useEventEmitter";
12
+ export { useSessionStorage } from "./useSessionStorage";
13
+ export { useLocalStorage } from "./useLocalStorage";
14
+ export { parseJSON } from "./utils/json";
15
+ export { default as useConstant } from "use-constant";
16
+ export { useWS } from "./useWS";
17
+ export { useConfig } from "./useConfig";
18
+ export * from "./orderlyContext";
19
+ export * from "./statusProvider";
20
+ export { useWsStatus, WsNetworkStatus } from "./useWsStatus";
21
+ export type { ConfigProviderProps } from "./configProvider";
22
+ export { OrderlyConfigProvider } from "./configProvider";
23
+ export { WalletConnectorContext, useWalletConnector, } from "./walletConnectorContext";
24
+ export * from "./orderly/orderlyHooks";
25
+ import useSWR, { type SWRConfiguration, SWRConfig } from "swr";
26
+ export { useSWR, SWRConfig, type SWRConfiguration };
27
+ export * from "use-debounce";
28
+ export { useMediaQuery } from "./useMediaQuery";
29
+ export { usePoster, type drawOptions } from "./usePoster";
30
+ export * from "./orderly/orderlyHooks";
31
+ export { cleanStringStyle } from "./utils/orderEntryHelper";
32
+ export type { WalletAdapter } from "@orderly.network/core";
33
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,MAAM,WAAW,CAAC;AAC/C,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AACpE,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE1D,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,cAAc,CAAC;AACtD,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAC7D,YAAY,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAC5D,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AAEzD,OAAO,EACL,sBAAsB,EACtB,kBAAkB,GACnB,MAAM,0BAA0B,CAAC;AAElC,cAAc,wBAAwB,CAAC;AAGvC,OAAO,MAAM,EAAE,EAAE,KAAK,gBAAgB,EAAE,SAAS,EAAE,MAAM,KAAK,CAAC;AAE/D,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,KAAK,gBAAgB,EAAE,CAAC;AAEpD,cAAc,cAAc,CAAC;AAE7B,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD,OAAO,EAAE,SAAS,EAAE,KAAK,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1D,cAAc,wBAAwB,CAAC;AAEvC,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAE5D,YAAY,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC"}
package/esm/index.js ADDED
@@ -0,0 +1,30 @@
1
+ export { default as version } from "./version";
2
+ export { useQuery } from "./useQuery";
3
+ export { useLazyQuery } from "./useLazyQuery";
4
+ export { useMutation } from "./useMutation";
5
+ export { usePrivateQuery } from "./usePrivateQuery";
6
+ export { usePrivateInfiniteQuery } from "./usePrivateInfiniteQuery";
7
+ export { useBoolean } from "./useBoolean";
8
+ export { useAccount } from "./useAccount";
9
+ export { useAccountInstance } from "./useAccountInstance";
10
+ export { usePreLoadData } from "./usePreloadData";
11
+ export { useEventEmitter } from "./useEventEmitter";
12
+ export { useSessionStorage } from "./useSessionStorage";
13
+ export { useLocalStorage } from "./useLocalStorage";
14
+ export { parseJSON } from "./utils/json";
15
+ export { default as useConstant } from "use-constant";
16
+ export { useWS } from "./useWS";
17
+ export { useConfig } from "./useConfig";
18
+ export * from "./orderlyContext";
19
+ export * from "./statusProvider";
20
+ export { useWsStatus, WsNetworkStatus } from "./useWsStatus";
21
+ export { OrderlyConfigProvider } from "./configProvider";
22
+ export { WalletConnectorContext, useWalletConnector, } from "./walletConnectorContext";
23
+ export * from "./orderly/orderlyHooks";
24
+ import useSWR, { SWRConfig } from "swr";
25
+ export { useSWR, SWRConfig };
26
+ export * from "use-debounce";
27
+ export { useMediaQuery } from "./useMediaQuery";
28
+ export { usePoster } from "./usePoster";
29
+ export * from "./orderly/orderlyHooks";
30
+ export { cleanStringStyle } from "./utils/orderEntryHelper";
@@ -0,0 +1,3 @@
1
+ import { Middleware } from "swr";
2
+ export declare const signatureMiddleware: Middleware;
3
+ //# sourceMappingURL=signatureMiddleware.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"signatureMiddleware.d.ts","sourceRoot":"","sources":["../../src/middleware/signatureMiddleware.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,UAAU,EAAE,MAAM,KAAK,CAAC;AAI1C,eAAO,MAAM,mBAAmB,EAAE,UAiCjC,CAAC"}
@@ -0,0 +1,32 @@
1
+ import { SimpleDI } from "@orderly.network/core";
2
+ import { useConfig } from "../useConfig";
3
+ export const signatureMiddleware = (useSWRNext) => {
4
+ const apiBaseUrl = useConfig("apiBaseUrl");
5
+ return (key, fetcher, config) => {
6
+ try {
7
+ const extendedFetcher = async (args) => {
8
+ let url = Array.isArray(args) ? args[0] : args;
9
+ let account = SimpleDI.get("account");
10
+ let fullUrl = `${apiBaseUrl}${url}`;
11
+ const signer = account.signer;
12
+ const payload = {
13
+ method: "GET",
14
+ url,
15
+ };
16
+ const signature = await signer.sign(payload);
17
+ // @ts-ignore
18
+ return fetcher(fullUrl, {
19
+ headers: {
20
+ ...signature,
21
+ "orderly-account-id": account.accountId,
22
+ },
23
+ });
24
+ };
25
+ return useSWRNext(key, extendedFetcher, config);
26
+ }
27
+ catch (e) {
28
+ console.error("signature error:", e);
29
+ throw e;
30
+ }
31
+ };
32
+ };
@@ -0,0 +1,30 @@
1
+ export { useOrderbookStream } from "./useOrderbookStream";
2
+ export { useOrderEntry } from "./useOrderEntry";
3
+ export type { UseOrderEntryMetaState, OrderParams } from "./useOrderEntry";
4
+ export { useSymbolsInfo } from "./useSymbolsInfo";
5
+ export { useAccountInfo } from "./useAccountInfo";
6
+ export { useMarketsStream } from "./useMarketsStream";
7
+ export { useMarkets, MarketsType } from "./useMarkets";
8
+ export type { FavoriteTab, Favorite, Recent } from "./useMarkets";
9
+ export { useMarkPricesStream } from "./useMarkPricesStream";
10
+ export { useMarkPrice } from "./useMarkPrice";
11
+ export { useIndexPrice } from "./useIndexPrice";
12
+ export { useLeverage } from "./useLeverage";
13
+ export { useTickerStream } from "./useTickerStream";
14
+ export { useFundingRate } from "./useFundingRate";
15
+ export { usePositionStream } from "./usePositionStream";
16
+ export { useOrderStream } from "./useOrderStream";
17
+ export { useMarketTradeStream } from "./useMarketTradeStream";
18
+ export { useCollateral } from "./useCollateral";
19
+ export { useMaxQty } from "./useMaxQty";
20
+ export { useMarginRatio } from "./useMarginRatio";
21
+ export { useChains } from "./useChains";
22
+ export { useChain } from "./useChain";
23
+ export { useWithdraw } from "./useWithdraw";
24
+ export { useDeposit } from "./useDeposit";
25
+ export { useHoldingStream } from "./useHoldingStream";
26
+ export { useWalletSubscription } from "./useWalletSubscription";
27
+ export { useSettleSubscription } from "./useSettleSubscription";
28
+ export { usePrivateDataObserver } from "./usePrivateDataObserver";
29
+ export { useSymbolPriceRange } from "./useSymbolPriceRange";
30
+ //# sourceMappingURL=orderlyHooks.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"orderlyHooks.d.ts","sourceRoot":"","sources":["../../src/orderly/orderlyHooks.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,YAAY,EAAE,sBAAsB,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC3E,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AACvD,YAAY,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAClE,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAE9D,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAElE,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC"}
@@ -0,0 +1,27 @@
1
+ export { useOrderbookStream } from "./useOrderbookStream";
2
+ export { useOrderEntry } from "./useOrderEntry";
3
+ export { useSymbolsInfo } from "./useSymbolsInfo";
4
+ export { useAccountInfo } from "./useAccountInfo";
5
+ export { useMarketsStream } from "./useMarketsStream";
6
+ export { useMarkets, MarketsType } from "./useMarkets";
7
+ export { useMarkPricesStream } from "./useMarkPricesStream";
8
+ export { useMarkPrice } from "./useMarkPrice";
9
+ export { useIndexPrice } from "./useIndexPrice";
10
+ export { useLeverage } from "./useLeverage";
11
+ export { useTickerStream } from "./useTickerStream";
12
+ export { useFundingRate } from "./useFundingRate";
13
+ export { usePositionStream } from "./usePositionStream";
14
+ export { useOrderStream } from "./useOrderStream";
15
+ export { useMarketTradeStream } from "./useMarketTradeStream";
16
+ export { useCollateral } from "./useCollateral";
17
+ export { useMaxQty } from "./useMaxQty";
18
+ export { useMarginRatio } from "./useMarginRatio";
19
+ export { useChains } from "./useChains";
20
+ export { useChain } from "./useChain";
21
+ export { useWithdraw } from "./useWithdraw";
22
+ export { useDeposit } from "./useDeposit";
23
+ export { useHoldingStream } from "./useHoldingStream";
24
+ export { useWalletSubscription } from "./useWalletSubscription";
25
+ export { useSettleSubscription } from "./useSettleSubscription";
26
+ export { usePrivateDataObserver } from "./usePrivateDataObserver";
27
+ export { useSymbolPriceRange } from "./useSymbolPriceRange";
@@ -0,0 +1,3 @@
1
+ import { API } from "@orderly.network/types";
2
+ export declare const useAccountInfo: () => import("swr/_internal").SWRResponse<API.AccountInfo, any, any>;
3
+ //# sourceMappingURL=useAccountInfo.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useAccountInfo.d.ts","sourceRoot":"","sources":["../../src/orderly/useAccountInfo.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,wBAAwB,CAAC;AAG7C,eAAO,MAAM,cAAc,sEAE1B,CAAC"}
@@ -0,0 +1,4 @@
1
+ import { usePrivateQuery } from "../usePrivateQuery";
2
+ export const useAccountInfo = () => {
3
+ return usePrivateQuery("/v1/client/info");
4
+ };
@@ -0,0 +1,6 @@
1
+ import { API } from "@orderly.network/types";
2
+ export declare const useChain: (token: string) => {
3
+ chains: API.Chain | null;
4
+ isLoading: boolean;
5
+ };
6
+ //# sourceMappingURL=useChain.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useChain.d.ts","sourceRoot":"","sources":["../../src/orderly/useChain.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,GAAG,EAAiB,MAAM,wBAAwB,CAAC;AAE5D,eAAO,MAAM,QAAQ,UAAW,MAAM;;;CAsBrC,CAAC"}
@@ -0,0 +1,22 @@
1
+ import { useMemo } from "react";
2
+ import { useQuery } from "../useQuery";
3
+ import { chainsInfoMap } from "@orderly.network/types";
4
+ export const useChain = (token) => {
5
+ const { data, isLoading } = useQuery("/v1/public/token");
6
+ const chains = useMemo(() => {
7
+ if (!data)
8
+ return null;
9
+ let item = data.find((chain) => chain.token === token);
10
+ if (item) {
11
+ item.chain_details = item.chain_details.map((d) => {
12
+ const chain = chainsInfoMap.get(Number(d.chain_id));
13
+ return {
14
+ ...d,
15
+ chain_name: chain?.chainName ?? "--",
16
+ };
17
+ });
18
+ }
19
+ return item || null;
20
+ }, [data, token]);
21
+ return { chains, isLoading };
22
+ };
@@ -0,0 +1,34 @@
1
+ import { NetworkId, type API } from "@orderly.network/types";
2
+ import { SWRConfiguration } from "swr";
3
+ type InputOptions = {
4
+ filter?: (item: API.Chain) => boolean;
5
+ pick?: "dexs" | "network_infos" | "token_infos";
6
+ };
7
+ export type Chain = API.Chain & {
8
+ nativeToken?: API.TokenInfo;
9
+ };
10
+ export type Chains<T extends NetworkId | undefined = undefined, K extends keyof API.Chain | undefined = undefined> = T extends NetworkId ? K extends keyof API.Chain ? API.Chain[K][] : API.Chain[] : K extends keyof API.Chain ? {
11
+ testnet: API.Chain[K][];
12
+ mainnet: API.Chain[K][];
13
+ } : {
14
+ testnet: API.Chain[];
15
+ mainnet: API.Chain[];
16
+ };
17
+ export type Options = InputOptions & SWRConfiguration;
18
+ export type ReturnObject = {
19
+ findByChainId: (chainId: number, field?: string) => Chain | undefined;
20
+ error: any;
21
+ };
22
+ export declare function useChains(networkId?: undefined, options?: undefined): [Chains<undefined, undefined>, ReturnObject];
23
+ export declare function useChains<T extends NetworkId | undefined, K extends Options | undefined>(networkId?: T, options?: K): [
24
+ Chains<T, K extends Options ? K["pick"] extends keyof API.Chain ? K["pick"] : undefined : undefined>,
25
+ ReturnObject
26
+ ];
27
+ /** orderly chains array form (/v1/public/token) api */
28
+ export declare function fillChainsInfo(chains?: API.Chain[], filter?: (chain: any) => boolean): API.Chain[];
29
+ /** update network_infos by chain_info api(v1/public/chain_info) */
30
+ export declare function updateOrderlyChains(chains: API.Chain[], chainInfos: any, filter?: (chain: any) => boolean): API.Chain[];
31
+ /** if chain is testnet, update testnet network_infos */
32
+ export declare function updateTestnetInfo(testnetArr: API.Chain[], chainId: number, chain: API.Chain): void;
33
+ export {};
34
+ //# sourceMappingURL=useChains.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useChains.d.ts","sourceRoot":"","sources":["../../src/orderly/useChains.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,KAAK,GAAG,EAAiB,MAAM,wBAAwB,CAAC;AAE5E,OAAO,EAAE,gBAAgB,EAAE,MAAM,KAAK,CAAC;AAMvC,KAAK,YAAY,GAAG;IAClB,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,GAAG,CAAC,KAAK,KAAK,OAAO,CAAC;IACtC,IAAI,CAAC,EAAE,MAAM,GAAG,eAAe,GAAG,aAAa,CAAC;CACjD,CAAC;AAEF,MAAM,MAAM,KAAK,GAAG,GAAG,CAAC,KAAK,GAAG;IAC9B,WAAW,CAAC,EAAE,GAAG,CAAC,SAAS,CAAC;CAC7B,CAAC;AAEF,MAAM,MAAM,MAAM,CAChB,CAAC,SAAS,SAAS,GAAG,SAAS,GAAG,SAAS,EAC3C,CAAC,SAAS,MAAM,GAAG,CAAC,KAAK,GAAG,SAAS,GAAG,SAAS,IAC/C,CAAC,SAAS,SAAS,GACnB,CAAC,SAAS,MAAM,GAAG,CAAC,KAAK,GACvB,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,GACd,GAAG,CAAC,KAAK,EAAE,GACb,CAAC,SAAS,MAAM,GAAG,CAAC,KAAK,GACzB;IACE,OAAO,EAAE,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;IACxB,OAAO,EAAE,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;CACzB,GACD;IACE,OAAO,EAAE,GAAG,CAAC,KAAK,EAAE,CAAC;IACrB,OAAO,EAAE,GAAG,CAAC,KAAK,EAAE,CAAC;CACtB,CAAC;AAEN,MAAM,MAAM,OAAO,GAAG,YAAY,GAAG,gBAAgB,CAAC;AAEtD,MAAM,MAAM,YAAY,GAAG;IACzB,aAAa,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,KAAK,KAAK,GAAG,SAAS,CAAC;IACtE,KAAK,EAAE,GAAG,CAAC;CACZ,CAAC;AAEF,wBAAgB,SAAS,CACvB,SAAS,CAAC,EAAE,SAAS,EACrB,OAAO,CAAC,EAAE,SAAS,GAClB,CAAC,MAAM,CAAC,SAAS,EAAE,SAAS,CAAC,EAAE,YAAY,CAAC,CAAC;AAEhD,wBAAgB,SAAS,CACvB,CAAC,SAAS,SAAS,GAAG,SAAS,EAC/B,CAAC,SAAS,OAAO,GAAG,SAAS,EAE7B,SAAS,CAAC,EAAE,CAAC,EACb,OAAO,CAAC,EAAE,CAAC,GACV;IACD,MAAM,CACJ,CAAC,EACD,CAAC,SAAS,OAAO,GACb,CAAC,CAAC,MAAM,CAAC,SAAS,MAAM,GAAG,CAAC,KAAK,GAC/B,CAAC,CAAC,MAAM,CAAC,GACT,SAAS,GACX,SAAS,CACd;IACD,YAAY;CACb,CAAC;AA6HF,uDAAuD;AACvD,wBAAgB,cAAc,CAC5B,MAAM,CAAC,EAAE,GAAG,CAAC,KAAK,EAAE,EACpB,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,KAAK,OAAO,eAmCjC;AAED,mEAAmE;AACnE,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,GAAG,CAAC,KAAK,EAAE,EACnB,UAAU,EAAE,GAAG,EACf,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,KAAK,OAAO,eAkCjC;AAED,wDAAwD;AACxD,wBAAgB,iBAAiB,CAC/B,UAAU,EAAE,GAAG,CAAC,KAAK,EAAE,EACvB,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,GAAG,CAAC,KAAK,QAUjB"}
@@ -0,0 +1,159 @@
1
+ import { chainsInfoMap } from "@orderly.network/types";
2
+ import { useCallback, useMemo, useRef } from "react";
3
+ import { useQuery } from "../useQuery";
4
+ import { prop } from "ramda";
5
+ import { isTestnet } from "@orderly.network/utils";
6
+ import { TestnetChains, nativeTokenAddress } from "@orderly.network/types";
7
+ export function useChains(networkId, options = {}) {
8
+ const { pick: pickField, ...swrOptions } = options;
9
+ const filterFun = useRef(options?.filter);
10
+ filterFun.current = options?.filter;
11
+ const chainsMap = useRef(new Map());
12
+ const commonSwrOpts = {
13
+ revalidateIfStale: false,
14
+ revalidateOnFocus: false,
15
+ revalidateOnReconnect: false,
16
+ // If false, undefined data gets cached against the key.
17
+ revalidateOnMount: true,
18
+ // dont duplicate a request w/ same key for 1hr
19
+ dedupingInterval: 3600000,
20
+ ...swrOptions,
21
+ };
22
+ // only prod env return mainnet chains info
23
+ // TODO: remove https://api-evm.orderly.org api base
24
+ const { data: tokenChains, error: tokenError } = useQuery("https://api-evm.orderly.org/v1/public/token", { ...commonSwrOpts });
25
+ // only prod env return mainnet chains info
26
+ const { data: chainInfos, error: chainInfoErr } = useQuery("/v1/public/chain_info", { ...commonSwrOpts });
27
+ const chains = useMemo(() => {
28
+ const orderlyChainsArr = fillChainsInfo(tokenChains, filterFun.current);
29
+ let testnetArr = [...TestnetChains];
30
+ orderlyChainsArr?.forEach((item) => {
31
+ const chainId = item.network_infos?.chain_id;
32
+ chainsMap.current.set(chainId, item);
33
+ updateTestnetInfo(testnetArr, chainId, item);
34
+ });
35
+ testnetArr.forEach((chain) => {
36
+ chainsMap.current.set(chain.network_infos?.chain_id, chain);
37
+ });
38
+ let mainnetArr = [];
39
+ // TODO: /v1/public/chain_info api data is not match /v1/public/token api data, so it can effect is prod
40
+ mainnetArr = updateOrderlyChains(orderlyChainsArr, chainInfos, filterFun.current);
41
+ mainnetArr.forEach((item) => {
42
+ const chainId = item.network_infos?.chain_id;
43
+ chainsMap.current.set(chainId, item);
44
+ updateTestnetInfo(testnetArr, chainId, item);
45
+ });
46
+ mainnetArr.sort((a, b) => {
47
+ return a.network_infos.bridgeless ? -1 : 1;
48
+ });
49
+ testnetArr.sort((a, b) => {
50
+ return a.network_infos.bridgeless ? -1 : 1;
51
+ });
52
+ if (!!pickField) {
53
+ //@ts-ignore
54
+ testnetArr = testnetArr.map((item) => item[pickField]);
55
+ //@ts-ignore
56
+ mainnetArr = mainnetArr.map((item) => item[pickField]);
57
+ }
58
+ if (networkId === "mainnet") {
59
+ return mainnetArr;
60
+ }
61
+ if (networkId === "testnet") {
62
+ return testnetArr;
63
+ }
64
+ return {
65
+ testnet: testnetArr,
66
+ mainnet: mainnetArr,
67
+ };
68
+ }, [networkId, tokenChains, chainInfos, pickField]);
69
+ const findByChainId = useCallback((chainId, field) => {
70
+ const chain = chainsMap.current.get(chainId);
71
+ if (chain) {
72
+ chain.nativeToken =
73
+ chain.token_infos?.find((item) => item.address === nativeTokenAddress) ||
74
+ {
75
+ symbol: chain.network_infos?.currency_symbol,
76
+ };
77
+ }
78
+ if (typeof field === "string") {
79
+ return prop(field, chain);
80
+ }
81
+ return chain;
82
+ }, [chains, chainsMap]);
83
+ return [
84
+ chains,
85
+ {
86
+ findByChainId,
87
+ error: tokenError,
88
+ },
89
+ ];
90
+ }
91
+ /** orderly chains array form (/v1/public/token) api */
92
+ export function fillChainsInfo(chains, filter) {
93
+ let _chains = [];
94
+ chains?.forEach((item) => {
95
+ item.chain_details.forEach((chain) => {
96
+ const chainId = Number(chain.chain_id);
97
+ const chainInfo = chainsInfoMap.get(chainId);
98
+ const _chain = {
99
+ network_infos: {
100
+ name: chain.chain_name ?? chainInfo?.chainName ?? "--",
101
+ chain_id: chainId,
102
+ withdrawal_fee: chain.withdrawal_fee,
103
+ cross_chain_withdrawal_fee: chain.cross_chain_withdrawal_fee,
104
+ bridgeless: true,
105
+ },
106
+ token_infos: [
107
+ {
108
+ symbol: item.token,
109
+ address: chain.contract_address,
110
+ decimals: chain.decimals,
111
+ },
112
+ ],
113
+ };
114
+ if (typeof filter === "function") {
115
+ if (!filter(_chain))
116
+ return;
117
+ }
118
+ _chains.push(_chain);
119
+ });
120
+ });
121
+ return _chains;
122
+ }
123
+ /** update network_infos by chain_info api(v1/public/chain_info) */
124
+ export function updateOrderlyChains(chains, chainInfos, filter) {
125
+ const _chains = [];
126
+ chains.forEach((chain) => {
127
+ let _chain = { ...chain };
128
+ const networkInfo = chainInfos?.find((item) => item.chain_id == chain.network_infos.chain_id);
129
+ if (networkInfo) {
130
+ const { name, public_rpc_url, currency_symbol, explorer_base_url } = networkInfo;
131
+ _chain.network_infos = {
132
+ ..._chain.network_infos,
133
+ name,
134
+ shortName: name,
135
+ public_rpc_url,
136
+ currency_symbol,
137
+ bridge_enable: true,
138
+ mainnet: true,
139
+ explorer_base_url,
140
+ est_txn_mins: null,
141
+ };
142
+ }
143
+ if (typeof filter === "function") {
144
+ if (!filter(_chain))
145
+ return;
146
+ }
147
+ _chains.push(_chain);
148
+ });
149
+ return _chains;
150
+ }
151
+ /** if chain is testnet, update testnet network_infos */
152
+ export function updateTestnetInfo(testnetArr, chainId, chain) {
153
+ if (isTestnet(chainId)) {
154
+ const index = testnetArr?.findIndex((item) => item.network_infos.chain_id === chainId);
155
+ if (index > -1) {
156
+ testnetArr[index] = chain;
157
+ }
158
+ }
159
+ }
@@ -0,0 +1,16 @@
1
+ import { type API } from "@orderly.network/types";
2
+ export type CollateralOutputs = {
3
+ totalCollateral: number;
4
+ freeCollateral: number;
5
+ totalValue: number;
6
+ availableBalance: number;
7
+ unsettledPnL: number;
8
+ positions: API.Position[];
9
+ accountInfo?: API.AccountInfo;
10
+ };
11
+ type Options = {
12
+ dp: number;
13
+ };
14
+ export declare const useCollateral: (options?: Options) => CollateralOutputs;
15
+ export {};
16
+ //# sourceMappingURL=useCollateral.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useCollateral.d.ts","sourceRoot":"","sources":["../../src/orderly/useCollateral.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,KAAK,GAAG,EAAe,MAAM,wBAAwB,CAAC;AAO/D,MAAM,MAAM,iBAAiB,GAAG;IAC9B,eAAe,EAAE,MAAM,CAAC;IACxB,cAAc,EAAE,MAAM,CAAC;IACvB,UAAU,EAAE,MAAM,CAAC;IACnB,gBAAgB,EAAE,MAAM,CAAC;IACzB,YAAY,EAAE,MAAM,CAAC;IAErB,SAAS,EAAE,GAAG,CAAC,QAAQ,EAAE,CAAC;IAC1B,WAAW,CAAC,EAAE,GAAG,CAAC,WAAW,CAAC;CAC/B,CAAC;AAKF,KAAK,OAAO,GAAG;IACb,EAAE,EAAE,MAAM,CAAC;CACZ,CAAC;AAEF,eAAO,MAAM,aAAa,aACf,OAAO,KACf,iBA0EF,CAAC"}
@@ -0,0 +1,72 @@
1
+ import { useMemo } from "react";
2
+ import { usePrivateQuery } from "../usePrivateQuery";
3
+ import { pathOr_unsettledPnLPathOr, usePositionStream, } from "./usePositionStream";
4
+ import { pathOr } from "ramda";
5
+ import { account } from "@orderly.network/perp";
6
+ import { OrderStatus } from "@orderly.network/types";
7
+ import { useSymbolsInfo } from "./useSymbolsInfo";
8
+ import { zero } from "@orderly.network/utils";
9
+ import { useMarkPricesStream } from "./useMarkPricesStream";
10
+ import { useHoldingStream } from "./useHoldingStream";
11
+ import { useOrderStream } from "./useOrderStream";
12
+ const positionsPath = pathOr([], [0, "rows"]);
13
+ const totalCollateralPath = pathOr(0, [0, "totalCollateral"]);
14
+ export const useCollateral = (options = { dp: 6 }) => {
15
+ const { dp } = options;
16
+ const positions = usePositionStream();
17
+ const [orders] = useOrderStream({ status: OrderStatus.NEW });
18
+ const { data: accountInfo } = usePrivateQuery("/v1/client/info");
19
+ const symbolInfo = useSymbolsInfo();
20
+ const { data: markPrices } = useMarkPricesStream();
21
+ const { usdc } = useHoldingStream();
22
+ const filterAlgoOrders = orders?.filter((item) => item.algo_order_id === undefined) ?? [];
23
+ // const { data: holding } = usePrivateQuery<API.Holding[]>(
24
+ // "/v1/client/holding",
25
+ // {
26
+ // formatter: (data) => {
27
+ // return data.holding;
28
+ // },
29
+ // }
30
+ // );
31
+ const [totalCollateral, totalValue] = useMemo(() => {
32
+ return [
33
+ pathOr(zero, [0, "totalCollateral"], positions),
34
+ pathOr(zero, [0, "totalValue"], positions),
35
+ ];
36
+ }, [positions, markPrices]);
37
+ const totalInitialMarginWithOrders = useMemo(() => {
38
+ if (!accountInfo || !symbolInfo || !markPrices) {
39
+ return 0;
40
+ }
41
+ return account.totalInitialMarginWithOrders({
42
+ positions: positionsPath(positions),
43
+ orders: filterAlgoOrders,
44
+ markPrices,
45
+ IMR_Factors: accountInfo.imr_factor,
46
+ maxLeverage: accountInfo.max_leverage,
47
+ symbolInfo,
48
+ });
49
+ }, [positions, filterAlgoOrders, markPrices, accountInfo, symbolInfo]);
50
+ const freeCollateral = useMemo(() => {
51
+ return account.freeCollateral({
52
+ totalCollateral,
53
+ totalInitialMarginWithOrders,
54
+ });
55
+ }, [totalCollateral, totalInitialMarginWithOrders]);
56
+ const availableBalance = useMemo(() => {
57
+ return account.availableBalance({
58
+ USDCHolding: usdc?.holding ?? 0,
59
+ unsettlementPnL: pathOr_unsettledPnLPathOr(positions),
60
+ });
61
+ }, [usdc?.holding, pathOr_unsettledPnLPathOr(positions)]);
62
+ return {
63
+ totalCollateral: totalCollateral.toDecimalPlaces(dp).toNumber(),
64
+ freeCollateral: freeCollateral.toDecimalPlaces(dp).toNumber(),
65
+ totalValue: totalValue.toDecimalPlaces(dp).toNumber(),
66
+ availableBalance,
67
+ unsettledPnL: pathOr_unsettledPnLPathOr(positions),
68
+ accountInfo,
69
+ // @hidden
70
+ positions: positionsPath(positions),
71
+ };
72
+ };