@nktkas/hyperliquid 0.24.3 → 0.25.0-beta.2
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/README.md +141 -32
- package/esm/mod.d.ts +11 -11
- package/esm/mod.d.ts.map +1 -1
- package/esm/mod.js +2 -1
- package/esm/mod.js.map +1 -0
- package/esm/src/clients/exchange.d.ts +29 -25
- package/esm/src/clients/exchange.d.ts.map +1 -1
- package/esm/src/clients/exchange.js +54 -53
- package/esm/src/clients/exchange.js.map +1 -0
- package/esm/src/clients/info.d.ts +80 -20
- package/esm/src/clients/info.d.ts.map +1 -1
- package/esm/src/clients/info.js +312 -73
- package/esm/src/clients/info.js.map +1 -0
- package/esm/src/clients/multiSign.d.ts +11 -7
- package/esm/src/clients/multiSign.d.ts.map +1 -1
- package/esm/src/clients/multiSign.js +2 -1
- package/esm/src/clients/multiSign.js.map +1 -0
- package/esm/src/clients/subscription.d.ts +9 -9
- package/esm/src/clients/subscription.d.ts.map +1 -1
- package/esm/src/clients/subscription.js +29 -27
- package/esm/src/clients/subscription.js.map +1 -0
- package/esm/src/{base.d.ts → errors.d.ts} +1 -1
- package/esm/src/errors.d.ts.map +1 -0
- package/esm/src/{base.js → errors.js} +1 -0
- package/esm/src/errors.js.map +1 -0
- package/esm/src/schemas/_base.d.ts +14 -0
- package/esm/src/schemas/_base.d.ts.map +1 -0
- package/esm/src/schemas/_base.js +15 -0
- package/esm/src/schemas/_base.js.map +1 -0
- package/esm/src/schemas/exchange/requests.d.ts +8953 -0
- package/esm/src/schemas/exchange/requests.d.ts.map +1 -0
- package/esm/src/schemas/exchange/requests.js +1414 -0
- package/esm/src/schemas/exchange/requests.js.map +1 -0
- package/esm/src/schemas/exchange/responses.d.ts +567 -0
- package/esm/src/schemas/exchange/responses.d.ts.map +1 -0
- package/esm/src/schemas/exchange/responses.js +244 -0
- package/esm/src/schemas/exchange/responses.js.map +1 -0
- package/esm/src/schemas/explorer/requests.d.ts +44 -0
- package/esm/src/schemas/explorer/requests.d.ts.map +1 -0
- package/esm/src/schemas/explorer/requests.js +33 -0
- package/esm/src/schemas/explorer/requests.js.map +1 -0
- package/esm/src/schemas/explorer/responses.d.ts +360 -0
- package/esm/src/schemas/explorer/responses.d.ts.map +1 -0
- package/esm/src/schemas/explorer/responses.js +57 -0
- package/esm/src/schemas/explorer/responses.js.map +1 -0
- package/esm/src/schemas/info/accounts.d.ts +2159 -0
- package/esm/src/schemas/info/accounts.d.ts.map +1 -0
- package/esm/src/schemas/info/accounts.js +623 -0
- package/esm/src/schemas/info/accounts.js.map +1 -0
- package/esm/src/schemas/info/assets.d.ts +974 -0
- package/esm/src/schemas/info/assets.d.ts.map +1 -0
- package/esm/src/schemas/info/assets.js +285 -0
- package/esm/src/schemas/info/assets.js.map +1 -0
- package/esm/src/schemas/info/markets.d.ts +155 -0
- package/esm/src/schemas/info/markets.d.ts.map +1 -0
- package/esm/src/schemas/info/markets.js +70 -0
- package/esm/src/schemas/info/markets.js.map +1 -0
- package/esm/src/schemas/info/orders.d.ts +957 -0
- package/esm/src/schemas/info/orders.d.ts.map +1 -0
- package/esm/src/schemas/info/orders.js +298 -0
- package/esm/src/schemas/info/orders.js.map +1 -0
- package/esm/src/schemas/info/requests.d.ts +924 -0
- package/esm/src/schemas/info/requests.d.ts.map +1 -0
- package/esm/src/schemas/info/requests.js +687 -0
- package/esm/src/schemas/info/requests.js.map +1 -0
- package/esm/src/schemas/info/validators.d.ts +326 -0
- package/esm/src/schemas/info/validators.d.ts.map +1 -0
- package/esm/src/schemas/info/validators.js +126 -0
- package/esm/src/schemas/info/validators.js.map +1 -0
- package/esm/src/schemas/info/vaults.d.ts +447 -0
- package/esm/src/schemas/info/vaults.d.ts.map +1 -0
- package/esm/src/schemas/info/vaults.js +111 -0
- package/esm/src/schemas/info/vaults.js.map +1 -0
- package/esm/src/schemas/mod.d.ts +101 -0
- package/esm/src/schemas/mod.d.ts.map +1 -0
- package/esm/src/schemas/mod.js +115 -0
- package/esm/src/schemas/mod.js.map +1 -0
- package/esm/src/schemas/subscriptions/requests.d.ts +332 -0
- package/esm/src/schemas/subscriptions/requests.d.ts.map +1 -0
- package/esm/src/schemas/subscriptions/requests.js +259 -0
- package/esm/src/schemas/subscriptions/requests.js.map +1 -0
- package/esm/src/schemas/subscriptions/responses.d.ts +3643 -0
- package/esm/src/schemas/subscriptions/responses.d.ts.map +1 -0
- package/esm/src/schemas/subscriptions/responses.js +234 -0
- package/esm/src/schemas/subscriptions/responses.js.map +1 -0
- package/esm/src/signing/_signTypedData/ethers.js +1 -0
- package/esm/src/signing/_signTypedData/ethers.js.map +1 -0
- package/esm/src/signing/_signTypedData/mod.js +1 -0
- package/esm/src/signing/_signTypedData/mod.js.map +1 -0
- package/esm/src/signing/_signTypedData/private_key.js +1 -0
- package/esm/src/signing/_signTypedData/private_key.js.map +1 -0
- package/esm/src/signing/_signTypedData/viem.js +1 -0
- package/esm/src/signing/_signTypedData/viem.js.map +1 -0
- package/esm/src/signing/mod.d.ts +109 -29
- package/esm/src/signing/mod.d.ts.map +1 -1
- package/esm/src/signing/mod.js +136 -29
- package/esm/src/signing/mod.js.map +1 -0
- package/esm/src/transports/base.d.ts +4 -4
- package/esm/src/transports/base.d.ts.map +1 -1
- package/esm/src/transports/base.js +3 -2
- package/esm/src/transports/base.js.map +1 -0
- package/esm/src/transports/http/http_transport.d.ts +3 -2
- package/esm/src/transports/http/http_transport.d.ts.map +1 -1
- package/esm/src/transports/http/http_transport.js +1 -0
- package/esm/src/transports/http/http_transport.js.map +1 -0
- package/esm/src/transports/websocket/_hyperliquid_event_target.d.ts +1 -1
- package/esm/src/transports/websocket/_hyperliquid_event_target.d.ts.map +1 -1
- package/esm/src/transports/websocket/_hyperliquid_event_target.js +1 -0
- package/esm/src/transports/websocket/_hyperliquid_event_target.js.map +1 -0
- package/esm/src/transports/websocket/_reconnecting_websocket.js +1 -0
- package/esm/src/transports/websocket/_reconnecting_websocket.js.map +1 -0
- package/esm/src/transports/websocket/_websocket_async_request.js +1 -0
- package/esm/src/transports/websocket/_websocket_async_request.js.map +1 -0
- package/esm/src/transports/websocket/websocket_transport.d.ts +9 -1
- package/esm/src/transports/websocket/websocket_transport.d.ts.map +1 -1
- package/esm/src/transports/websocket/websocket_transport.js +4 -0
- package/esm/src/transports/websocket/websocket_transport.js.map +1 -0
- package/package.json +6 -5
- package/script/mod.d.ts +11 -11
- package/script/mod.d.ts.map +1 -1
- package/script/mod.js +2 -1
- package/script/mod.js.map +1 -0
- package/script/src/clients/exchange.d.ts +29 -25
- package/script/src/clients/exchange.d.ts.map +1 -1
- package/script/src/clients/exchange.js +60 -59
- package/script/src/clients/exchange.js.map +1 -0
- package/script/src/clients/info.d.ts +80 -20
- package/script/src/clients/info.d.ts.map +1 -1
- package/script/src/clients/info.js +312 -73
- package/script/src/clients/info.js.map +1 -0
- package/script/src/clients/multiSign.d.ts +11 -7
- package/script/src/clients/multiSign.d.ts.map +1 -1
- package/script/src/clients/multiSign.js +2 -1
- package/script/src/clients/multiSign.js.map +1 -0
- package/script/src/clients/subscription.d.ts +9 -9
- package/script/src/clients/subscription.d.ts.map +1 -1
- package/script/src/clients/subscription.js +29 -27
- package/script/src/clients/subscription.js.map +1 -0
- package/script/src/{base.d.ts → errors.d.ts} +1 -1
- package/script/src/errors.d.ts.map +1 -0
- package/script/src/{base.js → errors.js} +1 -0
- package/script/src/errors.js.map +1 -0
- package/script/src/schemas/_base.d.ts +14 -0
- package/script/src/schemas/_base.d.ts.map +1 -0
- package/script/src/schemas/_base.js +51 -0
- package/script/src/schemas/_base.js.map +1 -0
- package/script/src/schemas/exchange/requests.d.ts +8953 -0
- package/script/src/schemas/exchange/requests.d.ts.map +1 -0
- package/script/src/schemas/exchange/requests.js +1450 -0
- package/script/src/schemas/exchange/requests.js.map +1 -0
- package/script/src/schemas/exchange/responses.d.ts +567 -0
- package/script/src/schemas/exchange/responses.d.ts.map +1 -0
- package/script/src/schemas/exchange/responses.js +280 -0
- package/script/src/schemas/exchange/responses.js.map +1 -0
- package/script/src/schemas/explorer/requests.d.ts +44 -0
- package/script/src/schemas/explorer/requests.d.ts.map +1 -0
- package/script/src/schemas/explorer/requests.js +69 -0
- package/script/src/schemas/explorer/requests.js.map +1 -0
- package/script/src/schemas/explorer/responses.d.ts +360 -0
- package/script/src/schemas/explorer/responses.d.ts.map +1 -0
- package/script/src/schemas/explorer/responses.js +93 -0
- package/script/src/schemas/explorer/responses.js.map +1 -0
- package/script/src/schemas/info/accounts.d.ts +2159 -0
- package/script/src/schemas/info/accounts.d.ts.map +1 -0
- package/script/src/schemas/info/accounts.js +659 -0
- package/script/src/schemas/info/accounts.js.map +1 -0
- package/script/src/schemas/info/assets.d.ts +974 -0
- package/script/src/schemas/info/assets.d.ts.map +1 -0
- package/script/src/schemas/info/assets.js +321 -0
- package/script/src/schemas/info/assets.js.map +1 -0
- package/script/src/schemas/info/markets.d.ts +155 -0
- package/script/src/schemas/info/markets.d.ts.map +1 -0
- package/script/src/schemas/info/markets.js +106 -0
- package/script/src/schemas/info/markets.js.map +1 -0
- package/script/src/schemas/info/orders.d.ts +957 -0
- package/script/src/schemas/info/orders.d.ts.map +1 -0
- package/script/src/schemas/info/orders.js +334 -0
- package/script/src/schemas/info/orders.js.map +1 -0
- package/script/src/schemas/info/requests.d.ts +924 -0
- package/script/src/schemas/info/requests.d.ts.map +1 -0
- package/script/src/schemas/info/requests.js +724 -0
- package/script/src/schemas/info/requests.js.map +1 -0
- package/script/src/schemas/info/validators.d.ts +326 -0
- package/script/src/schemas/info/validators.d.ts.map +1 -0
- package/script/src/schemas/info/validators.js +162 -0
- package/script/src/schemas/info/validators.js.map +1 -0
- package/script/src/schemas/info/vaults.d.ts +447 -0
- package/script/src/schemas/info/vaults.d.ts.map +1 -0
- package/script/src/schemas/info/vaults.js +147 -0
- package/script/src/schemas/info/vaults.js.map +1 -0
- package/script/src/schemas/mod.d.ts +101 -0
- package/script/src/schemas/mod.d.ts.map +1 -0
- package/script/src/schemas/mod.js +157 -0
- package/script/src/schemas/mod.js.map +1 -0
- package/script/src/schemas/subscriptions/requests.d.ts +332 -0
- package/script/src/schemas/subscriptions/requests.d.ts.map +1 -0
- package/script/src/schemas/subscriptions/requests.js +295 -0
- package/script/src/schemas/subscriptions/requests.js.map +1 -0
- package/script/src/schemas/subscriptions/responses.d.ts +3643 -0
- package/script/src/schemas/subscriptions/responses.d.ts.map +1 -0
- package/script/src/schemas/subscriptions/responses.js +270 -0
- package/script/src/schemas/subscriptions/responses.js.map +1 -0
- package/script/src/signing/_signTypedData/ethers.js +1 -0
- package/script/src/signing/_signTypedData/ethers.js.map +1 -0
- package/script/src/signing/_signTypedData/mod.js +1 -0
- package/script/src/signing/_signTypedData/mod.js.map +1 -0
- package/script/src/signing/_signTypedData/private_key.js +1 -0
- package/script/src/signing/_signTypedData/private_key.js.map +1 -0
- package/script/src/signing/_signTypedData/viem.js +1 -0
- package/script/src/signing/_signTypedData/viem.js.map +1 -0
- package/script/src/signing/mod.d.ts +109 -29
- package/script/src/signing/mod.d.ts.map +1 -1
- package/script/src/signing/mod.js +138 -33
- package/script/src/signing/mod.js.map +1 -0
- package/script/src/transports/base.d.ts +4 -4
- package/script/src/transports/base.d.ts.map +1 -1
- package/script/src/transports/base.js +4 -3
- package/script/src/transports/base.js.map +1 -0
- package/script/src/transports/http/http_transport.d.ts +3 -2
- package/script/src/transports/http/http_transport.d.ts.map +1 -1
- package/script/src/transports/http/http_transport.js +1 -0
- package/script/src/transports/http/http_transport.js.map +1 -0
- package/script/src/transports/websocket/_hyperliquid_event_target.d.ts +1 -1
- package/script/src/transports/websocket/_hyperliquid_event_target.d.ts.map +1 -1
- package/script/src/transports/websocket/_hyperliquid_event_target.js +1 -0
- package/script/src/transports/websocket/_hyperliquid_event_target.js.map +1 -0
- package/script/src/transports/websocket/_reconnecting_websocket.js +1 -0
- package/script/src/transports/websocket/_reconnecting_websocket.js.map +1 -0
- package/script/src/transports/websocket/_websocket_async_request.js +1 -0
- package/script/src/transports/websocket/_websocket_async_request.js.map +1 -0
- package/script/src/transports/websocket/websocket_transport.d.ts +9 -1
- package/script/src/transports/websocket/websocket_transport.d.ts.map +1 -1
- package/script/src/transports/websocket/websocket_transport.js +4 -0
- package/script/src/transports/websocket/websocket_transport.js.map +1 -0
- package/src/mod.ts +28 -0
- package/src/src/clients/exchange.ts +2246 -0
- package/src/src/clients/info.ts +2076 -0
- package/src/src/clients/multiSign.ts +183 -0
- package/src/src/clients/subscription.ts +841 -0
- package/src/src/errors.ts +7 -0
- package/src/src/schemas/_base.ts +43 -0
- package/src/src/schemas/exchange/requests.ts +3057 -0
- package/src/src/schemas/exchange/responses.ts +540 -0
- package/src/src/schemas/explorer/requests.ts +65 -0
- package/src/src/schemas/explorer/responses.ts +138 -0
- package/src/src/schemas/info/accounts.ts +1490 -0
- package/src/src/schemas/info/assets.ts +693 -0
- package/src/src/schemas/info/markets.ts +171 -0
- package/src/src/schemas/info/orders.ts +597 -0
- package/src/src/schemas/info/requests.ts +1369 -0
- package/src/src/schemas/info/validators.ts +299 -0
- package/src/src/schemas/info/vaults.ts +262 -0
- package/src/src/schemas/mod.ts +121 -0
- package/src/src/schemas/subscriptions/requests.ts +504 -0
- package/src/src/schemas/subscriptions/responses.ts +576 -0
- package/src/src/signing/_signTypedData/ethers.ts +59 -0
- package/src/src/signing/_signTypedData/mod.ts +121 -0
- package/src/src/signing/_signTypedData/private_key.ts +229 -0
- package/src/src/signing/_signTypedData/viem.ts +55 -0
- package/src/src/signing/mod.ts +572 -0
- package/src/src/transports/base.ts +54 -0
- package/src/src/transports/http/http_transport.ts +208 -0
- package/src/src/transports/websocket/_hyperliquid_event_target.ts +118 -0
- package/src/src/transports/websocket/_reconnecting_websocket.ts +404 -0
- package/src/src/transports/websocket/_websocket_async_request.ts +229 -0
- package/src/src/transports/websocket/websocket_transport.ts +394 -0
- package/esm/src/base.d.ts.map +0 -1
- package/esm/src/signing/_sorter.d.ts +0 -127
- package/esm/src/signing/_sorter.d.ts.map +0 -1
- package/esm/src/signing/_sorter.js +0 -693
- package/esm/src/types/exchange/requests.d.ts +0 -1345
- package/esm/src/types/exchange/requests.d.ts.map +0 -1
- package/esm/src/types/exchange/requests.js +0 -1
- package/esm/src/types/exchange/responses.d.ts +0 -233
- package/esm/src/types/exchange/responses.d.ts.map +0 -1
- package/esm/src/types/exchange/responses.js +0 -1
- package/esm/src/types/explorer/requests.d.ts +0 -32
- package/esm/src/types/explorer/requests.d.ts.map +0 -1
- package/esm/src/types/explorer/requests.js +0 -1
- package/esm/src/types/explorer/responses.d.ts +0 -58
- package/esm/src/types/explorer/responses.d.ts.map +0 -1
- package/esm/src/types/explorer/responses.js +0 -1
- package/esm/src/types/info/accounts.d.ts +0 -864
- package/esm/src/types/info/accounts.d.ts.map +0 -1
- package/esm/src/types/info/accounts.js +0 -1
- package/esm/src/types/info/assets.d.ts +0 -354
- package/esm/src/types/info/assets.d.ts.map +0 -1
- package/esm/src/types/info/assets.js +0 -1
- package/esm/src/types/info/markets.d.ts +0 -79
- package/esm/src/types/info/markets.d.ts.map +0 -1
- package/esm/src/types/info/markets.js +0 -1
- package/esm/src/types/info/orders.d.ts +0 -266
- package/esm/src/types/info/orders.d.ts.map +0 -1
- package/esm/src/types/info/orders.js +0 -1
- package/esm/src/types/info/requests.d.ts +0 -640
- package/esm/src/types/info/requests.d.ts.map +0 -1
- package/esm/src/types/info/requests.js +0 -1
- package/esm/src/types/info/validators.d.ts +0 -147
- package/esm/src/types/info/validators.d.ts.map +0 -1
- package/esm/src/types/info/validators.js +0 -1
- package/esm/src/types/info/vaults.d.ts +0 -119
- package/esm/src/types/info/vaults.d.ts.map +0 -1
- package/esm/src/types/info/vaults.js +0 -1
- package/esm/src/types/mod.d.ts +0 -38
- package/esm/src/types/mod.d.ts.map +0 -1
- package/esm/src/types/mod.js +0 -24
- package/esm/src/types/subscriptions/requests.d.ts +0 -154
- package/esm/src/types/subscriptions/requests.d.ts.map +0 -1
- package/esm/src/types/subscriptions/requests.js +0 -1
- package/esm/src/types/subscriptions/responses.d.ts +0 -238
- package/esm/src/types/subscriptions/responses.d.ts.map +0 -1
- package/esm/src/types/subscriptions/responses.js +0 -1
- package/script/src/base.d.ts.map +0 -1
- package/script/src/signing/_sorter.d.ts +0 -127
- package/script/src/signing/_sorter.d.ts.map +0 -1
- package/script/src/signing/_sorter.js +0 -696
- package/script/src/types/exchange/requests.d.ts +0 -1345
- package/script/src/types/exchange/requests.d.ts.map +0 -1
- package/script/src/types/exchange/requests.js +0 -2
- package/script/src/types/exchange/responses.d.ts +0 -233
- package/script/src/types/exchange/responses.d.ts.map +0 -1
- package/script/src/types/exchange/responses.js +0 -2
- package/script/src/types/explorer/requests.d.ts +0 -32
- package/script/src/types/explorer/requests.d.ts.map +0 -1
- package/script/src/types/explorer/requests.js +0 -2
- package/script/src/types/explorer/responses.d.ts +0 -58
- package/script/src/types/explorer/responses.d.ts.map +0 -1
- package/script/src/types/explorer/responses.js +0 -2
- package/script/src/types/info/accounts.d.ts +0 -864
- package/script/src/types/info/accounts.d.ts.map +0 -1
- package/script/src/types/info/accounts.js +0 -2
- package/script/src/types/info/assets.d.ts +0 -354
- package/script/src/types/info/assets.d.ts.map +0 -1
- package/script/src/types/info/assets.js +0 -2
- package/script/src/types/info/markets.d.ts +0 -79
- package/script/src/types/info/markets.d.ts.map +0 -1
- package/script/src/types/info/markets.js +0 -2
- package/script/src/types/info/orders.d.ts +0 -266
- package/script/src/types/info/orders.d.ts.map +0 -1
- package/script/src/types/info/orders.js +0 -2
- package/script/src/types/info/requests.d.ts +0 -640
- package/script/src/types/info/requests.d.ts.map +0 -1
- package/script/src/types/info/requests.js +0 -2
- package/script/src/types/info/validators.d.ts +0 -147
- package/script/src/types/info/validators.d.ts.map +0 -1
- package/script/src/types/info/validators.js +0 -2
- package/script/src/types/info/vaults.d.ts +0 -119
- package/script/src/types/info/vaults.d.ts.map +0 -1
- package/script/src/types/info/vaults.js +0 -2
- package/script/src/types/mod.d.ts +0 -38
- package/script/src/types/mod.d.ts.map +0 -1
- package/script/src/types/mod.js +0 -25
- package/script/src/types/subscriptions/requests.d.ts +0 -154
- package/script/src/types/subscriptions/requests.d.ts.map +0 -1
- package/script/src/types/subscriptions/requests.js +0 -2
- package/script/src/types/subscriptions/responses.d.ts +0 -238
- package/script/src/types/subscriptions/responses.d.ts.map +0 -1
- package/script/src/types/subscriptions/responses.js +0 -2
|
@@ -0,0 +1,841 @@
|
|
|
1
|
+
import type { ISubscriptionTransport, Subscription } from "../transports/base.js";
|
|
2
|
+
import {
|
|
3
|
+
type ActiveAssetData,
|
|
4
|
+
type Book,
|
|
5
|
+
type Candle,
|
|
6
|
+
type OrderStatus,
|
|
7
|
+
parser,
|
|
8
|
+
type TxDetails,
|
|
9
|
+
type WsActiveAssetCtx,
|
|
10
|
+
WsActiveAssetCtxRequest,
|
|
11
|
+
WsActiveAssetDataRequest,
|
|
12
|
+
type WsActiveSpotAssetCtx,
|
|
13
|
+
type WsAllMids,
|
|
14
|
+
WsAllMidsRequest,
|
|
15
|
+
type WsAssetCtxs,
|
|
16
|
+
WsAssetCtxsRequest,
|
|
17
|
+
type WsBbo,
|
|
18
|
+
WsBboRequest,
|
|
19
|
+
type WsBlockDetails,
|
|
20
|
+
WsCandleRequest,
|
|
21
|
+
type WsClearinghouseState,
|
|
22
|
+
WsClearinghouseStateRequest,
|
|
23
|
+
WsExplorerBlockRequest,
|
|
24
|
+
WsExplorerTxsRequest,
|
|
25
|
+
WsL2BookRequest,
|
|
26
|
+
type WsNotification,
|
|
27
|
+
WsNotificationRequest,
|
|
28
|
+
type WsOpenOrders,
|
|
29
|
+
WsOpenOrdersRequest,
|
|
30
|
+
WsOrderUpdatesRequest,
|
|
31
|
+
type WsTrade,
|
|
32
|
+
WsTradesRequest,
|
|
33
|
+
type WsUserEvent,
|
|
34
|
+
WsUserEventsRequest,
|
|
35
|
+
type WsUserFills,
|
|
36
|
+
WsUserFillsRequest,
|
|
37
|
+
type WsUserFundings,
|
|
38
|
+
WsUserFundingsRequest,
|
|
39
|
+
type WsUserNonFundingLedgerUpdates,
|
|
40
|
+
WsUserNonFundingLedgerUpdatesRequest,
|
|
41
|
+
type WsUserTwapHistory,
|
|
42
|
+
WsUserTwapHistoryRequest,
|
|
43
|
+
type WsUserTwapSliceFills,
|
|
44
|
+
WsUserTwapSliceFillsRequest,
|
|
45
|
+
type WsWebData2,
|
|
46
|
+
WsWebData2Request,
|
|
47
|
+
} from "../schemas/mod.js";
|
|
48
|
+
|
|
49
|
+
/** @see https://github.com/microsoft/TypeScript/issues/13923#issuecomment-2191862501 */
|
|
50
|
+
type DeepImmutable<T> = {
|
|
51
|
+
readonly [K in keyof T]: DeepImmutable<T[K]>;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
/** Parameters for the {@linkcode SubscriptionClient} constructor. */
|
|
55
|
+
export interface SubscriptionClientParameters<T extends ISubscriptionTransport = ISubscriptionTransport> {
|
|
56
|
+
/** The transport used to connect to the Hyperliquid API. */
|
|
57
|
+
transport: T;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** Subscription parameters for the {@linkcode SubscriptionClient.activeAssetCtx} method. */
|
|
61
|
+
export type WsActiveAssetCtxParameters = Omit<WsActiveAssetCtxRequest, "type">;
|
|
62
|
+
/** Subscription parameters for the {@linkcode SubscriptionClient.activeAssetData} method. */
|
|
63
|
+
export type WsActiveAssetDataParameters = Omit<WsActiveAssetDataRequest, "type">;
|
|
64
|
+
/** Subscription parameters for the {@linkcode SubscriptionClient.allMids} method. */
|
|
65
|
+
export type WsAllMidsParameters = Omit<WsAllMidsRequest, "type">;
|
|
66
|
+
/** Subscription parameters for the {@linkcode SubscriptionClient.assetCtxs} method. */
|
|
67
|
+
export type WsAssetCtxsParameters = Omit<WsAssetCtxsRequest, "type">;
|
|
68
|
+
/** Subscription parameters for the {@linkcode SubscriptionClient.bbo} method. */
|
|
69
|
+
export type WsBboParameters = Omit<WsBboRequest, "type">;
|
|
70
|
+
/** Subscription parameters for the {@linkcode SubscriptionClient.candle} method. */
|
|
71
|
+
export type WsCandleParameters = Omit<WsCandleRequest, "type">;
|
|
72
|
+
/** Subscription parameters for the {@linkcode SubscriptionClient.clearinghouseState} method. */
|
|
73
|
+
export type WsClearinghouseStateParameters = Omit<WsClearinghouseStateRequest, "type">;
|
|
74
|
+
/** Subscription parameters for the {@linkcode SubscriptionClient.l2Book} method. */
|
|
75
|
+
export type WsL2BookParameters = Omit<WsL2BookRequest, "type">;
|
|
76
|
+
/** Subscription parameters for the {@linkcode SubscriptionClient.notification} method. */
|
|
77
|
+
export type WsNotificationParameters = Omit<WsNotificationRequest, "type">;
|
|
78
|
+
/** Subscription parameters for the {@linkcode SubscriptionClient.openOrders} method. */
|
|
79
|
+
export type WsOpenOrdersParameters = Omit<WsOpenOrdersRequest, "type">;
|
|
80
|
+
/** Subscription parameters for the {@linkcode SubscriptionClient.orderUpdates} method. */
|
|
81
|
+
export type WsOrderUpdatesParameters = Omit<WsOrderUpdatesRequest, "type">;
|
|
82
|
+
/** Subscription parameters for the {@linkcode SubscriptionClient.trades} method. */
|
|
83
|
+
export type WsTradesParameters = Omit<WsTradesRequest, "type">;
|
|
84
|
+
/** Subscription parameters for the {@linkcode SubscriptionClient.userEvents} method. */
|
|
85
|
+
export type WsUserEventsParameters = Omit<WsUserEventsRequest, "type">;
|
|
86
|
+
/** Subscription parameters for the {@linkcode SubscriptionClient.userFills} method. */
|
|
87
|
+
export type WsUserFillsParameters = Omit<WsUserFillsRequest, "type">;
|
|
88
|
+
/** Subscription parameters for the {@linkcode SubscriptionClient.userFundings} method. */
|
|
89
|
+
export type WsUserFundingsParameters = Omit<WsUserFundingsRequest, "type">;
|
|
90
|
+
/** Subscription parameters for the {@linkcode SubscriptionClient.userNonFundingLedgerUpdates} method. */
|
|
91
|
+
export type WsUserNonFundingLedgerUpdatesParameters = Omit<WsUserNonFundingLedgerUpdatesRequest, "type">;
|
|
92
|
+
/** Subscription parameters for the {@linkcode SubscriptionClient.userTwapHistory} method. */
|
|
93
|
+
export type WsUserTwapHistoryParameters = Omit<WsUserTwapHistoryRequest, "type">;
|
|
94
|
+
/** Subscription parameters for the {@linkcode SubscriptionClient.userTwapSliceFills} method. */
|
|
95
|
+
export type WsUserTwapSliceFillsParameters = Omit<WsUserTwapSliceFillsRequest, "type">;
|
|
96
|
+
/** Subscription parameters for the {@linkcode SubscriptionClient.webData2} method. */
|
|
97
|
+
export type WsWebData2Parameters = Omit<WsWebData2Request, "type">;
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Subscription client for subscribing to various Hyperliquid events.
|
|
101
|
+
* @typeParam T The type of transport used to connect to the Hyperliquid Websocket API.
|
|
102
|
+
*/
|
|
103
|
+
export class SubscriptionClient<
|
|
104
|
+
T extends ISubscriptionTransport = ISubscriptionTransport,
|
|
105
|
+
> implements SubscriptionClientParameters<T>, AsyncDisposable {
|
|
106
|
+
transport: T;
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Initialises a new instance.
|
|
110
|
+
* @param args - The arguments for initialisation.
|
|
111
|
+
*
|
|
112
|
+
* @example
|
|
113
|
+
* ```ts
|
|
114
|
+
* import * as hl from "@nktkas/hyperliquid";
|
|
115
|
+
*
|
|
116
|
+
* const transport = new hl.WebSocketTransport();
|
|
117
|
+
* const subsClient = new hl.SubscriptionClient({ transport });
|
|
118
|
+
* ```
|
|
119
|
+
*/
|
|
120
|
+
constructor(args: SubscriptionClientParameters<T>) {
|
|
121
|
+
this.transport = args.transport;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Subscribe to context updates for a specific perpetual asset.
|
|
126
|
+
* @param params - Subscription-specific parameters.
|
|
127
|
+
* @param listener - A callback function to be called when the event is received.
|
|
128
|
+
* @returns A request-promise that resolves with a {@link Subscription} object to manage the subscription lifecycle.
|
|
129
|
+
*
|
|
130
|
+
* @throws {TransportError} When the transport layer throws an error.
|
|
131
|
+
*
|
|
132
|
+
* @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions
|
|
133
|
+
* @example
|
|
134
|
+
* ```ts
|
|
135
|
+
* import * as hl from "@nktkas/hyperliquid";
|
|
136
|
+
*
|
|
137
|
+
* const transport = new hl.WebSocketTransport();
|
|
138
|
+
* const subsClient = new hl.SubscriptionClient({ transport });
|
|
139
|
+
*
|
|
140
|
+
* const sub = await subsClient.activeAssetCtx({ coin: "ETH" }, (data) => {
|
|
141
|
+
* console.log(data);
|
|
142
|
+
* });
|
|
143
|
+
* ```
|
|
144
|
+
*/
|
|
145
|
+
activeAssetCtx(
|
|
146
|
+
params: DeepImmutable<WsActiveAssetCtxParameters>,
|
|
147
|
+
listener: (data: WsActiveAssetCtx | WsActiveSpotAssetCtx) => void,
|
|
148
|
+
): Promise<Subscription> {
|
|
149
|
+
const payload = parser(WsActiveAssetCtxRequest)({ type: "activeAssetCtx", ...params });
|
|
150
|
+
const channel = params.coin.startsWith("@") ? "activeSpotAssetCtx" : "activeAssetCtx";
|
|
151
|
+
return this.transport.subscribe<WsActiveAssetCtx | WsActiveSpotAssetCtx>(channel, payload, (e) => {
|
|
152
|
+
if (e.detail.coin === payload.coin) {
|
|
153
|
+
listener(e.detail);
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Subscribe to trading data updates for a specific asset and user.
|
|
160
|
+
* @param params - Subscription-specific parameters.
|
|
161
|
+
* @param listener - A callback function to be called when the event is received.
|
|
162
|
+
* @returns A request-promise that resolves with a {@link Subscription} object to manage the subscription lifecycle.
|
|
163
|
+
*
|
|
164
|
+
* @throws {TransportError} When the transport layer throws an error.
|
|
165
|
+
*
|
|
166
|
+
* @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions
|
|
167
|
+
* @example
|
|
168
|
+
* ```ts
|
|
169
|
+
* import * as hl from "@nktkas/hyperliquid";
|
|
170
|
+
*
|
|
171
|
+
* const transport = new hl.WebSocketTransport();
|
|
172
|
+
* const subsClient = new hl.SubscriptionClient({ transport });
|
|
173
|
+
*
|
|
174
|
+
* const sub = await subsClient.activeAssetData({ coin: "ETH", user: "0x..." }, (data) => {
|
|
175
|
+
* console.log(data);
|
|
176
|
+
* });
|
|
177
|
+
* ```
|
|
178
|
+
*/
|
|
179
|
+
activeAssetData(
|
|
180
|
+
params: DeepImmutable<WsActiveAssetDataParameters>,
|
|
181
|
+
listener: (data: ActiveAssetData) => void,
|
|
182
|
+
): Promise<Subscription> {
|
|
183
|
+
const payload = parser(WsActiveAssetDataRequest)({ type: "activeAssetData", ...params });
|
|
184
|
+
return this.transport.subscribe<ActiveAssetData>(payload.type, payload, (e) => {
|
|
185
|
+
if (e.detail.coin === payload.coin && e.detail.user === payload.user.toLowerCase()) {
|
|
186
|
+
listener(e.detail);
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Subscribe to mid prices for all actively traded assets.
|
|
193
|
+
* @param params - An optional subscription-specific parameters.
|
|
194
|
+
* @param listener - A callback function to be called when the event is received.
|
|
195
|
+
* @returns A request-promise that resolves with a {@link Subscription} object to manage the subscription lifecycle.
|
|
196
|
+
*
|
|
197
|
+
* @throws {TransportError} When the transport layer throws an error.
|
|
198
|
+
*
|
|
199
|
+
* @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions
|
|
200
|
+
* @example
|
|
201
|
+
* ```ts
|
|
202
|
+
* import * as hl from "@nktkas/hyperliquid";
|
|
203
|
+
*
|
|
204
|
+
* const transport = new hl.WebSocketTransport();
|
|
205
|
+
* const subsClient = new hl.SubscriptionClient({ transport });
|
|
206
|
+
*
|
|
207
|
+
* const sub = await subsClient.allMids((data) => {
|
|
208
|
+
* console.log(data);
|
|
209
|
+
* });
|
|
210
|
+
* ```
|
|
211
|
+
*/
|
|
212
|
+
allMids(listener: (data: WsAllMids) => void): Promise<Subscription>;
|
|
213
|
+
allMids(params: DeepImmutable<WsAllMidsParameters>, listener: (data: WsAllMids) => void): Promise<Subscription>;
|
|
214
|
+
allMids(
|
|
215
|
+
params_or_listener: DeepImmutable<WsAllMidsParameters> | ((data: WsAllMids) => void),
|
|
216
|
+
maybeListener?: (data: WsAllMids) => void,
|
|
217
|
+
): Promise<Subscription> {
|
|
218
|
+
const params = typeof params_or_listener === "function" ? {} : params_or_listener;
|
|
219
|
+
const listener = typeof params_or_listener === "function" ? params_or_listener : maybeListener!;
|
|
220
|
+
|
|
221
|
+
const payload = parser(WsAllMidsRequest)({ type: "allMids", ...params });
|
|
222
|
+
return this.transport.subscribe<WsAllMids>(payload.type, payload, (e) => {
|
|
223
|
+
listener(e.detail);
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* Subscribe to asset contexts for all perpetual assets.
|
|
229
|
+
* @param params - An optional subscription-specific parameters.
|
|
230
|
+
* @param listener - A callback function to be called when the event is received.
|
|
231
|
+
* @returns A request-promise that resolves with a {@link Subscription} object to manage the subscription lifecycle.
|
|
232
|
+
*
|
|
233
|
+
* @throws {TransportError} When the transport layer throws an error.
|
|
234
|
+
*
|
|
235
|
+
* @see null
|
|
236
|
+
* @example
|
|
237
|
+
* ```ts
|
|
238
|
+
* import * as hl from "@nktkas/hyperliquid";
|
|
239
|
+
*
|
|
240
|
+
* const transport = new hl.WebSocketTransport();
|
|
241
|
+
* const subsClient = new hl.SubscriptionClient({ transport });
|
|
242
|
+
*
|
|
243
|
+
* const sub = await subsClient.assetCtxs((data) => {
|
|
244
|
+
* console.log(data);
|
|
245
|
+
* });
|
|
246
|
+
* ```
|
|
247
|
+
*/
|
|
248
|
+
assetCtxs(listener: (data: WsAssetCtxs) => void): Promise<Subscription>;
|
|
249
|
+
assetCtxs(
|
|
250
|
+
params: DeepImmutable<WsAssetCtxsParameters>,
|
|
251
|
+
listener: (data: WsAssetCtxs) => void,
|
|
252
|
+
): Promise<Subscription>;
|
|
253
|
+
assetCtxs(
|
|
254
|
+
params_or_listener: DeepImmutable<WsAssetCtxsParameters> | ((data: WsAssetCtxs) => void),
|
|
255
|
+
maybeListener?: (data: WsAssetCtxs) => void,
|
|
256
|
+
): Promise<Subscription> {
|
|
257
|
+
const params = typeof params_or_listener === "function" ? {} : params_or_listener;
|
|
258
|
+
const listener = typeof params_or_listener === "function" ? params_or_listener : maybeListener!;
|
|
259
|
+
|
|
260
|
+
const payload = parser(WsAssetCtxsRequest)({
|
|
261
|
+
type: "assetCtxs",
|
|
262
|
+
...params,
|
|
263
|
+
dex: params.dex ?? "",
|
|
264
|
+
});
|
|
265
|
+
return this.transport.subscribe<WsAssetCtxs>(payload.type, payload, (e) => {
|
|
266
|
+
if (e.detail.dex === payload.dex) {
|
|
267
|
+
listener(e.detail);
|
|
268
|
+
}
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* Subscribe to best bid and offer updates for a specific asset.
|
|
274
|
+
* @param params - Subscription-specific parameters.
|
|
275
|
+
* @param listener - A callback function to be called when the event is received.
|
|
276
|
+
* @returns A request-promise that resolves with a {@link Subscription} object to manage the subscription lifecycle.
|
|
277
|
+
*
|
|
278
|
+
* @throws {TransportError} When the transport layer throws an error.
|
|
279
|
+
*
|
|
280
|
+
* @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions
|
|
281
|
+
* @example
|
|
282
|
+
* ```ts
|
|
283
|
+
* import * as hl from "@nktkas/hyperliquid";
|
|
284
|
+
*
|
|
285
|
+
* const transport = new hl.WebSocketTransport();
|
|
286
|
+
* const subsClient = new hl.SubscriptionClient({ transport });
|
|
287
|
+
*
|
|
288
|
+
* const sub = await subsClient.bbo({ coin: "ETH" }, (data) => {
|
|
289
|
+
* console.log(data);
|
|
290
|
+
* });
|
|
291
|
+
* ```
|
|
292
|
+
*/
|
|
293
|
+
bbo(
|
|
294
|
+
params: DeepImmutable<WsBboParameters>,
|
|
295
|
+
listener: (data: WsBbo) => void,
|
|
296
|
+
): Promise<Subscription> {
|
|
297
|
+
const payload = parser(WsBboRequest)({ type: "bbo", ...params });
|
|
298
|
+
return this.transport.subscribe<WsBbo>(payload.type, payload, (e) => {
|
|
299
|
+
if (e.detail.coin === payload.coin) {
|
|
300
|
+
listener(e.detail);
|
|
301
|
+
}
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
/**
|
|
306
|
+
* Subscribe to candlestick data updates for a specific asset.
|
|
307
|
+
* @param params - Subscription-specific parameters.
|
|
308
|
+
* @param listener - A callback function to be called when the event is received.
|
|
309
|
+
* @returns A request-promise that resolves with a {@link Subscription} object to manage the subscription lifecycle.
|
|
310
|
+
*
|
|
311
|
+
* @throws {TransportError} When the transport layer throws an error.
|
|
312
|
+
*
|
|
313
|
+
* @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions
|
|
314
|
+
* @example
|
|
315
|
+
* ```ts
|
|
316
|
+
* import * as hl from "@nktkas/hyperliquid";
|
|
317
|
+
*
|
|
318
|
+
* const transport = new hl.WebSocketTransport();
|
|
319
|
+
* const subsClient = new hl.SubscriptionClient({ transport });
|
|
320
|
+
*
|
|
321
|
+
* const sub = await subsClient.candle({ coin: "ETH", interval: "1h" }, (data) => {
|
|
322
|
+
* console.log(data);
|
|
323
|
+
* });
|
|
324
|
+
* ```
|
|
325
|
+
*/
|
|
326
|
+
candle(
|
|
327
|
+
params: DeepImmutable<WsCandleParameters>,
|
|
328
|
+
listener: (data: Candle) => void,
|
|
329
|
+
): Promise<Subscription> {
|
|
330
|
+
const payload = parser(WsCandleRequest)({ type: "candle", ...params });
|
|
331
|
+
return this.transport.subscribe<Candle>(payload.type, payload, (e) => {
|
|
332
|
+
if (e.detail.s === payload.coin && e.detail.i === payload.interval) {
|
|
333
|
+
listener(e.detail);
|
|
334
|
+
}
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
/**
|
|
339
|
+
* Subscribe to clearinghouse state updates for a specific user.
|
|
340
|
+
* @param params - Subscription-specific parameters.
|
|
341
|
+
* @param listener - A callback function to be called when the event is received.
|
|
342
|
+
* @returns A request-promise that resolves with a {@link Subscription} object to manage the subscription lifecycle.
|
|
343
|
+
*
|
|
344
|
+
* @throws {TransportError} When the transport layer throws an error.
|
|
345
|
+
*
|
|
346
|
+
* @see null
|
|
347
|
+
* @example
|
|
348
|
+
* ```ts
|
|
349
|
+
* import * as hl from "@nktkas/hyperliquid";
|
|
350
|
+
*
|
|
351
|
+
* const transport = new hl.WebSocketTransport();
|
|
352
|
+
* const subsClient = new hl.SubscriptionClient({ transport });
|
|
353
|
+
*
|
|
354
|
+
* const sub = await subsClient.clearinghouseState({ user: "0x..." }, (data) => {
|
|
355
|
+
* console.log(data);
|
|
356
|
+
* });
|
|
357
|
+
* ```
|
|
358
|
+
*/
|
|
359
|
+
clearinghouseState(
|
|
360
|
+
params: DeepImmutable<WsClearinghouseStateParameters>,
|
|
361
|
+
listener: (data: WsClearinghouseState) => void,
|
|
362
|
+
): Promise<Subscription> {
|
|
363
|
+
const payload = parser(WsClearinghouseStateRequest)({
|
|
364
|
+
type: "clearinghouseState",
|
|
365
|
+
...params,
|
|
366
|
+
dex: params.dex ?? "",
|
|
367
|
+
});
|
|
368
|
+
return this.transport.subscribe<WsClearinghouseState>(payload.type, payload, (e) => {
|
|
369
|
+
if (e.detail.user === payload.user.toLowerCase() && e.detail.dex === payload.dex) {
|
|
370
|
+
listener(e.detail);
|
|
371
|
+
}
|
|
372
|
+
});
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
/**
|
|
376
|
+
* Subscribe to explorer block updates.
|
|
377
|
+
* @param listener - A callback function to be called when the event is received.
|
|
378
|
+
* @returns A request-promise that resolves with a {@link Subscription} object to manage the subscription lifecycle.
|
|
379
|
+
* @note Make sure the endpoint in the {@link transport} supports this method.
|
|
380
|
+
*
|
|
381
|
+
* @throws {TransportError} When the transport layer throws an error.
|
|
382
|
+
*
|
|
383
|
+
* @see null
|
|
384
|
+
* @example
|
|
385
|
+
* ```ts
|
|
386
|
+
* import * as hl from "@nktkas/hyperliquid";
|
|
387
|
+
*
|
|
388
|
+
* const transport = new hl.WebSocketTransport();
|
|
389
|
+
* const subsClient = new hl.SubscriptionClient({ transport });
|
|
390
|
+
*
|
|
391
|
+
* const sub = await subsClient.explorerBlock((data) => {
|
|
392
|
+
* console.log(data);
|
|
393
|
+
* });
|
|
394
|
+
* ```
|
|
395
|
+
*/
|
|
396
|
+
explorerBlock(listener: (data: WsBlockDetails[]) => void): Promise<Subscription> {
|
|
397
|
+
const payload = parser(WsExplorerBlockRequest)({ type: "explorerBlock" });
|
|
398
|
+
return this.transport.subscribe<WsBlockDetails[]>("_explorerBlock", payload, (e) => { // Internal channel as it does not have its own channel
|
|
399
|
+
listener(e.detail);
|
|
400
|
+
});
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
/**
|
|
404
|
+
* Subscribe to explorer transaction updates.
|
|
405
|
+
* @param listener - A callback function to be called when the event is received.
|
|
406
|
+
* @returns A request-promise that resolves with a {@link Subscription} object to manage the subscription lifecycle.
|
|
407
|
+
* @note Make sure the endpoint in the {@link transport} supports this method.
|
|
408
|
+
*
|
|
409
|
+
* @throws {TransportError} When the transport layer throws an error.
|
|
410
|
+
*
|
|
411
|
+
* @see null
|
|
412
|
+
* @example
|
|
413
|
+
* ```ts
|
|
414
|
+
* import * as hl from "@nktkas/hyperliquid";
|
|
415
|
+
*
|
|
416
|
+
* const transport = new hl.WebSocketTransport();
|
|
417
|
+
* const subsClient = new hl.SubscriptionClient({ transport });
|
|
418
|
+
*
|
|
419
|
+
* const sub = await subsClient.explorerTxs((data) => {
|
|
420
|
+
* console.log(data);
|
|
421
|
+
* });
|
|
422
|
+
* ```
|
|
423
|
+
*/
|
|
424
|
+
explorerTxs(listener: (data: TxDetails[]) => void): Promise<Subscription> {
|
|
425
|
+
const payload = parser(WsExplorerTxsRequest)({ type: "explorerTxs" });
|
|
426
|
+
return this.transport.subscribe<TxDetails[]>("_explorerTxs", payload, (e) => { // Internal channel as it does not have its own channel
|
|
427
|
+
listener(e.detail);
|
|
428
|
+
});
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
/**
|
|
432
|
+
* Subscribe to L2 order book updates for a specific asset.
|
|
433
|
+
* @param params - Subscription-specific parameters.
|
|
434
|
+
* @param listener - A callback function to be called when the event is received.
|
|
435
|
+
* @returns A request-promise that resolves with a {@link Subscription} object to manage the subscription lifecycle.
|
|
436
|
+
*
|
|
437
|
+
* @throws {TransportError} When the transport layer throws an error.
|
|
438
|
+
*
|
|
439
|
+
* @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions
|
|
440
|
+
* @example
|
|
441
|
+
* ```ts
|
|
442
|
+
* import * as hl from "@nktkas/hyperliquid";
|
|
443
|
+
*
|
|
444
|
+
* const transport = new hl.WebSocketTransport();
|
|
445
|
+
* const subsClient = new hl.SubscriptionClient({ transport });
|
|
446
|
+
*
|
|
447
|
+
* const sub = await subsClient.l2Book({ coin: "ETH" }, (data) => {
|
|
448
|
+
* console.log(data);
|
|
449
|
+
* });
|
|
450
|
+
* ```
|
|
451
|
+
*/
|
|
452
|
+
l2Book(
|
|
453
|
+
params: DeepImmutable<WsL2BookParameters>,
|
|
454
|
+
listener: (data: Book) => void,
|
|
455
|
+
): Promise<Subscription> {
|
|
456
|
+
const payload = parser(WsL2BookRequest)({
|
|
457
|
+
type: "l2Book",
|
|
458
|
+
...params,
|
|
459
|
+
nSigFigs: params.nSigFigs ?? null,
|
|
460
|
+
mantissa: params.mantissa ?? null,
|
|
461
|
+
});
|
|
462
|
+
return this.transport.subscribe<Book>(payload.type, payload, (e) => {
|
|
463
|
+
if (e.detail.coin === payload.coin) {
|
|
464
|
+
listener(e.detail);
|
|
465
|
+
}
|
|
466
|
+
});
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
/**
|
|
470
|
+
* Subscribe to notification updates for a specific user.
|
|
471
|
+
* @param params - Subscription-specific parameters.
|
|
472
|
+
* @param listener - A callback function to be called when the event is received.
|
|
473
|
+
* @returns A request-promise that resolves with a {@link Subscription} object to manage the subscription lifecycle.
|
|
474
|
+
*
|
|
475
|
+
* @throws {TransportError} When the transport layer throws an error.
|
|
476
|
+
*
|
|
477
|
+
* @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions
|
|
478
|
+
* @example
|
|
479
|
+
* ```ts
|
|
480
|
+
* import * as hl from "@nktkas/hyperliquid";
|
|
481
|
+
*
|
|
482
|
+
* const transport = new hl.WebSocketTransport();
|
|
483
|
+
* const subsClient = new hl.SubscriptionClient({ transport });
|
|
484
|
+
*
|
|
485
|
+
* const sub = await subsClient.notification({ user: "0x..." }, (data) => {
|
|
486
|
+
* console.log(data);
|
|
487
|
+
* });
|
|
488
|
+
* ```
|
|
489
|
+
*/
|
|
490
|
+
notification(
|
|
491
|
+
params: DeepImmutable<WsNotificationParameters>,
|
|
492
|
+
listener: (data: WsNotification) => void,
|
|
493
|
+
): Promise<Subscription> {
|
|
494
|
+
const payload = parser(WsNotificationRequest)({ type: "notification", ...params });
|
|
495
|
+
return this.transport.subscribe<WsNotification>(payload.type, payload, (e) => {
|
|
496
|
+
listener(e.detail);
|
|
497
|
+
});
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
/**
|
|
501
|
+
* Subscribe to open orders updates for a specific user.
|
|
502
|
+
* @param params - Subscription-specific parameters.
|
|
503
|
+
* @param listener - A callback function to be called when the event is received.
|
|
504
|
+
* @returns A request-promise that resolves with a {@link Subscription} object to manage the subscription lifecycle.
|
|
505
|
+
*
|
|
506
|
+
* @throws {TransportError} When the transport layer throws an error.
|
|
507
|
+
*
|
|
508
|
+
* @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions
|
|
509
|
+
* @example
|
|
510
|
+
* ```ts
|
|
511
|
+
* import * as hl from "@nktkas/hyperliquid";
|
|
512
|
+
*
|
|
513
|
+
* const transport = new hl.WebSocketTransport();
|
|
514
|
+
* const subsClient = new hl.SubscriptionClient({ transport });
|
|
515
|
+
*
|
|
516
|
+
* const sub = await subsClient.openOrders({ user: "0x..." }, (data) => {
|
|
517
|
+
* console.log(data);
|
|
518
|
+
* });
|
|
519
|
+
* ```
|
|
520
|
+
*/
|
|
521
|
+
openOrders(
|
|
522
|
+
params: DeepImmutable<WsOpenOrdersParameters>,
|
|
523
|
+
listener: (data: WsOpenOrders) => void,
|
|
524
|
+
): Promise<Subscription> {
|
|
525
|
+
const payload = parser(WsOpenOrdersRequest)({
|
|
526
|
+
type: "openOrders",
|
|
527
|
+
...params,
|
|
528
|
+
dex: params.dex ?? "",
|
|
529
|
+
});
|
|
530
|
+
return this.transport.subscribe<WsOpenOrders>(payload.type, payload, (e) => {
|
|
531
|
+
if (e.detail.user === payload.user.toLowerCase() && e.detail.dex === payload.dex) {
|
|
532
|
+
listener(e.detail);
|
|
533
|
+
}
|
|
534
|
+
});
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
/**
|
|
538
|
+
* Subscribe to order status updates for a specific user.
|
|
539
|
+
* @param params - Subscription-specific parameters.
|
|
540
|
+
* @param listener - A callback function to be called when the event is received.
|
|
541
|
+
* @returns A request-promise that resolves with a {@link Subscription} object to manage the subscription lifecycle.
|
|
542
|
+
*
|
|
543
|
+
* @throws {TransportError} When the transport layer throws an error.
|
|
544
|
+
*
|
|
545
|
+
* @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions
|
|
546
|
+
* @example
|
|
547
|
+
* ```ts
|
|
548
|
+
* import * as hl from "@nktkas/hyperliquid";
|
|
549
|
+
*
|
|
550
|
+
* const transport = new hl.WebSocketTransport();
|
|
551
|
+
* const subsClient = new hl.SubscriptionClient({ transport });
|
|
552
|
+
*
|
|
553
|
+
* const sub = await subsClient.orderUpdates({ user: "0x..." }, (data) => {
|
|
554
|
+
* console.log(data);
|
|
555
|
+
* });
|
|
556
|
+
* ```
|
|
557
|
+
*/
|
|
558
|
+
orderUpdates(
|
|
559
|
+
params: DeepImmutable<WsOrderUpdatesParameters>,
|
|
560
|
+
listener: (data: OrderStatus[]) => void,
|
|
561
|
+
): Promise<Subscription> {
|
|
562
|
+
const payload = parser(WsOrderUpdatesRequest)({ type: "orderUpdates", ...params });
|
|
563
|
+
return this.transport.subscribe<OrderStatus[]>(payload.type, payload, (e) => {
|
|
564
|
+
listener(e.detail);
|
|
565
|
+
});
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
/**
|
|
569
|
+
* Subscribe to real-time trade updates for a specific asset.
|
|
570
|
+
* @param params - Subscription-specific parameters.
|
|
571
|
+
* @param listener - A callback function to be called when the event is received.
|
|
572
|
+
* @returns A request-promise that resolves with a {@link Subscription} object to manage the subscription lifecycle.
|
|
573
|
+
*
|
|
574
|
+
* @throws {TransportError} When the transport layer throws an error.
|
|
575
|
+
*
|
|
576
|
+
* @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions
|
|
577
|
+
* @example
|
|
578
|
+
* ```ts
|
|
579
|
+
* import * as hl from "@nktkas/hyperliquid";
|
|
580
|
+
*
|
|
581
|
+
* const transport = new hl.WebSocketTransport();
|
|
582
|
+
* const subsClient = new hl.SubscriptionClient({ transport });
|
|
583
|
+
*
|
|
584
|
+
* const sub = await subsClient.trades({ coin: "ETH" }, (data) => {
|
|
585
|
+
* console.log(data);
|
|
586
|
+
* });
|
|
587
|
+
* ```
|
|
588
|
+
*/
|
|
589
|
+
trades(
|
|
590
|
+
params: DeepImmutable<WsTradesParameters>,
|
|
591
|
+
listener: (data: WsTrade[]) => void,
|
|
592
|
+
): Promise<Subscription> {
|
|
593
|
+
const payload = parser(WsTradesRequest)({ type: "trades", ...params });
|
|
594
|
+
return this.transport.subscribe<WsTrade[]>(payload.type, payload, (e) => {
|
|
595
|
+
if (e.detail[0]?.coin === payload.coin) {
|
|
596
|
+
listener(e.detail);
|
|
597
|
+
}
|
|
598
|
+
});
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
/**
|
|
602
|
+
* Subscribe to non-order events for a specific user.
|
|
603
|
+
* @param params - Subscription-specific parameters.
|
|
604
|
+
* @param listener - A callback function to be called when the event is received.
|
|
605
|
+
* @returns A request-promise that resolves with a {@link Subscription} object to manage the subscription lifecycle.
|
|
606
|
+
* @note Different subscriptions cannot be distinguished from each other.
|
|
607
|
+
*
|
|
608
|
+
* @throws {TransportError} When the transport layer throws an error.
|
|
609
|
+
*
|
|
610
|
+
* @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions
|
|
611
|
+
* @example
|
|
612
|
+
* ```ts
|
|
613
|
+
* import * as hl from "@nktkas/hyperliquid";
|
|
614
|
+
*
|
|
615
|
+
* const transport = new hl.WebSocketTransport();
|
|
616
|
+
* const subsClient = new hl.SubscriptionClient({ transport });
|
|
617
|
+
*
|
|
618
|
+
* const sub = await subsClient.userEvents({ user: "0x..." }, (data) => {
|
|
619
|
+
* console.log(data);
|
|
620
|
+
* });
|
|
621
|
+
* ```
|
|
622
|
+
*/
|
|
623
|
+
userEvents(
|
|
624
|
+
params: DeepImmutable<WsUserEventsParameters>,
|
|
625
|
+
listener: (data: WsUserEvent) => void,
|
|
626
|
+
): Promise<Subscription> {
|
|
627
|
+
const payload = parser(WsUserEventsRequest)({ type: "userEvents", ...params });
|
|
628
|
+
return this.transport.subscribe<WsUserEvent>("user", payload, (e) => {
|
|
629
|
+
listener(e.detail);
|
|
630
|
+
});
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
/**
|
|
634
|
+
* Subscribe to trade fill updates for a specific user.
|
|
635
|
+
* @param params - Subscription-specific parameters.
|
|
636
|
+
* @param listener - A callback function to be called when the event is received.
|
|
637
|
+
* @returns A request-promise that resolves with a {@link Subscription} object to manage the subscription lifecycle.
|
|
638
|
+
*
|
|
639
|
+
* @throws {TransportError} When the transport layer throws an error.
|
|
640
|
+
*
|
|
641
|
+
* @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions
|
|
642
|
+
* @example
|
|
643
|
+
* ```ts
|
|
644
|
+
* import * as hl from "@nktkas/hyperliquid";
|
|
645
|
+
*
|
|
646
|
+
* const transport = new hl.WebSocketTransport();
|
|
647
|
+
* const subsClient = new hl.SubscriptionClient({ transport });
|
|
648
|
+
*
|
|
649
|
+
* const sub = await subsClient.userFills({ user: "0x..." }, (data) => {
|
|
650
|
+
* console.log(data);
|
|
651
|
+
* });
|
|
652
|
+
* ```
|
|
653
|
+
*/
|
|
654
|
+
userFills(
|
|
655
|
+
params: DeepImmutable<WsUserFillsParameters>,
|
|
656
|
+
listener: (data: WsUserFills) => void,
|
|
657
|
+
): Promise<Subscription> {
|
|
658
|
+
const payload = parser(WsUserFillsRequest)({
|
|
659
|
+
type: "userFills",
|
|
660
|
+
...params,
|
|
661
|
+
aggregateByTime: params.aggregateByTime ?? false,
|
|
662
|
+
});
|
|
663
|
+
return this.transport.subscribe<WsUserFills>(payload.type, payload, (e) => {
|
|
664
|
+
if (e.detail.user === payload.user.toLowerCase()) {
|
|
665
|
+
listener(e.detail);
|
|
666
|
+
}
|
|
667
|
+
});
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
/**
|
|
671
|
+
* Subscribe to funding payment updates for a specific user.
|
|
672
|
+
* @param params - Subscription-specific parameters.
|
|
673
|
+
* @param listener - A callback function to be called when the event is received.
|
|
674
|
+
* @returns A request-promise that resolves with a {@link Subscription} object to manage the subscription lifecycle.
|
|
675
|
+
*
|
|
676
|
+
* @throws {TransportError} When the transport layer throws an error.
|
|
677
|
+
*
|
|
678
|
+
* @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions
|
|
679
|
+
* @example
|
|
680
|
+
* ```ts
|
|
681
|
+
* import * as hl from "@nktkas/hyperliquid";
|
|
682
|
+
*
|
|
683
|
+
* const transport = new hl.WebSocketTransport();
|
|
684
|
+
* const subsClient = new hl.SubscriptionClient({ transport });
|
|
685
|
+
*
|
|
686
|
+
* const sub = await subsClient.userFundings({ user: "0x..." }, (data) => {
|
|
687
|
+
* console.log(data);
|
|
688
|
+
* });
|
|
689
|
+
* ```
|
|
690
|
+
*/
|
|
691
|
+
userFundings(
|
|
692
|
+
params: DeepImmutable<WsUserFundingsParameters>,
|
|
693
|
+
listener: (data: WsUserFundings) => void,
|
|
694
|
+
): Promise<Subscription> {
|
|
695
|
+
const payload = parser(WsUserFundingsRequest)({ type: "userFundings", ...params });
|
|
696
|
+
return this.transport.subscribe<WsUserFundings>(payload.type, payload, (e) => {
|
|
697
|
+
if (e.detail.user === payload.user.toLowerCase()) {
|
|
698
|
+
listener(e.detail);
|
|
699
|
+
}
|
|
700
|
+
});
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
/**
|
|
704
|
+
* Subscribe to non-funding ledger updates for a specific user.
|
|
705
|
+
* @param params - Subscription-specific parameters.
|
|
706
|
+
* @param listener - A callback function to be called when the event is received.
|
|
707
|
+
* @returns A request-promise that resolves with a {@link Subscription} object to manage the subscription lifecycle.
|
|
708
|
+
*
|
|
709
|
+
* @throws {TransportError} When the transport layer throws an error.
|
|
710
|
+
*
|
|
711
|
+
* @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions
|
|
712
|
+
* @example
|
|
713
|
+
* ```ts
|
|
714
|
+
* import * as hl from "@nktkas/hyperliquid";
|
|
715
|
+
*
|
|
716
|
+
* const transport = new hl.WebSocketTransport();
|
|
717
|
+
* const subsClient = new hl.SubscriptionClient({ transport });
|
|
718
|
+
*
|
|
719
|
+
* const sub = await subsClient.userNonFundingLedgerUpdates({ user: "0x..." }, (data) => {
|
|
720
|
+
* console.log(data);
|
|
721
|
+
* });
|
|
722
|
+
* ```
|
|
723
|
+
*/
|
|
724
|
+
userNonFundingLedgerUpdates(
|
|
725
|
+
params: DeepImmutable<WsUserNonFundingLedgerUpdatesParameters>,
|
|
726
|
+
listener: (data: WsUserNonFundingLedgerUpdates) => void,
|
|
727
|
+
): Promise<Subscription> {
|
|
728
|
+
const payload = parser(WsUserNonFundingLedgerUpdatesRequest)({
|
|
729
|
+
type: "userNonFundingLedgerUpdates",
|
|
730
|
+
...params,
|
|
731
|
+
});
|
|
732
|
+
return this.transport.subscribe<WsUserNonFundingLedgerUpdates>(payload.type, payload, (e) => {
|
|
733
|
+
if (e.detail.user === payload.user.toLowerCase()) {
|
|
734
|
+
listener(e.detail);
|
|
735
|
+
}
|
|
736
|
+
});
|
|
737
|
+
}
|
|
738
|
+
|
|
739
|
+
/**
|
|
740
|
+
* Subscribe to TWAP order history updates for a specific user.
|
|
741
|
+
* @param params - Subscription-specific parameters.
|
|
742
|
+
* @param listener - A callback function to be called when the event is received.
|
|
743
|
+
* @returns A request-promise that resolves with a {@link Subscription} object to manage the subscription lifecycle.
|
|
744
|
+
*
|
|
745
|
+
* @throws {TransportError} When the transport layer throws an error.
|
|
746
|
+
*
|
|
747
|
+
* @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions
|
|
748
|
+
* @example
|
|
749
|
+
* ```ts
|
|
750
|
+
* import * as hl from "@nktkas/hyperliquid";
|
|
751
|
+
*
|
|
752
|
+
* const transport = new hl.WebSocketTransport();
|
|
753
|
+
* const subsClient = new hl.SubscriptionClient({ transport });
|
|
754
|
+
*
|
|
755
|
+
* const sub = await subsClient.userTwapHistory({ user: "0x..." }, (data) => {
|
|
756
|
+
* console.log(data);
|
|
757
|
+
* });
|
|
758
|
+
* ```
|
|
759
|
+
*/
|
|
760
|
+
userTwapHistory(
|
|
761
|
+
params: DeepImmutable<WsUserTwapHistoryParameters>,
|
|
762
|
+
listener: (data: WsUserTwapHistory) => void,
|
|
763
|
+
): Promise<Subscription> {
|
|
764
|
+
const payload = parser(WsUserTwapHistoryRequest)({ type: "userTwapHistory", ...params });
|
|
765
|
+
return this.transport.subscribe<WsUserTwapHistory>(payload.type, payload, (e) => {
|
|
766
|
+
if (e.detail.user === payload.user.toLowerCase()) {
|
|
767
|
+
listener(e.detail);
|
|
768
|
+
}
|
|
769
|
+
});
|
|
770
|
+
}
|
|
771
|
+
|
|
772
|
+
/**
|
|
773
|
+
* Subscribe to TWAP execution updates for a specific user.
|
|
774
|
+
* @param params - Subscription-specific parameters.
|
|
775
|
+
* @param listener - A callback function to be called when the event is received.
|
|
776
|
+
* @returns A request-promise that resolves with a {@link Subscription} object to manage the subscription lifecycle.
|
|
777
|
+
*
|
|
778
|
+
* @throws {TransportError} When the transport layer throws an error.
|
|
779
|
+
*
|
|
780
|
+
* @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions
|
|
781
|
+
* @example
|
|
782
|
+
* ```ts
|
|
783
|
+
* import * as hl from "@nktkas/hyperliquid";
|
|
784
|
+
*
|
|
785
|
+
* const transport = new hl.WebSocketTransport();
|
|
786
|
+
* const subsClient = new hl.SubscriptionClient({ transport });
|
|
787
|
+
*
|
|
788
|
+
* const sub = await subsClient.userTwapSliceFills({ user: "0x..." }, (data) => {
|
|
789
|
+
* console.log(data);
|
|
790
|
+
* });
|
|
791
|
+
* ```
|
|
792
|
+
*/
|
|
793
|
+
userTwapSliceFills(
|
|
794
|
+
params: DeepImmutable<WsUserTwapSliceFillsParameters>,
|
|
795
|
+
listener: (data: WsUserTwapSliceFills) => void,
|
|
796
|
+
): Promise<Subscription> {
|
|
797
|
+
const payload = parser(WsUserTwapSliceFillsRequest)({ type: "userTwapSliceFills", ...params });
|
|
798
|
+
return this.transport.subscribe<WsUserTwapSliceFills>(payload.type, payload, (e) => {
|
|
799
|
+
if (e.detail.user === payload.user.toLowerCase()) {
|
|
800
|
+
listener(e.detail);
|
|
801
|
+
}
|
|
802
|
+
});
|
|
803
|
+
}
|
|
804
|
+
|
|
805
|
+
/**
|
|
806
|
+
* Subscribe to comprehensive user and market data updates.
|
|
807
|
+
* @param params - Subscription-specific parameters.
|
|
808
|
+
* @param listener - A callback function to be called when the event is received.
|
|
809
|
+
* @returns A request-promise that resolves with a {@link Subscription} object to manage the subscription lifecycle.
|
|
810
|
+
*
|
|
811
|
+
* @throws {TransportError} When the transport layer throws an error.
|
|
812
|
+
*
|
|
813
|
+
* @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions
|
|
814
|
+
* @example
|
|
815
|
+
* ```ts
|
|
816
|
+
* import * as hl from "@nktkas/hyperliquid";
|
|
817
|
+
*
|
|
818
|
+
* const transport = new hl.WebSocketTransport();
|
|
819
|
+
* const subsClient = new hl.SubscriptionClient({ transport });
|
|
820
|
+
*
|
|
821
|
+
* const sub = await subsClient.webData2({ user: "0x..." }, (data) => {
|
|
822
|
+
* console.log(data);
|
|
823
|
+
* });
|
|
824
|
+
* ```
|
|
825
|
+
*/
|
|
826
|
+
webData2(
|
|
827
|
+
params: DeepImmutable<WsWebData2Parameters>,
|
|
828
|
+
listener: (data: WsWebData2) => void,
|
|
829
|
+
): Promise<Subscription> {
|
|
830
|
+
const payload = parser(WsWebData2Request)({ type: "webData2", ...params });
|
|
831
|
+
return this.transport.subscribe<WsWebData2>(payload.type, payload, (e) => {
|
|
832
|
+
if (e.detail.user === payload.user.toLowerCase()) {
|
|
833
|
+
listener(e.detail);
|
|
834
|
+
}
|
|
835
|
+
});
|
|
836
|
+
}
|
|
837
|
+
|
|
838
|
+
async [Symbol.asyncDispose](): Promise<void> {
|
|
839
|
+
await this.transport[Symbol.asyncDispose]?.();
|
|
840
|
+
}
|
|
841
|
+
}
|