clodds 1.1.0
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/LICENSE +21 -0
- package/README.md +468 -0
- package/dist/acp/agreement.d.ts +110 -0
- package/dist/acp/agreement.js +514 -0
- package/dist/acp/agreement.js.map +1 -0
- package/dist/acp/discovery.d.ts +84 -0
- package/dist/acp/discovery.js +332 -0
- package/dist/acp/discovery.js.map +1 -0
- package/dist/acp/escrow.d.ts +139 -0
- package/dist/acp/escrow.js +880 -0
- package/dist/acp/escrow.js.map +1 -0
- package/dist/acp/identity.d.ts +135 -0
- package/dist/acp/identity.js +716 -0
- package/dist/acp/identity.js.map +1 -0
- package/dist/acp/index.d.ts +205 -0
- package/dist/acp/index.js +583 -0
- package/dist/acp/index.js.map +1 -0
- package/dist/acp/persistence.d.ts +59 -0
- package/dist/acp/persistence.js +590 -0
- package/dist/acp/persistence.js.map +1 -0
- package/dist/acp/predictions.d.ts +89 -0
- package/dist/acp/predictions.js +417 -0
- package/dist/acp/predictions.js.map +1 -0
- package/dist/acp/registry.d.ts +143 -0
- package/dist/acp/registry.js +584 -0
- package/dist/acp/registry.js.map +1 -0
- package/dist/agents/handlers/acp.d.ts +12 -0
- package/dist/agents/handlers/acp.js +987 -0
- package/dist/agents/handlers/acp.js.map +1 -0
- package/dist/agents/handlers/agentbets.d.ts +8 -0
- package/dist/agents/handlers/agentbets.js +63 -0
- package/dist/agents/handlers/agentbets.js.map +1 -0
- package/dist/agents/handlers/arbitrage.d.ts +16 -0
- package/dist/agents/handlers/arbitrage.js +187 -0
- package/dist/agents/handlers/arbitrage.js.map +1 -0
- package/dist/agents/handlers/betfair.d.ts +11 -0
- package/dist/agents/handlers/betfair.js +214 -0
- package/dist/agents/handlers/betfair.js.map +1 -0
- package/dist/agents/handlers/binance.d.ts +9 -0
- package/dist/agents/handlers/binance.js +227 -0
- package/dist/agents/handlers/binance.js.map +1 -0
- package/dist/agents/handlers/bittensor.d.ts +10 -0
- package/dist/agents/handlers/bittensor.js +90 -0
- package/dist/agents/handlers/bittensor.js.map +1 -0
- package/dist/agents/handlers/bybit.d.ts +9 -0
- package/dist/agents/handlers/bybit.js +226 -0
- package/dist/agents/handlers/bybit.js.map +1 -0
- package/dist/agents/handlers/credentials.d.ts +8 -0
- package/dist/agents/handlers/credentials.js +103 -0
- package/dist/agents/handlers/credentials.js.map +1 -0
- package/dist/agents/handlers/hyperliquid.d.ts +9 -0
- package/dist/agents/handlers/hyperliquid.js +326 -0
- package/dist/agents/handlers/hyperliquid.js.map +1 -0
- package/dist/agents/handlers/index.d.ts +82 -0
- package/dist/agents/handlers/index.js +143 -0
- package/dist/agents/handlers/index.js.map +1 -0
- package/dist/agents/handlers/kalshi.d.ts +10 -0
- package/dist/agents/handlers/kalshi.js +1377 -0
- package/dist/agents/handlers/kalshi.js.map +1 -0
- package/dist/agents/handlers/manifold.d.ts +9 -0
- package/dist/agents/handlers/manifold.js +1001 -0
- package/dist/agents/handlers/manifold.js.map +1 -0
- package/dist/agents/handlers/markets.d.ts +8 -0
- package/dist/agents/handlers/markets.js +321 -0
- package/dist/agents/handlers/markets.js.map +1 -0
- package/dist/agents/handlers/opinion.d.ts +11 -0
- package/dist/agents/handlers/opinion.js +374 -0
- package/dist/agents/handlers/opinion.js.map +1 -0
- package/dist/agents/handlers/paper-trading.d.ts +8 -0
- package/dist/agents/handlers/paper-trading.js +124 -0
- package/dist/agents/handlers/paper-trading.js.map +1 -0
- package/dist/agents/handlers/polymarket.d.ts +17 -0
- package/dist/agents/handlers/polymarket.js +455 -0
- package/dist/agents/handlers/polymarket.js.map +1 -0
- package/dist/agents/handlers/predictfun.d.ts +9 -0
- package/dist/agents/handlers/predictfun.js +488 -0
- package/dist/agents/handlers/predictfun.js.map +1 -0
- package/dist/agents/handlers/smarkets.d.ts +11 -0
- package/dist/agents/handlers/smarkets.js +205 -0
- package/dist/agents/handlers/smarkets.js.map +1 -0
- package/dist/agents/handlers/solana.d.ts +14 -0
- package/dist/agents/handlers/solana.js +1530 -0
- package/dist/agents/handlers/solana.js.map +1 -0
- package/dist/agents/handlers/types.d.ts +58 -0
- package/dist/agents/handlers/types.js +34 -0
- package/dist/agents/handlers/types.js.map +1 -0
- package/dist/agents/handlers/virtuals.d.ts +11 -0
- package/dist/agents/handlers/virtuals.js +135 -0
- package/dist/agents/handlers/virtuals.js.map +1 -0
- package/dist/agents/handlers/wallets.d.ts +9 -0
- package/dist/agents/handlers/wallets.js +222 -0
- package/dist/agents/handlers/wallets.js.map +1 -0
- package/dist/agents/index.d.ts +79 -0
- package/dist/agents/index.js +16690 -0
- package/dist/agents/index.js.map +1 -0
- package/dist/agents/subagents.d.ts +219 -0
- package/dist/agents/subagents.js +736 -0
- package/dist/agents/subagents.js.map +1 -0
- package/dist/alerts/index.d.ts +110 -0
- package/dist/alerts/index.js +421 -0
- package/dist/alerts/index.js.map +1 -0
- package/dist/alerts/realtime.d.ts +114 -0
- package/dist/alerts/realtime.js +262 -0
- package/dist/alerts/realtime.js.map +1 -0
- package/dist/api/apikeys.d.ts +74 -0
- package/dist/api/apikeys.js +319 -0
- package/dist/api/apikeys.js.map +1 -0
- package/dist/api/compute/code.d.ts +28 -0
- package/dist/api/compute/code.js +257 -0
- package/dist/api/compute/code.js.map +1 -0
- package/dist/api/compute/data.d.ts +72 -0
- package/dist/api/compute/data.js +264 -0
- package/dist/api/compute/data.js.map +1 -0
- package/dist/api/compute/gateway.d.ts +185 -0
- package/dist/api/compute/gateway.js +958 -0
- package/dist/api/compute/gateway.js.map +1 -0
- package/dist/api/compute/index.d.ts +21 -0
- package/dist/api/compute/index.js +46 -0
- package/dist/api/compute/index.js.map +1 -0
- package/dist/api/compute/llm.d.ts +64 -0
- package/dist/api/compute/llm.js +602 -0
- package/dist/api/compute/llm.js.map +1 -0
- package/dist/api/compute/persistence.d.ts +77 -0
- package/dist/api/compute/persistence.js +251 -0
- package/dist/api/compute/persistence.js.map +1 -0
- package/dist/api/compute/storage.d.ts +48 -0
- package/dist/api/compute/storage.js +283 -0
- package/dist/api/compute/storage.js.map +1 -0
- package/dist/api/compute/trade.d.ts +69 -0
- package/dist/api/compute/trade.js +460 -0
- package/dist/api/compute/trade.js.map +1 -0
- package/dist/api/compute/types.d.ts +271 -0
- package/dist/api/compute/types.js +87 -0
- package/dist/api/compute/types.js.map +1 -0
- package/dist/api/compute/web.d.ts +29 -0
- package/dist/api/compute/web.js +255 -0
- package/dist/api/compute/web.js.map +1 -0
- package/dist/api/custody.d.ts +48 -0
- package/dist/api/custody.js +272 -0
- package/dist/api/custody.js.map +1 -0
- package/dist/api/fees.d.ts +91 -0
- package/dist/api/fees.js +155 -0
- package/dist/api/fees.js.map +1 -0
- package/dist/api/gateway.d.ts +40 -0
- package/dist/api/gateway.js +569 -0
- package/dist/api/gateway.js.map +1 -0
- package/dist/api/index.d.ts +29 -0
- package/dist/api/index.js +55 -0
- package/dist/api/index.js.map +1 -0
- package/dist/api/jobs.d.ts +59 -0
- package/dist/api/jobs.js +362 -0
- package/dist/api/jobs.js.map +1 -0
- package/dist/api/middleware.d.ts +60 -0
- package/dist/api/middleware.js +315 -0
- package/dist/api/middleware.js.map +1 -0
- package/dist/api/prompt.d.ts +44 -0
- package/dist/api/prompt.js +345 -0
- package/dist/api/prompt.js.map +1 -0
- package/dist/api/sdk.d.ts +258 -0
- package/dist/api/sdk.js +341 -0
- package/dist/api/sdk.js.map +1 -0
- package/dist/api/server.d.ts +17 -0
- package/dist/api/server.js +852 -0
- package/dist/api/server.js.map +1 -0
- package/dist/api/types.d.ts +307 -0
- package/dist/api/types.js +64 -0
- package/dist/api/types.js.map +1 -0
- package/dist/arbitrage/index.d.ts +124 -0
- package/dist/arbitrage/index.js +482 -0
- package/dist/arbitrage/index.js.map +1 -0
- package/dist/auth/copilot.d.ts +87 -0
- package/dist/auth/copilot.js +328 -0
- package/dist/auth/copilot.js.map +1 -0
- package/dist/auth/google.d.ts +121 -0
- package/dist/auth/google.js +479 -0
- package/dist/auth/google.js.map +1 -0
- package/dist/auth/index.d.ts +8 -0
- package/dist/auth/index.js +25 -0
- package/dist/auth/index.js.map +1 -0
- package/dist/auth/oauth.d.ts +94 -0
- package/dist/auth/oauth.js +502 -0
- package/dist/auth/oauth.js.map +1 -0
- package/dist/auth/qwen.d.ts +110 -0
- package/dist/auth/qwen.js +351 -0
- package/dist/auth/qwen.js.map +1 -0
- package/dist/auto-reply/index.d.ts +143 -0
- package/dist/auto-reply/index.js +391 -0
- package/dist/auto-reply/index.js.map +1 -0
- package/dist/automation/cron.d.ts +66 -0
- package/dist/automation/cron.js +226 -0
- package/dist/automation/cron.js.map +1 -0
- package/dist/automation/heartbeats.d.ts +63 -0
- package/dist/automation/heartbeats.js +144 -0
- package/dist/automation/heartbeats.js.map +1 -0
- package/dist/automation/index.d.ts +9 -0
- package/dist/automation/index.js +15 -0
- package/dist/automation/index.js.map +1 -0
- package/dist/automation/webhooks.d.ts +60 -0
- package/dist/automation/webhooks.js +225 -0
- package/dist/automation/webhooks.js.map +1 -0
- package/dist/bankr/client.d.ts +86 -0
- package/dist/bankr/client.js +177 -0
- package/dist/bankr/client.js.map +1 -0
- package/dist/bankr/index.d.ts +6 -0
- package/dist/bankr/index.js +23 -0
- package/dist/bankr/index.js.map +1 -0
- package/dist/base/index.d.ts +6 -0
- package/dist/base/index.js +23 -0
- package/dist/base/index.js.map +1 -0
- package/dist/base/provider.d.ts +27 -0
- package/dist/base/provider.js +128 -0
- package/dist/base/provider.js.map +1 -0
- package/dist/bin/worker.d.ts +31 -0
- package/dist/bin/worker.js +127 -0
- package/dist/bin/worker.js.map +1 -0
- package/dist/bittensor/chutes.d.ts +14 -0
- package/dist/bittensor/chutes.js +141 -0
- package/dist/bittensor/chutes.js.map +1 -0
- package/dist/bittensor/index.d.ts +7 -0
- package/dist/bittensor/index.js +13 -0
- package/dist/bittensor/index.js.map +1 -0
- package/dist/bittensor/persistence.d.ts +8 -0
- package/dist/bittensor/persistence.js +188 -0
- package/dist/bittensor/persistence.js.map +1 -0
- package/dist/bittensor/plugin.d.ts +30 -0
- package/dist/bittensor/plugin.js +134 -0
- package/dist/bittensor/plugin.js.map +1 -0
- package/dist/bittensor/python-runner.d.ts +7 -0
- package/dist/bittensor/python-runner.js +83 -0
- package/dist/bittensor/python-runner.js.map +1 -0
- package/dist/bittensor/server.d.ts +7 -0
- package/dist/bittensor/server.js +110 -0
- package/dist/bittensor/server.js.map +1 -0
- package/dist/bittensor/service.d.ts +7 -0
- package/dist/bittensor/service.js +291 -0
- package/dist/bittensor/service.js.map +1 -0
- package/dist/bittensor/tool.d.ts +45 -0
- package/dist/bittensor/tool.js +147 -0
- package/dist/bittensor/tool.js.map +1 -0
- package/dist/bittensor/types.d.ts +188 -0
- package/dist/bittensor/types.js +6 -0
- package/dist/bittensor/types.js.map +1 -0
- package/dist/bittensor/wallet.d.ts +18 -0
- package/dist/bittensor/wallet.js +192 -0
- package/dist/bittensor/wallet.js.map +1 -0
- package/dist/bridge/wormhole.d.ts +239 -0
- package/dist/bridge/wormhole.js +404 -0
- package/dist/bridge/wormhole.js.map +1 -0
- package/dist/browser/index.d.ts +67 -0
- package/dist/browser/index.js +458 -0
- package/dist/browser/index.js.map +1 -0
- package/dist/cache/index.d.ts +105 -0
- package/dist/cache/index.js +306 -0
- package/dist/cache/index.js.map +1 -0
- package/dist/canvas/index.d.ts +66 -0
- package/dist/canvas/index.js +391 -0
- package/dist/canvas/index.js.map +1 -0
- package/dist/channels/base-adapter.d.ts +126 -0
- package/dist/channels/base-adapter.js +416 -0
- package/dist/channels/base-adapter.js.map +1 -0
- package/dist/channels/bluebubbles/index.d.ts +23 -0
- package/dist/channels/bluebubbles/index.js +182 -0
- package/dist/channels/bluebubbles/index.js.map +1 -0
- package/dist/channels/discord/index.d.ts +25 -0
- package/dist/channels/discord/index.js +419 -0
- package/dist/channels/discord/index.js.map +1 -0
- package/dist/channels/googlechat/index.d.ts +35 -0
- package/dist/channels/googlechat/index.js +223 -0
- package/dist/channels/googlechat/index.js.map +1 -0
- package/dist/channels/imessage/index.d.ts +28 -0
- package/dist/channels/imessage/index.js +340 -0
- package/dist/channels/imessage/index.js.map +1 -0
- package/dist/channels/index.d.ts +58 -0
- package/dist/channels/index.js +382 -0
- package/dist/channels/index.js.map +1 -0
- package/dist/channels/line/index.d.ts +307 -0
- package/dist/channels/line/index.js +760 -0
- package/dist/channels/line/index.js.map +1 -0
- package/dist/channels/matrix/index.d.ts +35 -0
- package/dist/channels/matrix/index.js +328 -0
- package/dist/channels/matrix/index.js.map +1 -0
- package/dist/channels/mattermost/index.d.ts +25 -0
- package/dist/channels/mattermost/index.js +239 -0
- package/dist/channels/mattermost/index.js.map +1 -0
- package/dist/channels/nextcloud-talk/index.d.ts +25 -0
- package/dist/channels/nextcloud-talk/index.js +175 -0
- package/dist/channels/nextcloud-talk/index.js.map +1 -0
- package/dist/channels/nostr/index.d.ts +21 -0
- package/dist/channels/nostr/index.js +278 -0
- package/dist/channels/nostr/index.js.map +1 -0
- package/dist/channels/signal/index.d.ts +33 -0
- package/dist/channels/signal/index.js +333 -0
- package/dist/channels/signal/index.js.map +1 -0
- package/dist/channels/slack/index.d.ts +26 -0
- package/dist/channels/slack/index.js +266 -0
- package/dist/channels/slack/index.js.map +1 -0
- package/dist/channels/teams/index.d.ts +42 -0
- package/dist/channels/teams/index.js +312 -0
- package/dist/channels/teams/index.js.map +1 -0
- package/dist/channels/telegram/index.d.ts +9 -0
- package/dist/channels/telegram/index.js +761 -0
- package/dist/channels/telegram/index.js.map +1 -0
- package/dist/channels/tlon/index.d.ts +25 -0
- package/dist/channels/tlon/index.js +236 -0
- package/dist/channels/tlon/index.js.map +1 -0
- package/dist/channels/twitch/index.d.ts +25 -0
- package/dist/channels/twitch/index.js +182 -0
- package/dist/channels/twitch/index.js.map +1 -0
- package/dist/channels/voice/index.d.ts +31 -0
- package/dist/channels/voice/index.js +208 -0
- package/dist/channels/voice/index.js.map +1 -0
- package/dist/channels/webchat/index.d.ts +29 -0
- package/dist/channels/webchat/index.js +366 -0
- package/dist/channels/webchat/index.js.map +1 -0
- package/dist/channels/whatsapp/index.d.ts +72 -0
- package/dist/channels/whatsapp/index.js +767 -0
- package/dist/channels/whatsapp/index.js.map +1 -0
- package/dist/channels/zalo/index.d.ts +45 -0
- package/dist/channels/zalo/index.js +285 -0
- package/dist/channels/zalo/index.js.map +1 -0
- package/dist/cli/commands/doctor.d.ts +23 -0
- package/dist/cli/commands/doctor.js +649 -0
- package/dist/cli/commands/doctor.js.map +1 -0
- package/dist/cli/commands/gateway.d.ts +6 -0
- package/dist/cli/commands/gateway.js +32 -0
- package/dist/cli/commands/gateway.js.map +1 -0
- package/dist/cli/commands/index.d.ts +31 -0
- package/dist/cli/commands/index.js +3743 -0
- package/dist/cli/commands/index.js.map +1 -0
- package/dist/cli/commands/onboard.d.ts +4 -0
- package/dist/cli/commands/onboard.js +334 -0
- package/dist/cli/commands/onboard.js.map +1 -0
- package/dist/cli/commands/repl.d.ts +11 -0
- package/dist/cli/commands/repl.js +185 -0
- package/dist/cli/commands/repl.js.map +1 -0
- package/dist/cli/commands/skills.d.ts +29 -0
- package/dist/cli/commands/skills.js +297 -0
- package/dist/cli/commands/skills.js.map +1 -0
- package/dist/cli/index.d.ts +12 -0
- package/dist/cli/index.js +449 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/secure.d.ts +14 -0
- package/dist/cli/secure.js +626 -0
- package/dist/cli/secure.js.map +1 -0
- package/dist/commands/index.d.ts +61 -0
- package/dist/commands/index.js +290 -0
- package/dist/commands/index.js.map +1 -0
- package/dist/commands/registry.d.ts +69 -0
- package/dist/commands/registry.js +3142 -0
- package/dist/commands/registry.js.map +1 -0
- package/dist/config/index.d.ts +465 -0
- package/dist/config/index.js +1451 -0
- package/dist/config/index.js.map +1 -0
- package/dist/credentials/index.d.ts +51 -0
- package/dist/credentials/index.js +270 -0
- package/dist/credentials/index.js.map +1 -0
- package/dist/cron/index.d.ts +151 -0
- package/dist/cron/index.js +1283 -0
- package/dist/cron/index.js.map +1 -0
- package/dist/cron/types.d.ts +102 -0
- package/dist/cron/types.js +6 -0
- package/dist/cron/types.js.map +1 -0
- package/dist/daemon/index.d.ts +23 -0
- package/dist/daemon/index.js +159 -0
- package/dist/daemon/index.js.map +1 -0
- package/dist/db/index.d.ts +825 -0
- package/dist/db/index.js +3382 -0
- package/dist/db/index.js.map +1 -0
- package/dist/db/migrations.d.ts +70 -0
- package/dist/db/migrations.js +1373 -0
- package/dist/db/migrations.js.map +1 -0
- package/dist/docker/index.d.ts +188 -0
- package/dist/docker/index.js +571 -0
- package/dist/docker/index.js.map +1 -0
- package/dist/doctor/index.d.ts +47 -0
- package/dist/doctor/index.js +379 -0
- package/dist/doctor/index.js.map +1 -0
- package/dist/embeddings/index.d.ts +65 -0
- package/dist/embeddings/index.js +399 -0
- package/dist/embeddings/index.js.map +1 -0
- package/dist/evm/contracts.d.ts +112 -0
- package/dist/evm/contracts.js +332 -0
- package/dist/evm/contracts.js.map +1 -0
- package/dist/evm/index.d.ts +21 -0
- package/dist/evm/index.js +45 -0
- package/dist/evm/index.js.map +1 -0
- package/dist/evm/multichain.d.ts +87 -0
- package/dist/evm/multichain.js +308 -0
- package/dist/evm/multichain.js.map +1 -0
- package/dist/evm/odos.d.ts +62 -0
- package/dist/evm/odos.js +261 -0
- package/dist/evm/odos.js.map +1 -0
- package/dist/evm/oneinch.d.ts +55 -0
- package/dist/evm/oneinch.js +324 -0
- package/dist/evm/oneinch.js.map +1 -0
- package/dist/evm/transfers.d.ts +83 -0
- package/dist/evm/transfers.js +393 -0
- package/dist/evm/transfers.js.map +1 -0
- package/dist/evm/uniswap.d.ts +56 -0
- package/dist/evm/uniswap.js +307 -0
- package/dist/evm/uniswap.js.map +1 -0
- package/dist/evm/virtuals.d.ts +220 -0
- package/dist/evm/virtuals.js +735 -0
- package/dist/evm/virtuals.js.map +1 -0
- package/dist/evm/wallet.d.ts +96 -0
- package/dist/evm/wallet.js +258 -0
- package/dist/evm/wallet.js.map +1 -0
- package/dist/exchanges/binance-futures/index.d.ts +83 -0
- package/dist/exchanges/binance-futures/index.js +394 -0
- package/dist/exchanges/binance-futures/index.js.map +1 -0
- package/dist/exchanges/bybit/index.d.ts +78 -0
- package/dist/exchanges/bybit/index.js +379 -0
- package/dist/exchanges/bybit/index.js.map +1 -0
- package/dist/exchanges/hyperliquid/index.d.ts +594 -0
- package/dist/exchanges/hyperliquid/index.js +1101 -0
- package/dist/exchanges/hyperliquid/index.js.map +1 -0
- package/dist/exchanges/mexc/index.d.ts +80 -0
- package/dist/exchanges/mexc/index.js +389 -0
- package/dist/exchanges/mexc/index.js.map +1 -0
- package/dist/exchanges/opinion/index.d.ts +128 -0
- package/dist/exchanges/opinion/index.js +443 -0
- package/dist/exchanges/opinion/index.js.map +1 -0
- package/dist/exchanges/predictfun/index.d.ts +107 -0
- package/dist/exchanges/predictfun/index.js +398 -0
- package/dist/exchanges/predictfun/index.js.map +1 -0
- package/dist/execution/auto-redeem.d.ts +55 -0
- package/dist/execution/auto-redeem.js +324 -0
- package/dist/execution/auto-redeem.js.map +1 -0
- package/dist/execution/bracket-orders.d.ts +84 -0
- package/dist/execution/bracket-orders.js +387 -0
- package/dist/execution/bracket-orders.js.map +1 -0
- package/dist/execution/circuit-breaker.d.ts +87 -0
- package/dist/execution/circuit-breaker.js +274 -0
- package/dist/execution/circuit-breaker.js.map +1 -0
- package/dist/execution/dca-persistence.d.ts +47 -0
- package/dist/execution/dca-persistence.js +159 -0
- package/dist/execution/dca-persistence.js.map +1 -0
- package/dist/execution/dca.d.ts +60 -0
- package/dist/execution/dca.js +273 -0
- package/dist/execution/dca.js.map +1 -0
- package/dist/execution/futures.d.ts +162 -0
- package/dist/execution/futures.js +1336 -0
- package/dist/execution/futures.js.map +1 -0
- package/dist/execution/index.d.ts +346 -0
- package/dist/execution/index.js +2532 -0
- package/dist/execution/index.js.map +1 -0
- package/dist/execution/mev-protection.d.ts +150 -0
- package/dist/execution/mev-protection.js +377 -0
- package/dist/execution/mev-protection.js.map +1 -0
- package/dist/execution/order-persistence.d.ts +81 -0
- package/dist/execution/order-persistence.js +350 -0
- package/dist/execution/order-persistence.js.map +1 -0
- package/dist/execution/position-manager.d.ts +142 -0
- package/dist/execution/position-manager.js +404 -0
- package/dist/execution/position-manager.js.map +1 -0
- package/dist/execution/smart-router.d.ts +90 -0
- package/dist/execution/smart-router.js +323 -0
- package/dist/execution/smart-router.js.map +1 -0
- package/dist/execution/trigger-orders.d.ts +81 -0
- package/dist/execution/trigger-orders.js +266 -0
- package/dist/execution/trigger-orders.js.map +1 -0
- package/dist/execution/twap.d.ts +87 -0
- package/dist/execution/twap.js +405 -0
- package/dist/execution/twap.js.map +1 -0
- package/dist/extensions/copilot-proxy/index.d.ts +49 -0
- package/dist/extensions/copilot-proxy/index.js +204 -0
- package/dist/extensions/copilot-proxy/index.js.map +1 -0
- package/dist/extensions/diagnostics-otel/index.d.ts +54 -0
- package/dist/extensions/diagnostics-otel/index.js +290 -0
- package/dist/extensions/diagnostics-otel/index.js.map +1 -0
- package/dist/extensions/google-auth/index.d.ts +71 -0
- package/dist/extensions/google-auth/index.js +350 -0
- package/dist/extensions/google-auth/index.js.map +1 -0
- package/dist/extensions/index.d.ts +11 -0
- package/dist/extensions/index.js +29 -0
- package/dist/extensions/index.js.map +1 -0
- package/dist/extensions/llm-task/index.d.ts +80 -0
- package/dist/extensions/llm-task/index.js +248 -0
- package/dist/extensions/llm-task/index.js.map +1 -0
- package/dist/extensions/lobster/index.d.ts +69 -0
- package/dist/extensions/lobster/index.js +178 -0
- package/dist/extensions/lobster/index.js.map +1 -0
- package/dist/extensions/memory-lancedb/index.d.ts +62 -0
- package/dist/extensions/memory-lancedb/index.js +343 -0
- package/dist/extensions/memory-lancedb/index.js.map +1 -0
- package/dist/extensions/open-prose/index.d.ts +82 -0
- package/dist/extensions/open-prose/index.js +565 -0
- package/dist/extensions/open-prose/index.js.map +1 -0
- package/dist/extensions/qwen-portal/index.d.ts +48 -0
- package/dist/extensions/qwen-portal/index.js +161 -0
- package/dist/extensions/qwen-portal/index.js.map +1 -0
- package/dist/extensions/task-runner/index.d.ts +121 -0
- package/dist/extensions/task-runner/index.js +640 -0
- package/dist/extensions/task-runner/index.js.map +1 -0
- package/dist/farcaster/client.d.ts +101 -0
- package/dist/farcaster/client.js +282 -0
- package/dist/farcaster/client.js.map +1 -0
- package/dist/farcaster/index.d.ts +4 -0
- package/dist/farcaster/index.js +21 -0
- package/dist/farcaster/index.js.map +1 -0
- package/dist/feeds/acled/index.d.ts +86 -0
- package/dist/feeds/acled/index.js +215 -0
- package/dist/feeds/acled/index.js.map +1 -0
- package/dist/feeds/agentbets/index.d.ts +17 -0
- package/dist/feeds/agentbets/index.js +137 -0
- package/dist/feeds/agentbets/index.js.map +1 -0
- package/dist/feeds/betfair/index.d.ts +132 -0
- package/dist/feeds/betfair/index.js +640 -0
- package/dist/feeds/betfair/index.js.map +1 -0
- package/dist/feeds/crypto/index.d.ts +101 -0
- package/dist/feeds/crypto/index.js +506 -0
- package/dist/feeds/crypto/index.js.map +1 -0
- package/dist/feeds/crypto/whale-tracker.d.ts +138 -0
- package/dist/feeds/crypto/whale-tracker.js +685 -0
- package/dist/feeds/crypto/whale-tracker.js.map +1 -0
- package/dist/feeds/descriptors.d.ts +14 -0
- package/dist/feeds/descriptors.js +582 -0
- package/dist/feeds/descriptors.js.map +1 -0
- package/dist/feeds/drift/index.d.ts +23 -0
- package/dist/feeds/drift/index.js +182 -0
- package/dist/feeds/drift/index.js.map +1 -0
- package/dist/feeds/drift/trading.d.ts +75 -0
- package/dist/feeds/drift/trading.js +457 -0
- package/dist/feeds/drift/trading.js.map +1 -0
- package/dist/feeds/external/index.d.ts +48 -0
- package/dist/feeds/external/index.js +575 -0
- package/dist/feeds/external/index.js.map +1 -0
- package/dist/feeds/fred/index.d.ts +134 -0
- package/dist/feeds/fred/index.js +263 -0
- package/dist/feeds/fred/index.js.map +1 -0
- package/dist/feeds/freshness.d.ts +79 -0
- package/dist/feeds/freshness.js +259 -0
- package/dist/feeds/freshness.js.map +1 -0
- package/dist/feeds/hedgehog/index.d.ts +24 -0
- package/dist/feeds/hedgehog/index.js +589 -0
- package/dist/feeds/hedgehog/index.js.map +1 -0
- package/dist/feeds/hedgehog/types.d.ts +215 -0
- package/dist/feeds/hedgehog/types.js +7 -0
- package/dist/feeds/hedgehog/types.js.map +1 -0
- package/dist/feeds/index.d.ts +38 -0
- package/dist/feeds/index.js +469 -0
- package/dist/feeds/index.js.map +1 -0
- package/dist/feeds/kalshi/index.d.ts +116 -0
- package/dist/feeds/kalshi/index.js +970 -0
- package/dist/feeds/kalshi/index.js.map +1 -0
- package/dist/feeds/manifold/index.d.ts +15 -0
- package/dist/feeds/manifold/index.js +269 -0
- package/dist/feeds/manifold/index.js.map +1 -0
- package/dist/feeds/metaculus/index.d.ts +22 -0
- package/dist/feeds/metaculus/index.js +149 -0
- package/dist/feeds/metaculus/index.js.map +1 -0
- package/dist/feeds/news/index.d.ts +20 -0
- package/dist/feeds/news/index.js +308 -0
- package/dist/feeds/news/index.js.map +1 -0
- package/dist/feeds/opinion/index.d.ts +31 -0
- package/dist/feeds/opinion/index.js +389 -0
- package/dist/feeds/opinion/index.js.map +1 -0
- package/dist/feeds/polymarket/index.d.ts +21 -0
- package/dist/feeds/polymarket/index.js +501 -0
- package/dist/feeds/polymarket/index.js.map +1 -0
- package/dist/feeds/polymarket/rtds.d.ts +40 -0
- package/dist/feeds/polymarket/rtds.js +159 -0
- package/dist/feeds/polymarket/rtds.js.map +1 -0
- package/dist/feeds/polymarket/user-ws.d.ts +64 -0
- package/dist/feeds/polymarket/user-ws.js +230 -0
- package/dist/feeds/polymarket/user-ws.js.map +1 -0
- package/dist/feeds/polymarket/whale-tracker.d.ts +152 -0
- package/dist/feeds/polymarket/whale-tracker.js +709 -0
- package/dist/feeds/polymarket/whale-tracker.js.map +1 -0
- package/dist/feeds/predictfun/index.d.ts +24 -0
- package/dist/feeds/predictfun/index.js +234 -0
- package/dist/feeds/predictfun/index.js.map +1 -0
- package/dist/feeds/predictit/index.d.ts +14 -0
- package/dist/feeds/predictit/index.js +88 -0
- package/dist/feeds/predictit/index.js.map +1 -0
- package/dist/feeds/registry.d.ts +148 -0
- package/dist/feeds/registry.js +197 -0
- package/dist/feeds/registry.js.map +1 -0
- package/dist/feeds/smarkets/index.d.ts +76 -0
- package/dist/feeds/smarkets/index.js +415 -0
- package/dist/feeds/smarkets/index.js.map +1 -0
- package/dist/feeds/virtuals/index.d.ts +92 -0
- package/dist/feeds/virtuals/index.js +341 -0
- package/dist/feeds/virtuals/index.js.map +1 -0
- package/dist/feeds/weather-nws/index.d.ts +73 -0
- package/dist/feeds/weather-nws/index.js +162 -0
- package/dist/feeds/weather-nws/index.js.map +1 -0
- package/dist/feeds/weather-openmeteo/index.d.ts +80 -0
- package/dist/feeds/weather-openmeteo/index.js +197 -0
- package/dist/feeds/weather-openmeteo/index.js.map +1 -0
- package/dist/gateway/alerts-routes.d.ts +15 -0
- package/dist/gateway/alerts-routes.js +188 -0
- package/dist/gateway/alerts-routes.js.map +1 -0
- package/dist/gateway/alt-data-routes.d.ts +15 -0
- package/dist/gateway/alt-data-routes.js +67 -0
- package/dist/gateway/alt-data-routes.js.map +1 -0
- package/dist/gateway/api-routes.d.ts +39 -0
- package/dist/gateway/api-routes.js +1028 -0
- package/dist/gateway/api-routes.js.map +1 -0
- package/dist/gateway/audit-routes.d.ts +8 -0
- package/dist/gateway/audit-routes.js +61 -0
- package/dist/gateway/audit-routes.js.map +1 -0
- package/dist/gateway/bracket-routes.d.ts +12 -0
- package/dist/gateway/bracket-routes.js +122 -0
- package/dist/gateway/bracket-routes.js.map +1 -0
- package/dist/gateway/control-ui.d.ts +45 -0
- package/dist/gateway/control-ui.js +301 -0
- package/dist/gateway/control-ui.js.map +1 -0
- package/dist/gateway/copy-trading-routes.d.ts +12 -0
- package/dist/gateway/copy-trading-routes.js +159 -0
- package/dist/gateway/copy-trading-routes.js.map +1 -0
- package/dist/gateway/cron-routes.d.ts +14 -0
- package/dist/gateway/cron-routes.js +132 -0
- package/dist/gateway/cron-routes.js.map +1 -0
- package/dist/gateway/dca-routes.d.ts +8 -0
- package/dist/gateway/dca-routes.js +179 -0
- package/dist/gateway/dca-routes.js.map +1 -0
- package/dist/gateway/embeddings-routes.d.ts +12 -0
- package/dist/gateway/embeddings-routes.js +102 -0
- package/dist/gateway/embeddings-routes.js.map +1 -0
- package/dist/gateway/feeds-routes.d.ts +34 -0
- package/dist/gateway/feeds-routes.js +167 -0
- package/dist/gateway/feeds-routes.js.map +1 -0
- package/dist/gateway/index.d.ts +100 -0
- package/dist/gateway/index.js +2321 -0
- package/dist/gateway/index.js.map +1 -0
- package/dist/gateway/monitoring-routes.d.ts +12 -0
- package/dist/gateway/monitoring-routes.js +73 -0
- package/dist/gateway/monitoring-routes.js.map +1 -0
- package/dist/gateway/opportunity-routes.d.ts +12 -0
- package/dist/gateway/opportunity-routes.js +238 -0
- package/dist/gateway/opportunity-routes.js.map +1 -0
- package/dist/gateway/payments-routes.d.ts +14 -0
- package/dist/gateway/payments-routes.js +82 -0
- package/dist/gateway/payments-routes.js.map +1 -0
- package/dist/gateway/percolator-routes.d.ts +16 -0
- package/dist/gateway/percolator-routes.js +139 -0
- package/dist/gateway/percolator-routes.js.map +1 -0
- package/dist/gateway/queue-routes.d.ts +12 -0
- package/dist/gateway/queue-routes.js +47 -0
- package/dist/gateway/queue-routes.js.map +1 -0
- package/dist/gateway/risk-routes.d.ts +12 -0
- package/dist/gateway/risk-routes.js +119 -0
- package/dist/gateway/risk-routes.js.map +1 -0
- package/dist/gateway/routing-routes.d.ts +12 -0
- package/dist/gateway/routing-routes.js +86 -0
- package/dist/gateway/routing-routes.js.map +1 -0
- package/dist/gateway/server.d.ts +215 -0
- package/dist/gateway/server.js +2287 -0
- package/dist/gateway/server.js.map +1 -0
- package/dist/gateway/shield-routes.d.ts +8 -0
- package/dist/gateway/shield-routes.js +88 -0
- package/dist/gateway/shield-routes.js.map +1 -0
- package/dist/gateway/signal-bus.d.ts +51 -0
- package/dist/gateway/signal-bus.js +64 -0
- package/dist/gateway/signal-bus.js.map +1 -0
- package/dist/gateway/trigger-routes.d.ts +12 -0
- package/dist/gateway/trigger-routes.js +127 -0
- package/dist/gateway/trigger-routes.js.map +1 -0
- package/dist/gateway/twap-routes.d.ts +12 -0
- package/dist/gateway/twap-routes.js +142 -0
- package/dist/gateway/twap-routes.js.map +1 -0
- package/dist/gateway/webhooks-routes.d.ts +31 -0
- package/dist/gateway/webhooks-routes.js +107 -0
- package/dist/gateway/webhooks-routes.js.map +1 -0
- package/dist/gateway/whale-routes.d.ts +12 -0
- package/dist/gateway/whale-routes.js +204 -0
- package/dist/gateway/whale-routes.js.map +1 -0
- package/dist/history/index.d.ts +81 -0
- package/dist/history/index.js +362 -0
- package/dist/history/index.js.map +1 -0
- package/dist/hooks/index.d.ts +279 -0
- package/dist/hooks/index.js +739 -0
- package/dist/hooks/index.js.map +1 -0
- package/dist/i18n/index.d.ts +65 -0
- package/dist/i18n/index.js +183 -0
- package/dist/i18n/index.js.map +1 -0
- package/dist/identity/erc8004.d.ts +104 -0
- package/dist/identity/erc8004.js +493 -0
- package/dist/identity/erc8004.js.map +1 -0
- package/dist/identity/index.d.ts +1 -0
- package/dist/identity/index.js +18 -0
- package/dist/identity/index.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +240 -0
- package/dist/index.js.map +1 -0
- package/dist/infra/index.d.ts +133 -0
- package/dist/infra/index.js +481 -0
- package/dist/infra/index.js.map +1 -0
- package/dist/infra/retry.d.ts +132 -0
- package/dist/infra/retry.js +450 -0
- package/dist/infra/retry.js.map +1 -0
- package/dist/ledger/anchor.d.ts +45 -0
- package/dist/ledger/anchor.js +271 -0
- package/dist/ledger/anchor.js.map +1 -0
- package/dist/ledger/hash.d.ts +26 -0
- package/dist/ledger/hash.js +69 -0
- package/dist/ledger/hash.js.map +1 -0
- package/dist/ledger/hooks.d.ts +107 -0
- package/dist/ledger/hooks.js +314 -0
- package/dist/ledger/hooks.js.map +1 -0
- package/dist/ledger/index.d.ts +67 -0
- package/dist/ledger/index.js +221 -0
- package/dist/ledger/index.js.map +1 -0
- package/dist/ledger/storage.d.ts +57 -0
- package/dist/ledger/storage.js +368 -0
- package/dist/ledger/storage.js.map +1 -0
- package/dist/ledger/types.d.ts +138 -0
- package/dist/ledger/types.js +16 -0
- package/dist/ledger/types.js.map +1 -0
- package/dist/link-understanding/index.d.ts +61 -0
- package/dist/link-understanding/index.js +320 -0
- package/dist/link-understanding/index.js.map +1 -0
- package/dist/logging/index.d.ts +50 -0
- package/dist/logging/index.js +255 -0
- package/dist/logging/index.js.map +1 -0
- package/dist/macos/index.d.ts +143 -0
- package/dist/macos/index.js +587 -0
- package/dist/macos/index.js.map +1 -0
- package/dist/markdown/index.d.ts +43 -0
- package/dist/markdown/index.js +305 -0
- package/dist/markdown/index.js.map +1 -0
- package/dist/market-index/index.d.ts +51 -0
- package/dist/market-index/index.js +553 -0
- package/dist/market-index/index.js.map +1 -0
- package/dist/mcp/index.d.ts +263 -0
- package/dist/mcp/index.js +940 -0
- package/dist/mcp/index.js.map +1 -0
- package/dist/mcp/installer.d.ts +11 -0
- package/dist/mcp/installer.js +128 -0
- package/dist/mcp/installer.js.map +1 -0
- package/dist/mcp/server.d.ts +7 -0
- package/dist/mcp/server.js +172 -0
- package/dist/mcp/server.js.map +1 -0
- package/dist/media/index.d.ts +119 -0
- package/dist/media/index.js +740 -0
- package/dist/media/index.js.map +1 -0
- package/dist/memory/context.d.ts +189 -0
- package/dist/memory/context.js +541 -0
- package/dist/memory/context.js.map +1 -0
- package/dist/memory/index.d.ts +74 -0
- package/dist/memory/index.js +352 -0
- package/dist/memory/index.js.map +1 -0
- package/dist/memory/summarizer.d.ts +10 -0
- package/dist/memory/summarizer.js +51 -0
- package/dist/memory/summarizer.js.map +1 -0
- package/dist/memory/tokenizer.d.ts +4 -0
- package/dist/memory/tokenizer.js +61 -0
- package/dist/memory/tokenizer.js.map +1 -0
- package/dist/messages/unified.d.ts +7 -0
- package/dist/messages/unified.js +77 -0
- package/dist/messages/unified.js.map +1 -0
- package/dist/ml-pipeline/collector.d.ts +23 -0
- package/dist/ml-pipeline/collector.js +176 -0
- package/dist/ml-pipeline/collector.js.map +1 -0
- package/dist/ml-pipeline/index.d.ts +21 -0
- package/dist/ml-pipeline/index.js +72 -0
- package/dist/ml-pipeline/index.js.map +1 -0
- package/dist/ml-pipeline/trainer.d.ts +32 -0
- package/dist/ml-pipeline/trainer.js +228 -0
- package/dist/ml-pipeline/trainer.js.map +1 -0
- package/dist/ml-pipeline/types.d.ts +51 -0
- package/dist/ml-pipeline/types.js +23 -0
- package/dist/ml-pipeline/types.js.map +1 -0
- package/dist/models/adaptive.d.ts +11 -0
- package/dist/models/adaptive.js +64 -0
- package/dist/models/adaptive.js.map +1 -0
- package/dist/models/failover.d.ts +51 -0
- package/dist/models/failover.js +151 -0
- package/dist/models/failover.js.map +1 -0
- package/dist/models/index.d.ts +7 -0
- package/dist/models/index.js +13 -0
- package/dist/models/index.js.map +1 -0
- package/dist/monitoring/alerts.d.ts +185 -0
- package/dist/monitoring/alerts.js +565 -0
- package/dist/monitoring/alerts.js.map +1 -0
- package/dist/monitoring/health.d.ts +151 -0
- package/dist/monitoring/health.js +423 -0
- package/dist/monitoring/health.js.map +1 -0
- package/dist/monitoring/index.d.ts +25 -0
- package/dist/monitoring/index.js +258 -0
- package/dist/monitoring/index.js.map +1 -0
- package/dist/monitoring/metrics.d.ts +147 -0
- package/dist/monitoring/metrics.js +519 -0
- package/dist/monitoring/metrics.js.map +1 -0
- package/dist/nodes/index.d.ts +81 -0
- package/dist/nodes/index.js +475 -0
- package/dist/nodes/index.js.map +1 -0
- package/dist/opportunity/analytics.d.ts +221 -0
- package/dist/opportunity/analytics.js +678 -0
- package/dist/opportunity/analytics.js.map +1 -0
- package/dist/opportunity/combinatorial.d.ts +147 -0
- package/dist/opportunity/combinatorial.js +765 -0
- package/dist/opportunity/combinatorial.js.map +1 -0
- package/dist/opportunity/correlation.d.ts +107 -0
- package/dist/opportunity/correlation.js +410 -0
- package/dist/opportunity/correlation.js.map +1 -0
- package/dist/opportunity/executor.d.ts +108 -0
- package/dist/opportunity/executor.js +356 -0
- package/dist/opportunity/executor.js.map +1 -0
- package/dist/opportunity/index.d.ts +285 -0
- package/dist/opportunity/index.js +839 -0
- package/dist/opportunity/index.js.map +1 -0
- package/dist/opportunity/links.d.ts +87 -0
- package/dist/opportunity/links.js +344 -0
- package/dist/opportunity/links.js.map +1 -0
- package/dist/opportunity/matching.d.ts +101 -0
- package/dist/opportunity/matching.js +551 -0
- package/dist/opportunity/matching.js.map +1 -0
- package/dist/opportunity/outcomes.d.ts +74 -0
- package/dist/opportunity/outcomes.js +321 -0
- package/dist/opportunity/outcomes.js.map +1 -0
- package/dist/opportunity/risk.d.ts +128 -0
- package/dist/opportunity/risk.js +381 -0
- package/dist/opportunity/risk.js.map +1 -0
- package/dist/opportunity/scoring.d.ts +151 -0
- package/dist/opportunity/scoring.js +421 -0
- package/dist/opportunity/scoring.js.map +1 -0
- package/dist/pairing/index.d.ts +108 -0
- package/dist/pairing/index.js +431 -0
- package/dist/pairing/index.js.map +1 -0
- package/dist/payments/index.d.ts +12 -0
- package/dist/payments/index.js +34 -0
- package/dist/payments/index.js.map +1 -0
- package/dist/payments/x402/evm.d.ts +53 -0
- package/dist/payments/x402/evm.js +282 -0
- package/dist/payments/x402/evm.js.map +1 -0
- package/dist/payments/x402/index.d.ts +158 -0
- package/dist/payments/x402/index.js +531 -0
- package/dist/payments/x402/index.js.map +1 -0
- package/dist/payments/x402/solana.d.ts +51 -0
- package/dist/payments/x402/solana.js +397 -0
- package/dist/payments/x402/solana.js.map +1 -0
- package/dist/percolator/accounts.d.ts +21 -0
- package/dist/percolator/accounts.js +76 -0
- package/dist/percolator/accounts.js.map +1 -0
- package/dist/percolator/encode.d.ts +14 -0
- package/dist/percolator/encode.js +90 -0
- package/dist/percolator/encode.js.map +1 -0
- package/dist/percolator/execution.d.ts +29 -0
- package/dist/percolator/execution.js +239 -0
- package/dist/percolator/execution.js.map +1 -0
- package/dist/percolator/feed.d.ts +15 -0
- package/dist/percolator/feed.js +160 -0
- package/dist/percolator/feed.js.map +1 -0
- package/dist/percolator/index.d.ts +20 -0
- package/dist/percolator/index.js +24 -0
- package/dist/percolator/index.js.map +1 -0
- package/dist/percolator/instructions.d.ts +29 -0
- package/dist/percolator/instructions.js +52 -0
- package/dist/percolator/instructions.js.map +1 -0
- package/dist/percolator/keeper.d.ts +11 -0
- package/dist/percolator/keeper.js +83 -0
- package/dist/percolator/keeper.js.map +1 -0
- package/dist/percolator/pda.d.ts +15 -0
- package/dist/percolator/pda.js +26 -0
- package/dist/percolator/pda.js.map +1 -0
- package/dist/percolator/slab.d.ts +122 -0
- package/dist/percolator/slab.js +325 -0
- package/dist/percolator/slab.js.map +1 -0
- package/dist/percolator/tx.d.ts +27 -0
- package/dist/percolator/tx.js +77 -0
- package/dist/percolator/tx.js.map +1 -0
- package/dist/percolator/types.d.ts +51 -0
- package/dist/percolator/types.js +9 -0
- package/dist/percolator/types.js.map +1 -0
- package/dist/permissions/index.d.ts +262 -0
- package/dist/permissions/index.js +929 -0
- package/dist/permissions/index.js.map +1 -0
- package/dist/plugins/index.d.ts +158 -0
- package/dist/plugins/index.js +444 -0
- package/dist/plugins/index.js.map +1 -0
- package/dist/portfolio/index.d.ts +170 -0
- package/dist/portfolio/index.js +970 -0
- package/dist/portfolio/index.js.map +1 -0
- package/dist/presence/index.d.ts +34 -0
- package/dist/presence/index.js +124 -0
- package/dist/presence/index.js.map +1 -0
- package/dist/process/index.d.ts +82 -0
- package/dist/process/index.js +402 -0
- package/dist/process/index.js.map +1 -0
- package/dist/providers/discovery.d.ts +209 -0
- package/dist/providers/discovery.js +751 -0
- package/dist/providers/discovery.js.map +1 -0
- package/dist/providers/health.d.ts +27 -0
- package/dist/providers/health.js +80 -0
- package/dist/providers/health.js.map +1 -0
- package/dist/providers/index.d.ts +154 -0
- package/dist/providers/index.js +897 -0
- package/dist/providers/index.js.map +1 -0
- package/dist/queue/index.d.ts +36 -0
- package/dist/queue/index.js +146 -0
- package/dist/queue/index.js.map +1 -0
- package/dist/queue/jobs/index.d.ts +11 -0
- package/dist/queue/jobs/index.js +32 -0
- package/dist/queue/jobs/index.js.map +1 -0
- package/dist/queue/jobs/producer.d.ts +43 -0
- package/dist/queue/jobs/producer.js +233 -0
- package/dist/queue/jobs/producer.js.map +1 -0
- package/dist/queue/jobs/types.d.ts +128 -0
- package/dist/queue/jobs/types.js +14 -0
- package/dist/queue/jobs/types.js.map +1 -0
- package/dist/queue/jobs/worker.d.ts +22 -0
- package/dist/queue/jobs/worker.js +220 -0
- package/dist/queue/jobs/worker.js.map +1 -0
- package/dist/remote/index.d.ts +136 -0
- package/dist/remote/index.js +456 -0
- package/dist/remote/index.js.map +1 -0
- package/dist/risk/circuit-breaker.d.ts +99 -0
- package/dist/risk/circuit-breaker.js +300 -0
- package/dist/risk/circuit-breaker.js.map +1 -0
- package/dist/risk/dashboard.d.ts +69 -0
- package/dist/risk/dashboard.js +127 -0
- package/dist/risk/dashboard.js.map +1 -0
- package/dist/risk/engine.d.ts +128 -0
- package/dist/risk/engine.js +311 -0
- package/dist/risk/engine.js.map +1 -0
- package/dist/risk/index.d.ts +10 -0
- package/dist/risk/index.js +38 -0
- package/dist/risk/index.js.map +1 -0
- package/dist/risk/stress.d.ts +70 -0
- package/dist/risk/stress.js +215 -0
- package/dist/risk/stress.js.map +1 -0
- package/dist/risk/var.d.ts +72 -0
- package/dist/risk/var.js +173 -0
- package/dist/risk/var.js.map +1 -0
- package/dist/risk/volatility.d.ts +61 -0
- package/dist/risk/volatility.js +132 -0
- package/dist/risk/volatility.js.map +1 -0
- package/dist/routing/index.d.ts +116 -0
- package/dist/routing/index.js +371 -0
- package/dist/routing/index.js.map +1 -0
- package/dist/search/index.d.ts +30 -0
- package/dist/search/index.js +129 -0
- package/dist/search/index.js.map +1 -0
- package/dist/security/address-checker.d.ts +6 -0
- package/dist/security/address-checker.js +213 -0
- package/dist/security/address-checker.js.map +1 -0
- package/dist/security/code-scanner.d.ts +3 -0
- package/dist/security/code-scanner.js +190 -0
- package/dist/security/code-scanner.js.map +1 -0
- package/dist/security/index.d.ts +176 -0
- package/dist/security/index.js +498 -0
- package/dist/security/index.js.map +1 -0
- package/dist/security/sanitizer.d.ts +2 -0
- package/dist/security/sanitizer.js +135 -0
- package/dist/security/sanitizer.js.map +1 -0
- package/dist/security/scam-db.d.ts +5 -0
- package/dist/security/scam-db.js +116 -0
- package/dist/security/scam-db.js.map +1 -0
- package/dist/security/shield.d.ts +12 -0
- package/dist/security/shield.js +80 -0
- package/dist/security/shield.js.map +1 -0
- package/dist/security/tx-validator.d.ts +5 -0
- package/dist/security/tx-validator.js +115 -0
- package/dist/security/tx-validator.js.map +1 -0
- package/dist/security/types.d.ts +84 -0
- package/dist/security/types.js +6 -0
- package/dist/security/types.js.map +1 -0
- package/dist/services/alt-data/feeds/fear-greed.d.ts +14 -0
- package/dist/services/alt-data/feeds/fear-greed.js +81 -0
- package/dist/services/alt-data/feeds/fear-greed.js.map +1 -0
- package/dist/services/alt-data/feeds/funding-rates.d.ts +13 -0
- package/dist/services/alt-data/feeds/funding-rates.js +90 -0
- package/dist/services/alt-data/feeds/funding-rates.js.map +1 -0
- package/dist/services/alt-data/feeds/reddit.d.ts +13 -0
- package/dist/services/alt-data/feeds/reddit.js +112 -0
- package/dist/services/alt-data/feeds/reddit.js.map +1 -0
- package/dist/services/alt-data/index.d.ts +31 -0
- package/dist/services/alt-data/index.js +278 -0
- package/dist/services/alt-data/index.js.map +1 -0
- package/dist/services/alt-data/market-matcher.d.ts +29 -0
- package/dist/services/alt-data/market-matcher.js +157 -0
- package/dist/services/alt-data/market-matcher.js.map +1 -0
- package/dist/services/alt-data/sentiment.d.ts +11 -0
- package/dist/services/alt-data/sentiment.js +277 -0
- package/dist/services/alt-data/sentiment.js.map +1 -0
- package/dist/services/alt-data/types.d.ts +86 -0
- package/dist/services/alt-data/types.js +9 -0
- package/dist/services/alt-data/types.js.map +1 -0
- package/dist/services/feature-engineering/accessor.d.ts +19 -0
- package/dist/services/feature-engineering/accessor.js +31 -0
- package/dist/services/feature-engineering/accessor.js.map +1 -0
- package/dist/services/feature-engineering/index.d.ts +15 -0
- package/dist/services/feature-engineering/index.js +345 -0
- package/dist/services/feature-engineering/index.js.map +1 -0
- package/dist/services/feature-engineering/indicators.d.ts +90 -0
- package/dist/services/feature-engineering/indicators.js +254 -0
- package/dist/services/feature-engineering/indicators.js.map +1 -0
- package/dist/services/feature-engineering/rolling-window.d.ts +89 -0
- package/dist/services/feature-engineering/rolling-window.js +173 -0
- package/dist/services/feature-engineering/rolling-window.js.map +1 -0
- package/dist/services/feature-engineering/thresholds.d.ts +137 -0
- package/dist/services/feature-engineering/thresholds.js +280 -0
- package/dist/services/feature-engineering/thresholds.js.map +1 -0
- package/dist/services/feature-engineering/types.d.ts +138 -0
- package/dist/services/feature-engineering/types.js +6 -0
- package/dist/services/feature-engineering/types.js.map +1 -0
- package/dist/services/tick-recorder/index.d.ts +12 -0
- package/dist/services/tick-recorder/index.js +200 -0
- package/dist/services/tick-recorder/index.js.map +1 -0
- package/dist/services/tick-recorder/queries.d.ts +46 -0
- package/dist/services/tick-recorder/queries.js +291 -0
- package/dist/services/tick-recorder/queries.js.map +1 -0
- package/dist/services/tick-recorder/schema.d.ts +27 -0
- package/dist/services/tick-recorder/schema.js +185 -0
- package/dist/services/tick-recorder/schema.js.map +1 -0
- package/dist/services/tick-recorder/timescale.d.ts +27 -0
- package/dist/services/tick-recorder/timescale.js +105 -0
- package/dist/services/tick-recorder/timescale.js.map +1 -0
- package/dist/services/tick-recorder/types.d.ts +113 -0
- package/dist/services/tick-recorder/types.js +7 -0
- package/dist/services/tick-recorder/types.js.map +1 -0
- package/dist/services/tick-streamer/index.d.ts +12 -0
- package/dist/services/tick-streamer/index.js +317 -0
- package/dist/services/tick-streamer/index.js.map +1 -0
- package/dist/services/tick-streamer/types.d.ts +134 -0
- package/dist/services/tick-streamer/types.js +6 -0
- package/dist/services/tick-streamer/types.js.map +1 -0
- package/dist/session/index.d.ts +147 -0
- package/dist/session/index.js +429 -0
- package/dist/session/index.js.map +1 -0
- package/dist/sessions/index.d.ts +69 -0
- package/dist/sessions/index.js +447 -0
- package/dist/sessions/index.js.map +1 -0
- package/dist/signal-router/index.d.ts +2 -0
- package/dist/signal-router/index.js +6 -0
- package/dist/signal-router/index.js.map +1 -0
- package/dist/signal-router/router.d.ts +25 -0
- package/dist/signal-router/router.js +391 -0
- package/dist/signal-router/router.js.map +1 -0
- package/dist/signal-router/types.d.ts +64 -0
- package/dist/signal-router/types.js +9 -0
- package/dist/signal-router/types.js.map +1 -0
- package/dist/skills/bundled/acp/index.d.ts +25 -0
- package/dist/skills/bundled/acp/index.js +472 -0
- package/dist/skills/bundled/acp/index.js.map +1 -0
- package/dist/skills/bundled/agentbets/index.d.ts +15 -0
- package/dist/skills/bundled/agentbets/index.js +168 -0
- package/dist/skills/bundled/agentbets/index.js.map +1 -0
- package/dist/skills/bundled/ai-strategy/index.d.ts +21 -0
- package/dist/skills/bundled/ai-strategy/index.js +647 -0
- package/dist/skills/bundled/ai-strategy/index.js.map +1 -0
- package/dist/skills/bundled/alerts/index.d.ts +20 -0
- package/dist/skills/bundled/alerts/index.js +249 -0
- package/dist/skills/bundled/alerts/index.js.map +1 -0
- package/dist/skills/bundled/analytics/index.d.ts +17 -0
- package/dist/skills/bundled/analytics/index.js +112 -0
- package/dist/skills/bundled/analytics/index.js.map +1 -0
- package/dist/skills/bundled/arbitrage/index.d.ts +24 -0
- package/dist/skills/bundled/arbitrage/index.js +253 -0
- package/dist/skills/bundled/arbitrage/index.js.map +1 -0
- package/dist/skills/bundled/auto-reply/index.d.ts +18 -0
- package/dist/skills/bundled/auto-reply/index.js +215 -0
- package/dist/skills/bundled/auto-reply/index.js.map +1 -0
- package/dist/skills/bundled/automation/index.d.ts +19 -0
- package/dist/skills/bundled/automation/index.js +160 -0
- package/dist/skills/bundled/automation/index.js.map +1 -0
- package/dist/skills/bundled/backtest/index.d.ts +18 -0
- package/dist/skills/bundled/backtest/index.js +250 -0
- package/dist/skills/bundled/backtest/index.js.map +1 -0
- package/dist/skills/bundled/bags/index.d.ts +49 -0
- package/dist/skills/bundled/bags/index.js +1069 -0
- package/dist/skills/bundled/bags/index.js.map +1 -0
- package/dist/skills/bundled/bankr/index.d.ts +161 -0
- package/dist/skills/bundled/bankr/index.js +271 -0
- package/dist/skills/bundled/bankr/index.js.map +1 -0
- package/dist/skills/bundled/betfair/index.d.ts +24 -0
- package/dist/skills/bundled/betfair/index.js +511 -0
- package/dist/skills/bundled/betfair/index.js.map +1 -0
- package/dist/skills/bundled/binance-futures/index.d.ts +15 -0
- package/dist/skills/bundled/binance-futures/index.js +485 -0
- package/dist/skills/bundled/binance-futures/index.js.map +1 -0
- package/dist/skills/bundled/botchan/index.d.ts +130 -0
- package/dist/skills/bundled/botchan/index.js +427 -0
- package/dist/skills/bundled/botchan/index.js.map +1 -0
- package/dist/skills/bundled/bridge/index.d.ts +17 -0
- package/dist/skills/bundled/bridge/index.js +297 -0
- package/dist/skills/bundled/bridge/index.js.map +1 -0
- package/dist/skills/bundled/bybit-futures/index.d.ts +15 -0
- package/dist/skills/bundled/bybit-futures/index.js +380 -0
- package/dist/skills/bundled/bybit-futures/index.js.map +1 -0
- package/dist/skills/bundled/clanker/index.d.ts +236 -0
- package/dist/skills/bundled/clanker/index.js +759 -0
- package/dist/skills/bundled/clanker/index.js.map +1 -0
- package/dist/skills/bundled/copy-trading/index.d.ts +20 -0
- package/dist/skills/bundled/copy-trading/index.js +213 -0
- package/dist/skills/bundled/copy-trading/index.js.map +1 -0
- package/dist/skills/bundled/copy-trading-solana/index.d.ts +21 -0
- package/dist/skills/bundled/copy-trading-solana/index.js +421 -0
- package/dist/skills/bundled/copy-trading-solana/index.js.map +1 -0
- package/dist/skills/bundled/credentials/index.d.ts +17 -0
- package/dist/skills/bundled/credentials/index.js +137 -0
- package/dist/skills/bundled/credentials/index.js.map +1 -0
- package/dist/skills/bundled/crypto-hft/index.d.ts +26 -0
- package/dist/skills/bundled/crypto-hft/index.js +361 -0
- package/dist/skills/bundled/crypto-hft/index.js.map +1 -0
- package/dist/skills/bundled/dca/index.d.ts +26 -0
- package/dist/skills/bundled/dca/index.js +1342 -0
- package/dist/skills/bundled/dca/index.js.map +1 -0
- package/dist/skills/bundled/divergence/index.d.ts +19 -0
- package/dist/skills/bundled/divergence/index.js +272 -0
- package/dist/skills/bundled/divergence/index.js.map +1 -0
- package/dist/skills/bundled/doctor/index.d.ts +18 -0
- package/dist/skills/bundled/doctor/index.js +78 -0
- package/dist/skills/bundled/doctor/index.js.map +1 -0
- package/dist/skills/bundled/drift/index.d.ts +13 -0
- package/dist/skills/bundled/drift/index.js +378 -0
- package/dist/skills/bundled/drift/index.js.map +1 -0
- package/dist/skills/bundled/drift-sdk/index.d.ts +17 -0
- package/dist/skills/bundled/drift-sdk/index.js +501 -0
- package/dist/skills/bundled/drift-sdk/index.js.map +1 -0
- package/dist/skills/bundled/edge/index.d.ts +16 -0
- package/dist/skills/bundled/edge/index.js +91 -0
- package/dist/skills/bundled/edge/index.js.map +1 -0
- package/dist/skills/bundled/embeddings/index.d.ts +19 -0
- package/dist/skills/bundled/embeddings/index.js +215 -0
- package/dist/skills/bundled/embeddings/index.js.map +1 -0
- package/dist/skills/bundled/endaoment/index.d.ts +105 -0
- package/dist/skills/bundled/endaoment/index.js +285 -0
- package/dist/skills/bundled/endaoment/index.js.map +1 -0
- package/dist/skills/bundled/ens/index.d.ts +151 -0
- package/dist/skills/bundled/ens/index.js +278 -0
- package/dist/skills/bundled/ens/index.js.map +1 -0
- package/dist/skills/bundled/erc8004/index.d.ts +123 -0
- package/dist/skills/bundled/erc8004/index.js +301 -0
- package/dist/skills/bundled/erc8004/index.js.map +1 -0
- package/dist/skills/bundled/execution/index.d.ts +18 -0
- package/dist/skills/bundled/execution/index.js +358 -0
- package/dist/skills/bundled/execution/index.js.map +1 -0
- package/dist/skills/bundled/farcaster/index.d.ts +121 -0
- package/dist/skills/bundled/farcaster/index.js +314 -0
- package/dist/skills/bundled/farcaster/index.js.map +1 -0
- package/dist/skills/bundled/features/index.d.ts +17 -0
- package/dist/skills/bundled/features/index.js +305 -0
- package/dist/skills/bundled/features/index.js.map +1 -0
- package/dist/skills/bundled/feeds/index.d.ts +26 -0
- package/dist/skills/bundled/feeds/index.js +462 -0
- package/dist/skills/bundled/feeds/index.js.map +1 -0
- package/dist/skills/bundled/harden/index.d.ts +55 -0
- package/dist/skills/bundled/harden/index.js +510 -0
- package/dist/skills/bundled/harden/index.js.map +1 -0
- package/dist/skills/bundled/history/index.d.ts +21 -0
- package/dist/skills/bundled/history/index.js +195 -0
- package/dist/skills/bundled/history/index.js.map +1 -0
- package/dist/skills/bundled/hyperliquid/index.d.ts +19 -0
- package/dist/skills/bundled/hyperliquid/index.js +1280 -0
- package/dist/skills/bundled/hyperliquid/index.js.map +1 -0
- package/dist/skills/bundled/identity/index.d.ts +17 -0
- package/dist/skills/bundled/identity/index.js +223 -0
- package/dist/skills/bundled/identity/index.js.map +1 -0
- package/dist/skills/bundled/integrations/index.d.ts +17 -0
- package/dist/skills/bundled/integrations/index.js +138 -0
- package/dist/skills/bundled/integrations/index.js.map +1 -0
- package/dist/skills/bundled/jupiter/index.d.ts +41 -0
- package/dist/skills/bundled/jupiter/index.js +872 -0
- package/dist/skills/bundled/jupiter/index.js.map +1 -0
- package/dist/skills/bundled/kamino/index.d.ts +33 -0
- package/dist/skills/bundled/kamino/index.js +578 -0
- package/dist/skills/bundled/kamino/index.js.map +1 -0
- package/dist/skills/bundled/ledger/index.d.ts +14 -0
- package/dist/skills/bundled/ledger/index.js +186 -0
- package/dist/skills/bundled/ledger/index.js.map +1 -0
- package/dist/skills/bundled/market-index/index.d.ts +18 -0
- package/dist/skills/bundled/market-index/index.js +182 -0
- package/dist/skills/bundled/market-index/index.js.map +1 -0
- package/dist/skills/bundled/markets/index.d.ts +16 -0
- package/dist/skills/bundled/markets/index.js +95 -0
- package/dist/skills/bundled/markets/index.js.map +1 -0
- package/dist/skills/bundled/mcp/index.d.ts +19 -0
- package/dist/skills/bundled/mcp/index.js +212 -0
- package/dist/skills/bundled/mcp/index.js.map +1 -0
- package/dist/skills/bundled/memory/index.d.ts +20 -0
- package/dist/skills/bundled/memory/index.js +210 -0
- package/dist/skills/bundled/memory/index.js.map +1 -0
- package/dist/skills/bundled/metaculus/index.d.ts +17 -0
- package/dist/skills/bundled/metaculus/index.js +168 -0
- package/dist/skills/bundled/metaculus/index.js.map +1 -0
- package/dist/skills/bundled/meteora/index.d.ts +39 -0
- package/dist/skills/bundled/meteora/index.js +837 -0
- package/dist/skills/bundled/meteora/index.js.map +1 -0
- package/dist/skills/bundled/meteora-dbc/index.d.ts +33 -0
- package/dist/skills/bundled/meteora-dbc/index.js +993 -0
- package/dist/skills/bundled/meteora-dbc/index.js.map +1 -0
- package/dist/skills/bundled/metrics/index.d.ts +18 -0
- package/dist/skills/bundled/metrics/index.js +91 -0
- package/dist/skills/bundled/metrics/index.js.map +1 -0
- package/dist/skills/bundled/mev/index.d.ts +17 -0
- package/dist/skills/bundled/mev/index.js +108 -0
- package/dist/skills/bundled/mev/index.js.map +1 -0
- package/dist/skills/bundled/mexc-futures/index.d.ts +16 -0
- package/dist/skills/bundled/mexc-futures/index.js +389 -0
- package/dist/skills/bundled/mexc-futures/index.js.map +1 -0
- package/dist/skills/bundled/mm/index.d.ts +18 -0
- package/dist/skills/bundled/mm/index.js +315 -0
- package/dist/skills/bundled/mm/index.js.map +1 -0
- package/dist/skills/bundled/monitoring/index.d.ts +18 -0
- package/dist/skills/bundled/monitoring/index.js +146 -0
- package/dist/skills/bundled/monitoring/index.js.map +1 -0
- package/dist/skills/bundled/news/index.d.ts +17 -0
- package/dist/skills/bundled/news/index.js +161 -0
- package/dist/skills/bundled/news/index.js.map +1 -0
- package/dist/skills/bundled/onchainkit/index.d.ts +92 -0
- package/dist/skills/bundled/onchainkit/index.js +429 -0
- package/dist/skills/bundled/onchainkit/index.js.map +1 -0
- package/dist/skills/bundled/opinion/index.d.ts +12 -0
- package/dist/skills/bundled/opinion/index.js +429 -0
- package/dist/skills/bundled/opinion/index.js.map +1 -0
- package/dist/skills/bundled/opportunity/index.d.ts +25 -0
- package/dist/skills/bundled/opportunity/index.js +289 -0
- package/dist/skills/bundled/opportunity/index.js.map +1 -0
- package/dist/skills/bundled/orca/index.d.ts +12 -0
- package/dist/skills/bundled/orca/index.js +663 -0
- package/dist/skills/bundled/orca/index.js.map +1 -0
- package/dist/skills/bundled/pairing/index.d.ts +24 -0
- package/dist/skills/bundled/pairing/index.js +228 -0
- package/dist/skills/bundled/pairing/index.js.map +1 -0
- package/dist/skills/bundled/percolator/index.d.ts +20 -0
- package/dist/skills/bundled/percolator/index.js +229 -0
- package/dist/skills/bundled/percolator/index.js.map +1 -0
- package/dist/skills/bundled/permissions/index.d.ts +21 -0
- package/dist/skills/bundled/permissions/index.js +204 -0
- package/dist/skills/bundled/permissions/index.js.map +1 -0
- package/dist/skills/bundled/plugins/index.d.ts +20 -0
- package/dist/skills/bundled/plugins/index.js +209 -0
- package/dist/skills/bundled/plugins/index.js.map +1 -0
- package/dist/skills/bundled/portfolio/index.d.ts +20 -0
- package/dist/skills/bundled/portfolio/index.js +367 -0
- package/dist/skills/bundled/portfolio/index.js.map +1 -0
- package/dist/skills/bundled/portfolio-sync/index.d.ts +17 -0
- package/dist/skills/bundled/portfolio-sync/index.js +116 -0
- package/dist/skills/bundled/portfolio-sync/index.js.map +1 -0
- package/dist/skills/bundled/positions/index.d.ts +18 -0
- package/dist/skills/bundled/positions/index.js +161 -0
- package/dist/skills/bundled/positions/index.js.map +1 -0
- package/dist/skills/bundled/predictfun/index.d.ts +13 -0
- package/dist/skills/bundled/predictfun/index.js +612 -0
- package/dist/skills/bundled/predictfun/index.js.map +1 -0
- package/dist/skills/bundled/predictit/index.d.ts +16 -0
- package/dist/skills/bundled/predictit/index.js +138 -0
- package/dist/skills/bundled/predictit/index.js.map +1 -0
- package/dist/skills/bundled/presence/index.d.ts +18 -0
- package/dist/skills/bundled/presence/index.js +151 -0
- package/dist/skills/bundled/presence/index.js.map +1 -0
- package/dist/skills/bundled/processes/index.d.ts +17 -0
- package/dist/skills/bundled/processes/index.js +121 -0
- package/dist/skills/bundled/processes/index.js.map +1 -0
- package/dist/skills/bundled/pump-swarm/index.d.ts +16 -0
- package/dist/skills/bundled/pump-swarm/index.js +2235 -0
- package/dist/skills/bundled/pump-swarm/index.js.map +1 -0
- package/dist/skills/bundled/pumpfun/index.d.ts +47 -0
- package/dist/skills/bundled/pumpfun/index.js +1400 -0
- package/dist/skills/bundled/pumpfun/index.js.map +1 -0
- package/dist/skills/bundled/qmd/index.d.ts +18 -0
- package/dist/skills/bundled/qmd/index.js +116 -0
- package/dist/skills/bundled/qmd/index.js.map +1 -0
- package/dist/skills/bundled/qrcoin/index.d.ts +92 -0
- package/dist/skills/bundled/qrcoin/index.js +328 -0
- package/dist/skills/bundled/qrcoin/index.js.map +1 -0
- package/dist/skills/bundled/raydium/index.d.ts +35 -0
- package/dist/skills/bundled/raydium/index.js +695 -0
- package/dist/skills/bundled/raydium/index.js.map +1 -0
- package/dist/skills/bundled/remote/index.d.ts +19 -0
- package/dist/skills/bundled/remote/index.js +186 -0
- package/dist/skills/bundled/remote/index.js.map +1 -0
- package/dist/skills/bundled/research/index.d.ts +17 -0
- package/dist/skills/bundled/research/index.js +185 -0
- package/dist/skills/bundled/research/index.js.map +1 -0
- package/dist/skills/bundled/risk/index.d.ts +31 -0
- package/dist/skills/bundled/risk/index.js +379 -0
- package/dist/skills/bundled/risk/index.js.map +1 -0
- package/dist/skills/bundled/router/index.d.ts +17 -0
- package/dist/skills/bundled/router/index.js +160 -0
- package/dist/skills/bundled/router/index.js.map +1 -0
- package/dist/skills/bundled/routing/index.d.ts +23 -0
- package/dist/skills/bundled/routing/index.js +257 -0
- package/dist/skills/bundled/routing/index.js.map +1 -0
- package/dist/skills/bundled/sandbox/index.d.ts +18 -0
- package/dist/skills/bundled/sandbox/index.js +119 -0
- package/dist/skills/bundled/sandbox/index.js.map +1 -0
- package/dist/skills/bundled/search-config/index.d.ts +18 -0
- package/dist/skills/bundled/search-config/index.js +170 -0
- package/dist/skills/bundled/search-config/index.js.map +1 -0
- package/dist/skills/bundled/sessions/index.d.ts +29 -0
- package/dist/skills/bundled/sessions/index.js +193 -0
- package/dist/skills/bundled/sessions/index.js.map +1 -0
- package/dist/skills/bundled/shield/index.d.ts +22 -0
- package/dist/skills/bundled/shield/index.js +245 -0
- package/dist/skills/bundled/shield/index.js.map +1 -0
- package/dist/skills/bundled/signals/index.d.ts +24 -0
- package/dist/skills/bundled/signals/index.js +776 -0
- package/dist/skills/bundled/signals/index.js.map +1 -0
- package/dist/skills/bundled/sizing/index.d.ts +16 -0
- package/dist/skills/bundled/sizing/index.js +168 -0
- package/dist/skills/bundled/sizing/index.js.map +1 -0
- package/dist/skills/bundled/slippage/index.d.ts +16 -0
- package/dist/skills/bundled/slippage/index.js +111 -0
- package/dist/skills/bundled/slippage/index.js.map +1 -0
- package/dist/skills/bundled/smarkets/index.d.ts +23 -0
- package/dist/skills/bundled/smarkets/index.js +473 -0
- package/dist/skills/bundled/smarkets/index.js.map +1 -0
- package/dist/skills/bundled/strategy/index.d.ts +18 -0
- package/dist/skills/bundled/strategy/index.js +168 -0
- package/dist/skills/bundled/strategy/index.js.map +1 -0
- package/dist/skills/bundled/streaming/index.d.ts +19 -0
- package/dist/skills/bundled/streaming/index.js +147 -0
- package/dist/skills/bundled/streaming/index.js.map +1 -0
- package/dist/skills/bundled/tailscale/index.d.ts +18 -0
- package/dist/skills/bundled/tailscale/index.js +173 -0
- package/dist/skills/bundled/tailscale/index.js.map +1 -0
- package/dist/skills/bundled/ticks/index.d.ts +17 -0
- package/dist/skills/bundled/ticks/index.js +287 -0
- package/dist/skills/bundled/ticks/index.js.map +1 -0
- package/dist/skills/bundled/token-security/index.d.ts +19 -0
- package/dist/skills/bundled/token-security/index.js +138 -0
- package/dist/skills/bundled/token-security/index.js.map +1 -0
- package/dist/skills/bundled/trading-evm/index.d.ts +19 -0
- package/dist/skills/bundled/trading-evm/index.js +302 -0
- package/dist/skills/bundled/trading-evm/index.js.map +1 -0
- package/dist/skills/bundled/trading-futures/index.d.ts +14 -0
- package/dist/skills/bundled/trading-futures/index.js +874 -0
- package/dist/skills/bundled/trading-futures/index.js.map +1 -0
- package/dist/skills/bundled/trading-kalshi/index.d.ts +36 -0
- package/dist/skills/bundled/trading-kalshi/index.js +1199 -0
- package/dist/skills/bundled/trading-kalshi/index.js.map +1 -0
- package/dist/skills/bundled/trading-manifold/index.d.ts +23 -0
- package/dist/skills/bundled/trading-manifold/index.js +391 -0
- package/dist/skills/bundled/trading-manifold/index.js.map +1 -0
- package/dist/skills/bundled/trading-polymarket/index.d.ts +27 -0
- package/dist/skills/bundled/trading-polymarket/index.js +1321 -0
- package/dist/skills/bundled/trading-polymarket/index.js.map +1 -0
- package/dist/skills/bundled/trading-solana/index.d.ts +19 -0
- package/dist/skills/bundled/trading-solana/index.js +383 -0
- package/dist/skills/bundled/trading-solana/index.js.map +1 -0
- package/dist/skills/bundled/trading-system/index.d.ts +22 -0
- package/dist/skills/bundled/trading-system/index.js +355 -0
- package/dist/skills/bundled/trading-system/index.js.map +1 -0
- package/dist/skills/bundled/triggers/index.d.ts +18 -0
- package/dist/skills/bundled/triggers/index.js +172 -0
- package/dist/skills/bundled/triggers/index.js.map +1 -0
- package/dist/skills/bundled/tts/index.d.ts +16 -0
- package/dist/skills/bundled/tts/index.js +150 -0
- package/dist/skills/bundled/tts/index.js.map +1 -0
- package/dist/skills/bundled/tweet-ideas/index.d.ts +20 -0
- package/dist/skills/bundled/tweet-ideas/index.js +470 -0
- package/dist/skills/bundled/tweet-ideas/index.js.map +1 -0
- package/dist/skills/bundled/usage/index.d.ts +17 -0
- package/dist/skills/bundled/usage/index.js +145 -0
- package/dist/skills/bundled/usage/index.js.map +1 -0
- package/dist/skills/bundled/veil/index.d.ts +79 -0
- package/dist/skills/bundled/veil/index.js +322 -0
- package/dist/skills/bundled/veil/index.js.map +1 -0
- package/dist/skills/bundled/verify/index.d.ts +20 -0
- package/dist/skills/bundled/verify/index.js +157 -0
- package/dist/skills/bundled/verify/index.js.map +1 -0
- package/dist/skills/bundled/virtuals/index.d.ts +20 -0
- package/dist/skills/bundled/virtuals/index.js +255 -0
- package/dist/skills/bundled/virtuals/index.js.map +1 -0
- package/dist/skills/bundled/voice/index.d.ts +18 -0
- package/dist/skills/bundled/voice/index.js +190 -0
- package/dist/skills/bundled/voice/index.js.map +1 -0
- package/dist/skills/bundled/weather/index.d.ts +20 -0
- package/dist/skills/bundled/weather/index.js +475 -0
- package/dist/skills/bundled/weather/index.js.map +1 -0
- package/dist/skills/bundled/webhooks/index.d.ts +18 -0
- package/dist/skills/bundled/webhooks/index.js +136 -0
- package/dist/skills/bundled/webhooks/index.js.map +1 -0
- package/dist/skills/bundled/whale-tracking/index.d.ts +18 -0
- package/dist/skills/bundled/whale-tracking/index.js +441 -0
- package/dist/skills/bundled/whale-tracking/index.js.map +1 -0
- package/dist/skills/bundled/yoink/index.d.ts +78 -0
- package/dist/skills/bundled/yoink/index.js +236 -0
- package/dist/skills/bundled/yoink/index.js.map +1 -0
- package/dist/skills/executor.d.ts +117 -0
- package/dist/skills/executor.js +469 -0
- package/dist/skills/executor.js.map +1 -0
- package/dist/skills/frontmatter.d.ts +69 -0
- package/dist/skills/frontmatter.js +187 -0
- package/dist/skills/frontmatter.js.map +1 -0
- package/dist/skills/index.d.ts +150 -0
- package/dist/skills/index.js +531 -0
- package/dist/skills/index.js.map +1 -0
- package/dist/skills/loader.d.ts +48 -0
- package/dist/skills/loader.js +594 -0
- package/dist/skills/loader.js.map +1 -0
- package/dist/skills/registry.d.ts +94 -0
- package/dist/skills/registry.js +308 -0
- package/dist/skills/registry.js.map +1 -0
- package/dist/solana/copytrade.d.ts +116 -0
- package/dist/solana/copytrade.js +493 -0
- package/dist/solana/copytrade.js.map +1 -0
- package/dist/solana/drift.d.ts +154 -0
- package/dist/solana/drift.js +599 -0
- package/dist/solana/drift.js.map +1 -0
- package/dist/solana/jupiter.d.ts +283 -0
- package/dist/solana/jupiter.js +553 -0
- package/dist/solana/jupiter.js.map +1 -0
- package/dist/solana/kamino.d.ts +206 -0
- package/dist/solana/kamino.js +546 -0
- package/dist/solana/kamino.js.map +1 -0
- package/dist/solana/meteora-dbc.d.ts +430 -0
- package/dist/solana/meteora-dbc.js +1105 -0
- package/dist/solana/meteora-dbc.js.map +1 -0
- package/dist/solana/meteora.d.ts +232 -0
- package/dist/solana/meteora.js +682 -0
- package/dist/solana/meteora.js.map +1 -0
- package/dist/solana/orca.d.ts +163 -0
- package/dist/solana/orca.js +378 -0
- package/dist/solana/orca.js.map +1 -0
- package/dist/solana/pools.d.ts +26 -0
- package/dist/solana/pools.js +96 -0
- package/dist/solana/pools.js.map +1 -0
- package/dist/solana/pump-swarm.d.ts +349 -0
- package/dist/solana/pump-swarm.js +1663 -0
- package/dist/solana/pump-swarm.js.map +1 -0
- package/dist/solana/pumpapi.d.ts +196 -0
- package/dist/solana/pumpapi.js +462 -0
- package/dist/solana/pumpapi.js.map +1 -0
- package/dist/solana/raydium.d.ts +170 -0
- package/dist/solana/raydium.js +673 -0
- package/dist/solana/raydium.js.map +1 -0
- package/dist/solana/swarm-ai-builder.d.ts +97 -0
- package/dist/solana/swarm-ai-builder.js +571 -0
- package/dist/solana/swarm-ai-builder.js.map +1 -0
- package/dist/solana/swarm-arbitrage.d.ts +111 -0
- package/dist/solana/swarm-arbitrage.js +437 -0
- package/dist/solana/swarm-arbitrage.js.map +1 -0
- package/dist/solana/swarm-builders.d.ts +71 -0
- package/dist/solana/swarm-builders.js +402 -0
- package/dist/solana/swarm-builders.js.map +1 -0
- package/dist/solana/swarm-copytrade.d.ts +103 -0
- package/dist/solana/swarm-copytrade.js +420 -0
- package/dist/solana/swarm-copytrade.js.map +1 -0
- package/dist/solana/swarm-presets.d.ts +49 -0
- package/dist/solana/swarm-presets.js +282 -0
- package/dist/solana/swarm-presets.js.map +1 -0
- package/dist/solana/swarm-signals.d.ts +128 -0
- package/dist/solana/swarm-signals.js +529 -0
- package/dist/solana/swarm-signals.js.map +1 -0
- package/dist/solana/swarm-strategies.d.ts +230 -0
- package/dist/solana/swarm-strategies.js +611 -0
- package/dist/solana/swarm-strategies.js.map +1 -0
- package/dist/solana/tokenlist.d.ts +10 -0
- package/dist/solana/tokenlist.js +54 -0
- package/dist/solana/tokenlist.js.map +1 -0
- package/dist/solana/wallet.d.ts +12 -0
- package/dist/solana/wallet.js +90 -0
- package/dist/solana/wallet.js.map +1 -0
- package/dist/strategies/crypto-hft/index.d.ts +46 -0
- package/dist/strategies/crypto-hft/index.js +469 -0
- package/dist/strategies/crypto-hft/index.js.map +1 -0
- package/dist/strategies/crypto-hft/market-scanner.d.ts +26 -0
- package/dist/strategies/crypto-hft/market-scanner.js +177 -0
- package/dist/strategies/crypto-hft/market-scanner.js.map +1 -0
- package/dist/strategies/crypto-hft/orderbook.d.ts +37 -0
- package/dist/strategies/crypto-hft/orderbook.js +184 -0
- package/dist/strategies/crypto-hft/orderbook.js.map +1 -0
- package/dist/strategies/crypto-hft/positions.d.ts +49 -0
- package/dist/strategies/crypto-hft/positions.js +376 -0
- package/dist/strategies/crypto-hft/positions.js.map +1 -0
- package/dist/strategies/crypto-hft/presets.d.ts +11 -0
- package/dist/strategies/crypto-hft/presets.js +164 -0
- package/dist/strategies/crypto-hft/presets.js.map +1 -0
- package/dist/strategies/crypto-hft/strategies.d.ts +96 -0
- package/dist/strategies/crypto-hft/strategies.js +330 -0
- package/dist/strategies/crypto-hft/strategies.js.map +1 -0
- package/dist/strategies/crypto-hft/types.d.ts +196 -0
- package/dist/strategies/crypto-hft/types.js +32 -0
- package/dist/strategies/crypto-hft/types.js.map +1 -0
- package/dist/strategies/hft-divergence/detector.d.ts +29 -0
- package/dist/strategies/hft-divergence/detector.js +182 -0
- package/dist/strategies/hft-divergence/detector.js.map +1 -0
- package/dist/strategies/hft-divergence/index.d.ts +12 -0
- package/dist/strategies/hft-divergence/index.js +19 -0
- package/dist/strategies/hft-divergence/index.js.map +1 -0
- package/dist/strategies/hft-divergence/market-rotator.d.ts +17 -0
- package/dist/strategies/hft-divergence/market-rotator.js +128 -0
- package/dist/strategies/hft-divergence/market-rotator.js.map +1 -0
- package/dist/strategies/hft-divergence/position-manager.d.ts +35 -0
- package/dist/strategies/hft-divergence/position-manager.js +188 -0
- package/dist/strategies/hft-divergence/position-manager.js.map +1 -0
- package/dist/strategies/hft-divergence/strategy.d.ts +31 -0
- package/dist/strategies/hft-divergence/strategy.js +295 -0
- package/dist/strategies/hft-divergence/strategy.js.map +1 -0
- package/dist/strategies/hft-divergence/types.d.ts +114 -0
- package/dist/strategies/hft-divergence/types.js +10 -0
- package/dist/strategies/hft-divergence/types.js.map +1 -0
- package/dist/streaming/index.d.ts +70 -0
- package/dist/streaming/index.js +296 -0
- package/dist/streaming/index.js.map +1 -0
- package/dist/tailscale/index.d.ts +139 -0
- package/dist/tailscale/index.js +345 -0
- package/dist/tailscale/index.js.map +1 -0
- package/dist/telemetry/index.d.ts +143 -0
- package/dist/telemetry/index.js +535 -0
- package/dist/telemetry/index.js.map +1 -0
- package/dist/terminal/index.d.ts +121 -0
- package/dist/terminal/index.js +548 -0
- package/dist/terminal/index.js.map +1 -0
- package/dist/token-security/index.d.ts +36 -0
- package/dist/token-security/index.js +253 -0
- package/dist/token-security/index.js.map +1 -0
- package/dist/tools/browser.d.ts +128 -0
- package/dist/tools/browser.js +459 -0
- package/dist/tools/browser.js.map +1 -0
- package/dist/tools/canvas.d.ts +93 -0
- package/dist/tools/canvas.js +349 -0
- package/dist/tools/canvas.js.map +1 -0
- package/dist/tools/docker.d.ts +59 -0
- package/dist/tools/docker.js +191 -0
- package/dist/tools/docker.js.map +1 -0
- package/dist/tools/email.d.ts +25 -0
- package/dist/tools/email.js +131 -0
- package/dist/tools/email.js.map +1 -0
- package/dist/tools/exec.d.ts +81 -0
- package/dist/tools/exec.js +373 -0
- package/dist/tools/exec.js.map +1 -0
- package/dist/tools/files.d.ts +46 -0
- package/dist/tools/files.js +185 -0
- package/dist/tools/files.js.map +1 -0
- package/dist/tools/git.d.ts +29 -0
- package/dist/tools/git.js +105 -0
- package/dist/tools/git.js.map +1 -0
- package/dist/tools/image.d.ts +57 -0
- package/dist/tools/image.js +308 -0
- package/dist/tools/image.js.map +1 -0
- package/dist/tools/index.d.ts +39 -0
- package/dist/tools/index.js +46 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/message.d.ts +99 -0
- package/dist/tools/message.js +200 -0
- package/dist/tools/message.js.map +1 -0
- package/dist/tools/nodes.d.ts +134 -0
- package/dist/tools/nodes.js +357 -0
- package/dist/tools/nodes.js.map +1 -0
- package/dist/tools/sessions.d.ts +60 -0
- package/dist/tools/sessions.js +119 -0
- package/dist/tools/sessions.js.map +1 -0
- package/dist/tools/shell-history.d.ts +17 -0
- package/dist/tools/shell-history.js +118 -0
- package/dist/tools/shell-history.js.map +1 -0
- package/dist/tools/sms.d.ts +18 -0
- package/dist/tools/sms.js +66 -0
- package/dist/tools/sms.js.map +1 -0
- package/dist/tools/sql.d.ts +19 -0
- package/dist/tools/sql.js +91 -0
- package/dist/tools/sql.js.map +1 -0
- package/dist/tools/transcription.d.ts +13 -0
- package/dist/tools/transcription.js +99 -0
- package/dist/tools/transcription.js.map +1 -0
- package/dist/tools/web-fetch.d.ts +69 -0
- package/dist/tools/web-fetch.js +251 -0
- package/dist/tools/web-fetch.js.map +1 -0
- package/dist/tools/web-search.d.ts +58 -0
- package/dist/tools/web-search.js +204 -0
- package/dist/tools/web-search.js.map +1 -0
- package/dist/tools/webhooks.d.ts +74 -0
- package/dist/tools/webhooks.js +165 -0
- package/dist/tools/webhooks.js.map +1 -0
- package/dist/trading/accounts.d.ts +167 -0
- package/dist/trading/accounts.js +394 -0
- package/dist/trading/accounts.js.map +1 -0
- package/dist/trading/adapters/index.d.ts +27 -0
- package/dist/trading/adapters/index.js +165 -0
- package/dist/trading/adapters/index.js.map +1 -0
- package/dist/trading/backtest.d.ts +161 -0
- package/dist/trading/backtest.js +665 -0
- package/dist/trading/backtest.js.map +1 -0
- package/dist/trading/bots/index.d.ts +196 -0
- package/dist/trading/bots/index.js +688 -0
- package/dist/trading/bots/index.js.map +1 -0
- package/dist/trading/bridge.d.ts +33 -0
- package/dist/trading/bridge.js +121 -0
- package/dist/trading/bridge.js.map +1 -0
- package/dist/trading/builder.d.ts +102 -0
- package/dist/trading/builder.js +430 -0
- package/dist/trading/builder.js.map +1 -0
- package/dist/trading/copy-trading.d.ts +125 -0
- package/dist/trading/copy-trading.js +611 -0
- package/dist/trading/copy-trading.js.map +1 -0
- package/dist/trading/devtools.d.ts +172 -0
- package/dist/trading/devtools.js +425 -0
- package/dist/trading/devtools.js.map +1 -0
- package/dist/trading/futures/index.d.ts +981 -0
- package/dist/trading/futures/index.js +4011 -0
- package/dist/trading/futures/index.js.map +1 -0
- package/dist/trading/index.d.ts +102 -0
- package/dist/trading/index.js +310 -0
- package/dist/trading/index.js.map +1 -0
- package/dist/trading/kelly.d.ts +137 -0
- package/dist/trading/kelly.js +328 -0
- package/dist/trading/kelly.js.map +1 -0
- package/dist/trading/logger.d.ts +163 -0
- package/dist/trading/logger.js +424 -0
- package/dist/trading/logger.js.map +1 -0
- package/dist/trading/market-making/engine.d.ts +44 -0
- package/dist/trading/market-making/engine.js +165 -0
- package/dist/trading/market-making/engine.js.map +1 -0
- package/dist/trading/market-making/index.d.ts +10 -0
- package/dist/trading/market-making/index.js +29 -0
- package/dist/trading/market-making/index.js.map +1 -0
- package/dist/trading/market-making/strategy.d.ts +25 -0
- package/dist/trading/market-making/strategy.js +250 -0
- package/dist/trading/market-making/strategy.js.map +1 -0
- package/dist/trading/market-making/types.d.ts +92 -0
- package/dist/trading/market-making/types.js +6 -0
- package/dist/trading/market-making/types.js.map +1 -0
- package/dist/trading/ml-signals.d.ts +175 -0
- package/dist/trading/ml-signals.js +548 -0
- package/dist/trading/ml-signals.js.map +1 -0
- package/dist/trading/orchestrator.d.ts +59 -0
- package/dist/trading/orchestrator.js +199 -0
- package/dist/trading/orchestrator.js.map +1 -0
- package/dist/trading/position-bridge.d.ts +41 -0
- package/dist/trading/position-bridge.js +178 -0
- package/dist/trading/position-bridge.js.map +1 -0
- package/dist/trading/resilience.d.ts +81 -0
- package/dist/trading/resilience.js +257 -0
- package/dist/trading/resilience.js.map +1 -0
- package/dist/trading/risk.d.ts +18 -0
- package/dist/trading/risk.js +91 -0
- package/dist/trading/risk.js.map +1 -0
- package/dist/trading/safety.d.ts +114 -0
- package/dist/trading/safety.js +372 -0
- package/dist/trading/safety.js.map +1 -0
- package/dist/trading/secrets.d.ts +48 -0
- package/dist/trading/secrets.js +243 -0
- package/dist/trading/secrets.js.map +1 -0
- package/dist/trading/state.d.ts +88 -0
- package/dist/trading/state.js +221 -0
- package/dist/trading/state.js.map +1 -0
- package/dist/trading/stream.d.ts +121 -0
- package/dist/trading/stream.js +396 -0
- package/dist/trading/stream.js.map +1 -0
- package/dist/trading/tracking.d.ts +136 -0
- package/dist/trading/tracking.js +512 -0
- package/dist/trading/tracking.js.map +1 -0
- package/dist/tts/index.d.ts +28 -0
- package/dist/tts/index.js +64 -0
- package/dist/tts/index.js.map +1 -0
- package/dist/tui/index.d.ts +159 -0
- package/dist/tui/index.js +580 -0
- package/dist/tui/index.js.map +1 -0
- package/dist/types.d.ts +1373 -0
- package/dist/types.js +7 -0
- package/dist/types.js.map +1 -0
- package/dist/usage/index.d.ts +57 -0
- package/dist/usage/index.js +191 -0
- package/dist/usage/index.js.map +1 -0
- package/dist/utils/attachments.d.ts +12 -0
- package/dist/utils/attachments.js +104 -0
- package/dist/utils/attachments.js.map +1 -0
- package/dist/utils/config.d.ts +14 -0
- package/dist/utils/config.js +474 -0
- package/dist/utils/config.js.map +1 -0
- package/dist/utils/http.d.ts +22 -0
- package/dist/utils/http.js +191 -0
- package/dist/utils/http.js.map +1 -0
- package/dist/utils/id.d.ts +21 -0
- package/dist/utils/id.js +41 -0
- package/dist/utils/id.js.map +1 -0
- package/dist/utils/json-utils.d.ts +201 -0
- package/dist/utils/json-utils.js +151 -0
- package/dist/utils/json-utils.js.map +1 -0
- package/dist/utils/kalshi-auth.d.ts +10 -0
- package/dist/utils/kalshi-auth.js +48 -0
- package/dist/utils/kalshi-auth.js.map +1 -0
- package/dist/utils/kelly.d.ts +153 -0
- package/dist/utils/kelly.js +322 -0
- package/dist/utils/kelly.js.map +1 -0
- package/dist/utils/logger.d.ts +7 -0
- package/dist/utils/logger.js +26 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/opinion-auth.d.ts +17 -0
- package/dist/utils/opinion-auth.js +25 -0
- package/dist/utils/opinion-auth.js.map +1 -0
- package/dist/utils/polymarket-auth.d.ts +11 -0
- package/dist/utils/polymarket-auth.js +32 -0
- package/dist/utils/polymarket-auth.js.map +1 -0
- package/dist/utils/polymarket-order-signer.d.ts +118 -0
- package/dist/utils/polymarket-order-signer.js +329 -0
- package/dist/utils/polymarket-order-signer.js.map +1 -0
- package/dist/utils/polymarket-setup.d.ts +70 -0
- package/dist/utils/polymarket-setup.js +288 -0
- package/dist/utils/polymarket-setup.js.map +1 -0
- package/dist/utils/production.d.ts +112 -0
- package/dist/utils/production.js +294 -0
- package/dist/utils/production.js.map +1 -0
- package/dist/utils/rate-limiter.d.ts +77 -0
- package/dist/utils/rate-limiter.js +271 -0
- package/dist/utils/rate-limiter.js.map +1 -0
- package/dist/utils/webhook-security.d.ts +63 -0
- package/dist/utils/webhook-security.js +183 -0
- package/dist/utils/webhook-security.js.map +1 -0
- package/dist/voice/index.d.ts +125 -0
- package/dist/voice/index.js +557 -0
- package/dist/voice/index.js.map +1 -0
- package/dist/weather/edge.d.ts +70 -0
- package/dist/weather/edge.js +281 -0
- package/dist/weather/edge.js.map +1 -0
- package/dist/weather/index.d.ts +6 -0
- package/dist/weather/index.js +23 -0
- package/dist/weather/index.js.map +1 -0
- package/dist/weather/markets.d.ts +84 -0
- package/dist/weather/markets.js +320 -0
- package/dist/weather/markets.js.map +1 -0
- package/dist/weather/noaa.d.ts +113 -0
- package/dist/weather/noaa.js +287 -0
- package/dist/weather/noaa.js.map +1 -0
- package/dist/web/index.d.ts +112 -0
- package/dist/web/index.js +639 -0
- package/dist/web/index.js.map +1 -0
- package/dist/wizard/index.d.ts +27 -0
- package/dist/wizard/index.js +186 -0
- package/dist/wizard/index.js.map +1 -0
- package/dist/workspace/index.d.ts +73 -0
- package/dist/workspace/index.js +403 -0
- package/dist/workspace/index.js.map +1 -0
- package/package.json +168 -0
|
@@ -0,0 +1,4011 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Futures Trading Module
|
|
4
|
+
*
|
|
5
|
+
* Real perpetual futures trading with leverage across multiple exchanges:
|
|
6
|
+
* - Binance Futures (USDT-M perpetuals)
|
|
7
|
+
* - Bybit (USDT perpetuals)
|
|
8
|
+
* - Hyperliquid (decentralized, on Arbitrum)
|
|
9
|
+
*
|
|
10
|
+
* Features:
|
|
11
|
+
* - Custom strategy support with variable tracking
|
|
12
|
+
* - Database persistence for trade history & A/B testing
|
|
13
|
+
* - Strategy variants for performance comparison
|
|
14
|
+
* - Easy setup with config or environment variables
|
|
15
|
+
*/
|
|
16
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
17
|
+
if (k2 === undefined) k2 = k;
|
|
18
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
19
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
20
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
21
|
+
}
|
|
22
|
+
Object.defineProperty(o, k2, desc);
|
|
23
|
+
}) : (function(o, m, k, k2) {
|
|
24
|
+
if (k2 === undefined) k2 = k;
|
|
25
|
+
o[k2] = m[k];
|
|
26
|
+
}));
|
|
27
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
28
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
29
|
+
}) : function(o, v) {
|
|
30
|
+
o["default"] = v;
|
|
31
|
+
});
|
|
32
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
33
|
+
var ownKeys = function(o) {
|
|
34
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
35
|
+
var ar = [];
|
|
36
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
37
|
+
return ar;
|
|
38
|
+
};
|
|
39
|
+
return ownKeys(o);
|
|
40
|
+
};
|
|
41
|
+
return function (mod) {
|
|
42
|
+
if (mod && mod.__esModule) return mod;
|
|
43
|
+
var result = {};
|
|
44
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
45
|
+
__setModuleDefault(result, mod);
|
|
46
|
+
return result;
|
|
47
|
+
};
|
|
48
|
+
})();
|
|
49
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
50
|
+
exports.MexcFuturesClient = exports.HyperliquidClient = exports.BybitFuturesClient = exports.BinanceFuturesClient = exports.GridStrategy = exports.MeanReversionStrategy = exports.MomentumStrategy = exports.FuturesService = exports.StrategyEngine = exports.FuturesDatabase = void 0;
|
|
51
|
+
exports.createFuturesService = createFuturesService;
|
|
52
|
+
exports.setupFromEnv = setupFromEnv;
|
|
53
|
+
const events_1 = require("events");
|
|
54
|
+
const crypto_1 = require("crypto");
|
|
55
|
+
const secp = __importStar(require("@noble/secp256k1"));
|
|
56
|
+
const sha3_1 = require("@noble/hashes/sha3");
|
|
57
|
+
const logger_1 = require("../../utils/logger");
|
|
58
|
+
const pg_1 = require("pg");
|
|
59
|
+
// =============================================================================
|
|
60
|
+
// HELPERS
|
|
61
|
+
// =============================================================================
|
|
62
|
+
/** Safe parseFloat that returns fallback instead of NaN */
|
|
63
|
+
function safeFloat(value, fallback = 0) {
|
|
64
|
+
const n = parseFloat(String(value));
|
|
65
|
+
return isNaN(n) || !isFinite(n) ? fallback : n;
|
|
66
|
+
}
|
|
67
|
+
/** Fetch with retry for transient errors (429, 502, 503, 504) */
|
|
68
|
+
async function fetchWithRetry(url, init, maxRetries = 3) {
|
|
69
|
+
const retryableStatuses = new Set([429, 502, 503, 504]);
|
|
70
|
+
let lastError;
|
|
71
|
+
for (let attempt = 0; attempt <= maxRetries; attempt++) {
|
|
72
|
+
try {
|
|
73
|
+
const response = await fetch(url, init);
|
|
74
|
+
if (retryableStatuses.has(response.status) && attempt < maxRetries) {
|
|
75
|
+
const delay = Math.min(1000 * 2 ** attempt, 10_000);
|
|
76
|
+
await new Promise(r => setTimeout(r, delay));
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
return response;
|
|
80
|
+
}
|
|
81
|
+
catch (err) {
|
|
82
|
+
lastError = err;
|
|
83
|
+
// Retry on network errors, not on abort (timeout)
|
|
84
|
+
if (err.name === 'AbortError')
|
|
85
|
+
throw err;
|
|
86
|
+
if (attempt < maxRetries) {
|
|
87
|
+
const delay = Math.min(1000 * 2 ** attempt, 10_000);
|
|
88
|
+
await new Promise(r => setTimeout(r, delay));
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
throw lastError || new Error('Fetch failed after retries');
|
|
94
|
+
}
|
|
95
|
+
// =============================================================================
|
|
96
|
+
// CRYPTO UTILITIES (using @noble/secp256k1 - no elliptic dependency)
|
|
97
|
+
// =============================================================================
|
|
98
|
+
function keccak256(data) {
|
|
99
|
+
return Buffer.from((0, sha3_1.keccak_256)(data));
|
|
100
|
+
}
|
|
101
|
+
function signMessage(message, privateKey) {
|
|
102
|
+
const privKeyBytes = Buffer.from(privateKey.replace('0x', ''), 'hex');
|
|
103
|
+
const msgHash = keccak256(message);
|
|
104
|
+
// Use 'recovered' format to get signature with recovery bit (65 bytes: r + s + v)
|
|
105
|
+
const sigBytes = secp.sign(msgHash, privKeyBytes, { format: 'recovered', prehash: false });
|
|
106
|
+
return {
|
|
107
|
+
r: '0x' + Buffer.from(sigBytes.slice(0, 32)).toString('hex'),
|
|
108
|
+
s: '0x' + Buffer.from(sigBytes.slice(32, 64)).toString('hex'),
|
|
109
|
+
v: sigBytes[64] + 27,
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
// =============================================================================
|
|
113
|
+
// BINANCE FUTURES CLIENT
|
|
114
|
+
// =============================================================================
|
|
115
|
+
class BinanceFuturesClient {
|
|
116
|
+
apiKey;
|
|
117
|
+
apiSecret;
|
|
118
|
+
baseUrl;
|
|
119
|
+
dryRun;
|
|
120
|
+
constructor(credentials, dryRun = false) {
|
|
121
|
+
this.apiKey = credentials.apiKey;
|
|
122
|
+
this.apiSecret = credentials.apiSecret;
|
|
123
|
+
this.baseUrl = credentials.testnet
|
|
124
|
+
? 'https://testnet.binancefuture.com'
|
|
125
|
+
: 'https://fapi.binance.com';
|
|
126
|
+
this.dryRun = dryRun;
|
|
127
|
+
}
|
|
128
|
+
sign(params) {
|
|
129
|
+
const queryString = Object.entries(params)
|
|
130
|
+
.map(([k, v]) => `${k}=${v}`)
|
|
131
|
+
.join('&');
|
|
132
|
+
return (0, crypto_1.createHmac)('sha256', this.apiSecret).update(queryString).digest('hex');
|
|
133
|
+
}
|
|
134
|
+
async request(method, endpoint, params = {}, signed = false) {
|
|
135
|
+
const url = new URL(endpoint, this.baseUrl);
|
|
136
|
+
if (signed) {
|
|
137
|
+
params.timestamp = Date.now();
|
|
138
|
+
params.signature = this.sign(params);
|
|
139
|
+
}
|
|
140
|
+
if (method === 'GET') {
|
|
141
|
+
Object.entries(params).forEach(([k, v]) => url.searchParams.set(k, String(v)));
|
|
142
|
+
}
|
|
143
|
+
const response = await fetchWithRetry(url.toString(), {
|
|
144
|
+
method,
|
|
145
|
+
headers: {
|
|
146
|
+
'X-MBX-APIKEY': this.apiKey,
|
|
147
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
148
|
+
},
|
|
149
|
+
body: method !== 'GET' ? new URLSearchParams(params).toString() : undefined,
|
|
150
|
+
signal: AbortSignal.timeout(30_000),
|
|
151
|
+
});
|
|
152
|
+
if (!response.ok) {
|
|
153
|
+
const error = await response.json().catch(() => ({ msg: response.statusText }));
|
|
154
|
+
throw new Error(`Binance error: ${error.msg || response.statusText}`);
|
|
155
|
+
}
|
|
156
|
+
return response.json();
|
|
157
|
+
}
|
|
158
|
+
async getBalance() {
|
|
159
|
+
const data = await this.request('GET', '/fapi/v2/balance', {}, true);
|
|
160
|
+
const usdt = data.find(b => b.asset === 'USDT') || { availableBalance: '0', balance: '0', crossUnPnl: '0' };
|
|
161
|
+
return {
|
|
162
|
+
exchange: 'binance',
|
|
163
|
+
asset: 'USDT',
|
|
164
|
+
available: safeFloat(usdt.availableBalance),
|
|
165
|
+
total: safeFloat(usdt.balance),
|
|
166
|
+
unrealizedPnl: safeFloat(usdt.crossUnPnl),
|
|
167
|
+
marginBalance: safeFloat(usdt.balance) + safeFloat(usdt.crossUnPnl),
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
async getPositions() {
|
|
171
|
+
const data = await this.request('GET', '/fapi/v2/positionRisk', {}, true);
|
|
172
|
+
return data
|
|
173
|
+
.filter(p => safeFloat(p.positionAmt) !== 0)
|
|
174
|
+
.map(p => {
|
|
175
|
+
const size = safeFloat(p.positionAmt);
|
|
176
|
+
const entryPrice = safeFloat(p.entryPrice);
|
|
177
|
+
const markPrice = safeFloat(p.markPrice);
|
|
178
|
+
const pnl = safeFloat(p.unRealizedProfit);
|
|
179
|
+
const leverage = parseInt(p.leverage, 10) || 1;
|
|
180
|
+
const positionValue = Math.abs(size) * entryPrice;
|
|
181
|
+
return {
|
|
182
|
+
exchange: 'binance',
|
|
183
|
+
symbol: p.symbol,
|
|
184
|
+
side: (size > 0 ? 'LONG' : 'SHORT'),
|
|
185
|
+
size: Math.abs(size),
|
|
186
|
+
entryPrice,
|
|
187
|
+
markPrice,
|
|
188
|
+
liquidationPrice: safeFloat(p.liquidationPrice),
|
|
189
|
+
leverage,
|
|
190
|
+
marginType: p.marginType.toUpperCase(),
|
|
191
|
+
unrealizedPnl: pnl,
|
|
192
|
+
unrealizedPnlPct: positionValue > 0 ? (pnl / positionValue) * 100 : 0,
|
|
193
|
+
margin: safeFloat(p.isolatedMargin) || (leverage > 0 ? positionValue / leverage : 0),
|
|
194
|
+
timestamp: Date.now(),
|
|
195
|
+
};
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
async setLeverage(symbol, leverage) {
|
|
199
|
+
await this.request('POST', '/fapi/v1/leverage', { symbol, leverage }, true);
|
|
200
|
+
}
|
|
201
|
+
async setMarginType(symbol, marginType) {
|
|
202
|
+
try {
|
|
203
|
+
await this.request('POST', '/fapi/v1/marginType', { symbol, marginType }, true);
|
|
204
|
+
}
|
|
205
|
+
catch (err) {
|
|
206
|
+
const msg = err.message;
|
|
207
|
+
if (!msg.includes('No need to change'))
|
|
208
|
+
throw err;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
async placeOrder(order) {
|
|
212
|
+
if (this.dryRun) {
|
|
213
|
+
logger_1.logger.info({ order }, '[DRY RUN] Would place Binance futures order');
|
|
214
|
+
return this.createDryRunOrder(order);
|
|
215
|
+
}
|
|
216
|
+
if (order.leverage) {
|
|
217
|
+
await this.setLeverage(order.symbol, order.leverage);
|
|
218
|
+
}
|
|
219
|
+
const params = {
|
|
220
|
+
symbol: order.symbol,
|
|
221
|
+
side: order.side,
|
|
222
|
+
type: order.type,
|
|
223
|
+
quantity: order.size,
|
|
224
|
+
};
|
|
225
|
+
if (order.price && order.type === 'LIMIT') {
|
|
226
|
+
params.price = order.price;
|
|
227
|
+
params.timeInForce = 'GTC';
|
|
228
|
+
}
|
|
229
|
+
if (order.stopPrice) {
|
|
230
|
+
params.stopPrice = order.stopPrice;
|
|
231
|
+
}
|
|
232
|
+
if (order.reduceOnly) {
|
|
233
|
+
params.reduceOnly = 'true';
|
|
234
|
+
}
|
|
235
|
+
const result = await this.request('POST', '/fapi/v1/order', params, true);
|
|
236
|
+
const mainOrder = {
|
|
237
|
+
id: String(result.orderId),
|
|
238
|
+
exchange: 'binance',
|
|
239
|
+
symbol: result.symbol,
|
|
240
|
+
side: result.side,
|
|
241
|
+
type: result.type,
|
|
242
|
+
size: parseFloat(result.origQty),
|
|
243
|
+
leverage: order.leverage || 1,
|
|
244
|
+
reduceOnly: order.reduceOnly || false,
|
|
245
|
+
status: result.status,
|
|
246
|
+
filledSize: parseFloat(result.executedQty),
|
|
247
|
+
avgFillPrice: parseFloat(result.avgPrice),
|
|
248
|
+
timestamp: result.updateTime,
|
|
249
|
+
};
|
|
250
|
+
// Place TP/SL orders if specified — don't let failures lose the main order
|
|
251
|
+
try {
|
|
252
|
+
if (order.takeProfit) {
|
|
253
|
+
await this.request('POST', '/fapi/v1/order', {
|
|
254
|
+
symbol: order.symbol,
|
|
255
|
+
side: order.side === 'BUY' ? 'SELL' : 'BUY',
|
|
256
|
+
type: 'TAKE_PROFIT_MARKET',
|
|
257
|
+
stopPrice: order.takeProfit,
|
|
258
|
+
closePosition: 'true',
|
|
259
|
+
}, true);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
catch (err) {
|
|
263
|
+
logger_1.logger.error({ err, symbol: order.symbol, takeProfit: order.takeProfit }, 'Failed to place take-profit order (main order succeeded)');
|
|
264
|
+
}
|
|
265
|
+
try {
|
|
266
|
+
if (order.stopLoss) {
|
|
267
|
+
await this.request('POST', '/fapi/v1/order', {
|
|
268
|
+
symbol: order.symbol,
|
|
269
|
+
side: order.side === 'BUY' ? 'SELL' : 'BUY',
|
|
270
|
+
type: 'STOP_MARKET',
|
|
271
|
+
stopPrice: order.stopLoss,
|
|
272
|
+
closePosition: 'true',
|
|
273
|
+
}, true);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
catch (err) {
|
|
277
|
+
logger_1.logger.error({ err, symbol: order.symbol, stopLoss: order.stopLoss }, 'Failed to place stop-loss order (main order succeeded)');
|
|
278
|
+
}
|
|
279
|
+
return mainOrder;
|
|
280
|
+
}
|
|
281
|
+
createDryRunOrder(order) {
|
|
282
|
+
const isMarket = order.type === 'MARKET';
|
|
283
|
+
return {
|
|
284
|
+
id: `dry-${Date.now()}-${(0, crypto_1.randomBytes)(4).toString('hex')}`,
|
|
285
|
+
exchange: 'binance',
|
|
286
|
+
symbol: order.symbol,
|
|
287
|
+
side: order.side,
|
|
288
|
+
type: order.type,
|
|
289
|
+
size: order.size,
|
|
290
|
+
price: order.price,
|
|
291
|
+
leverage: order.leverage || 1,
|
|
292
|
+
reduceOnly: order.reduceOnly || false,
|
|
293
|
+
status: isMarket ? 'FILLED' : 'NEW',
|
|
294
|
+
filledSize: isMarket ? order.size : 0,
|
|
295
|
+
avgFillPrice: isMarket ? (order.price || 0) : 0,
|
|
296
|
+
timestamp: Date.now(),
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
async cancelOrder(symbol, orderId) {
|
|
300
|
+
await this.request('DELETE', '/fapi/v1/order', { symbol, orderId }, true);
|
|
301
|
+
}
|
|
302
|
+
async closePosition(symbol) {
|
|
303
|
+
const positions = await this.getPositions();
|
|
304
|
+
const position = positions.find(p => p.symbol === symbol);
|
|
305
|
+
if (!position)
|
|
306
|
+
return null;
|
|
307
|
+
return this.placeOrder({
|
|
308
|
+
symbol,
|
|
309
|
+
side: position.side === 'LONG' ? 'SELL' : 'BUY',
|
|
310
|
+
type: 'MARKET',
|
|
311
|
+
size: position.size,
|
|
312
|
+
reduceOnly: true,
|
|
313
|
+
});
|
|
314
|
+
}
|
|
315
|
+
async getMarkets() {
|
|
316
|
+
const [exchangeInfo, tickers, fundingRates] = await Promise.all([
|
|
317
|
+
this.request('GET', '/fapi/v1/exchangeInfo'),
|
|
318
|
+
this.request('GET', '/fapi/v1/ticker/24hr'),
|
|
319
|
+
this.request('GET', '/fapi/v1/premiumIndex'),
|
|
320
|
+
]);
|
|
321
|
+
const tickerMap = new Map(tickers.map(t => [t.symbol, t]));
|
|
322
|
+
const fundingMap = new Map(fundingRates.map(f => [f.symbol, f]));
|
|
323
|
+
return exchangeInfo.symbols
|
|
324
|
+
.filter(s => s.quoteAsset === 'USDT')
|
|
325
|
+
.map(s => {
|
|
326
|
+
const ticker = tickerMap.get(s.symbol);
|
|
327
|
+
const funding = fundingMap.get(s.symbol);
|
|
328
|
+
const priceFilter = s.filters.find(f => f.filterType === 'PRICE_FILTER');
|
|
329
|
+
const lotFilter = s.filters.find(f => f.filterType === 'LOT_SIZE');
|
|
330
|
+
const notionalFilter = s.filters.find(f => f.filterType === 'MIN_NOTIONAL');
|
|
331
|
+
return {
|
|
332
|
+
exchange: 'binance',
|
|
333
|
+
symbol: s.symbol,
|
|
334
|
+
baseAsset: s.baseAsset,
|
|
335
|
+
quoteAsset: s.quoteAsset,
|
|
336
|
+
tickSize: parseFloat(priceFilter?.tickSize || '0.01'),
|
|
337
|
+
lotSize: parseFloat(lotFilter?.stepSize || '0.001'),
|
|
338
|
+
minNotional: parseFloat(notionalFilter?.notional || '5'),
|
|
339
|
+
maxLeverage: 125,
|
|
340
|
+
fundingRate: parseFloat(funding?.lastFundingRate || '0') * 100,
|
|
341
|
+
markPrice: parseFloat(funding?.markPrice || ticker?.lastPrice || '0'),
|
|
342
|
+
indexPrice: parseFloat(funding?.indexPrice || '0'),
|
|
343
|
+
volume24h: parseFloat(ticker?.volume || '0'),
|
|
344
|
+
};
|
|
345
|
+
});
|
|
346
|
+
}
|
|
347
|
+
async getFundingRate(symbol) {
|
|
348
|
+
const data = await this.request('GET', '/fapi/v1/premiumIndex', { symbol });
|
|
349
|
+
return {
|
|
350
|
+
rate: parseFloat(data.lastFundingRate) * 100,
|
|
351
|
+
nextFundingTime: data.nextFundingTime,
|
|
352
|
+
};
|
|
353
|
+
}
|
|
354
|
+
async getOpenOrders(symbol) {
|
|
355
|
+
const params = {};
|
|
356
|
+
if (symbol)
|
|
357
|
+
params.symbol = symbol;
|
|
358
|
+
const data = await this.request('GET', '/fapi/v1/openOrders', params, true);
|
|
359
|
+
return data.map(o => ({
|
|
360
|
+
id: String(o.orderId),
|
|
361
|
+
exchange: 'binance',
|
|
362
|
+
symbol: o.symbol,
|
|
363
|
+
side: o.side,
|
|
364
|
+
type: o.type,
|
|
365
|
+
size: parseFloat(o.origQty),
|
|
366
|
+
price: parseFloat(o.price),
|
|
367
|
+
leverage: 1,
|
|
368
|
+
reduceOnly: false,
|
|
369
|
+
status: o.status,
|
|
370
|
+
filledSize: parseFloat(o.executedQty),
|
|
371
|
+
avgFillPrice: parseFloat(o.price),
|
|
372
|
+
timestamp: o.time,
|
|
373
|
+
}));
|
|
374
|
+
}
|
|
375
|
+
// =========== ADDITIONAL COMPREHENSIVE METHODS ===========
|
|
376
|
+
async getAccountInfo() {
|
|
377
|
+
const data = await this.request('GET', '/fapi/v2/account', {}, true);
|
|
378
|
+
const positions = data.positions
|
|
379
|
+
.filter(p => safeFloat(p.positionAmt) !== 0)
|
|
380
|
+
.map(p => {
|
|
381
|
+
const size = safeFloat(p.positionAmt);
|
|
382
|
+
const entryPrice = safeFloat(p.entryPrice);
|
|
383
|
+
const markPrice = safeFloat(p.markPrice);
|
|
384
|
+
const pnl = safeFloat(p.unRealizedProfit);
|
|
385
|
+
return {
|
|
386
|
+
exchange: 'binance',
|
|
387
|
+
symbol: p.symbol,
|
|
388
|
+
side: (size > 0 ? 'LONG' : 'SHORT'),
|
|
389
|
+
size: Math.abs(size),
|
|
390
|
+
entryPrice,
|
|
391
|
+
markPrice,
|
|
392
|
+
liquidationPrice: safeFloat(p.liquidationPrice),
|
|
393
|
+
leverage: parseInt(p.leverage, 10) || 1,
|
|
394
|
+
marginType: p.marginType.toUpperCase(),
|
|
395
|
+
unrealizedPnl: pnl,
|
|
396
|
+
unrealizedPnlPct: Math.abs(size) * entryPrice > 0 ? (pnl / (Math.abs(size) * entryPrice)) * 100 : 0,
|
|
397
|
+
margin: safeFloat(p.isolatedMargin),
|
|
398
|
+
timestamp: Date.now(),
|
|
399
|
+
};
|
|
400
|
+
});
|
|
401
|
+
return {
|
|
402
|
+
exchange: 'binance',
|
|
403
|
+
totalWalletBalance: safeFloat(data.totalWalletBalance),
|
|
404
|
+
totalUnrealizedProfit: safeFloat(data.totalUnrealizedProfit),
|
|
405
|
+
totalMarginBalance: safeFloat(data.totalMarginBalance),
|
|
406
|
+
totalPositionInitialMargin: safeFloat(data.totalPositionInitialMargin),
|
|
407
|
+
totalOpenOrderInitialMargin: safeFloat(data.totalOpenOrderInitialMargin),
|
|
408
|
+
availableBalance: safeFloat(data.availableBalance),
|
|
409
|
+
maxWithdrawAmount: safeFloat(data.maxWithdrawAmount),
|
|
410
|
+
canTrade: data.canTrade,
|
|
411
|
+
canDeposit: data.canDeposit,
|
|
412
|
+
canWithdraw: data.canWithdraw,
|
|
413
|
+
positions,
|
|
414
|
+
};
|
|
415
|
+
}
|
|
416
|
+
async getTradeHistory(symbol, limit = 500) {
|
|
417
|
+
const data = await this.request('GET', '/fapi/v1/userTrades', { symbol, limit }, true);
|
|
418
|
+
return data.map(t => ({
|
|
419
|
+
id: String(t.id),
|
|
420
|
+
exchange: 'binance',
|
|
421
|
+
symbol: t.symbol,
|
|
422
|
+
orderId: String(t.orderId),
|
|
423
|
+
side: t.side,
|
|
424
|
+
price: parseFloat(t.price),
|
|
425
|
+
quantity: parseFloat(t.qty),
|
|
426
|
+
realizedPnl: parseFloat(t.realizedPnl),
|
|
427
|
+
commission: parseFloat(t.commission),
|
|
428
|
+
commissionAsset: t.commissionAsset,
|
|
429
|
+
timestamp: t.time,
|
|
430
|
+
isMaker: t.maker,
|
|
431
|
+
}));
|
|
432
|
+
}
|
|
433
|
+
async getOrderHistory(symbol, limit = 500) {
|
|
434
|
+
const params = { limit };
|
|
435
|
+
if (symbol)
|
|
436
|
+
params.symbol = symbol;
|
|
437
|
+
const data = await this.request('GET', '/fapi/v1/allOrders', params, true);
|
|
438
|
+
return data.map(o => ({
|
|
439
|
+
id: String(o.orderId),
|
|
440
|
+
exchange: 'binance',
|
|
441
|
+
symbol: o.symbol,
|
|
442
|
+
side: o.side,
|
|
443
|
+
type: o.type,
|
|
444
|
+
size: parseFloat(o.origQty),
|
|
445
|
+
price: parseFloat(o.price),
|
|
446
|
+
leverage: 1,
|
|
447
|
+
reduceOnly: o.reduceOnly,
|
|
448
|
+
status: o.status,
|
|
449
|
+
filledSize: parseFloat(o.executedQty),
|
|
450
|
+
avgFillPrice: parseFloat(o.avgPrice),
|
|
451
|
+
timestamp: o.time,
|
|
452
|
+
}));
|
|
453
|
+
}
|
|
454
|
+
async getKlines(symbol, interval, limit = 500) {
|
|
455
|
+
const data = await this.request('GET', '/fapi/v1/klines', { symbol, interval, limit });
|
|
456
|
+
return data.map(k => ({
|
|
457
|
+
openTime: k[0],
|
|
458
|
+
open: parseFloat(k[1]),
|
|
459
|
+
high: parseFloat(k[2]),
|
|
460
|
+
low: parseFloat(k[3]),
|
|
461
|
+
close: parseFloat(k[4]),
|
|
462
|
+
volume: parseFloat(k[5]),
|
|
463
|
+
closeTime: k[6],
|
|
464
|
+
quoteVolume: parseFloat(k[7]),
|
|
465
|
+
trades: k[8],
|
|
466
|
+
takerBuyVolume: parseFloat(k[9]),
|
|
467
|
+
takerBuyQuoteVolume: parseFloat(k[10]),
|
|
468
|
+
}));
|
|
469
|
+
}
|
|
470
|
+
async getOrderBook(symbol, limit = 100) {
|
|
471
|
+
const data = await this.request('GET', '/fapi/v1/depth', { symbol, limit });
|
|
472
|
+
return {
|
|
473
|
+
exchange: 'binance',
|
|
474
|
+
symbol,
|
|
475
|
+
lastUpdateId: data.lastUpdateId,
|
|
476
|
+
bids: data.bids.map(([p, q]) => [parseFloat(p), parseFloat(q)]),
|
|
477
|
+
asks: data.asks.map(([p, q]) => [parseFloat(p), parseFloat(q)]),
|
|
478
|
+
timestamp: Date.now(),
|
|
479
|
+
};
|
|
480
|
+
}
|
|
481
|
+
async getIncomeHistory(symbol, incomeType, limit = 1000) {
|
|
482
|
+
const params = { limit };
|
|
483
|
+
if (symbol)
|
|
484
|
+
params.symbol = symbol;
|
|
485
|
+
if (incomeType)
|
|
486
|
+
params.incomeType = incomeType;
|
|
487
|
+
const data = await this.request('GET', '/fapi/v1/income', params, true);
|
|
488
|
+
return data.map(i => ({
|
|
489
|
+
symbol: i.symbol,
|
|
490
|
+
incomeType: i.incomeType,
|
|
491
|
+
income: parseFloat(i.income),
|
|
492
|
+
asset: i.asset,
|
|
493
|
+
timestamp: i.time,
|
|
494
|
+
tradeId: i.tradeId,
|
|
495
|
+
}));
|
|
496
|
+
}
|
|
497
|
+
async getLeverageBrackets(symbol) {
|
|
498
|
+
const params = {};
|
|
499
|
+
if (symbol)
|
|
500
|
+
params.symbol = symbol;
|
|
501
|
+
const data = await this.request('GET', '/fapi/v1/leverageBracket', params, true);
|
|
502
|
+
return data.map(lb => ({
|
|
503
|
+
symbol: lb.symbol,
|
|
504
|
+
brackets: lb.brackets,
|
|
505
|
+
}));
|
|
506
|
+
}
|
|
507
|
+
async getPositionMarginHistory(symbol, limit = 500) {
|
|
508
|
+
const data = await this.request('GET', '/fapi/v1/positionMargin/history', { symbol, limit }, true);
|
|
509
|
+
return data.map(h => ({
|
|
510
|
+
symbol: h.symbol,
|
|
511
|
+
type: h.type,
|
|
512
|
+
amount: parseFloat(h.deltaAmount),
|
|
513
|
+
asset: h.asset,
|
|
514
|
+
timestamp: h.time,
|
|
515
|
+
positionSide: h.positionSide,
|
|
516
|
+
}));
|
|
517
|
+
}
|
|
518
|
+
async modifyPositionMargin(symbol, amount, type) {
|
|
519
|
+
// type: 1 = add, 2 = reduce
|
|
520
|
+
await this.request('POST', '/fapi/v1/positionMargin', { symbol, amount, type }, true);
|
|
521
|
+
}
|
|
522
|
+
async placeBatchOrders(orders) {
|
|
523
|
+
if (this.dryRun) {
|
|
524
|
+
return orders.map(o => this.createDryRunOrder(o));
|
|
525
|
+
}
|
|
526
|
+
const batchOrders = orders.map(order => ({
|
|
527
|
+
symbol: order.symbol,
|
|
528
|
+
side: order.side,
|
|
529
|
+
type: order.type,
|
|
530
|
+
quantity: String(order.size),
|
|
531
|
+
price: order.price ? String(order.price) : undefined,
|
|
532
|
+
stopPrice: order.stopPrice ? String(order.stopPrice) : undefined,
|
|
533
|
+
reduceOnly: order.reduceOnly ? 'true' : undefined,
|
|
534
|
+
timeInForce: order.type === 'LIMIT' ? 'GTC' : undefined,
|
|
535
|
+
}));
|
|
536
|
+
const result = await this.request('POST', '/fapi/v1/batchOrders', {
|
|
537
|
+
batchOrders: JSON.stringify(batchOrders),
|
|
538
|
+
}, true);
|
|
539
|
+
return result.map((r, i) => ({
|
|
540
|
+
id: String(r.orderId),
|
|
541
|
+
exchange: 'binance',
|
|
542
|
+
symbol: r.symbol,
|
|
543
|
+
side: r.side,
|
|
544
|
+
type: r.type,
|
|
545
|
+
size: parseFloat(r.origQty),
|
|
546
|
+
leverage: orders[i].leverage || 1,
|
|
547
|
+
reduceOnly: orders[i].reduceOnly || false,
|
|
548
|
+
status: r.status,
|
|
549
|
+
filledSize: parseFloat(r.executedQty),
|
|
550
|
+
avgFillPrice: parseFloat(r.avgPrice),
|
|
551
|
+
timestamp: r.updateTime,
|
|
552
|
+
}));
|
|
553
|
+
}
|
|
554
|
+
async cancelAllOrders(symbol) {
|
|
555
|
+
await this.request('DELETE', '/fapi/v1/allOpenOrders', { symbol }, true);
|
|
556
|
+
}
|
|
557
|
+
async getTickerPrice(symbol) {
|
|
558
|
+
const params = {};
|
|
559
|
+
if (symbol)
|
|
560
|
+
params.symbol = symbol;
|
|
561
|
+
const data = await this.request('GET', '/fapi/v2/ticker/price', params);
|
|
562
|
+
const tickers = Array.isArray(data) ? data : [data];
|
|
563
|
+
return tickers.map(t => ({
|
|
564
|
+
symbol: t.symbol,
|
|
565
|
+
price: parseFloat(t.price),
|
|
566
|
+
timestamp: t.time,
|
|
567
|
+
}));
|
|
568
|
+
}
|
|
569
|
+
async getFundingHistory(symbol, limit = 100) {
|
|
570
|
+
const data = await this.request('GET', '/fapi/v1/fundingRate', { symbol, limit });
|
|
571
|
+
return data.map(f => ({
|
|
572
|
+
symbol: f.symbol,
|
|
573
|
+
fundingRate: parseFloat(f.fundingRate) * 100,
|
|
574
|
+
fundingTime: f.fundingTime,
|
|
575
|
+
markPrice: f.markPrice ? parseFloat(f.markPrice) : undefined,
|
|
576
|
+
}));
|
|
577
|
+
}
|
|
578
|
+
async setPositionMode(dualSidePosition) {
|
|
579
|
+
await this.request('POST', '/fapi/v1/positionSide/dual', { dualSidePosition: String(dualSidePosition) }, true);
|
|
580
|
+
}
|
|
581
|
+
async getPositionMode() {
|
|
582
|
+
const data = await this.request('GET', '/fapi/v1/positionSide/dual', {}, true);
|
|
583
|
+
return data.dualSidePosition;
|
|
584
|
+
}
|
|
585
|
+
async modifyOrder(symbol, orderId, quantity, price) {
|
|
586
|
+
const params = { symbol, orderId };
|
|
587
|
+
if (quantity)
|
|
588
|
+
params.quantity = quantity;
|
|
589
|
+
if (price)
|
|
590
|
+
params.price = price;
|
|
591
|
+
const result = await this.request('PUT', '/fapi/v1/order', params, true);
|
|
592
|
+
return {
|
|
593
|
+
id: String(result.orderId),
|
|
594
|
+
exchange: 'binance',
|
|
595
|
+
symbol: result.symbol,
|
|
596
|
+
side: result.side,
|
|
597
|
+
type: result.type,
|
|
598
|
+
size: parseFloat(result.origQty),
|
|
599
|
+
leverage: 1,
|
|
600
|
+
reduceOnly: false,
|
|
601
|
+
status: result.status,
|
|
602
|
+
filledSize: parseFloat(result.executedQty),
|
|
603
|
+
avgFillPrice: parseFloat(result.avgPrice),
|
|
604
|
+
timestamp: result.updateTime,
|
|
605
|
+
};
|
|
606
|
+
}
|
|
607
|
+
async getForceOrders(symbol, limit = 50) {
|
|
608
|
+
const params = { limit };
|
|
609
|
+
if (symbol)
|
|
610
|
+
params.symbol = symbol;
|
|
611
|
+
const data = await this.request('GET', '/fapi/v1/forceOrders', params, true);
|
|
612
|
+
return data.map(o => ({
|
|
613
|
+
orderId: String(o.orderId),
|
|
614
|
+
symbol: o.symbol,
|
|
615
|
+
side: o.side,
|
|
616
|
+
price: parseFloat(o.price),
|
|
617
|
+
quantity: parseFloat(o.origQty),
|
|
618
|
+
status: o.status,
|
|
619
|
+
timestamp: o.time,
|
|
620
|
+
}));
|
|
621
|
+
}
|
|
622
|
+
async getCommissionRate(symbol) {
|
|
623
|
+
const data = await this.request('GET', '/fapi/v1/commissionRate', { symbol }, true);
|
|
624
|
+
return {
|
|
625
|
+
symbol: data.symbol,
|
|
626
|
+
makerCommission: parseFloat(data.makerCommissionRate) * 100,
|
|
627
|
+
takerCommission: parseFloat(data.takerCommissionRate) * 100,
|
|
628
|
+
};
|
|
629
|
+
}
|
|
630
|
+
async createListenKey() {
|
|
631
|
+
const data = await this.request('POST', '/fapi/v1/listenKey', {}, true);
|
|
632
|
+
return data.listenKey;
|
|
633
|
+
}
|
|
634
|
+
async keepAliveListenKey() {
|
|
635
|
+
await this.request('PUT', '/fapi/v1/listenKey', {}, true);
|
|
636
|
+
}
|
|
637
|
+
async deleteListenKey() {
|
|
638
|
+
await this.request('DELETE', '/fapi/v1/listenKey', {}, true);
|
|
639
|
+
}
|
|
640
|
+
// =========== ADDITIONAL MARKET DATA & ANALYTICS ===========
|
|
641
|
+
async getServerTime() {
|
|
642
|
+
const data = await this.request('GET', '/fapi/v1/time');
|
|
643
|
+
return data.serverTime;
|
|
644
|
+
}
|
|
645
|
+
async ping() {
|
|
646
|
+
await this.request('GET', '/fapi/v1/ping');
|
|
647
|
+
return true;
|
|
648
|
+
}
|
|
649
|
+
async getExchangeInfo() {
|
|
650
|
+
return this.request('GET', '/fapi/v1/exchangeInfo');
|
|
651
|
+
}
|
|
652
|
+
async getRecentTrades(symbol, limit = 500) {
|
|
653
|
+
const data = await this.request('GET', '/fapi/v1/trades', { symbol, limit });
|
|
654
|
+
return data.map(t => ({
|
|
655
|
+
id: t.id,
|
|
656
|
+
price: parseFloat(t.price),
|
|
657
|
+
qty: parseFloat(t.qty),
|
|
658
|
+
quoteQty: parseFloat(t.quoteQty),
|
|
659
|
+
time: t.time,
|
|
660
|
+
isBuyerMaker: t.isBuyerMaker,
|
|
661
|
+
}));
|
|
662
|
+
}
|
|
663
|
+
async getAggTrades(symbol, limit = 500) {
|
|
664
|
+
const data = await this.request('GET', '/fapi/v1/aggTrades', { symbol, limit });
|
|
665
|
+
return data.map(t => ({
|
|
666
|
+
aggTradeId: t.a,
|
|
667
|
+
price: parseFloat(t.p),
|
|
668
|
+
quantity: parseFloat(t.q),
|
|
669
|
+
firstTradeId: t.f,
|
|
670
|
+
lastTradeId: t.l,
|
|
671
|
+
timestamp: t.T,
|
|
672
|
+
isBuyerMaker: t.m,
|
|
673
|
+
}));
|
|
674
|
+
}
|
|
675
|
+
async getContinuousKlines(pair, contractType, interval, limit = 500) {
|
|
676
|
+
const data = await this.request('GET', '/fapi/v1/continuousKlines', { pair, contractType, interval, limit });
|
|
677
|
+
return data.map(k => ({
|
|
678
|
+
openTime: k[0],
|
|
679
|
+
open: parseFloat(k[1]),
|
|
680
|
+
high: parseFloat(k[2]),
|
|
681
|
+
low: parseFloat(k[3]),
|
|
682
|
+
close: parseFloat(k[4]),
|
|
683
|
+
volume: parseFloat(k[5]),
|
|
684
|
+
closeTime: k[6],
|
|
685
|
+
quoteVolume: parseFloat(k[7]),
|
|
686
|
+
trades: k[8],
|
|
687
|
+
takerBuyVolume: parseFloat(k[9]),
|
|
688
|
+
takerBuyQuoteVolume: parseFloat(k[10]),
|
|
689
|
+
}));
|
|
690
|
+
}
|
|
691
|
+
async getIndexPriceKlines(pair, interval, limit = 500) {
|
|
692
|
+
const data = await this.request('GET', '/fapi/v1/indexPriceKlines', { pair, interval, limit });
|
|
693
|
+
return data.map(k => ({
|
|
694
|
+
openTime: k[0],
|
|
695
|
+
open: parseFloat(k[1]),
|
|
696
|
+
high: parseFloat(k[2]),
|
|
697
|
+
low: parseFloat(k[3]),
|
|
698
|
+
close: parseFloat(k[4]),
|
|
699
|
+
volume: 0,
|
|
700
|
+
closeTime: k[6],
|
|
701
|
+
quoteVolume: 0,
|
|
702
|
+
trades: 0,
|
|
703
|
+
takerBuyVolume: 0,
|
|
704
|
+
takerBuyQuoteVolume: 0,
|
|
705
|
+
}));
|
|
706
|
+
}
|
|
707
|
+
async getMarkPriceKlines(symbol, interval, limit = 500) {
|
|
708
|
+
const data = await this.request('GET', '/fapi/v1/markPriceKlines', { symbol, interval, limit });
|
|
709
|
+
return data.map(k => ({
|
|
710
|
+
openTime: k[0],
|
|
711
|
+
open: parseFloat(k[1]),
|
|
712
|
+
high: parseFloat(k[2]),
|
|
713
|
+
low: parseFloat(k[3]),
|
|
714
|
+
close: parseFloat(k[4]),
|
|
715
|
+
volume: 0,
|
|
716
|
+
closeTime: k[6],
|
|
717
|
+
quoteVolume: 0,
|
|
718
|
+
trades: 0,
|
|
719
|
+
takerBuyVolume: 0,
|
|
720
|
+
takerBuyQuoteVolume: 0,
|
|
721
|
+
}));
|
|
722
|
+
}
|
|
723
|
+
async get24hrTicker(symbol) {
|
|
724
|
+
const params = {};
|
|
725
|
+
if (symbol)
|
|
726
|
+
params.symbol = symbol;
|
|
727
|
+
const data = await this.request('GET', '/fapi/v1/ticker/24hr', params);
|
|
728
|
+
const tickers = Array.isArray(data) ? data : [data];
|
|
729
|
+
return tickers.map(t => ({
|
|
730
|
+
symbol: t.symbol,
|
|
731
|
+
priceChange: parseFloat(t.priceChange),
|
|
732
|
+
priceChangePercent: parseFloat(t.priceChangePercent),
|
|
733
|
+
weightedAvgPrice: parseFloat(t.weightedAvgPrice),
|
|
734
|
+
lastPrice: parseFloat(t.lastPrice),
|
|
735
|
+
lastQty: parseFloat(t.lastQty),
|
|
736
|
+
openPrice: parseFloat(t.openPrice),
|
|
737
|
+
highPrice: parseFloat(t.highPrice),
|
|
738
|
+
lowPrice: parseFloat(t.lowPrice),
|
|
739
|
+
volume: parseFloat(t.volume),
|
|
740
|
+
quoteVolume: parseFloat(t.quoteVolume),
|
|
741
|
+
openTime: t.openTime,
|
|
742
|
+
closeTime: t.closeTime,
|
|
743
|
+
count: t.count,
|
|
744
|
+
}));
|
|
745
|
+
}
|
|
746
|
+
async getBookTicker(symbol) {
|
|
747
|
+
const params = {};
|
|
748
|
+
if (symbol)
|
|
749
|
+
params.symbol = symbol;
|
|
750
|
+
const data = await this.request('GET', '/fapi/v1/ticker/bookTicker', params);
|
|
751
|
+
const tickers = Array.isArray(data) ? data : [data];
|
|
752
|
+
return tickers.map(t => ({
|
|
753
|
+
symbol: t.symbol,
|
|
754
|
+
bidPrice: parseFloat(t.bidPrice),
|
|
755
|
+
bidQty: parseFloat(t.bidQty),
|
|
756
|
+
askPrice: parseFloat(t.askPrice),
|
|
757
|
+
askQty: parseFloat(t.askQty),
|
|
758
|
+
time: t.time,
|
|
759
|
+
}));
|
|
760
|
+
}
|
|
761
|
+
async getOpenInterest(symbol) {
|
|
762
|
+
const data = await this.request('GET', '/fapi/v1/openInterest', { symbol });
|
|
763
|
+
return {
|
|
764
|
+
symbol: data.symbol,
|
|
765
|
+
openInterest: parseFloat(data.openInterest),
|
|
766
|
+
time: data.time,
|
|
767
|
+
};
|
|
768
|
+
}
|
|
769
|
+
async getOpenInterestHistory(symbol, period, limit = 30) {
|
|
770
|
+
const data = await this.request('GET', '/futures/data/openInterestHist', { symbol, period, limit });
|
|
771
|
+
return data.map(d => ({
|
|
772
|
+
symbol: d.symbol,
|
|
773
|
+
sumOpenInterest: parseFloat(d.sumOpenInterest),
|
|
774
|
+
sumOpenInterestValue: parseFloat(d.sumOpenInterestValue),
|
|
775
|
+
timestamp: d.timestamp,
|
|
776
|
+
}));
|
|
777
|
+
}
|
|
778
|
+
async getTopTraderLongShortRatio(symbol, period, limit = 30) {
|
|
779
|
+
const data = await this.request('GET', '/futures/data/topLongShortAccountRatio', { symbol, period, limit });
|
|
780
|
+
return data.map(d => ({
|
|
781
|
+
symbol: d.symbol,
|
|
782
|
+
longShortRatio: parseFloat(d.longShortRatio),
|
|
783
|
+
longAccount: parseFloat(d.longAccount),
|
|
784
|
+
shortAccount: parseFloat(d.shortAccount),
|
|
785
|
+
timestamp: d.timestamp,
|
|
786
|
+
}));
|
|
787
|
+
}
|
|
788
|
+
async getGlobalLongShortRatio(symbol, period, limit = 30) {
|
|
789
|
+
const data = await this.request('GET', '/futures/data/globalLongShortAccountRatio', { symbol, period, limit });
|
|
790
|
+
return data.map(d => ({
|
|
791
|
+
symbol: d.symbol,
|
|
792
|
+
longShortRatio: parseFloat(d.longShortRatio),
|
|
793
|
+
longAccount: parseFloat(d.longAccount),
|
|
794
|
+
shortAccount: parseFloat(d.shortAccount),
|
|
795
|
+
timestamp: d.timestamp,
|
|
796
|
+
}));
|
|
797
|
+
}
|
|
798
|
+
async getTakerBuySellVolume(symbol, period, limit = 30) {
|
|
799
|
+
const data = await this.request('GET', '/futures/data/takerlongshortRatio', { symbol, period, limit });
|
|
800
|
+
return data.map(d => ({
|
|
801
|
+
buySellRatio: parseFloat(d.buySellRatio),
|
|
802
|
+
buyVol: parseFloat(d.buyVol),
|
|
803
|
+
sellVol: parseFloat(d.sellVol),
|
|
804
|
+
timestamp: d.timestamp,
|
|
805
|
+
}));
|
|
806
|
+
}
|
|
807
|
+
async getFundingInfo() {
|
|
808
|
+
const data = await this.request('GET', '/fapi/v1/fundingInfo');
|
|
809
|
+
return data.map(f => ({
|
|
810
|
+
symbol: f.symbol,
|
|
811
|
+
adjustedFundingRateCap: parseFloat(f.adjustedFundingRateCap),
|
|
812
|
+
adjustedFundingRateFloor: parseFloat(f.adjustedFundingRateFloor),
|
|
813
|
+
fundingIntervalHours: f.fundingIntervalHours,
|
|
814
|
+
}));
|
|
815
|
+
}
|
|
816
|
+
async getADLQuantile(symbol) {
|
|
817
|
+
const params = {};
|
|
818
|
+
if (symbol)
|
|
819
|
+
params.symbol = symbol;
|
|
820
|
+
const data = await this.request('GET', '/fapi/v1/adlQuantile', params, true);
|
|
821
|
+
return data;
|
|
822
|
+
}
|
|
823
|
+
async setMultiAssetsMode(multiAssetsMargin) {
|
|
824
|
+
await this.request('POST', '/fapi/v1/multiAssetsMargin', { multiAssetsMargin: String(multiAssetsMargin) }, true);
|
|
825
|
+
}
|
|
826
|
+
async getMultiAssetsMode() {
|
|
827
|
+
const data = await this.request('GET', '/fapi/v1/multiAssetsMargin', {}, true);
|
|
828
|
+
return data.multiAssetsMargin;
|
|
829
|
+
}
|
|
830
|
+
async testOrder(order) {
|
|
831
|
+
const params = {
|
|
832
|
+
symbol: order.symbol,
|
|
833
|
+
side: order.side,
|
|
834
|
+
type: order.type,
|
|
835
|
+
quantity: order.size,
|
|
836
|
+
};
|
|
837
|
+
if (order.price)
|
|
838
|
+
params.price = order.price;
|
|
839
|
+
if (order.stopPrice)
|
|
840
|
+
params.stopPrice = order.stopPrice;
|
|
841
|
+
await this.request('POST', '/fapi/v1/order/test', params, true);
|
|
842
|
+
}
|
|
843
|
+
async setAutoCancel(symbol, countdownTime) {
|
|
844
|
+
const data = await this.request('POST', '/fapi/v1/countdownCancelAll', { symbol, countdownTime }, true);
|
|
845
|
+
return { symbol: data.symbol, countdownTime: parseInt(data.countdownTime) };
|
|
846
|
+
}
|
|
847
|
+
async getOrderModifyHistory(symbol, orderId, limit = 50) {
|
|
848
|
+
const params = { symbol, limit };
|
|
849
|
+
if (orderId)
|
|
850
|
+
params.orderId = orderId;
|
|
851
|
+
const data = await this.request('GET', '/fapi/v1/orderAmendment', params, true);
|
|
852
|
+
return data.map(d => ({
|
|
853
|
+
symbol: d.symbol,
|
|
854
|
+
orderId: d.orderId,
|
|
855
|
+
amendmentId: d.amendmentId,
|
|
856
|
+
time: d.time,
|
|
857
|
+
amendment: {
|
|
858
|
+
price: { before: parseFloat(d.amendment.price.before), after: parseFloat(d.amendment.price.after) },
|
|
859
|
+
origQty: { before: parseFloat(d.amendment.origQty.before), after: parseFloat(d.amendment.origQty.after) },
|
|
860
|
+
},
|
|
861
|
+
}));
|
|
862
|
+
}
|
|
863
|
+
async getSymbolConfig(symbol) {
|
|
864
|
+
const params = {};
|
|
865
|
+
if (symbol)
|
|
866
|
+
params.symbol = symbol;
|
|
867
|
+
const data = await this.request('GET', '/fapi/v1/symbolConfig', params, true);
|
|
868
|
+
return data.map(c => ({
|
|
869
|
+
symbol: c.symbol,
|
|
870
|
+
marginType: c.marginType,
|
|
871
|
+
isAutoAddMargin: c.isAutoAddMargin,
|
|
872
|
+
leverage: c.leverage,
|
|
873
|
+
maxNotionalValue: parseFloat(c.maxNotionalValue),
|
|
874
|
+
}));
|
|
875
|
+
}
|
|
876
|
+
async getOrderRateLimit() {
|
|
877
|
+
return this.request('GET', '/fapi/v1/rateLimit/order', {}, true);
|
|
878
|
+
}
|
|
879
|
+
}
|
|
880
|
+
exports.BinanceFuturesClient = BinanceFuturesClient;
|
|
881
|
+
// =============================================================================
|
|
882
|
+
// BYBIT FUTURES CLIENT
|
|
883
|
+
// =============================================================================
|
|
884
|
+
class BybitFuturesClient {
|
|
885
|
+
apiKey;
|
|
886
|
+
apiSecret;
|
|
887
|
+
baseUrl;
|
|
888
|
+
dryRun;
|
|
889
|
+
recvWindow = 5000;
|
|
890
|
+
constructor(credentials, dryRun = false) {
|
|
891
|
+
this.apiKey = credentials.apiKey;
|
|
892
|
+
this.apiSecret = credentials.apiSecret;
|
|
893
|
+
this.baseUrl = credentials.testnet
|
|
894
|
+
? 'https://api-testnet.bybit.com'
|
|
895
|
+
: 'https://api.bybit.com';
|
|
896
|
+
this.dryRun = dryRun;
|
|
897
|
+
}
|
|
898
|
+
sign(timestamp, params) {
|
|
899
|
+
const payload = `${timestamp}${this.apiKey}${this.recvWindow}${params}`;
|
|
900
|
+
return (0, crypto_1.createHmac)('sha256', this.apiSecret).update(payload).digest('hex');
|
|
901
|
+
}
|
|
902
|
+
async request(method, endpoint, params = {}) {
|
|
903
|
+
const timestamp = Date.now();
|
|
904
|
+
let queryString = '';
|
|
905
|
+
let body = '';
|
|
906
|
+
if (method === 'GET') {
|
|
907
|
+
queryString = Object.entries(params)
|
|
908
|
+
.sort(([a], [b]) => a.localeCompare(b))
|
|
909
|
+
.map(([k, v]) => `${k}=${v}`)
|
|
910
|
+
.join('&');
|
|
911
|
+
}
|
|
912
|
+
else {
|
|
913
|
+
body = JSON.stringify(params);
|
|
914
|
+
}
|
|
915
|
+
const signature = this.sign(timestamp, method === 'GET' ? queryString : body);
|
|
916
|
+
const url = new URL(endpoint, this.baseUrl);
|
|
917
|
+
if (method === 'GET' && queryString) {
|
|
918
|
+
url.search = queryString;
|
|
919
|
+
}
|
|
920
|
+
const response = await fetchWithRetry(url.toString(), {
|
|
921
|
+
method,
|
|
922
|
+
headers: {
|
|
923
|
+
'X-BAPI-API-KEY': this.apiKey,
|
|
924
|
+
'X-BAPI-SIGN': signature,
|
|
925
|
+
'X-BAPI-TIMESTAMP': String(timestamp),
|
|
926
|
+
'X-BAPI-RECV-WINDOW': String(this.recvWindow),
|
|
927
|
+
'Content-Type': 'application/json',
|
|
928
|
+
},
|
|
929
|
+
body: method === 'POST' ? body : undefined,
|
|
930
|
+
signal: AbortSignal.timeout(30_000),
|
|
931
|
+
});
|
|
932
|
+
const data = await response.json();
|
|
933
|
+
if (data.retCode !== 0) {
|
|
934
|
+
throw new Error(`Bybit error: ${data.retMsg}`);
|
|
935
|
+
}
|
|
936
|
+
return data.result;
|
|
937
|
+
}
|
|
938
|
+
async getBalance() {
|
|
939
|
+
const data = await this.request('GET', '/v5/account/wallet-balance', {
|
|
940
|
+
accountType: 'UNIFIED',
|
|
941
|
+
});
|
|
942
|
+
const account = data.list[0];
|
|
943
|
+
const usdt = account?.coin?.find(c => c.coin === 'USDT') || {
|
|
944
|
+
availableToWithdraw: '0',
|
|
945
|
+
walletBalance: '0',
|
|
946
|
+
unrealisedPnl: '0',
|
|
947
|
+
};
|
|
948
|
+
return {
|
|
949
|
+
exchange: 'bybit',
|
|
950
|
+
asset: 'USDT',
|
|
951
|
+
available: safeFloat(usdt.availableToWithdraw),
|
|
952
|
+
total: safeFloat(usdt.walletBalance),
|
|
953
|
+
unrealizedPnl: safeFloat(usdt.unrealisedPnl),
|
|
954
|
+
marginBalance: safeFloat(usdt.walletBalance),
|
|
955
|
+
};
|
|
956
|
+
}
|
|
957
|
+
async getPositions() {
|
|
958
|
+
const data = await this.request('GET', '/v5/position/list', {
|
|
959
|
+
category: 'linear',
|
|
960
|
+
settleCoin: 'USDT',
|
|
961
|
+
});
|
|
962
|
+
return data.list
|
|
963
|
+
.filter(p => safeFloat(p.size) > 0)
|
|
964
|
+
.map(p => {
|
|
965
|
+
const size = safeFloat(p.size);
|
|
966
|
+
const entryPrice = safeFloat(p.avgPrice);
|
|
967
|
+
const markPrice = safeFloat(p.markPrice);
|
|
968
|
+
const pnl = safeFloat(p.unrealisedPnl);
|
|
969
|
+
const positionValue = size * entryPrice;
|
|
970
|
+
return {
|
|
971
|
+
exchange: 'bybit',
|
|
972
|
+
symbol: p.symbol,
|
|
973
|
+
side: (p.side === 'Buy' ? 'LONG' : 'SHORT'),
|
|
974
|
+
size,
|
|
975
|
+
entryPrice,
|
|
976
|
+
markPrice,
|
|
977
|
+
liquidationPrice: safeFloat(p.liqPrice),
|
|
978
|
+
leverage: parseInt(p.leverage, 10) || 1,
|
|
979
|
+
marginType: (p.tradeMode === 0 ? 'CROSS' : 'ISOLATED'),
|
|
980
|
+
unrealizedPnl: pnl,
|
|
981
|
+
unrealizedPnlPct: positionValue > 0 ? (pnl / positionValue) * 100 : 0,
|
|
982
|
+
margin: safeFloat(p.positionIM),
|
|
983
|
+
timestamp: Date.now(),
|
|
984
|
+
};
|
|
985
|
+
});
|
|
986
|
+
}
|
|
987
|
+
async setLeverage(symbol, leverage) {
|
|
988
|
+
try {
|
|
989
|
+
await this.request('POST', '/v5/position/set-leverage', {
|
|
990
|
+
category: 'linear',
|
|
991
|
+
symbol,
|
|
992
|
+
buyLeverage: String(leverage),
|
|
993
|
+
sellLeverage: String(leverage),
|
|
994
|
+
});
|
|
995
|
+
}
|
|
996
|
+
catch (err) {
|
|
997
|
+
const msg = err.message;
|
|
998
|
+
if (!msg.includes('leverage not modified'))
|
|
999
|
+
throw err;
|
|
1000
|
+
}
|
|
1001
|
+
}
|
|
1002
|
+
async placeOrder(order) {
|
|
1003
|
+
if (this.dryRun) {
|
|
1004
|
+
logger_1.logger.info({ order }, '[DRY RUN] Would place Bybit futures order');
|
|
1005
|
+
return this.createDryRunOrder(order);
|
|
1006
|
+
}
|
|
1007
|
+
if (order.leverage) {
|
|
1008
|
+
await this.setLeverage(order.symbol, order.leverage);
|
|
1009
|
+
}
|
|
1010
|
+
const isStopOrder = order.type === 'STOP_MARKET' || order.type === 'TAKE_PROFIT_MARKET';
|
|
1011
|
+
const params = {
|
|
1012
|
+
category: 'linear',
|
|
1013
|
+
symbol: order.symbol,
|
|
1014
|
+
side: order.side === 'BUY' ? 'Buy' : 'Sell',
|
|
1015
|
+
orderType: (order.type === 'MARKET' || isStopOrder) ? 'Market' : 'Limit',
|
|
1016
|
+
qty: String(order.size),
|
|
1017
|
+
};
|
|
1018
|
+
if (order.price && order.type === 'LIMIT') {
|
|
1019
|
+
params.price = String(order.price);
|
|
1020
|
+
}
|
|
1021
|
+
if (order.reduceOnly || isStopOrder) {
|
|
1022
|
+
params.reduceOnly = true;
|
|
1023
|
+
}
|
|
1024
|
+
// Set trigger price for stop/TP orders
|
|
1025
|
+
if (isStopOrder && order.stopPrice) {
|
|
1026
|
+
params.triggerPrice = String(order.stopPrice);
|
|
1027
|
+
params.triggerBy = 'MarkPrice';
|
|
1028
|
+
}
|
|
1029
|
+
if (order.takeProfit) {
|
|
1030
|
+
params.takeProfit = String(order.takeProfit);
|
|
1031
|
+
}
|
|
1032
|
+
if (order.stopLoss) {
|
|
1033
|
+
params.stopLoss = String(order.stopLoss);
|
|
1034
|
+
}
|
|
1035
|
+
const result = await this.request('POST', '/v5/order/create', params);
|
|
1036
|
+
return {
|
|
1037
|
+
id: result.orderId,
|
|
1038
|
+
exchange: 'bybit',
|
|
1039
|
+
symbol: order.symbol,
|
|
1040
|
+
side: order.side,
|
|
1041
|
+
type: order.type,
|
|
1042
|
+
size: order.size,
|
|
1043
|
+
price: order.price,
|
|
1044
|
+
stopPrice: order.stopPrice,
|
|
1045
|
+
leverage: order.leverage || 1,
|
|
1046
|
+
reduceOnly: order.reduceOnly || isStopOrder,
|
|
1047
|
+
status: 'NEW',
|
|
1048
|
+
filledSize: 0,
|
|
1049
|
+
avgFillPrice: 0,
|
|
1050
|
+
timestamp: Date.now(),
|
|
1051
|
+
};
|
|
1052
|
+
}
|
|
1053
|
+
createDryRunOrder(order) {
|
|
1054
|
+
const isMarket = order.type === 'MARKET';
|
|
1055
|
+
return {
|
|
1056
|
+
id: `dry-${Date.now()}-${(0, crypto_1.randomBytes)(4).toString('hex')}`,
|
|
1057
|
+
exchange: 'bybit',
|
|
1058
|
+
symbol: order.symbol,
|
|
1059
|
+
side: order.side,
|
|
1060
|
+
type: order.type,
|
|
1061
|
+
size: order.size,
|
|
1062
|
+
price: order.price,
|
|
1063
|
+
leverage: order.leverage || 1,
|
|
1064
|
+
reduceOnly: order.reduceOnly || false,
|
|
1065
|
+
status: isMarket ? 'FILLED' : 'NEW',
|
|
1066
|
+
filledSize: isMarket ? order.size : 0,
|
|
1067
|
+
avgFillPrice: isMarket ? (order.price || 0) : 0,
|
|
1068
|
+
timestamp: Date.now(),
|
|
1069
|
+
};
|
|
1070
|
+
}
|
|
1071
|
+
async cancelOrder(symbol, orderId) {
|
|
1072
|
+
await this.request('POST', '/v5/order/cancel', {
|
|
1073
|
+
category: 'linear',
|
|
1074
|
+
symbol,
|
|
1075
|
+
orderId,
|
|
1076
|
+
});
|
|
1077
|
+
}
|
|
1078
|
+
async closePosition(symbol) {
|
|
1079
|
+
const positions = await this.getPositions();
|
|
1080
|
+
const position = positions.find(p => p.symbol === symbol);
|
|
1081
|
+
if (!position)
|
|
1082
|
+
return null;
|
|
1083
|
+
return this.placeOrder({
|
|
1084
|
+
symbol,
|
|
1085
|
+
side: position.side === 'LONG' ? 'SELL' : 'BUY',
|
|
1086
|
+
type: 'MARKET',
|
|
1087
|
+
size: position.size,
|
|
1088
|
+
reduceOnly: true,
|
|
1089
|
+
});
|
|
1090
|
+
}
|
|
1091
|
+
async getMarkets() {
|
|
1092
|
+
const [instruments, tickers] = await Promise.all([
|
|
1093
|
+
this.request('GET', '/v5/market/instruments-info', { category: 'linear' }),
|
|
1094
|
+
this.request('GET', '/v5/market/tickers', { category: 'linear' }),
|
|
1095
|
+
]);
|
|
1096
|
+
const tickerMap = new Map(tickers.list.map(t => [t.symbol, t]));
|
|
1097
|
+
return instruments.list
|
|
1098
|
+
.filter(i => i.quoteCoin === 'USDT')
|
|
1099
|
+
.map(i => {
|
|
1100
|
+
const ticker = tickerMap.get(i.symbol);
|
|
1101
|
+
return {
|
|
1102
|
+
exchange: 'bybit',
|
|
1103
|
+
symbol: i.symbol,
|
|
1104
|
+
baseAsset: i.baseCoin,
|
|
1105
|
+
quoteAsset: i.quoteCoin,
|
|
1106
|
+
tickSize: parseFloat(i.priceFilter.tickSize),
|
|
1107
|
+
lotSize: parseFloat(i.lotSizeFilter.qtyStep),
|
|
1108
|
+
minNotional: parseFloat(i.lotSizeFilter.minOrderQty),
|
|
1109
|
+
maxLeverage: parseInt(i.leverageFilter.maxLeverage),
|
|
1110
|
+
fundingRate: parseFloat(ticker?.fundingRate || '0') * 100,
|
|
1111
|
+
markPrice: parseFloat(ticker?.markPrice || '0'),
|
|
1112
|
+
indexPrice: parseFloat(ticker?.indexPrice || '0'),
|
|
1113
|
+
volume24h: parseFloat(ticker?.volume24h || '0'),
|
|
1114
|
+
};
|
|
1115
|
+
});
|
|
1116
|
+
}
|
|
1117
|
+
async getFundingRate(symbol) {
|
|
1118
|
+
const data = await this.request('GET', '/v5/market/tickers', {
|
|
1119
|
+
category: 'linear',
|
|
1120
|
+
symbol,
|
|
1121
|
+
});
|
|
1122
|
+
const ticker = data.list[0];
|
|
1123
|
+
return {
|
|
1124
|
+
rate: parseFloat(ticker?.fundingRate || '0') * 100,
|
|
1125
|
+
nextFundingTime: parseInt(ticker?.nextFundingTime || '0'),
|
|
1126
|
+
};
|
|
1127
|
+
}
|
|
1128
|
+
async getOpenOrders(symbol) {
|
|
1129
|
+
const params = { category: 'linear' };
|
|
1130
|
+
if (symbol)
|
|
1131
|
+
params.symbol = symbol;
|
|
1132
|
+
const data = await this.request('GET', '/v5/order/realtime', params);
|
|
1133
|
+
return data.list.map(o => ({
|
|
1134
|
+
id: o.orderId,
|
|
1135
|
+
exchange: 'bybit',
|
|
1136
|
+
symbol: o.symbol,
|
|
1137
|
+
side: (o.side === 'Buy' ? 'BUY' : 'SELL'),
|
|
1138
|
+
type: (o.orderType === 'Market' ? 'MARKET' : 'LIMIT'),
|
|
1139
|
+
size: parseFloat(o.qty),
|
|
1140
|
+
price: parseFloat(o.price),
|
|
1141
|
+
leverage: 1,
|
|
1142
|
+
reduceOnly: false,
|
|
1143
|
+
status: this.mapBybitStatus(o.orderStatus),
|
|
1144
|
+
filledSize: parseFloat(o.cumExecQty),
|
|
1145
|
+
avgFillPrice: parseFloat(o.price),
|
|
1146
|
+
timestamp: parseInt(o.createdTime),
|
|
1147
|
+
}));
|
|
1148
|
+
}
|
|
1149
|
+
mapBybitStatus(status) {
|
|
1150
|
+
const statusMap = {
|
|
1151
|
+
'New': 'NEW',
|
|
1152
|
+
'PartiallyFilled': 'PARTIALLY_FILLED',
|
|
1153
|
+
'Filled': 'FILLED',
|
|
1154
|
+
'Cancelled': 'CANCELED',
|
|
1155
|
+
'Rejected': 'REJECTED',
|
|
1156
|
+
};
|
|
1157
|
+
return statusMap[status] || 'NEW';
|
|
1158
|
+
}
|
|
1159
|
+
// =========== ADDITIONAL COMPREHENSIVE METHODS ===========
|
|
1160
|
+
async getAccountInfo() {
|
|
1161
|
+
const data = await this.request('GET', '/v5/account/wallet-balance', { accountType: 'UNIFIED' });
|
|
1162
|
+
const account = data.list[0];
|
|
1163
|
+
const positions = await this.getPositions();
|
|
1164
|
+
return {
|
|
1165
|
+
exchange: 'bybit',
|
|
1166
|
+
totalWalletBalance: safeFloat(account?.totalWalletBalance || '0'),
|
|
1167
|
+
totalUnrealizedProfit: safeFloat(account?.totalPerpUPL || '0'),
|
|
1168
|
+
totalMarginBalance: safeFloat(account?.totalMarginBalance || '0'),
|
|
1169
|
+
totalPositionInitialMargin: safeFloat(account?.totalInitialMargin || '0'),
|
|
1170
|
+
totalOpenOrderInitialMargin: 0,
|
|
1171
|
+
availableBalance: safeFloat(account?.totalAvailableBalance || '0'),
|
|
1172
|
+
maxWithdrawAmount: safeFloat(account?.totalAvailableBalance || '0'),
|
|
1173
|
+
canTrade: true,
|
|
1174
|
+
canDeposit: true,
|
|
1175
|
+
canWithdraw: true,
|
|
1176
|
+
positions,
|
|
1177
|
+
};
|
|
1178
|
+
}
|
|
1179
|
+
async getTradeHistory(symbol, limit = 100) {
|
|
1180
|
+
const params = { category: 'linear', limit };
|
|
1181
|
+
if (symbol)
|
|
1182
|
+
params.symbol = symbol;
|
|
1183
|
+
const data = await this.request('GET', '/v5/execution/list', params);
|
|
1184
|
+
return data.list.map(t => ({
|
|
1185
|
+
id: t.execId,
|
|
1186
|
+
exchange: 'bybit',
|
|
1187
|
+
symbol: t.symbol,
|
|
1188
|
+
orderId: t.orderId,
|
|
1189
|
+
side: (t.side === 'Buy' ? 'BUY' : 'SELL'),
|
|
1190
|
+
price: parseFloat(t.execPrice),
|
|
1191
|
+
quantity: parseFloat(t.execQty),
|
|
1192
|
+
realizedPnl: parseFloat(t.closedPnl),
|
|
1193
|
+
commission: parseFloat(t.execFee),
|
|
1194
|
+
commissionAsset: t.feeCurrency,
|
|
1195
|
+
timestamp: parseInt(t.execTime),
|
|
1196
|
+
isMaker: t.isMaker,
|
|
1197
|
+
}));
|
|
1198
|
+
}
|
|
1199
|
+
async getOrderHistory(symbol, limit = 50) {
|
|
1200
|
+
const params = { category: 'linear', limit };
|
|
1201
|
+
if (symbol)
|
|
1202
|
+
params.symbol = symbol;
|
|
1203
|
+
const data = await this.request('GET', '/v5/order/history', params);
|
|
1204
|
+
return data.list.map(o => ({
|
|
1205
|
+
id: o.orderId,
|
|
1206
|
+
exchange: 'bybit',
|
|
1207
|
+
symbol: o.symbol,
|
|
1208
|
+
side: (o.side === 'Buy' ? 'BUY' : 'SELL'),
|
|
1209
|
+
type: (o.orderType === 'Market' ? 'MARKET' : 'LIMIT'),
|
|
1210
|
+
size: parseFloat(o.qty),
|
|
1211
|
+
price: parseFloat(o.price),
|
|
1212
|
+
leverage: 1,
|
|
1213
|
+
reduceOnly: o.reduceOnly,
|
|
1214
|
+
status: this.mapBybitStatus(o.orderStatus),
|
|
1215
|
+
filledSize: parseFloat(o.cumExecQty),
|
|
1216
|
+
avgFillPrice: parseFloat(o.avgPrice),
|
|
1217
|
+
timestamp: parseInt(o.createdTime),
|
|
1218
|
+
}));
|
|
1219
|
+
}
|
|
1220
|
+
async getKlines(symbol, interval, limit = 200) {
|
|
1221
|
+
const data = await this.request('GET', '/v5/market/kline', {
|
|
1222
|
+
category: 'linear',
|
|
1223
|
+
symbol,
|
|
1224
|
+
interval,
|
|
1225
|
+
limit,
|
|
1226
|
+
});
|
|
1227
|
+
return data.list.map(k => ({
|
|
1228
|
+
openTime: parseInt(k[0]),
|
|
1229
|
+
open: parseFloat(k[1]),
|
|
1230
|
+
high: parseFloat(k[2]),
|
|
1231
|
+
low: parseFloat(k[3]),
|
|
1232
|
+
close: parseFloat(k[4]),
|
|
1233
|
+
volume: parseFloat(k[5]),
|
|
1234
|
+
closeTime: parseInt(k[0]) + 60000,
|
|
1235
|
+
quoteVolume: parseFloat(k[6]),
|
|
1236
|
+
trades: 0,
|
|
1237
|
+
takerBuyVolume: 0,
|
|
1238
|
+
takerBuyQuoteVolume: 0,
|
|
1239
|
+
}));
|
|
1240
|
+
}
|
|
1241
|
+
async getOrderBook(symbol, limit = 50) {
|
|
1242
|
+
const data = await this.request('GET', '/v5/market/orderbook', {
|
|
1243
|
+
category: 'linear',
|
|
1244
|
+
symbol,
|
|
1245
|
+
limit,
|
|
1246
|
+
});
|
|
1247
|
+
return {
|
|
1248
|
+
exchange: 'bybit',
|
|
1249
|
+
symbol,
|
|
1250
|
+
lastUpdateId: data.u,
|
|
1251
|
+
bids: data.b.map(([p, q]) => [parseFloat(p), parseFloat(q)]),
|
|
1252
|
+
asks: data.a.map(([p, q]) => [parseFloat(p), parseFloat(q)]),
|
|
1253
|
+
timestamp: data.ts,
|
|
1254
|
+
};
|
|
1255
|
+
}
|
|
1256
|
+
async getIncomeHistory(symbol, limit = 100) {
|
|
1257
|
+
const params = { category: 'linear', limit };
|
|
1258
|
+
if (symbol)
|
|
1259
|
+
params.symbol = symbol;
|
|
1260
|
+
const data = await this.request('GET', '/v5/position/closed-pnl', params);
|
|
1261
|
+
return data.list.map(i => ({
|
|
1262
|
+
symbol: i.symbol,
|
|
1263
|
+
incomeType: 'REALIZED_PNL',
|
|
1264
|
+
income: parseFloat(i.closedPnl),
|
|
1265
|
+
asset: 'USDT',
|
|
1266
|
+
timestamp: parseInt(i.updatedTime),
|
|
1267
|
+
tradeId: i.orderId,
|
|
1268
|
+
}));
|
|
1269
|
+
}
|
|
1270
|
+
async getRiskLimit(symbol) {
|
|
1271
|
+
const data = await this.request('GET', '/v5/market/risk-limit', {
|
|
1272
|
+
category: 'linear',
|
|
1273
|
+
symbol,
|
|
1274
|
+
});
|
|
1275
|
+
return data.list.map(r => ({
|
|
1276
|
+
symbol: r.symbol,
|
|
1277
|
+
maxLeverage: parseInt(r.maxLeverage),
|
|
1278
|
+
maintenanceMarginRate: parseFloat(r.maintainMargin),
|
|
1279
|
+
riskLimitValue: parseFloat(r.riskLimitValue),
|
|
1280
|
+
}));
|
|
1281
|
+
}
|
|
1282
|
+
async setRiskLimit(symbol, riskId) {
|
|
1283
|
+
await this.request('POST', '/v5/position/set-risk-limit', {
|
|
1284
|
+
category: 'linear',
|
|
1285
|
+
symbol,
|
|
1286
|
+
riskId,
|
|
1287
|
+
});
|
|
1288
|
+
}
|
|
1289
|
+
async amendOrder(symbol, orderId, qty, price) {
|
|
1290
|
+
const params = { category: 'linear', symbol, orderId };
|
|
1291
|
+
if (qty)
|
|
1292
|
+
params.qty = String(qty);
|
|
1293
|
+
if (price)
|
|
1294
|
+
params.price = String(price);
|
|
1295
|
+
const result = await this.request('POST', '/v5/order/amend', params);
|
|
1296
|
+
return {
|
|
1297
|
+
id: result.orderId,
|
|
1298
|
+
exchange: 'bybit',
|
|
1299
|
+
symbol,
|
|
1300
|
+
side: 'BUY',
|
|
1301
|
+
type: 'LIMIT',
|
|
1302
|
+
size: qty || 0,
|
|
1303
|
+
price,
|
|
1304
|
+
leverage: 1,
|
|
1305
|
+
reduceOnly: false,
|
|
1306
|
+
status: 'NEW',
|
|
1307
|
+
filledSize: 0,
|
|
1308
|
+
avgFillPrice: 0,
|
|
1309
|
+
timestamp: Date.now(),
|
|
1310
|
+
};
|
|
1311
|
+
}
|
|
1312
|
+
async cancelAllOrders(symbol) {
|
|
1313
|
+
const params = { category: 'linear' };
|
|
1314
|
+
if (symbol)
|
|
1315
|
+
params.symbol = symbol;
|
|
1316
|
+
await this.request('POST', '/v5/order/cancel-all', params);
|
|
1317
|
+
}
|
|
1318
|
+
async placeBatchOrders(orders) {
|
|
1319
|
+
if (this.dryRun) {
|
|
1320
|
+
return orders.map(o => this.createDryRunOrder(o));
|
|
1321
|
+
}
|
|
1322
|
+
const request = orders.map(order => ({
|
|
1323
|
+
symbol: order.symbol,
|
|
1324
|
+
side: order.side === 'BUY' ? 'Buy' : 'Sell',
|
|
1325
|
+
orderType: order.type === 'MARKET' ? 'Market' : 'Limit',
|
|
1326
|
+
qty: String(order.size),
|
|
1327
|
+
price: order.price ? String(order.price) : undefined,
|
|
1328
|
+
reduceOnly: order.reduceOnly,
|
|
1329
|
+
}));
|
|
1330
|
+
const result = await this.request('POST', '/v5/order/create-batch', {
|
|
1331
|
+
category: 'linear',
|
|
1332
|
+
request,
|
|
1333
|
+
});
|
|
1334
|
+
return result.list.map((r, i) => ({
|
|
1335
|
+
id: r.orderId,
|
|
1336
|
+
exchange: 'bybit',
|
|
1337
|
+
symbol: r.symbol,
|
|
1338
|
+
side: orders[i].side,
|
|
1339
|
+
type: orders[i].type,
|
|
1340
|
+
size: orders[i].size,
|
|
1341
|
+
price: orders[i].price,
|
|
1342
|
+
leverage: orders[i].leverage || 1,
|
|
1343
|
+
reduceOnly: orders[i].reduceOnly || false,
|
|
1344
|
+
status: 'NEW',
|
|
1345
|
+
filledSize: 0,
|
|
1346
|
+
avgFillPrice: 0,
|
|
1347
|
+
timestamp: Date.now(),
|
|
1348
|
+
}));
|
|
1349
|
+
}
|
|
1350
|
+
async getTickerPrice(symbol) {
|
|
1351
|
+
const params = { category: 'linear' };
|
|
1352
|
+
if (symbol)
|
|
1353
|
+
params.symbol = symbol;
|
|
1354
|
+
const data = await this.request('GET', '/v5/market/tickers', params);
|
|
1355
|
+
return data.list.map(t => ({
|
|
1356
|
+
symbol: t.symbol,
|
|
1357
|
+
price: parseFloat(t.lastPrice),
|
|
1358
|
+
timestamp: Date.now(),
|
|
1359
|
+
}));
|
|
1360
|
+
}
|
|
1361
|
+
async getFundingHistory(symbol, limit = 100) {
|
|
1362
|
+
const data = await this.request('GET', '/v5/market/funding/history', {
|
|
1363
|
+
category: 'linear',
|
|
1364
|
+
symbol,
|
|
1365
|
+
limit,
|
|
1366
|
+
});
|
|
1367
|
+
return data.list.map(f => ({
|
|
1368
|
+
symbol: f.symbol,
|
|
1369
|
+
fundingRate: parseFloat(f.fundingRate) * 100,
|
|
1370
|
+
fundingTime: parseInt(f.fundingRateTimestamp),
|
|
1371
|
+
}));
|
|
1372
|
+
}
|
|
1373
|
+
async setPositionMode(mode) {
|
|
1374
|
+
await this.request('POST', '/v5/position/switch-mode', {
|
|
1375
|
+
category: 'linear',
|
|
1376
|
+
mode,
|
|
1377
|
+
});
|
|
1378
|
+
}
|
|
1379
|
+
async setIsolatedMargin(symbol, tradeMode, leverage) {
|
|
1380
|
+
// 0 = cross, 1 = isolated
|
|
1381
|
+
const lev = String(leverage || 10);
|
|
1382
|
+
await this.request('POST', '/v5/position/switch-isolated', {
|
|
1383
|
+
category: 'linear',
|
|
1384
|
+
symbol,
|
|
1385
|
+
tradeMode,
|
|
1386
|
+
buyLeverage: lev,
|
|
1387
|
+
sellLeverage: lev,
|
|
1388
|
+
});
|
|
1389
|
+
}
|
|
1390
|
+
async modifyPositionMargin(symbol, margin) {
|
|
1391
|
+
await this.request('POST', '/v5/position/add-margin', {
|
|
1392
|
+
category: 'linear',
|
|
1393
|
+
symbol,
|
|
1394
|
+
margin: String(margin),
|
|
1395
|
+
});
|
|
1396
|
+
}
|
|
1397
|
+
async getRecentTrades(symbol, limit = 60) {
|
|
1398
|
+
const data = await this.request('GET', '/v5/market/recent-trade', {
|
|
1399
|
+
category: 'linear',
|
|
1400
|
+
symbol,
|
|
1401
|
+
limit,
|
|
1402
|
+
});
|
|
1403
|
+
return data.list.map(t => ({
|
|
1404
|
+
price: parseFloat(t.price),
|
|
1405
|
+
size: parseFloat(t.size),
|
|
1406
|
+
side: t.side,
|
|
1407
|
+
timestamp: parseInt(t.time),
|
|
1408
|
+
}));
|
|
1409
|
+
}
|
|
1410
|
+
async getServerTime() {
|
|
1411
|
+
const data = await this.request('GET', '/v5/market/time', {});
|
|
1412
|
+
return parseInt(data.timeSecond) * 1000;
|
|
1413
|
+
}
|
|
1414
|
+
// =========== ADDITIONAL BYBIT METHODS ===========
|
|
1415
|
+
async batchAmendOrders(orders) {
|
|
1416
|
+
const request = orders.map(o => ({
|
|
1417
|
+
symbol: o.symbol,
|
|
1418
|
+
orderId: o.orderId,
|
|
1419
|
+
qty: o.qty ? String(o.qty) : undefined,
|
|
1420
|
+
price: o.price ? String(o.price) : undefined,
|
|
1421
|
+
}));
|
|
1422
|
+
const result = await this.request('POST', '/v5/order/amend-batch', { category: 'linear', request });
|
|
1423
|
+
return result.list.map(r => ({ orderId: r.orderId, success: r.code === '0' }));
|
|
1424
|
+
}
|
|
1425
|
+
async batchCancelOrders(orders) {
|
|
1426
|
+
const request = orders.map(o => ({ symbol: o.symbol, orderId: o.orderId }));
|
|
1427
|
+
const result = await this.request('POST', '/v5/order/cancel-batch', { category: 'linear', request });
|
|
1428
|
+
return result.list.map(r => ({ orderId: r.orderId, success: r.code === '0' }));
|
|
1429
|
+
}
|
|
1430
|
+
async setDisconnectProtection(expiryTime) {
|
|
1431
|
+
// DCP: Disconnect Cancel Protection - auto-cancel orders if disconnected
|
|
1432
|
+
await this.request('POST', '/v5/order/disconnected-cancel-all', {
|
|
1433
|
+
timeWindow: expiryTime,
|
|
1434
|
+
});
|
|
1435
|
+
}
|
|
1436
|
+
async getSpotBorrowQuota(symbol, side) {
|
|
1437
|
+
const data = await this.request('GET', '/v5/order/spot-borrow-check', {
|
|
1438
|
+
category: 'spot',
|
|
1439
|
+
symbol,
|
|
1440
|
+
side,
|
|
1441
|
+
});
|
|
1442
|
+
return {
|
|
1443
|
+
symbol: data.symbol,
|
|
1444
|
+
maxTradeQty: parseFloat(data.maxTradeQty),
|
|
1445
|
+
side: data.side,
|
|
1446
|
+
borrowCoin: data.borrowCoin,
|
|
1447
|
+
};
|
|
1448
|
+
}
|
|
1449
|
+
async getOpenInterest(symbol, interval, limit = 50) {
|
|
1450
|
+
const data = await this.request('GET', '/v5/market/open-interest', {
|
|
1451
|
+
category: 'linear',
|
|
1452
|
+
symbol,
|
|
1453
|
+
intervalTime: interval,
|
|
1454
|
+
limit,
|
|
1455
|
+
});
|
|
1456
|
+
return data.list.map(d => ({
|
|
1457
|
+
openInterest: parseFloat(d.openInterest),
|
|
1458
|
+
timestamp: parseInt(d.timestamp),
|
|
1459
|
+
}));
|
|
1460
|
+
}
|
|
1461
|
+
async getLongShortRatio(symbol, period, limit = 50) {
|
|
1462
|
+
const data = await this.request('GET', '/v5/market/account-ratio', {
|
|
1463
|
+
category: 'linear',
|
|
1464
|
+
symbol,
|
|
1465
|
+
period,
|
|
1466
|
+
limit,
|
|
1467
|
+
});
|
|
1468
|
+
return data.list.map(d => ({
|
|
1469
|
+
buyRatio: parseFloat(d.buyRatio),
|
|
1470
|
+
sellRatio: parseFloat(d.sellRatio),
|
|
1471
|
+
timestamp: parseInt(d.timestamp),
|
|
1472
|
+
}));
|
|
1473
|
+
}
|
|
1474
|
+
async getInsurance(coin) {
|
|
1475
|
+
const params = {};
|
|
1476
|
+
if (coin)
|
|
1477
|
+
params.coin = coin;
|
|
1478
|
+
const data = await this.request('GET', '/v5/market/insurance', params);
|
|
1479
|
+
return data.list.map(d => ({
|
|
1480
|
+
coin: d.coin,
|
|
1481
|
+
balance: parseFloat(d.balance),
|
|
1482
|
+
value: parseFloat(d.value),
|
|
1483
|
+
}));
|
|
1484
|
+
}
|
|
1485
|
+
async getVolatility(category, baseCoin, period) {
|
|
1486
|
+
const params = { category };
|
|
1487
|
+
if (baseCoin)
|
|
1488
|
+
params.baseCoin = baseCoin;
|
|
1489
|
+
if (period)
|
|
1490
|
+
params.period = period;
|
|
1491
|
+
const data = await this.request('GET', '/v5/market/historical-volatility', params);
|
|
1492
|
+
return data.map(d => ({
|
|
1493
|
+
period: d.period,
|
|
1494
|
+
value: parseFloat(d.value),
|
|
1495
|
+
time: parseInt(d.time),
|
|
1496
|
+
}));
|
|
1497
|
+
}
|
|
1498
|
+
async getDeliveryPrice(symbol, limit = 50) {
|
|
1499
|
+
const data = await this.request('GET', '/v5/market/delivery-price', {
|
|
1500
|
+
category: 'linear',
|
|
1501
|
+
symbol,
|
|
1502
|
+
limit,
|
|
1503
|
+
});
|
|
1504
|
+
return data.list.map(d => ({
|
|
1505
|
+
symbol: d.symbol,
|
|
1506
|
+
deliveryPrice: parseFloat(d.deliveryPrice),
|
|
1507
|
+
deliveryTime: parseInt(d.deliveryTime),
|
|
1508
|
+
}));
|
|
1509
|
+
}
|
|
1510
|
+
async getPreListingInfo(symbol) {
|
|
1511
|
+
const params = { category: 'linear' };
|
|
1512
|
+
if (symbol)
|
|
1513
|
+
params.symbol = symbol;
|
|
1514
|
+
const data = await this.request('GET', '/v5/market/prelisting-info', params);
|
|
1515
|
+
return data.list.map(d => ({
|
|
1516
|
+
symbol: d.symbol,
|
|
1517
|
+
auctionPhaseType: d.auctionPhaseType,
|
|
1518
|
+
auctionFeeInfo: {
|
|
1519
|
+
auctionFeeRate: parseFloat(d.auctionFeeInfo.auctionFeeRate),
|
|
1520
|
+
takerFeeRate: parseFloat(d.auctionFeeInfo.takerFeeRate),
|
|
1521
|
+
makerFeeRate: parseFloat(d.auctionFeeInfo.makerFeeRate),
|
|
1522
|
+
},
|
|
1523
|
+
}));
|
|
1524
|
+
}
|
|
1525
|
+
async setTradingStop(symbol, takeProfit, stopLoss, trailingStop, positionIdx) {
|
|
1526
|
+
const params = { category: 'linear', symbol };
|
|
1527
|
+
if (takeProfit !== undefined)
|
|
1528
|
+
params.takeProfit = String(takeProfit);
|
|
1529
|
+
if (stopLoss !== undefined)
|
|
1530
|
+
params.stopLoss = String(stopLoss);
|
|
1531
|
+
if (trailingStop !== undefined)
|
|
1532
|
+
params.trailingStop = String(trailingStop);
|
|
1533
|
+
if (positionIdx !== undefined)
|
|
1534
|
+
params.positionIdx = positionIdx;
|
|
1535
|
+
await this.request('POST', '/v5/position/trading-stop', params);
|
|
1536
|
+
}
|
|
1537
|
+
async getClosedPnL(symbol, limit = 50) {
|
|
1538
|
+
const params = { category: 'linear', limit };
|
|
1539
|
+
if (symbol)
|
|
1540
|
+
params.symbol = symbol;
|
|
1541
|
+
const data = await this.request('GET', '/v5/position/closed-pnl', params);
|
|
1542
|
+
return data.list.map(d => ({
|
|
1543
|
+
symbol: d.symbol,
|
|
1544
|
+
orderId: d.orderId,
|
|
1545
|
+
side: d.side,
|
|
1546
|
+
qty: parseFloat(d.qty),
|
|
1547
|
+
orderPrice: parseFloat(d.orderPrice),
|
|
1548
|
+
closedPnl: parseFloat(d.closedPnl),
|
|
1549
|
+
createdTime: parseInt(d.createdTime),
|
|
1550
|
+
}));
|
|
1551
|
+
}
|
|
1552
|
+
async movePosition(fromUid, toUid, symbol, side, price, qty) {
|
|
1553
|
+
const data = await this.request('POST', '/v5/position/move-positions', {
|
|
1554
|
+
category: 'linear',
|
|
1555
|
+
fromUid,
|
|
1556
|
+
toUid,
|
|
1557
|
+
list: [{ symbol, side, price: String(price), qty: String(qty) }],
|
|
1558
|
+
});
|
|
1559
|
+
return data.list[0];
|
|
1560
|
+
}
|
|
1561
|
+
async confirmNewRiskLimit(symbol) {
|
|
1562
|
+
await this.request('POST', '/v5/position/confirm-pending-mmr', {
|
|
1563
|
+
category: 'linear',
|
|
1564
|
+
symbol,
|
|
1565
|
+
});
|
|
1566
|
+
}
|
|
1567
|
+
async getFeeRate(symbol) {
|
|
1568
|
+
const params = { category: 'linear' };
|
|
1569
|
+
if (symbol)
|
|
1570
|
+
params.symbol = symbol;
|
|
1571
|
+
const data = await this.request('GET', '/v5/account/fee-rate', params);
|
|
1572
|
+
return data.list.map(d => ({
|
|
1573
|
+
symbol: d.symbol,
|
|
1574
|
+
takerFeeRate: parseFloat(d.takerFeeRate),
|
|
1575
|
+
makerFeeRate: parseFloat(d.makerFeeRate),
|
|
1576
|
+
}));
|
|
1577
|
+
}
|
|
1578
|
+
async getAccountInfo2() {
|
|
1579
|
+
const data = await this.request('GET', '/v5/account/info', {});
|
|
1580
|
+
return data;
|
|
1581
|
+
}
|
|
1582
|
+
async getTransactionLog(accountType, category, currency, limit) {
|
|
1583
|
+
const params = {};
|
|
1584
|
+
if (accountType)
|
|
1585
|
+
params.accountType = accountType;
|
|
1586
|
+
if (category)
|
|
1587
|
+
params.category = category;
|
|
1588
|
+
if (currency)
|
|
1589
|
+
params.currency = currency;
|
|
1590
|
+
if (limit)
|
|
1591
|
+
params.limit = limit;
|
|
1592
|
+
const data = await this.request('GET', '/v5/account/transaction-log', params);
|
|
1593
|
+
return data.list.map(d => ({
|
|
1594
|
+
symbol: d.symbol,
|
|
1595
|
+
side: d.side,
|
|
1596
|
+
funding: parseFloat(d.funding),
|
|
1597
|
+
orderLinkId: d.orderLinkId,
|
|
1598
|
+
orderId: d.orderId,
|
|
1599
|
+
fee: parseFloat(d.fee),
|
|
1600
|
+
change: parseFloat(d.change),
|
|
1601
|
+
cashFlow: parseFloat(d.cashFlow),
|
|
1602
|
+
transactionTime: parseInt(d.transactionTime),
|
|
1603
|
+
type: d.type,
|
|
1604
|
+
}));
|
|
1605
|
+
}
|
|
1606
|
+
}
|
|
1607
|
+
exports.BybitFuturesClient = BybitFuturesClient;
|
|
1608
|
+
// =============================================================================
|
|
1609
|
+
// HYPERLIQUID CLIENT (Decentralized on Arbitrum)
|
|
1610
|
+
// =============================================================================
|
|
1611
|
+
class HyperliquidClient {
|
|
1612
|
+
walletAddress;
|
|
1613
|
+
privateKey;
|
|
1614
|
+
baseUrl = 'https://api.hyperliquid.xyz';
|
|
1615
|
+
dryRun;
|
|
1616
|
+
assetIndexMap = new Map();
|
|
1617
|
+
constructor(credentials, dryRun = false) {
|
|
1618
|
+
this.walletAddress = credentials.apiKey;
|
|
1619
|
+
this.privateKey = credentials.apiSecret;
|
|
1620
|
+
this.dryRun = dryRun;
|
|
1621
|
+
}
|
|
1622
|
+
async request(endpoint, body) {
|
|
1623
|
+
const response = await fetchWithRetry(`${this.baseUrl}${endpoint}`, {
|
|
1624
|
+
method: body ? 'POST' : 'GET',
|
|
1625
|
+
headers: { 'Content-Type': 'application/json' },
|
|
1626
|
+
body: body ? JSON.stringify(body) : undefined,
|
|
1627
|
+
signal: AbortSignal.timeout(30_000),
|
|
1628
|
+
});
|
|
1629
|
+
if (!response.ok) {
|
|
1630
|
+
const text = await response.text();
|
|
1631
|
+
throw new Error(`Hyperliquid error: ${response.status} ${text}`);
|
|
1632
|
+
}
|
|
1633
|
+
return response.json();
|
|
1634
|
+
}
|
|
1635
|
+
async ensureAssetIndex() {
|
|
1636
|
+
if (this.assetIndexMap.size > 0)
|
|
1637
|
+
return;
|
|
1638
|
+
const meta = await this.request('/info', { type: 'meta' });
|
|
1639
|
+
meta.universe.forEach((asset, index) => {
|
|
1640
|
+
this.assetIndexMap.set(asset.name, index);
|
|
1641
|
+
});
|
|
1642
|
+
}
|
|
1643
|
+
getAssetIndex(symbol) {
|
|
1644
|
+
const index = this.assetIndexMap.get(symbol);
|
|
1645
|
+
if (index === undefined) {
|
|
1646
|
+
throw new Error(`Unknown asset: ${symbol}`);
|
|
1647
|
+
}
|
|
1648
|
+
return index;
|
|
1649
|
+
}
|
|
1650
|
+
signL1Action(action, nonce) {
|
|
1651
|
+
// Create the message hash
|
|
1652
|
+
const actionHash = keccak256(Buffer.from(JSON.stringify(action)));
|
|
1653
|
+
const nonceBuffer = Buffer.alloc(8);
|
|
1654
|
+
nonceBuffer.writeBigUInt64BE(BigInt(nonce));
|
|
1655
|
+
const message = Buffer.concat([
|
|
1656
|
+
actionHash,
|
|
1657
|
+
nonceBuffer,
|
|
1658
|
+
]);
|
|
1659
|
+
return signMessage(message, this.privateKey);
|
|
1660
|
+
}
|
|
1661
|
+
async getBalance() {
|
|
1662
|
+
const data = await this.request('/info', {
|
|
1663
|
+
type: 'clearinghouseState',
|
|
1664
|
+
user: this.walletAddress,
|
|
1665
|
+
});
|
|
1666
|
+
const margin = data.marginSummary;
|
|
1667
|
+
const total = safeFloat(margin.accountValue);
|
|
1668
|
+
const used = safeFloat(margin.totalMarginUsed);
|
|
1669
|
+
return {
|
|
1670
|
+
exchange: 'hyperliquid',
|
|
1671
|
+
asset: 'USDC',
|
|
1672
|
+
available: total - used,
|
|
1673
|
+
total,
|
|
1674
|
+
unrealizedPnl: 0,
|
|
1675
|
+
marginBalance: total,
|
|
1676
|
+
};
|
|
1677
|
+
}
|
|
1678
|
+
async getPositions() {
|
|
1679
|
+
const data = await this.request('/info', {
|
|
1680
|
+
type: 'clearinghouseState',
|
|
1681
|
+
user: this.walletAddress,
|
|
1682
|
+
});
|
|
1683
|
+
const allMids = await this.request('/info', { type: 'allMids' });
|
|
1684
|
+
return data.assetPositions
|
|
1685
|
+
.filter(ap => safeFloat(ap.position.szi) !== 0)
|
|
1686
|
+
.map(ap => {
|
|
1687
|
+
const p = ap.position;
|
|
1688
|
+
const size = safeFloat(p.szi);
|
|
1689
|
+
const entryPrice = safeFloat(p.entryPx);
|
|
1690
|
+
const markPrice = safeFloat(allMids[p.coin] || p.entryPx);
|
|
1691
|
+
const pnl = safeFloat(p.unrealizedPnl);
|
|
1692
|
+
const positionValue = Math.abs(size) * entryPrice;
|
|
1693
|
+
return {
|
|
1694
|
+
exchange: 'hyperliquid',
|
|
1695
|
+
symbol: p.coin,
|
|
1696
|
+
side: (size > 0 ? 'LONG' : 'SHORT'),
|
|
1697
|
+
size: Math.abs(size),
|
|
1698
|
+
entryPrice,
|
|
1699
|
+
markPrice,
|
|
1700
|
+
liquidationPrice: safeFloat(p.liquidationPx || '0'),
|
|
1701
|
+
leverage: parseInt(p.leverage.value, 10) || 1,
|
|
1702
|
+
marginType: (p.leverage.type === 'cross' ? 'CROSS' : 'ISOLATED'),
|
|
1703
|
+
unrealizedPnl: pnl,
|
|
1704
|
+
unrealizedPnlPct: positionValue > 0 ? (pnl / positionValue) * 100 : 0,
|
|
1705
|
+
margin: safeFloat(p.marginUsed),
|
|
1706
|
+
timestamp: Date.now(),
|
|
1707
|
+
};
|
|
1708
|
+
});
|
|
1709
|
+
}
|
|
1710
|
+
async placeOrder(order) {
|
|
1711
|
+
if (this.dryRun) {
|
|
1712
|
+
logger_1.logger.info({ order }, '[DRY RUN] Would place Hyperliquid order');
|
|
1713
|
+
return this.createDryRunOrder(order);
|
|
1714
|
+
}
|
|
1715
|
+
await this.ensureAssetIndex();
|
|
1716
|
+
const assetIndex = this.getAssetIndex(order.symbol);
|
|
1717
|
+
const nonce = Date.now();
|
|
1718
|
+
const isStopOrder = order.type === 'STOP_MARKET' || order.type === 'TAKE_PROFIT_MARKET';
|
|
1719
|
+
// Get current price for market orders
|
|
1720
|
+
let limitPx = order.price;
|
|
1721
|
+
if ((order.type === 'MARKET' || isStopOrder) && !limitPx) {
|
|
1722
|
+
const allMids = await this.request('/info', { type: 'allMids' });
|
|
1723
|
+
const midPrice = parseFloat(allMids[order.symbol] || '0');
|
|
1724
|
+
if (midPrice <= 0) {
|
|
1725
|
+
throw new Error(`Cannot determine price for ${order.symbol} on Hyperliquid. Check symbol name (use bare coin name like BTC, not BTCUSDT).`);
|
|
1726
|
+
}
|
|
1727
|
+
// Add/subtract 1% slippage for market orders
|
|
1728
|
+
limitPx = order.side === 'BUY' ? midPrice * 1.01 : midPrice * 0.99;
|
|
1729
|
+
}
|
|
1730
|
+
let orderType;
|
|
1731
|
+
if (isStopOrder && order.stopPrice) {
|
|
1732
|
+
// Trigger order (stop loss or take profit)
|
|
1733
|
+
orderType = {
|
|
1734
|
+
trigger: {
|
|
1735
|
+
triggerPx: String(order.stopPrice),
|
|
1736
|
+
isMarket: true,
|
|
1737
|
+
tpsl: order.type === 'STOP_MARKET' ? 'sl' : 'tp',
|
|
1738
|
+
},
|
|
1739
|
+
};
|
|
1740
|
+
}
|
|
1741
|
+
else if (order.type === 'LIMIT') {
|
|
1742
|
+
orderType = { limit: { tif: 'Gtc' } };
|
|
1743
|
+
}
|
|
1744
|
+
else {
|
|
1745
|
+
orderType = { limit: { tif: 'Ioc' } }; // Market orders use IOC
|
|
1746
|
+
}
|
|
1747
|
+
const orderWire = {
|
|
1748
|
+
a: assetIndex,
|
|
1749
|
+
b: order.side === 'BUY',
|
|
1750
|
+
p: String(limitPx),
|
|
1751
|
+
s: String(order.size),
|
|
1752
|
+
r: order.reduceOnly || isStopOrder,
|
|
1753
|
+
t: orderType,
|
|
1754
|
+
};
|
|
1755
|
+
const action = {
|
|
1756
|
+
type: 'order',
|
|
1757
|
+
orders: [orderWire],
|
|
1758
|
+
grouping: isStopOrder ? 'normalTpsl' : 'na',
|
|
1759
|
+
};
|
|
1760
|
+
const signature = this.signL1Action(action, nonce);
|
|
1761
|
+
const result = await this.request('/exchange', {
|
|
1762
|
+
action,
|
|
1763
|
+
nonce,
|
|
1764
|
+
signature: {
|
|
1765
|
+
r: signature.r,
|
|
1766
|
+
s: signature.s,
|
|
1767
|
+
v: signature.v,
|
|
1768
|
+
},
|
|
1769
|
+
vaultAddress: null,
|
|
1770
|
+
});
|
|
1771
|
+
if (result.status !== 'ok') {
|
|
1772
|
+
throw new Error(`Hyperliquid order failed: ${JSON.stringify(result)}`);
|
|
1773
|
+
}
|
|
1774
|
+
const status = result.response?.data?.statuses?.[0];
|
|
1775
|
+
const orderId = status?.resting?.oid || status?.filled?.oid || nonce;
|
|
1776
|
+
return {
|
|
1777
|
+
id: String(orderId),
|
|
1778
|
+
exchange: 'hyperliquid',
|
|
1779
|
+
symbol: order.symbol,
|
|
1780
|
+
side: order.side,
|
|
1781
|
+
type: order.type,
|
|
1782
|
+
size: order.size,
|
|
1783
|
+
price: limitPx,
|
|
1784
|
+
stopPrice: order.stopPrice,
|
|
1785
|
+
leverage: order.leverage || 1,
|
|
1786
|
+
reduceOnly: order.reduceOnly || isStopOrder,
|
|
1787
|
+
status: status?.filled ? 'FILLED' : 'NEW',
|
|
1788
|
+
filledSize: status?.filled ? order.size : 0,
|
|
1789
|
+
avgFillPrice: limitPx || 0,
|
|
1790
|
+
timestamp: Date.now(),
|
|
1791
|
+
};
|
|
1792
|
+
}
|
|
1793
|
+
createDryRunOrder(order) {
|
|
1794
|
+
const isMarket = order.type === 'MARKET';
|
|
1795
|
+
return {
|
|
1796
|
+
id: `dry-${Date.now()}-${(0, crypto_1.randomBytes)(4).toString('hex')}`,
|
|
1797
|
+
exchange: 'hyperliquid',
|
|
1798
|
+
symbol: order.symbol,
|
|
1799
|
+
side: order.side,
|
|
1800
|
+
type: order.type,
|
|
1801
|
+
size: order.size,
|
|
1802
|
+
price: order.price,
|
|
1803
|
+
leverage: order.leverage || 1,
|
|
1804
|
+
reduceOnly: order.reduceOnly || false,
|
|
1805
|
+
status: isMarket ? 'FILLED' : 'NEW',
|
|
1806
|
+
filledSize: isMarket ? order.size : 0,
|
|
1807
|
+
avgFillPrice: isMarket ? (order.price || 0) : 0,
|
|
1808
|
+
timestamp: Date.now(),
|
|
1809
|
+
};
|
|
1810
|
+
}
|
|
1811
|
+
async cancelOrder(symbol, orderId) {
|
|
1812
|
+
await this.ensureAssetIndex();
|
|
1813
|
+
const assetIndex = this.getAssetIndex(symbol);
|
|
1814
|
+
const nonce = Date.now();
|
|
1815
|
+
const action = {
|
|
1816
|
+
type: 'cancel',
|
|
1817
|
+
cancels: [{ a: assetIndex, o: parseInt(orderId) }],
|
|
1818
|
+
};
|
|
1819
|
+
const signature = this.signL1Action(action, nonce);
|
|
1820
|
+
await this.request('/exchange', {
|
|
1821
|
+
action,
|
|
1822
|
+
nonce,
|
|
1823
|
+
signature: {
|
|
1824
|
+
r: signature.r,
|
|
1825
|
+
s: signature.s,
|
|
1826
|
+
v: signature.v,
|
|
1827
|
+
},
|
|
1828
|
+
vaultAddress: null,
|
|
1829
|
+
});
|
|
1830
|
+
}
|
|
1831
|
+
async closePosition(symbol) {
|
|
1832
|
+
const positions = await this.getPositions();
|
|
1833
|
+
const position = positions.find(p => p.symbol === symbol);
|
|
1834
|
+
if (!position)
|
|
1835
|
+
return null;
|
|
1836
|
+
return this.placeOrder({
|
|
1837
|
+
symbol,
|
|
1838
|
+
side: position.side === 'LONG' ? 'SELL' : 'BUY',
|
|
1839
|
+
type: 'MARKET',
|
|
1840
|
+
size: position.size,
|
|
1841
|
+
reduceOnly: true,
|
|
1842
|
+
});
|
|
1843
|
+
}
|
|
1844
|
+
async getMarkets() {
|
|
1845
|
+
const [meta, allMids, fundingRates] = await Promise.all([
|
|
1846
|
+
this.request('/info', { type: 'meta' }),
|
|
1847
|
+
this.request('/info', { type: 'allMids' }),
|
|
1848
|
+
this.request('/info', { type: 'metaAndAssetCtxs' }),
|
|
1849
|
+
]);
|
|
1850
|
+
return meta.universe.map((m, idx) => ({
|
|
1851
|
+
exchange: 'hyperliquid',
|
|
1852
|
+
symbol: m.name,
|
|
1853
|
+
baseAsset: m.name,
|
|
1854
|
+
quoteAsset: 'USDC',
|
|
1855
|
+
tickSize: 0.1,
|
|
1856
|
+
lotSize: Math.pow(10, -m.szDecimals),
|
|
1857
|
+
minNotional: 10,
|
|
1858
|
+
maxLeverage: m.maxLeverage,
|
|
1859
|
+
fundingRate: parseFloat(fundingRates[1]?.[idx]?.funding || '0') * 100,
|
|
1860
|
+
markPrice: parseFloat(allMids[m.name] || '0'),
|
|
1861
|
+
indexPrice: parseFloat(allMids[m.name] || '0'),
|
|
1862
|
+
volume24h: parseFloat(fundingRates[1]?.[idx]?.dayNtlVlm || '0'),
|
|
1863
|
+
}));
|
|
1864
|
+
}
|
|
1865
|
+
async getFundingRate(symbol) {
|
|
1866
|
+
await this.ensureAssetIndex();
|
|
1867
|
+
const assetIndex = this.getAssetIndex(symbol);
|
|
1868
|
+
const data = await this.request('/info', { type: 'metaAndAssetCtxs' });
|
|
1869
|
+
return {
|
|
1870
|
+
rate: parseFloat(data[1]?.[assetIndex]?.funding || '0') * 100,
|
|
1871
|
+
nextFundingTime: Date.now() + 3600000, // Hourly funding
|
|
1872
|
+
};
|
|
1873
|
+
}
|
|
1874
|
+
async setLeverage(symbol, leverage, marginType = 'CROSS') {
|
|
1875
|
+
await this.ensureAssetIndex();
|
|
1876
|
+
const assetIndex = this.getAssetIndex(symbol);
|
|
1877
|
+
const nonce = Date.now();
|
|
1878
|
+
const action = {
|
|
1879
|
+
type: 'updateLeverage',
|
|
1880
|
+
asset: assetIndex,
|
|
1881
|
+
isCross: marginType === 'CROSS',
|
|
1882
|
+
leverage,
|
|
1883
|
+
};
|
|
1884
|
+
const signature = this.signL1Action(action, nonce);
|
|
1885
|
+
await this.request('/exchange', {
|
|
1886
|
+
action,
|
|
1887
|
+
nonce,
|
|
1888
|
+
signature: {
|
|
1889
|
+
r: signature.r,
|
|
1890
|
+
s: signature.s,
|
|
1891
|
+
v: signature.v,
|
|
1892
|
+
},
|
|
1893
|
+
vaultAddress: null,
|
|
1894
|
+
});
|
|
1895
|
+
}
|
|
1896
|
+
async getOpenOrders(symbol) {
|
|
1897
|
+
const data = await this.request('/info', {
|
|
1898
|
+
type: 'openOrders',
|
|
1899
|
+
user: this.walletAddress,
|
|
1900
|
+
});
|
|
1901
|
+
const filtered = symbol ? data.filter(o => o.coin === symbol) : data;
|
|
1902
|
+
return filtered.map(o => ({
|
|
1903
|
+
id: String(o.oid),
|
|
1904
|
+
exchange: 'hyperliquid',
|
|
1905
|
+
symbol: o.coin,
|
|
1906
|
+
side: (o.side === 'B' ? 'BUY' : 'SELL'),
|
|
1907
|
+
type: 'LIMIT',
|
|
1908
|
+
size: parseFloat(o.sz),
|
|
1909
|
+
price: parseFloat(o.limitPx),
|
|
1910
|
+
leverage: 1,
|
|
1911
|
+
reduceOnly: false,
|
|
1912
|
+
status: 'NEW',
|
|
1913
|
+
filledSize: 0,
|
|
1914
|
+
avgFillPrice: parseFloat(o.limitPx),
|
|
1915
|
+
timestamp: o.timestamp,
|
|
1916
|
+
}));
|
|
1917
|
+
}
|
|
1918
|
+
// =========== ADDITIONAL COMPREHENSIVE METHODS ===========
|
|
1919
|
+
async getAccountInfo() {
|
|
1920
|
+
const [data, allMids] = await Promise.all([
|
|
1921
|
+
this.request('/info', {
|
|
1922
|
+
type: 'clearinghouseState',
|
|
1923
|
+
user: this.walletAddress,
|
|
1924
|
+
}),
|
|
1925
|
+
this.request('/info', { type: 'allMids' }),
|
|
1926
|
+
]);
|
|
1927
|
+
let totalUnrealized = 0;
|
|
1928
|
+
const positions = data.assetPositions
|
|
1929
|
+
.filter(ap => safeFloat(ap.position.szi) !== 0)
|
|
1930
|
+
.map(ap => {
|
|
1931
|
+
const p = ap.position;
|
|
1932
|
+
const size = safeFloat(p.szi);
|
|
1933
|
+
const unrealizedPnl = safeFloat(p.unrealizedPnl);
|
|
1934
|
+
totalUnrealized += unrealizedPnl;
|
|
1935
|
+
return {
|
|
1936
|
+
exchange: 'hyperliquid',
|
|
1937
|
+
symbol: p.coin,
|
|
1938
|
+
side: (size > 0 ? 'LONG' : 'SHORT'),
|
|
1939
|
+
size: Math.abs(size),
|
|
1940
|
+
entryPrice: safeFloat(p.entryPx),
|
|
1941
|
+
markPrice: safeFloat(allMids[p.coin] || p.entryPx),
|
|
1942
|
+
liquidationPrice: safeFloat(p.liquidationPx || '0'),
|
|
1943
|
+
leverage: parseInt(p.leverage.value, 10) || 1,
|
|
1944
|
+
marginType: (p.leverage.type === 'cross' ? 'CROSS' : 'ISOLATED'),
|
|
1945
|
+
unrealizedPnl,
|
|
1946
|
+
unrealizedPnlPct: 0,
|
|
1947
|
+
margin: 0,
|
|
1948
|
+
timestamp: Date.now(),
|
|
1949
|
+
};
|
|
1950
|
+
});
|
|
1951
|
+
const accountValue = safeFloat(data.marginSummary.accountValue);
|
|
1952
|
+
const marginUsed = safeFloat(data.marginSummary.totalMarginUsed);
|
|
1953
|
+
return {
|
|
1954
|
+
exchange: 'hyperliquid',
|
|
1955
|
+
totalWalletBalance: accountValue,
|
|
1956
|
+
totalUnrealizedProfit: totalUnrealized,
|
|
1957
|
+
totalMarginBalance: accountValue,
|
|
1958
|
+
totalPositionInitialMargin: marginUsed,
|
|
1959
|
+
totalOpenOrderInitialMargin: 0,
|
|
1960
|
+
availableBalance: accountValue - marginUsed,
|
|
1961
|
+
maxWithdrawAmount: safeFloat(data.marginSummary.totalRawUsd),
|
|
1962
|
+
canTrade: true,
|
|
1963
|
+
canDeposit: true,
|
|
1964
|
+
canWithdraw: true,
|
|
1965
|
+
positions,
|
|
1966
|
+
};
|
|
1967
|
+
}
|
|
1968
|
+
async getTradeHistory(limit = 500) {
|
|
1969
|
+
const data = await this.request('/info', {
|
|
1970
|
+
type: 'userFills',
|
|
1971
|
+
user: this.walletAddress,
|
|
1972
|
+
});
|
|
1973
|
+
return data.slice(0, limit).map(t => ({
|
|
1974
|
+
id: String(t.tid),
|
|
1975
|
+
exchange: 'hyperliquid',
|
|
1976
|
+
symbol: t.coin,
|
|
1977
|
+
orderId: String(t.oid),
|
|
1978
|
+
side: (t.side === 'B' ? 'BUY' : 'SELL'),
|
|
1979
|
+
price: parseFloat(t.px),
|
|
1980
|
+
quantity: parseFloat(t.sz),
|
|
1981
|
+
realizedPnl: parseFloat(t.closedPnl),
|
|
1982
|
+
commission: parseFloat(t.fee),
|
|
1983
|
+
commissionAsset: 'USDC',
|
|
1984
|
+
timestamp: t.time,
|
|
1985
|
+
isMaker: false,
|
|
1986
|
+
}));
|
|
1987
|
+
}
|
|
1988
|
+
async getOrderHistory() {
|
|
1989
|
+
const data = await this.request('/info', {
|
|
1990
|
+
type: 'historicalOrders',
|
|
1991
|
+
user: this.walletAddress,
|
|
1992
|
+
});
|
|
1993
|
+
return data.map(o => ({
|
|
1994
|
+
id: String(o.order.oid),
|
|
1995
|
+
exchange: 'hyperliquid',
|
|
1996
|
+
symbol: o.order.coin,
|
|
1997
|
+
side: (o.order.side === 'B' ? 'BUY' : 'SELL'),
|
|
1998
|
+
type: 'LIMIT',
|
|
1999
|
+
size: parseFloat(o.order.sz),
|
|
2000
|
+
price: parseFloat(o.order.limitPx),
|
|
2001
|
+
leverage: 1,
|
|
2002
|
+
reduceOnly: o.order.reduceOnly,
|
|
2003
|
+
status: (o.status === 'filled' ? 'FILLED' : o.status === 'canceled' ? 'CANCELED' : 'NEW'),
|
|
2004
|
+
filledSize: o.status === 'filled' ? parseFloat(o.order.sz) : 0,
|
|
2005
|
+
avgFillPrice: parseFloat(o.order.limitPx),
|
|
2006
|
+
timestamp: o.statusTimestamp,
|
|
2007
|
+
}));
|
|
2008
|
+
}
|
|
2009
|
+
async getOrderBook(symbol) {
|
|
2010
|
+
const data = await this.request('/info', {
|
|
2011
|
+
type: 'l2Book',
|
|
2012
|
+
coin: symbol,
|
|
2013
|
+
});
|
|
2014
|
+
return {
|
|
2015
|
+
exchange: 'hyperliquid',
|
|
2016
|
+
symbol,
|
|
2017
|
+
lastUpdateId: data.time,
|
|
2018
|
+
bids: data.levels[0]?.map(l => [parseFloat(l.px), parseFloat(l.sz)]) || [],
|
|
2019
|
+
asks: data.levels[1]?.map(l => [parseFloat(l.px), parseFloat(l.sz)]) || [],
|
|
2020
|
+
timestamp: data.time,
|
|
2021
|
+
};
|
|
2022
|
+
}
|
|
2023
|
+
async getKlines(symbol, interval, startTime, endTime) {
|
|
2024
|
+
const data = await this.request('/info', {
|
|
2025
|
+
type: 'candleSnapshot',
|
|
2026
|
+
coin: symbol,
|
|
2027
|
+
interval,
|
|
2028
|
+
startTime: startTime || Date.now() - 86400000,
|
|
2029
|
+
endTime: endTime || Date.now(),
|
|
2030
|
+
});
|
|
2031
|
+
return data.map(k => ({
|
|
2032
|
+
openTime: k.t,
|
|
2033
|
+
open: parseFloat(k.o),
|
|
2034
|
+
high: parseFloat(k.h),
|
|
2035
|
+
low: parseFloat(k.l),
|
|
2036
|
+
close: parseFloat(k.c),
|
|
2037
|
+
volume: parseFloat(k.v),
|
|
2038
|
+
closeTime: k.t + 60000,
|
|
2039
|
+
quoteVolume: 0,
|
|
2040
|
+
trades: 0,
|
|
2041
|
+
takerBuyVolume: 0,
|
|
2042
|
+
takerBuyQuoteVolume: 0,
|
|
2043
|
+
}));
|
|
2044
|
+
}
|
|
2045
|
+
async getUserFees() {
|
|
2046
|
+
const data = await this.request('/info', {
|
|
2047
|
+
type: 'userFees',
|
|
2048
|
+
user: this.walletAddress,
|
|
2049
|
+
});
|
|
2050
|
+
return {
|
|
2051
|
+
maker: parseFloat(data.feeSchedule.maker) * 100,
|
|
2052
|
+
taker: parseFloat(data.feeSchedule.taker) * 100,
|
|
2053
|
+
};
|
|
2054
|
+
}
|
|
2055
|
+
async getRateLimit() {
|
|
2056
|
+
const data = await this.request('/info', {
|
|
2057
|
+
type: 'userRateLimit',
|
|
2058
|
+
user: this.walletAddress,
|
|
2059
|
+
});
|
|
2060
|
+
return {
|
|
2061
|
+
used: data.nRequestsUsed,
|
|
2062
|
+
limit: data.nRequestsCap,
|
|
2063
|
+
};
|
|
2064
|
+
}
|
|
2065
|
+
async getOrderStatus(orderId) {
|
|
2066
|
+
const data = await this.request('/info', {
|
|
2067
|
+
type: 'orderStatus',
|
|
2068
|
+
user: this.walletAddress,
|
|
2069
|
+
oid: orderId,
|
|
2070
|
+
});
|
|
2071
|
+
return {
|
|
2072
|
+
status: data.order?.status || 'unknown',
|
|
2073
|
+
filled: parseFloat(data.order?.filledSz || '0'),
|
|
2074
|
+
};
|
|
2075
|
+
}
|
|
2076
|
+
async cancelByClientOrderId(symbol, cloid) {
|
|
2077
|
+
await this.ensureAssetIndex();
|
|
2078
|
+
const assetIndex = this.getAssetIndex(symbol);
|
|
2079
|
+
const nonce = Date.now();
|
|
2080
|
+
const action = {
|
|
2081
|
+
type: 'cancelByCloid',
|
|
2082
|
+
cancels: [{ asset: assetIndex, cloid }],
|
|
2083
|
+
};
|
|
2084
|
+
const signature = this.signL1Action(action, nonce);
|
|
2085
|
+
await this.request('/exchange', {
|
|
2086
|
+
action,
|
|
2087
|
+
nonce,
|
|
2088
|
+
signature: { r: signature.r, s: signature.s, v: signature.v },
|
|
2089
|
+
vaultAddress: null,
|
|
2090
|
+
});
|
|
2091
|
+
}
|
|
2092
|
+
async modifyOrder(symbol, orderId, price, size, isBuy) {
|
|
2093
|
+
await this.ensureAssetIndex();
|
|
2094
|
+
const assetIndex = this.getAssetIndex(symbol);
|
|
2095
|
+
const nonce = Date.now();
|
|
2096
|
+
const action = {
|
|
2097
|
+
type: 'batchModify',
|
|
2098
|
+
modifies: [{
|
|
2099
|
+
oid: orderId,
|
|
2100
|
+
order: {
|
|
2101
|
+
a: assetIndex,
|
|
2102
|
+
b: isBuy,
|
|
2103
|
+
p: String(price),
|
|
2104
|
+
s: String(size),
|
|
2105
|
+
r: false,
|
|
2106
|
+
t: { limit: { tif: 'Gtc' } },
|
|
2107
|
+
},
|
|
2108
|
+
}],
|
|
2109
|
+
};
|
|
2110
|
+
const signature = this.signL1Action(action, nonce);
|
|
2111
|
+
await this.request('/exchange', {
|
|
2112
|
+
action,
|
|
2113
|
+
nonce,
|
|
2114
|
+
signature: { r: signature.r, s: signature.s, v: signature.v },
|
|
2115
|
+
vaultAddress: null,
|
|
2116
|
+
});
|
|
2117
|
+
return {
|
|
2118
|
+
id: String(orderId),
|
|
2119
|
+
exchange: 'hyperliquid',
|
|
2120
|
+
symbol,
|
|
2121
|
+
side: isBuy ? 'BUY' : 'SELL',
|
|
2122
|
+
type: 'LIMIT',
|
|
2123
|
+
size,
|
|
2124
|
+
price,
|
|
2125
|
+
leverage: 1,
|
|
2126
|
+
reduceOnly: false,
|
|
2127
|
+
status: 'NEW',
|
|
2128
|
+
filledSize: 0,
|
|
2129
|
+
avgFillPrice: 0,
|
|
2130
|
+
timestamp: Date.now(),
|
|
2131
|
+
};
|
|
2132
|
+
}
|
|
2133
|
+
async updateIsolatedMargin(symbol, marginDelta) {
|
|
2134
|
+
await this.ensureAssetIndex();
|
|
2135
|
+
const assetIndex = this.getAssetIndex(symbol);
|
|
2136
|
+
const nonce = Date.now();
|
|
2137
|
+
const action = {
|
|
2138
|
+
type: 'updateIsolatedMargin',
|
|
2139
|
+
asset: assetIndex,
|
|
2140
|
+
isBuy: true,
|
|
2141
|
+
ntli: marginDelta,
|
|
2142
|
+
};
|
|
2143
|
+
const signature = this.signL1Action(action, nonce);
|
|
2144
|
+
await this.request('/exchange', {
|
|
2145
|
+
action,
|
|
2146
|
+
nonce,
|
|
2147
|
+
signature: { r: signature.r, s: signature.s, v: signature.v },
|
|
2148
|
+
vaultAddress: null,
|
|
2149
|
+
});
|
|
2150
|
+
}
|
|
2151
|
+
async transferUsd(amount, toPerp) {
|
|
2152
|
+
const nonce = Date.now();
|
|
2153
|
+
const action = {
|
|
2154
|
+
type: 'usdTransfer',
|
|
2155
|
+
amount: String(amount),
|
|
2156
|
+
toPerp,
|
|
2157
|
+
};
|
|
2158
|
+
const signature = this.signL1Action(action, nonce);
|
|
2159
|
+
await this.request('/exchange', {
|
|
2160
|
+
action,
|
|
2161
|
+
nonce,
|
|
2162
|
+
signature: { r: signature.r, s: signature.s, v: signature.v },
|
|
2163
|
+
vaultAddress: null,
|
|
2164
|
+
});
|
|
2165
|
+
}
|
|
2166
|
+
async getSubAccounts() {
|
|
2167
|
+
const data = await this.request('/info', {
|
|
2168
|
+
type: 'subAccounts',
|
|
2169
|
+
user: this.walletAddress,
|
|
2170
|
+
});
|
|
2171
|
+
return data;
|
|
2172
|
+
}
|
|
2173
|
+
async placeTwapOrder(symbol, isBuy, size, durationMinutes, randomize = true) {
|
|
2174
|
+
await this.ensureAssetIndex();
|
|
2175
|
+
const assetIndex = this.getAssetIndex(symbol);
|
|
2176
|
+
const nonce = Date.now();
|
|
2177
|
+
const action = {
|
|
2178
|
+
type: 'twapOrder',
|
|
2179
|
+
twap: {
|
|
2180
|
+
a: assetIndex,
|
|
2181
|
+
b: isBuy,
|
|
2182
|
+
s: String(size),
|
|
2183
|
+
r: false,
|
|
2184
|
+
m: durationMinutes,
|
|
2185
|
+
t: randomize,
|
|
2186
|
+
},
|
|
2187
|
+
};
|
|
2188
|
+
const signature = this.signL1Action(action, nonce);
|
|
2189
|
+
const result = await this.request('/exchange', {
|
|
2190
|
+
action,
|
|
2191
|
+
nonce,
|
|
2192
|
+
signature: { r: signature.r, s: signature.s, v: signature.v },
|
|
2193
|
+
vaultAddress: null,
|
|
2194
|
+
});
|
|
2195
|
+
return {
|
|
2196
|
+
status: result.status,
|
|
2197
|
+
twapId: result.response?.data?.running?.state?.twapId,
|
|
2198
|
+
};
|
|
2199
|
+
}
|
|
2200
|
+
async cancelTwapOrder(symbol, twapId) {
|
|
2201
|
+
await this.ensureAssetIndex();
|
|
2202
|
+
const assetIndex = this.getAssetIndex(symbol);
|
|
2203
|
+
const nonce = Date.now();
|
|
2204
|
+
const action = {
|
|
2205
|
+
type: 'twapCancel',
|
|
2206
|
+
a: assetIndex,
|
|
2207
|
+
t: twapId,
|
|
2208
|
+
};
|
|
2209
|
+
const signature = this.signL1Action(action, nonce);
|
|
2210
|
+
await this.request('/exchange', {
|
|
2211
|
+
action,
|
|
2212
|
+
nonce,
|
|
2213
|
+
signature: { r: signature.r, s: signature.s, v: signature.v },
|
|
2214
|
+
vaultAddress: null,
|
|
2215
|
+
});
|
|
2216
|
+
}
|
|
2217
|
+
async getMeta() {
|
|
2218
|
+
return this.request('/info', { type: 'meta' });
|
|
2219
|
+
}
|
|
2220
|
+
// =========== ADDITIONAL HYPERLIQUID METHODS ===========
|
|
2221
|
+
async scheduleCancel(time) {
|
|
2222
|
+
const nonce = Date.now();
|
|
2223
|
+
const action = { type: 'scheduleCancel', time };
|
|
2224
|
+
const signature = this.signL1Action(action, nonce);
|
|
2225
|
+
await this.request('/exchange', {
|
|
2226
|
+
action,
|
|
2227
|
+
nonce,
|
|
2228
|
+
signature: { r: signature.r, s: signature.s, v: signature.v },
|
|
2229
|
+
vaultAddress: null,
|
|
2230
|
+
});
|
|
2231
|
+
}
|
|
2232
|
+
async sendUsd(destination, amount) {
|
|
2233
|
+
const nonce = Date.now();
|
|
2234
|
+
const action = { type: 'usdSend', destination, amount: String(amount) };
|
|
2235
|
+
const signature = this.signL1Action(action, nonce);
|
|
2236
|
+
await this.request('/exchange', {
|
|
2237
|
+
action,
|
|
2238
|
+
nonce,
|
|
2239
|
+
signature: { r: signature.r, s: signature.s, v: signature.v },
|
|
2240
|
+
vaultAddress: null,
|
|
2241
|
+
});
|
|
2242
|
+
}
|
|
2243
|
+
async sendSpot(destination, token, amount) {
|
|
2244
|
+
const nonce = Date.now();
|
|
2245
|
+
const action = { type: 'spotSend', destination, token, amount: String(amount) };
|
|
2246
|
+
const signature = this.signL1Action(action, nonce);
|
|
2247
|
+
await this.request('/exchange', {
|
|
2248
|
+
action,
|
|
2249
|
+
nonce,
|
|
2250
|
+
signature: { r: signature.r, s: signature.s, v: signature.v },
|
|
2251
|
+
vaultAddress: null,
|
|
2252
|
+
});
|
|
2253
|
+
}
|
|
2254
|
+
async withdraw(destination, amount) {
|
|
2255
|
+
const nonce = Date.now();
|
|
2256
|
+
const action = { type: 'withdraw3', destination, amount: String(amount) };
|
|
2257
|
+
const signature = this.signL1Action(action, nonce);
|
|
2258
|
+
await this.request('/exchange', {
|
|
2259
|
+
action,
|
|
2260
|
+
nonce,
|
|
2261
|
+
signature: { r: signature.r, s: signature.s, v: signature.v },
|
|
2262
|
+
vaultAddress: null,
|
|
2263
|
+
});
|
|
2264
|
+
}
|
|
2265
|
+
async transferBetweenSpotAndPerp(amount, toPerp) {
|
|
2266
|
+
const nonce = Date.now();
|
|
2267
|
+
const action = { type: 'usdClassTransfer', amount: String(amount), toPerp };
|
|
2268
|
+
const signature = this.signL1Action(action, nonce);
|
|
2269
|
+
await this.request('/exchange', {
|
|
2270
|
+
action,
|
|
2271
|
+
nonce,
|
|
2272
|
+
signature: { r: signature.r, s: signature.s, v: signature.v },
|
|
2273
|
+
vaultAddress: null,
|
|
2274
|
+
});
|
|
2275
|
+
}
|
|
2276
|
+
async vaultTransfer(vaultAddress, amount, isDeposit) {
|
|
2277
|
+
const nonce = Date.now();
|
|
2278
|
+
const action = { type: 'vaultTransfer', vaultAddress, usd: String(amount), isDeposit };
|
|
2279
|
+
const signature = this.signL1Action(action, nonce);
|
|
2280
|
+
await this.request('/exchange', {
|
|
2281
|
+
action,
|
|
2282
|
+
nonce,
|
|
2283
|
+
signature: { r: signature.r, s: signature.s, v: signature.v },
|
|
2284
|
+
vaultAddress: null,
|
|
2285
|
+
});
|
|
2286
|
+
}
|
|
2287
|
+
async approveAgent(agentAddress, agentName) {
|
|
2288
|
+
const nonce = Date.now();
|
|
2289
|
+
const action = { type: 'approveAgent', agentAddress, agentName: agentName || null };
|
|
2290
|
+
const signature = this.signL1Action(action, nonce);
|
|
2291
|
+
await this.request('/exchange', {
|
|
2292
|
+
action,
|
|
2293
|
+
nonce,
|
|
2294
|
+
signature: { r: signature.r, s: signature.s, v: signature.v },
|
|
2295
|
+
vaultAddress: null,
|
|
2296
|
+
});
|
|
2297
|
+
}
|
|
2298
|
+
async approveBuilderFee(builder, maxFeeRate) {
|
|
2299
|
+
const nonce = Date.now();
|
|
2300
|
+
const action = { type: 'approveBuilderFee', builder, maxFeeRate: String(maxFeeRate) };
|
|
2301
|
+
const signature = this.signL1Action(action, nonce);
|
|
2302
|
+
await this.request('/exchange', {
|
|
2303
|
+
action,
|
|
2304
|
+
nonce,
|
|
2305
|
+
signature: { r: signature.r, s: signature.s, v: signature.v },
|
|
2306
|
+
vaultAddress: null,
|
|
2307
|
+
});
|
|
2308
|
+
}
|
|
2309
|
+
async setReferrer(code) {
|
|
2310
|
+
const nonce = Date.now();
|
|
2311
|
+
const action = { type: 'setReferrer', code };
|
|
2312
|
+
const signature = this.signL1Action(action, nonce);
|
|
2313
|
+
await this.request('/exchange', {
|
|
2314
|
+
action,
|
|
2315
|
+
nonce,
|
|
2316
|
+
signature: { r: signature.r, s: signature.s, v: signature.v },
|
|
2317
|
+
vaultAddress: null,
|
|
2318
|
+
});
|
|
2319
|
+
}
|
|
2320
|
+
async stakeDeposit(amount) {
|
|
2321
|
+
const nonce = Date.now();
|
|
2322
|
+
const action = { type: 'cDeposit', amount: String(amount) };
|
|
2323
|
+
const signature = this.signL1Action(action, nonce);
|
|
2324
|
+
await this.request('/exchange', {
|
|
2325
|
+
action,
|
|
2326
|
+
nonce,
|
|
2327
|
+
signature: { r: signature.r, s: signature.s, v: signature.v },
|
|
2328
|
+
vaultAddress: null,
|
|
2329
|
+
});
|
|
2330
|
+
}
|
|
2331
|
+
async stakeWithdraw(amount) {
|
|
2332
|
+
const nonce = Date.now();
|
|
2333
|
+
const action = { type: 'cWithdraw', amount: String(amount) };
|
|
2334
|
+
const signature = this.signL1Action(action, nonce);
|
|
2335
|
+
await this.request('/exchange', {
|
|
2336
|
+
action,
|
|
2337
|
+
nonce,
|
|
2338
|
+
signature: { r: signature.r, s: signature.s, v: signature.v },
|
|
2339
|
+
vaultAddress: null,
|
|
2340
|
+
});
|
|
2341
|
+
}
|
|
2342
|
+
async delegateTokens(validator, amount, undelegate) {
|
|
2343
|
+
const nonce = Date.now();
|
|
2344
|
+
const action = { type: 'tokenDelegate', validator, amount: String(amount), undelegate };
|
|
2345
|
+
const signature = this.signL1Action(action, nonce);
|
|
2346
|
+
await this.request('/exchange', {
|
|
2347
|
+
action,
|
|
2348
|
+
nonce,
|
|
2349
|
+
signature: { r: signature.r, s: signature.s, v: signature.v },
|
|
2350
|
+
vaultAddress: null,
|
|
2351
|
+
});
|
|
2352
|
+
}
|
|
2353
|
+
// Additional info queries
|
|
2354
|
+
async getVaultDetails(vaultAddress) {
|
|
2355
|
+
const data = await this.request('/info', { type: 'vaultDetails', vaultAddress });
|
|
2356
|
+
return {
|
|
2357
|
+
name: data.name,
|
|
2358
|
+
vaultAddress: data.vaultAddress,
|
|
2359
|
+
leader: data.leader,
|
|
2360
|
+
tvl: 0,
|
|
2361
|
+
totalPnl: 0,
|
|
2362
|
+
};
|
|
2363
|
+
}
|
|
2364
|
+
async getUserVaultEquities() {
|
|
2365
|
+
const data = await this.request('/info', {
|
|
2366
|
+
type: 'userVaultEquities',
|
|
2367
|
+
user: this.walletAddress,
|
|
2368
|
+
});
|
|
2369
|
+
return data.map(v => ({ vaultAddress: v.vaultAddress, equity: parseFloat(v.equity) }));
|
|
2370
|
+
}
|
|
2371
|
+
async getUserRole() {
|
|
2372
|
+
return this.request('/info', { type: 'userRole', user: this.walletAddress });
|
|
2373
|
+
}
|
|
2374
|
+
async getPortfolio() {
|
|
2375
|
+
const data = await this.request('/info', { type: 'portfolio', user: this.walletAddress });
|
|
2376
|
+
return data.map(p => ({
|
|
2377
|
+
name: p.name,
|
|
2378
|
+
allTimePnl: parseFloat(p.allTimePnl),
|
|
2379
|
+
dailyPnl: parseFloat(p.dailyPnl),
|
|
2380
|
+
monthlyPnl: parseFloat(p.monthlyPnl),
|
|
2381
|
+
}));
|
|
2382
|
+
}
|
|
2383
|
+
async getReferralInfo() {
|
|
2384
|
+
const data = await this.request('/info', { type: 'referral', user: this.walletAddress });
|
|
2385
|
+
return {
|
|
2386
|
+
referredBy: data.referredBy,
|
|
2387
|
+
cumVlm: parseFloat(data.cumVlm),
|
|
2388
|
+
unclaimedRewards: parseFloat(data.unclaimedRewards),
|
|
2389
|
+
claimedRewards: parseFloat(data.claimedRewards),
|
|
2390
|
+
};
|
|
2391
|
+
}
|
|
2392
|
+
async getStakingDelegations() {
|
|
2393
|
+
const data = await this.request('/info', { type: 'delegations', user: this.walletAddress });
|
|
2394
|
+
return data.map(d => ({
|
|
2395
|
+
validator: d.validator,
|
|
2396
|
+
amount: parseFloat(d.amount),
|
|
2397
|
+
lockedUntil: d.lockedUntil,
|
|
2398
|
+
}));
|
|
2399
|
+
}
|
|
2400
|
+
async getStakingSummary() {
|
|
2401
|
+
const data = await this.request('/info', { type: 'delegatorSummary', user: this.walletAddress });
|
|
2402
|
+
return {
|
|
2403
|
+
delegated: parseFloat(data.delegated),
|
|
2404
|
+
undelegating: parseFloat(data.undelegating),
|
|
2405
|
+
claimable: parseFloat(data.claimable),
|
|
2406
|
+
totalRewards: parseFloat(data.totalRewards),
|
|
2407
|
+
};
|
|
2408
|
+
}
|
|
2409
|
+
async getStakingRewards(limit = 100) {
|
|
2410
|
+
const data = await this.request('/info', { type: 'delegatorRewards', user: this.walletAddress });
|
|
2411
|
+
return data.slice(0, limit).map(r => ({
|
|
2412
|
+
validator: r.validator,
|
|
2413
|
+
amount: parseFloat(r.amount),
|
|
2414
|
+
timestamp: r.time,
|
|
2415
|
+
}));
|
|
2416
|
+
}
|
|
2417
|
+
async getBorrowLendState() {
|
|
2418
|
+
const data = await this.request('/info', { type: 'borrowLendUserState', user: this.walletAddress });
|
|
2419
|
+
return {
|
|
2420
|
+
borrowed: parseFloat(data.borrowed),
|
|
2421
|
+
lent: parseFloat(data.lent),
|
|
2422
|
+
borrowApy: parseFloat(data.borrowApy),
|
|
2423
|
+
lendApy: parseFloat(data.lendApy),
|
|
2424
|
+
};
|
|
2425
|
+
}
|
|
2426
|
+
async getAllBorrowLendReserves() {
|
|
2427
|
+
const data = await this.request('/info', { type: 'allBorrowLendReserveStates' });
|
|
2428
|
+
return data.map(r => ({
|
|
2429
|
+
coin: r.coin,
|
|
2430
|
+
totalBorrowed: parseFloat(r.totalBorrowed),
|
|
2431
|
+
totalLent: parseFloat(r.totalLent),
|
|
2432
|
+
borrowApy: parseFloat(r.borrowApy),
|
|
2433
|
+
lendApy: parseFloat(r.lendApy),
|
|
2434
|
+
}));
|
|
2435
|
+
}
|
|
2436
|
+
async getFrontendOpenOrders() {
|
|
2437
|
+
const data = await this.request('/info', {
|
|
2438
|
+
type: 'frontendOpenOrders',
|
|
2439
|
+
user: this.walletAddress,
|
|
2440
|
+
});
|
|
2441
|
+
return data.map(o => ({
|
|
2442
|
+
coin: o.coin,
|
|
2443
|
+
oid: o.oid,
|
|
2444
|
+
side: o.side,
|
|
2445
|
+
limitPx: parseFloat(o.limitPx),
|
|
2446
|
+
sz: parseFloat(o.sz),
|
|
2447
|
+
timestamp: o.timestamp,
|
|
2448
|
+
triggerCondition: o.triggerCondition,
|
|
2449
|
+
isTrigger: o.isTrigger,
|
|
2450
|
+
reduceOnly: o.reduceOnly,
|
|
2451
|
+
}));
|
|
2452
|
+
}
|
|
2453
|
+
async getTwapSliceFills() {
|
|
2454
|
+
const data = await this.request('/info', {
|
|
2455
|
+
type: 'userTwapSliceFills',
|
|
2456
|
+
user: this.walletAddress,
|
|
2457
|
+
});
|
|
2458
|
+
return data.map(f => ({
|
|
2459
|
+
coin: f.coin,
|
|
2460
|
+
px: parseFloat(f.px),
|
|
2461
|
+
sz: parseFloat(f.sz),
|
|
2462
|
+
side: f.side,
|
|
2463
|
+
time: f.time,
|
|
2464
|
+
fee: parseFloat(f.fee),
|
|
2465
|
+
twapId: f.twapId,
|
|
2466
|
+
}));
|
|
2467
|
+
}
|
|
2468
|
+
async getMaxBuilderFee(builder) {
|
|
2469
|
+
const data = await this.request('/info', {
|
|
2470
|
+
type: 'maxBuilderFee',
|
|
2471
|
+
user: this.walletAddress,
|
|
2472
|
+
builder,
|
|
2473
|
+
});
|
|
2474
|
+
return { maxFeeRate: parseFloat(data.maxFeeRate) };
|
|
2475
|
+
}
|
|
2476
|
+
async getSpotMeta() {
|
|
2477
|
+
return this.request('/info', { type: 'spotMeta' });
|
|
2478
|
+
}
|
|
2479
|
+
async getSpotClearinghouseState() {
|
|
2480
|
+
const data = await this.request('/info', {
|
|
2481
|
+
type: 'spotClearinghouseState',
|
|
2482
|
+
user: this.walletAddress,
|
|
2483
|
+
});
|
|
2484
|
+
return {
|
|
2485
|
+
balances: data.balances.map(b => ({
|
|
2486
|
+
coin: b.coin,
|
|
2487
|
+
hold: parseFloat(b.hold),
|
|
2488
|
+
total: parseFloat(b.total),
|
|
2489
|
+
})),
|
|
2490
|
+
};
|
|
2491
|
+
}
|
|
2492
|
+
}
|
|
2493
|
+
exports.HyperliquidClient = HyperliquidClient;
|
|
2494
|
+
// =============================================================================
|
|
2495
|
+
// MEXC FUTURES CLIENT (No KYC required for small amounts)
|
|
2496
|
+
// =============================================================================
|
|
2497
|
+
class MexcFuturesClient {
|
|
2498
|
+
apiKey;
|
|
2499
|
+
apiSecret;
|
|
2500
|
+
baseUrl = 'https://contract.mexc.com';
|
|
2501
|
+
dryRun;
|
|
2502
|
+
_marginType = 'ISOLATED';
|
|
2503
|
+
constructor(credentials, dryRun = false) {
|
|
2504
|
+
this.apiKey = credentials.apiKey;
|
|
2505
|
+
this.apiSecret = credentials.apiSecret;
|
|
2506
|
+
this.dryRun = dryRun;
|
|
2507
|
+
}
|
|
2508
|
+
setMarginTypePreference(marginType) {
|
|
2509
|
+
this._marginType = marginType;
|
|
2510
|
+
}
|
|
2511
|
+
sign(timestamp, params) {
|
|
2512
|
+
const payload = `${this.apiKey}${timestamp}${params}`;
|
|
2513
|
+
return (0, crypto_1.createHmac)('sha256', this.apiSecret).update(payload).digest('hex');
|
|
2514
|
+
}
|
|
2515
|
+
async request(method, endpoint, params = {}, signed = false) {
|
|
2516
|
+
const timestamp = String(Date.now());
|
|
2517
|
+
const url = new URL(endpoint, this.baseUrl);
|
|
2518
|
+
let queryString = '';
|
|
2519
|
+
let body = '';
|
|
2520
|
+
if (method === 'GET') {
|
|
2521
|
+
queryString = Object.entries(params)
|
|
2522
|
+
.filter(([, v]) => v !== undefined && typeof v !== 'object')
|
|
2523
|
+
.map(([k, v]) => `${k}=${encodeURIComponent(String(v))}`)
|
|
2524
|
+
.join('&');
|
|
2525
|
+
if (queryString)
|
|
2526
|
+
url.search = queryString;
|
|
2527
|
+
}
|
|
2528
|
+
else {
|
|
2529
|
+
body = JSON.stringify(params);
|
|
2530
|
+
}
|
|
2531
|
+
const headers = {
|
|
2532
|
+
'Content-Type': 'application/json',
|
|
2533
|
+
};
|
|
2534
|
+
if (signed) {
|
|
2535
|
+
const signData = method === 'GET' ? queryString : body;
|
|
2536
|
+
headers['ApiKey'] = this.apiKey;
|
|
2537
|
+
headers['Request-Time'] = timestamp;
|
|
2538
|
+
headers['Signature'] = this.sign(timestamp, signData);
|
|
2539
|
+
}
|
|
2540
|
+
const response = await fetchWithRetry(url.toString(), {
|
|
2541
|
+
method,
|
|
2542
|
+
headers,
|
|
2543
|
+
body: method !== 'GET' ? body : undefined,
|
|
2544
|
+
signal: AbortSignal.timeout(30_000),
|
|
2545
|
+
});
|
|
2546
|
+
const data = await response.json();
|
|
2547
|
+
if (!data.success || data.code !== 0) {
|
|
2548
|
+
throw new Error(`MEXC error: ${data.message || data.code}`);
|
|
2549
|
+
}
|
|
2550
|
+
return data.data;
|
|
2551
|
+
}
|
|
2552
|
+
async getBalance() {
|
|
2553
|
+
const data = await this.request('GET', '/api/v1/private/account/assets', {}, true);
|
|
2554
|
+
const usdt = data.find(b => b.currency === 'USDT') || {
|
|
2555
|
+
availableBalance: '0',
|
|
2556
|
+
equity: '0',
|
|
2557
|
+
unrealized: '0',
|
|
2558
|
+
};
|
|
2559
|
+
return {
|
|
2560
|
+
exchange: 'mexc',
|
|
2561
|
+
asset: 'USDT',
|
|
2562
|
+
available: safeFloat(usdt.availableBalance),
|
|
2563
|
+
total: safeFloat(usdt.equity),
|
|
2564
|
+
unrealizedPnl: safeFloat(usdt.unrealized),
|
|
2565
|
+
marginBalance: safeFloat(usdt.equity),
|
|
2566
|
+
};
|
|
2567
|
+
}
|
|
2568
|
+
async getPositions() {
|
|
2569
|
+
const data = await this.request('GET', '/api/v1/private/position/open_positions', {}, true);
|
|
2570
|
+
// Get mark prices
|
|
2571
|
+
const tickers = await this.request('GET', '/api/v1/contract/ticker');
|
|
2572
|
+
const priceMap = new Map(tickers.map(t => [t.symbol, safeFloat(t.lastPrice)]));
|
|
2573
|
+
return data.map(p => {
|
|
2574
|
+
const size = safeFloat(p.holdVol);
|
|
2575
|
+
const entryPrice = safeFloat(p.openAvgPrice);
|
|
2576
|
+
const markPrice = priceMap.get(p.symbol) || entryPrice;
|
|
2577
|
+
const pnl = safeFloat(p.unrealised);
|
|
2578
|
+
const positionValue = size * entryPrice;
|
|
2579
|
+
return {
|
|
2580
|
+
exchange: 'mexc',
|
|
2581
|
+
symbol: p.symbol,
|
|
2582
|
+
side: (p.positionType === 1 ? 'LONG' : 'SHORT'),
|
|
2583
|
+
size,
|
|
2584
|
+
entryPrice,
|
|
2585
|
+
markPrice,
|
|
2586
|
+
liquidationPrice: safeFloat(p.liquidatePrice),
|
|
2587
|
+
leverage: p.leverage || 1,
|
|
2588
|
+
marginType: 'ISOLATED', // MEXC uses isolated by default
|
|
2589
|
+
unrealizedPnl: pnl,
|
|
2590
|
+
unrealizedPnlPct: positionValue > 0 ? (pnl / positionValue) * 100 : 0,
|
|
2591
|
+
margin: safeFloat(p.margin || p.im),
|
|
2592
|
+
timestamp: Date.now(),
|
|
2593
|
+
};
|
|
2594
|
+
});
|
|
2595
|
+
}
|
|
2596
|
+
async setLeverage(symbol, leverage) {
|
|
2597
|
+
const openType = this._marginType === 'CROSS' ? 2 : 1;
|
|
2598
|
+
await this.request('POST', '/api/v1/private/position/change_leverage', {
|
|
2599
|
+
symbol,
|
|
2600
|
+
leverage,
|
|
2601
|
+
openType,
|
|
2602
|
+
positionType: 1, // long
|
|
2603
|
+
}, true);
|
|
2604
|
+
await this.request('POST', '/api/v1/private/position/change_leverage', {
|
|
2605
|
+
symbol,
|
|
2606
|
+
leverage,
|
|
2607
|
+
openType,
|
|
2608
|
+
positionType: 2, // short
|
|
2609
|
+
}, true);
|
|
2610
|
+
}
|
|
2611
|
+
async placeOrder(order) {
|
|
2612
|
+
if (this.dryRun) {
|
|
2613
|
+
logger_1.logger.info({ order }, '[DRY RUN] Would place MEXC futures order');
|
|
2614
|
+
return this.createDryRunOrder(order);
|
|
2615
|
+
}
|
|
2616
|
+
if (order.leverage) {
|
|
2617
|
+
await this.setLeverage(order.symbol, order.leverage);
|
|
2618
|
+
}
|
|
2619
|
+
const isStopOrder = order.type === 'STOP_MARKET' || order.type === 'TAKE_PROFIT_MARKET';
|
|
2620
|
+
// MEXC uses vol (contracts) not size
|
|
2621
|
+
const params = {
|
|
2622
|
+
symbol: order.symbol,
|
|
2623
|
+
side: order.side === 'BUY' ? 1 : 2, // 1=open long/close short, 2=close long/open short
|
|
2624
|
+
type: (order.type === 'MARKET' || isStopOrder) ? 5 : 1, // 1=limit, 5=market
|
|
2625
|
+
vol: order.size,
|
|
2626
|
+
openType: this._marginType === 'CROSS' ? 2 : 1, // 1=isolated, 2=cross
|
|
2627
|
+
};
|
|
2628
|
+
// Determine if opening or closing
|
|
2629
|
+
const isOpening = !order.reduceOnly && !isStopOrder;
|
|
2630
|
+
if (order.side === 'BUY') {
|
|
2631
|
+
params.side = isOpening ? 1 : 4; // 1=open long, 4=close short
|
|
2632
|
+
}
|
|
2633
|
+
else {
|
|
2634
|
+
params.side = isOpening ? 3 : 2; // 3=open short, 2=close long
|
|
2635
|
+
}
|
|
2636
|
+
if (order.price && order.type === 'LIMIT') {
|
|
2637
|
+
params.price = order.price;
|
|
2638
|
+
}
|
|
2639
|
+
// Set trigger price for stop orders
|
|
2640
|
+
if (isStopOrder && order.stopPrice) {
|
|
2641
|
+
params.triggerPrice = order.stopPrice;
|
|
2642
|
+
params.triggerType = 1; // trigger by mark price
|
|
2643
|
+
}
|
|
2644
|
+
const result = await this.request('POST', '/api/v1/private/order/submit', params, true);
|
|
2645
|
+
const mainOrder = {
|
|
2646
|
+
id: result.orderId,
|
|
2647
|
+
exchange: 'mexc',
|
|
2648
|
+
symbol: order.symbol,
|
|
2649
|
+
side: order.side,
|
|
2650
|
+
type: order.type,
|
|
2651
|
+
size: order.size,
|
|
2652
|
+
price: order.price,
|
|
2653
|
+
leverage: order.leverage || 1,
|
|
2654
|
+
reduceOnly: order.reduceOnly || false,
|
|
2655
|
+
status: 'NEW',
|
|
2656
|
+
filledSize: 0,
|
|
2657
|
+
avgFillPrice: 0,
|
|
2658
|
+
timestamp: Date.now(),
|
|
2659
|
+
};
|
|
2660
|
+
// Place TP/SL if specified — don't let failures lose the main order
|
|
2661
|
+
try {
|
|
2662
|
+
if (order.takeProfit) {
|
|
2663
|
+
await this.request('POST', '/api/v1/private/order/submit_tp_sl', {
|
|
2664
|
+
symbol: order.symbol,
|
|
2665
|
+
triggerPrice: order.takeProfit,
|
|
2666
|
+
triggerType: 1, // take profit
|
|
2667
|
+
executePriceType: 1, // market
|
|
2668
|
+
}, true);
|
|
2669
|
+
}
|
|
2670
|
+
}
|
|
2671
|
+
catch (err) {
|
|
2672
|
+
logger_1.logger.error({ err, symbol: order.symbol, takeProfit: order.takeProfit }, 'MEXC: Failed to place take-profit order (main order succeeded)');
|
|
2673
|
+
}
|
|
2674
|
+
try {
|
|
2675
|
+
if (order.stopLoss) {
|
|
2676
|
+
await this.request('POST', '/api/v1/private/order/submit_tp_sl', {
|
|
2677
|
+
symbol: order.symbol,
|
|
2678
|
+
triggerPrice: order.stopLoss,
|
|
2679
|
+
triggerType: 2, // stop loss
|
|
2680
|
+
executePriceType: 1, // market
|
|
2681
|
+
}, true);
|
|
2682
|
+
}
|
|
2683
|
+
}
|
|
2684
|
+
catch (err) {
|
|
2685
|
+
logger_1.logger.error({ err, symbol: order.symbol, stopLoss: order.stopLoss }, 'MEXC: Failed to place stop-loss order (main order succeeded)');
|
|
2686
|
+
}
|
|
2687
|
+
return mainOrder;
|
|
2688
|
+
}
|
|
2689
|
+
createDryRunOrder(order) {
|
|
2690
|
+
const isMarket = order.type === 'MARKET';
|
|
2691
|
+
return {
|
|
2692
|
+
id: `dry-${Date.now()}-${(0, crypto_1.randomBytes)(4).toString('hex')}`,
|
|
2693
|
+
exchange: 'mexc',
|
|
2694
|
+
symbol: order.symbol,
|
|
2695
|
+
side: order.side,
|
|
2696
|
+
type: order.type,
|
|
2697
|
+
size: order.size,
|
|
2698
|
+
price: order.price,
|
|
2699
|
+
leverage: order.leverage || 1,
|
|
2700
|
+
reduceOnly: order.reduceOnly || false,
|
|
2701
|
+
status: isMarket ? 'FILLED' : 'NEW',
|
|
2702
|
+
filledSize: isMarket ? order.size : 0,
|
|
2703
|
+
avgFillPrice: isMarket ? (order.price || 0) : 0,
|
|
2704
|
+
timestamp: Date.now(),
|
|
2705
|
+
};
|
|
2706
|
+
}
|
|
2707
|
+
async cancelOrder(symbol, orderId) {
|
|
2708
|
+
await this.request('POST', '/api/v1/private/order/cancel', {
|
|
2709
|
+
symbol,
|
|
2710
|
+
orderId,
|
|
2711
|
+
}, true);
|
|
2712
|
+
}
|
|
2713
|
+
async closePosition(symbol) {
|
|
2714
|
+
const positions = await this.getPositions();
|
|
2715
|
+
const position = positions.find(p => p.symbol === symbol);
|
|
2716
|
+
if (!position)
|
|
2717
|
+
return null;
|
|
2718
|
+
return this.placeOrder({
|
|
2719
|
+
symbol,
|
|
2720
|
+
side: position.side === 'LONG' ? 'SELL' : 'BUY',
|
|
2721
|
+
type: 'MARKET',
|
|
2722
|
+
size: position.size,
|
|
2723
|
+
reduceOnly: true,
|
|
2724
|
+
});
|
|
2725
|
+
}
|
|
2726
|
+
async getMarkets() {
|
|
2727
|
+
const [contracts, tickers] = await Promise.all([
|
|
2728
|
+
this.request('GET', '/api/v1/contract/detail'),
|
|
2729
|
+
this.request('GET', '/api/v1/contract/ticker'),
|
|
2730
|
+
]);
|
|
2731
|
+
const tickerMap = new Map(tickers.map(t => [t.symbol, t]));
|
|
2732
|
+
return contracts
|
|
2733
|
+
.filter(c => c.quoteCoin === 'USDT')
|
|
2734
|
+
.map(c => {
|
|
2735
|
+
const ticker = tickerMap.get(c.symbol);
|
|
2736
|
+
return {
|
|
2737
|
+
exchange: 'mexc',
|
|
2738
|
+
symbol: c.symbol,
|
|
2739
|
+
baseAsset: c.baseCoin,
|
|
2740
|
+
quoteAsset: c.quoteCoin,
|
|
2741
|
+
tickSize: parseFloat(c.priceUnit),
|
|
2742
|
+
lotSize: parseFloat(c.volUnit),
|
|
2743
|
+
minNotional: parseFloat(c.minVol),
|
|
2744
|
+
maxLeverage: c.maxLeverage,
|
|
2745
|
+
fundingRate: parseFloat(ticker?.fundingRate || '0') * 100,
|
|
2746
|
+
markPrice: parseFloat(ticker?.fairPrice || ticker?.lastPrice || '0'),
|
|
2747
|
+
indexPrice: parseFloat(ticker?.indexPrice || '0'),
|
|
2748
|
+
volume24h: parseFloat(ticker?.volume24 || '0'),
|
|
2749
|
+
};
|
|
2750
|
+
});
|
|
2751
|
+
}
|
|
2752
|
+
async getFundingRate(symbol) {
|
|
2753
|
+
const data = await this.request('GET', '/api/v1/contract/funding_rate', { symbol });
|
|
2754
|
+
return {
|
|
2755
|
+
rate: parseFloat(data.fundingRate) * 100,
|
|
2756
|
+
nextFundingTime: data.nextSettleTime,
|
|
2757
|
+
};
|
|
2758
|
+
}
|
|
2759
|
+
async getOpenOrders(symbol) {
|
|
2760
|
+
const params = {};
|
|
2761
|
+
if (symbol)
|
|
2762
|
+
params.symbol = symbol;
|
|
2763
|
+
const data = await this.request('GET', '/api/v1/private/order/open_orders', params, true);
|
|
2764
|
+
return data.map(o => ({
|
|
2765
|
+
id: o.orderId,
|
|
2766
|
+
exchange: 'mexc',
|
|
2767
|
+
symbol: o.symbol,
|
|
2768
|
+
side: ((o.side === 1 || o.side === 4) ? 'BUY' : 'SELL'),
|
|
2769
|
+
type: (o.type === 5 ? 'MARKET' : 'LIMIT'),
|
|
2770
|
+
size: parseFloat(o.vol),
|
|
2771
|
+
price: parseFloat(o.price),
|
|
2772
|
+
leverage: 1,
|
|
2773
|
+
reduceOnly: o.side === 2 || o.side === 4,
|
|
2774
|
+
status: this.mapMexcStatus(o.state),
|
|
2775
|
+
filledSize: parseFloat(o.dealVol),
|
|
2776
|
+
avgFillPrice: parseFloat(o.dealAvgPrice),
|
|
2777
|
+
timestamp: o.createTime,
|
|
2778
|
+
}));
|
|
2779
|
+
}
|
|
2780
|
+
mapMexcStatus(state) {
|
|
2781
|
+
// 1=pending, 2=filled, 3=partially filled, 4=canceled, 5=partially canceled
|
|
2782
|
+
const statusMap = {
|
|
2783
|
+
1: 'NEW',
|
|
2784
|
+
2: 'FILLED',
|
|
2785
|
+
3: 'PARTIALLY_FILLED',
|
|
2786
|
+
4: 'CANCELED',
|
|
2787
|
+
5: 'PARTIALLY_FILLED',
|
|
2788
|
+
};
|
|
2789
|
+
return statusMap[state] || 'NEW';
|
|
2790
|
+
}
|
|
2791
|
+
// =========== ADDITIONAL COMPREHENSIVE METHODS ===========
|
|
2792
|
+
async getAccountInfo() {
|
|
2793
|
+
const assets = await this.getBalance();
|
|
2794
|
+
const positions = await this.getPositions();
|
|
2795
|
+
return {
|
|
2796
|
+
exchange: 'mexc',
|
|
2797
|
+
totalWalletBalance: assets.total,
|
|
2798
|
+
totalUnrealizedProfit: assets.unrealizedPnl,
|
|
2799
|
+
totalMarginBalance: assets.marginBalance,
|
|
2800
|
+
totalPositionInitialMargin: 0,
|
|
2801
|
+
totalOpenOrderInitialMargin: 0,
|
|
2802
|
+
availableBalance: assets.available,
|
|
2803
|
+
maxWithdrawAmount: assets.available,
|
|
2804
|
+
canTrade: true,
|
|
2805
|
+
canDeposit: true,
|
|
2806
|
+
canWithdraw: true,
|
|
2807
|
+
positions,
|
|
2808
|
+
};
|
|
2809
|
+
}
|
|
2810
|
+
async getTradeHistory(symbol, limit = 100) {
|
|
2811
|
+
const params = { page_num: 1, page_size: limit };
|
|
2812
|
+
if (symbol)
|
|
2813
|
+
params.symbol = symbol;
|
|
2814
|
+
const data = await this.request('GET', '/api/v1/private/order/list/order_deals', params, true);
|
|
2815
|
+
return data.map(t => ({
|
|
2816
|
+
id: t.id,
|
|
2817
|
+
exchange: 'mexc',
|
|
2818
|
+
symbol: t.symbol,
|
|
2819
|
+
orderId: t.orderId,
|
|
2820
|
+
side: ((t.side === 1 || t.side === 4) ? 'BUY' : 'SELL'),
|
|
2821
|
+
price: parseFloat(t.price),
|
|
2822
|
+
quantity: parseFloat(t.vol),
|
|
2823
|
+
realizedPnl: parseFloat(t.profit),
|
|
2824
|
+
commission: parseFloat(t.fee),
|
|
2825
|
+
commissionAsset: t.feeCurrency,
|
|
2826
|
+
timestamp: t.timestamp,
|
|
2827
|
+
isMaker: t.maker,
|
|
2828
|
+
}));
|
|
2829
|
+
}
|
|
2830
|
+
async getOrderHistory(symbol, limit = 100) {
|
|
2831
|
+
const params = { page_num: 1, page_size: limit };
|
|
2832
|
+
if (symbol)
|
|
2833
|
+
params.symbol = symbol;
|
|
2834
|
+
const data = await this.request('GET', '/api/v1/private/order/list/history_orders', params, true);
|
|
2835
|
+
return data.map(o => ({
|
|
2836
|
+
id: o.orderId,
|
|
2837
|
+
exchange: 'mexc',
|
|
2838
|
+
symbol: o.symbol,
|
|
2839
|
+
side: ((o.side === 1 || o.side === 4) ? 'BUY' : 'SELL'),
|
|
2840
|
+
type: (o.type === 5 ? 'MARKET' : 'LIMIT'),
|
|
2841
|
+
size: parseFloat(o.vol),
|
|
2842
|
+
price: parseFloat(o.price),
|
|
2843
|
+
leverage: 1,
|
|
2844
|
+
reduceOnly: o.side === 2 || o.side === 4,
|
|
2845
|
+
status: this.mapMexcStatus(o.state),
|
|
2846
|
+
filledSize: parseFloat(o.dealVol),
|
|
2847
|
+
avgFillPrice: parseFloat(o.dealAvgPrice),
|
|
2848
|
+
timestamp: o.createTime,
|
|
2849
|
+
}));
|
|
2850
|
+
}
|
|
2851
|
+
async getKlines(symbol, interval, limit = 100) {
|
|
2852
|
+
const data = await this.request('GET', `/api/v1/contract/kline/${symbol}`, {
|
|
2853
|
+
interval,
|
|
2854
|
+
limit,
|
|
2855
|
+
});
|
|
2856
|
+
return data.time.map((t, i) => ({
|
|
2857
|
+
openTime: t * 1000,
|
|
2858
|
+
open: data.open[i],
|
|
2859
|
+
high: data.high[i],
|
|
2860
|
+
low: data.low[i],
|
|
2861
|
+
close: data.close[i],
|
|
2862
|
+
volume: data.vol[i],
|
|
2863
|
+
closeTime: (t + 60) * 1000,
|
|
2864
|
+
quoteVolume: 0,
|
|
2865
|
+
trades: 0,
|
|
2866
|
+
takerBuyVolume: 0,
|
|
2867
|
+
takerBuyQuoteVolume: 0,
|
|
2868
|
+
}));
|
|
2869
|
+
}
|
|
2870
|
+
async getOrderBook(symbol, limit = 100) {
|
|
2871
|
+
const data = await this.request('GET', `/api/v1/contract/depth/${symbol}`, { limit });
|
|
2872
|
+
return {
|
|
2873
|
+
exchange: 'mexc',
|
|
2874
|
+
symbol,
|
|
2875
|
+
lastUpdateId: data.version,
|
|
2876
|
+
bids: data.bids.map(([price, qty]) => [price, qty]),
|
|
2877
|
+
asks: data.asks.map(([price, qty]) => [price, qty]),
|
|
2878
|
+
timestamp: data.timestamp,
|
|
2879
|
+
};
|
|
2880
|
+
}
|
|
2881
|
+
async getPositionHistory(symbol, limit = 100) {
|
|
2882
|
+
const params = { page_num: 1, page_size: limit };
|
|
2883
|
+
if (symbol)
|
|
2884
|
+
params.symbol = symbol;
|
|
2885
|
+
const data = await this.request('GET', '/api/v1/private/position/list/history_positions', params, true);
|
|
2886
|
+
return data.map(p => ({
|
|
2887
|
+
symbol: p.symbol,
|
|
2888
|
+
side: (p.positionType === 1 ? 'LONG' : 'SHORT'),
|
|
2889
|
+
entryPrice: parseFloat(p.openAvgPrice),
|
|
2890
|
+
closePrice: parseFloat(p.closeAvgPrice),
|
|
2891
|
+
size: parseFloat(p.holdVol),
|
|
2892
|
+
realizedPnl: parseFloat(p.realised),
|
|
2893
|
+
openTime: p.openTime,
|
|
2894
|
+
closeTime: p.closeTime,
|
|
2895
|
+
}));
|
|
2896
|
+
}
|
|
2897
|
+
async getFundingHistory(symbol, limit = 100) {
|
|
2898
|
+
const params = { page_num: 1, page_size: limit };
|
|
2899
|
+
if (symbol)
|
|
2900
|
+
params.symbol = symbol;
|
|
2901
|
+
const data = await this.request('GET', '/api/v1/private/position/funding_records', params, true);
|
|
2902
|
+
return data.map(f => ({
|
|
2903
|
+
symbol: f.symbol,
|
|
2904
|
+
fundingRate: parseFloat(f.fundingRate) * 100,
|
|
2905
|
+
fundingTime: f.settleTime,
|
|
2906
|
+
}));
|
|
2907
|
+
}
|
|
2908
|
+
async modifyPositionMargin(symbol, amount, positionType) {
|
|
2909
|
+
await this.request('POST', '/api/v1/private/position/change_margin', {
|
|
2910
|
+
symbol,
|
|
2911
|
+
amount,
|
|
2912
|
+
type: amount > 0 ? 'ADD' : 'SUB',
|
|
2913
|
+
positionType, // 1=long, 2=short
|
|
2914
|
+
}, true);
|
|
2915
|
+
}
|
|
2916
|
+
async getPositionMode() {
|
|
2917
|
+
const data = await this.request('GET', '/api/v1/private/position/position_mode', {}, true);
|
|
2918
|
+
return data.positionMode === 1 ? 'hedge' : 'one_way';
|
|
2919
|
+
}
|
|
2920
|
+
async setPositionMode(hedgeMode) {
|
|
2921
|
+
await this.request('POST', '/api/v1/private/position/change_position_mode', {
|
|
2922
|
+
positionMode: hedgeMode ? 1 : 2,
|
|
2923
|
+
}, true);
|
|
2924
|
+
}
|
|
2925
|
+
async placeBatchOrders(orders) {
|
|
2926
|
+
if (this.dryRun) {
|
|
2927
|
+
return orders.map(o => this.createDryRunOrder(o));
|
|
2928
|
+
}
|
|
2929
|
+
const batchOrders = orders.map(order => ({
|
|
2930
|
+
symbol: order.symbol,
|
|
2931
|
+
side: order.side === 'BUY' ? (order.reduceOnly ? 4 : 1) : (order.reduceOnly ? 2 : 3),
|
|
2932
|
+
type: order.type === 'MARKET' ? 5 : 1,
|
|
2933
|
+
vol: order.size,
|
|
2934
|
+
price: order.price,
|
|
2935
|
+
openType: this._marginType === 'CROSS' ? 2 : 1,
|
|
2936
|
+
}));
|
|
2937
|
+
const result = await this.request('POST', '/api/v1/private/order/submit_batch', {
|
|
2938
|
+
orders: batchOrders,
|
|
2939
|
+
}, true);
|
|
2940
|
+
return result.map((r, i) => ({
|
|
2941
|
+
id: r.orderId,
|
|
2942
|
+
exchange: 'mexc',
|
|
2943
|
+
symbol: orders[i].symbol,
|
|
2944
|
+
side: orders[i].side,
|
|
2945
|
+
type: orders[i].type,
|
|
2946
|
+
size: orders[i].size,
|
|
2947
|
+
price: orders[i].price,
|
|
2948
|
+
leverage: orders[i].leverage || 1,
|
|
2949
|
+
reduceOnly: orders[i].reduceOnly || false,
|
|
2950
|
+
status: 'NEW',
|
|
2951
|
+
filledSize: 0,
|
|
2952
|
+
avgFillPrice: 0,
|
|
2953
|
+
timestamp: Date.now(),
|
|
2954
|
+
}));
|
|
2955
|
+
}
|
|
2956
|
+
async cancelAllOrders(symbol) {
|
|
2957
|
+
await this.request('POST', '/api/v1/private/order/cancel_all', { symbol }, true);
|
|
2958
|
+
}
|
|
2959
|
+
async getTickerPrice(symbol) {
|
|
2960
|
+
const data = await this.request('GET', '/api/v1/contract/ticker');
|
|
2961
|
+
const filtered = symbol ? data.filter(t => t.symbol === symbol) : data;
|
|
2962
|
+
return filtered.map(t => ({
|
|
2963
|
+
symbol: t.symbol,
|
|
2964
|
+
price: t.lastPrice,
|
|
2965
|
+
timestamp: t.timestamp,
|
|
2966
|
+
}));
|
|
2967
|
+
}
|
|
2968
|
+
async getRecentTrades(symbol, limit = 100) {
|
|
2969
|
+
const data = await this.request('GET', `/api/v1/contract/deals/${symbol}`, { limit });
|
|
2970
|
+
return data.map(t => ({
|
|
2971
|
+
price: t.p,
|
|
2972
|
+
size: t.v,
|
|
2973
|
+
side: t.T === 1 ? 'buy' : 'sell',
|
|
2974
|
+
timestamp: t.t,
|
|
2975
|
+
}));
|
|
2976
|
+
}
|
|
2977
|
+
async getRiskLimits() {
|
|
2978
|
+
const data = await this.request('GET', '/api/v1/private/account/risk_limit', {}, true);
|
|
2979
|
+
return data.map(r => ({
|
|
2980
|
+
symbol: r.symbol,
|
|
2981
|
+
maxLeverage: r.maxLeverage,
|
|
2982
|
+
maintenanceMarginRate: parseFloat(r.maintainMargin),
|
|
2983
|
+
riskLimitValue: parseFloat(r.riskLimitValue),
|
|
2984
|
+
}));
|
|
2985
|
+
}
|
|
2986
|
+
async getTieredFeeRate() {
|
|
2987
|
+
const data = await this.request('GET', '/api/v1/private/account/tiered_fee_rate', {}, true);
|
|
2988
|
+
return {
|
|
2989
|
+
makerFee: parseFloat(data.makerFeeRate) * 100,
|
|
2990
|
+
takerFee: parseFloat(data.takerFeeRate) * 100,
|
|
2991
|
+
level: data.level,
|
|
2992
|
+
};
|
|
2993
|
+
}
|
|
2994
|
+
async placeTriggerOrder(symbol, side, size, triggerPrice, triggerType, price) {
|
|
2995
|
+
const result = await this.request('POST', '/api/v1/private/planorder/place', {
|
|
2996
|
+
symbol,
|
|
2997
|
+
side: side === 'BUY' ? 1 : 3,
|
|
2998
|
+
vol: size,
|
|
2999
|
+
triggerPrice,
|
|
3000
|
+
triggerType: triggerType === 'ge' ? 1 : 2,
|
|
3001
|
+
executePriceType: price ? 1 : 2, // 1=limit, 2=market
|
|
3002
|
+
price: price || 0,
|
|
3003
|
+
openType: this._marginType === 'CROSS' ? 2 : 1,
|
|
3004
|
+
}, true);
|
|
3005
|
+
return result.orderId;
|
|
3006
|
+
}
|
|
3007
|
+
async cancelTriggerOrder(symbol, orderId) {
|
|
3008
|
+
await this.request('POST', '/api/v1/private/planorder/cancel', {
|
|
3009
|
+
symbol,
|
|
3010
|
+
orderId,
|
|
3011
|
+
}, true);
|
|
3012
|
+
}
|
|
3013
|
+
async cancelAllTriggerOrders(symbol) {
|
|
3014
|
+
await this.request('POST', '/api/v1/private/planorder/cancel_all', { symbol }, true);
|
|
3015
|
+
}
|
|
3016
|
+
async getTriggerOrders(symbol) {
|
|
3017
|
+
const params = { states: 'NOT_TRIGGERED', page_num: 1, page_size: 100 };
|
|
3018
|
+
if (symbol)
|
|
3019
|
+
params.symbol = symbol;
|
|
3020
|
+
const data = await this.request('GET', '/api/v1/private/planorder/list/orders', params, true);
|
|
3021
|
+
return data.map(o => ({
|
|
3022
|
+
orderId: o.id,
|
|
3023
|
+
symbol: o.symbol,
|
|
3024
|
+
side: ((o.side === 1 || o.side === 4) ? 'BUY' : 'SELL'),
|
|
3025
|
+
size: parseFloat(o.vol),
|
|
3026
|
+
triggerPrice: parseFloat(o.triggerPrice),
|
|
3027
|
+
status: o.state,
|
|
3028
|
+
}));
|
|
3029
|
+
}
|
|
3030
|
+
async getServerTime() {
|
|
3031
|
+
const data = await this.request('GET', '/api/v1/contract/ping');
|
|
3032
|
+
return data.serverTime;
|
|
3033
|
+
}
|
|
3034
|
+
}
|
|
3035
|
+
exports.MexcFuturesClient = MexcFuturesClient;
|
|
3036
|
+
// =============================================================================
|
|
3037
|
+
// FUTURES DATABASE MANAGER
|
|
3038
|
+
// =============================================================================
|
|
3039
|
+
class FuturesDatabase {
|
|
3040
|
+
pool = null;
|
|
3041
|
+
initialized = false;
|
|
3042
|
+
async connect(config) {
|
|
3043
|
+
const connectionString = config.connectionString ||
|
|
3044
|
+
`postgres://${config.user}:${config.password}@${config.host || 'localhost'}:${config.port || 5432}/${config.database}`;
|
|
3045
|
+
this.pool = new pg_1.Pool({ connectionString });
|
|
3046
|
+
// Test connection
|
|
3047
|
+
const client = await this.pool.connect();
|
|
3048
|
+
try {
|
|
3049
|
+
await client.query('SELECT 1');
|
|
3050
|
+
logger_1.logger.info('Connected to futures database');
|
|
3051
|
+
}
|
|
3052
|
+
finally {
|
|
3053
|
+
client.release();
|
|
3054
|
+
}
|
|
3055
|
+
}
|
|
3056
|
+
async initialize() {
|
|
3057
|
+
if (this.initialized || !this.pool)
|
|
3058
|
+
return;
|
|
3059
|
+
const client = await this.pool.connect();
|
|
3060
|
+
try {
|
|
3061
|
+
// Create futures_trades table
|
|
3062
|
+
await client.query(`
|
|
3063
|
+
CREATE TABLE IF NOT EXISTS futures_trades (
|
|
3064
|
+
id SERIAL PRIMARY KEY,
|
|
3065
|
+
exchange VARCHAR(20) NOT NULL,
|
|
3066
|
+
symbol VARCHAR(30) NOT NULL,
|
|
3067
|
+
side VARCHAR(10) NOT NULL,
|
|
3068
|
+
entry_price DECIMAL(20, 8) NOT NULL,
|
|
3069
|
+
exit_price DECIMAL(20, 8),
|
|
3070
|
+
size DECIMAL(20, 8) NOT NULL,
|
|
3071
|
+
leverage INTEGER NOT NULL,
|
|
3072
|
+
entry_time TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
|
3073
|
+
exit_time TIMESTAMPTZ,
|
|
3074
|
+
pnl DECIMAL(20, 8),
|
|
3075
|
+
pnl_pct DECIMAL(10, 4),
|
|
3076
|
+
fees DECIMAL(20, 8),
|
|
3077
|
+
strategy VARCHAR(100),
|
|
3078
|
+
strategy_variant VARCHAR(100),
|
|
3079
|
+
variables JSONB DEFAULT '{}',
|
|
3080
|
+
tags TEXT[],
|
|
3081
|
+
notes TEXT,
|
|
3082
|
+
created_at TIMESTAMPTZ DEFAULT NOW()
|
|
3083
|
+
)
|
|
3084
|
+
`);
|
|
3085
|
+
// Create futures_strategies table
|
|
3086
|
+
await client.query(`
|
|
3087
|
+
CREATE TABLE IF NOT EXISTS futures_strategies (
|
|
3088
|
+
id SERIAL PRIMARY KEY,
|
|
3089
|
+
name VARCHAR(100) UNIQUE NOT NULL,
|
|
3090
|
+
version VARCHAR(20) NOT NULL,
|
|
3091
|
+
description TEXT,
|
|
3092
|
+
variables JSONB NOT NULL DEFAULT '[]',
|
|
3093
|
+
enabled BOOLEAN DEFAULT true,
|
|
3094
|
+
created_at TIMESTAMPTZ DEFAULT NOW(),
|
|
3095
|
+
updated_at TIMESTAMPTZ DEFAULT NOW()
|
|
3096
|
+
)
|
|
3097
|
+
`);
|
|
3098
|
+
// Create futures_strategy_variants table
|
|
3099
|
+
await client.query(`
|
|
3100
|
+
CREATE TABLE IF NOT EXISTS futures_strategy_variants (
|
|
3101
|
+
id SERIAL PRIMARY KEY,
|
|
3102
|
+
strategy_name VARCHAR(100) NOT NULL,
|
|
3103
|
+
variant_name VARCHAR(100) NOT NULL,
|
|
3104
|
+
variables JSONB NOT NULL DEFAULT '{}',
|
|
3105
|
+
enabled BOOLEAN DEFAULT true,
|
|
3106
|
+
created_at TIMESTAMPTZ DEFAULT NOW(),
|
|
3107
|
+
UNIQUE(strategy_name, variant_name)
|
|
3108
|
+
)
|
|
3109
|
+
`);
|
|
3110
|
+
// Create indexes for performance
|
|
3111
|
+
await client.query(`
|
|
3112
|
+
CREATE INDEX IF NOT EXISTS idx_futures_trades_strategy ON futures_trades(strategy);
|
|
3113
|
+
CREATE INDEX IF NOT EXISTS idx_futures_trades_variant ON futures_trades(strategy_variant);
|
|
3114
|
+
CREATE INDEX IF NOT EXISTS idx_futures_trades_exchange ON futures_trades(exchange);
|
|
3115
|
+
CREATE INDEX IF NOT EXISTS idx_futures_trades_symbol ON futures_trades(symbol);
|
|
3116
|
+
CREATE INDEX IF NOT EXISTS idx_futures_trades_entry_time ON futures_trades(entry_time);
|
|
3117
|
+
`);
|
|
3118
|
+
this.initialized = true;
|
|
3119
|
+
logger_1.logger.info('Futures database initialized');
|
|
3120
|
+
}
|
|
3121
|
+
finally {
|
|
3122
|
+
client.release();
|
|
3123
|
+
}
|
|
3124
|
+
}
|
|
3125
|
+
async recordTrade(trade) {
|
|
3126
|
+
if (!this.pool)
|
|
3127
|
+
throw new Error('Database not connected');
|
|
3128
|
+
const result = await this.pool.query(`INSERT INTO futures_trades
|
|
3129
|
+
(exchange, symbol, side, entry_price, exit_price, size, leverage, entry_time, exit_time, pnl, pnl_pct, fees, strategy, strategy_variant, variables, tags, notes)
|
|
3130
|
+
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17)
|
|
3131
|
+
RETURNING id`, [
|
|
3132
|
+
trade.exchange,
|
|
3133
|
+
trade.symbol,
|
|
3134
|
+
trade.side,
|
|
3135
|
+
trade.entryPrice,
|
|
3136
|
+
trade.exitPrice || null,
|
|
3137
|
+
trade.size,
|
|
3138
|
+
trade.leverage,
|
|
3139
|
+
trade.entryTime,
|
|
3140
|
+
trade.exitTime || null,
|
|
3141
|
+
trade.pnl || null,
|
|
3142
|
+
trade.pnlPct || null,
|
|
3143
|
+
trade.fees || null,
|
|
3144
|
+
trade.strategy || null,
|
|
3145
|
+
trade.strategyVariant || null,
|
|
3146
|
+
JSON.stringify(trade.variables || {}),
|
|
3147
|
+
trade.tags || null,
|
|
3148
|
+
trade.notes || null,
|
|
3149
|
+
]);
|
|
3150
|
+
return result.rows[0].id;
|
|
3151
|
+
}
|
|
3152
|
+
async updateTrade(id, updates) {
|
|
3153
|
+
if (!this.pool)
|
|
3154
|
+
throw new Error('Database not connected');
|
|
3155
|
+
const setClauses = [];
|
|
3156
|
+
const values = [];
|
|
3157
|
+
let paramIndex = 1;
|
|
3158
|
+
if (updates.exitPrice !== undefined) {
|
|
3159
|
+
setClauses.push(`exit_price = $${paramIndex++}`);
|
|
3160
|
+
values.push(updates.exitPrice);
|
|
3161
|
+
}
|
|
3162
|
+
if (updates.exitTime !== undefined) {
|
|
3163
|
+
setClauses.push(`exit_time = $${paramIndex++}`);
|
|
3164
|
+
values.push(updates.exitTime);
|
|
3165
|
+
}
|
|
3166
|
+
if (updates.pnl !== undefined) {
|
|
3167
|
+
setClauses.push(`pnl = $${paramIndex++}`);
|
|
3168
|
+
values.push(updates.pnl);
|
|
3169
|
+
}
|
|
3170
|
+
if (updates.pnlPct !== undefined) {
|
|
3171
|
+
setClauses.push(`pnl_pct = $${paramIndex++}`);
|
|
3172
|
+
values.push(updates.pnlPct);
|
|
3173
|
+
}
|
|
3174
|
+
if (updates.fees !== undefined) {
|
|
3175
|
+
setClauses.push(`fees = $${paramIndex++}`);
|
|
3176
|
+
values.push(updates.fees);
|
|
3177
|
+
}
|
|
3178
|
+
if (updates.notes !== undefined) {
|
|
3179
|
+
setClauses.push(`notes = $${paramIndex++}`);
|
|
3180
|
+
values.push(updates.notes);
|
|
3181
|
+
}
|
|
3182
|
+
if (setClauses.length === 0)
|
|
3183
|
+
return;
|
|
3184
|
+
values.push(id);
|
|
3185
|
+
await this.pool.query(`UPDATE futures_trades SET ${setClauses.join(', ')} WHERE id = $${paramIndex}`, values);
|
|
3186
|
+
}
|
|
3187
|
+
async getTrades(filters) {
|
|
3188
|
+
if (!this.pool)
|
|
3189
|
+
throw new Error('Database not connected');
|
|
3190
|
+
let query = 'SELECT * FROM futures_trades WHERE 1=1';
|
|
3191
|
+
const values = [];
|
|
3192
|
+
let paramIndex = 1;
|
|
3193
|
+
if (filters?.strategy) {
|
|
3194
|
+
query += ` AND strategy = $${paramIndex++}`;
|
|
3195
|
+
values.push(filters.strategy);
|
|
3196
|
+
}
|
|
3197
|
+
if (filters?.strategyVariant) {
|
|
3198
|
+
query += ` AND strategy_variant = $${paramIndex++}`;
|
|
3199
|
+
values.push(filters.strategyVariant);
|
|
3200
|
+
}
|
|
3201
|
+
if (filters?.exchange) {
|
|
3202
|
+
query += ` AND exchange = $${paramIndex++}`;
|
|
3203
|
+
values.push(filters.exchange);
|
|
3204
|
+
}
|
|
3205
|
+
if (filters?.symbol) {
|
|
3206
|
+
query += ` AND symbol = $${paramIndex++}`;
|
|
3207
|
+
values.push(filters.symbol);
|
|
3208
|
+
}
|
|
3209
|
+
if (filters?.startDate) {
|
|
3210
|
+
query += ` AND entry_time >= $${paramIndex++}`;
|
|
3211
|
+
values.push(filters.startDate);
|
|
3212
|
+
}
|
|
3213
|
+
if (filters?.endDate) {
|
|
3214
|
+
query += ` AND entry_time <= $${paramIndex++}`;
|
|
3215
|
+
values.push(filters.endDate);
|
|
3216
|
+
}
|
|
3217
|
+
query += ' ORDER BY entry_time DESC';
|
|
3218
|
+
if (filters?.limit) {
|
|
3219
|
+
query += ` LIMIT $${paramIndex++}`;
|
|
3220
|
+
values.push(filters.limit);
|
|
3221
|
+
}
|
|
3222
|
+
const result = await this.pool.query(query, values);
|
|
3223
|
+
return result.rows.map(row => ({
|
|
3224
|
+
id: row.id,
|
|
3225
|
+
exchange: row.exchange,
|
|
3226
|
+
symbol: row.symbol,
|
|
3227
|
+
side: row.side,
|
|
3228
|
+
entryPrice: parseFloat(row.entry_price),
|
|
3229
|
+
exitPrice: row.exit_price ? parseFloat(row.exit_price) : undefined,
|
|
3230
|
+
size: parseFloat(row.size),
|
|
3231
|
+
leverage: row.leverage,
|
|
3232
|
+
entryTime: row.entry_time,
|
|
3233
|
+
exitTime: row.exit_time || undefined,
|
|
3234
|
+
pnl: row.pnl ? parseFloat(row.pnl) : undefined,
|
|
3235
|
+
pnlPct: row.pnl_pct ? parseFloat(row.pnl_pct) : undefined,
|
|
3236
|
+
fees: row.fees ? parseFloat(row.fees) : undefined,
|
|
3237
|
+
strategy: row.strategy || undefined,
|
|
3238
|
+
strategyVariant: row.strategy_variant || undefined,
|
|
3239
|
+
variables: row.variables,
|
|
3240
|
+
tags: row.tags || undefined,
|
|
3241
|
+
notes: row.notes || undefined,
|
|
3242
|
+
}));
|
|
3243
|
+
}
|
|
3244
|
+
async getStrategyPerformance(strategyName, variantName) {
|
|
3245
|
+
if (!this.pool)
|
|
3246
|
+
throw new Error('Database not connected');
|
|
3247
|
+
let query = `
|
|
3248
|
+
SELECT
|
|
3249
|
+
COUNT(*) as total_trades,
|
|
3250
|
+
COUNT(CASE WHEN pnl > 0 THEN 1 END) as winning_trades,
|
|
3251
|
+
COUNT(CASE WHEN pnl <= 0 THEN 1 END) as losing_trades,
|
|
3252
|
+
COALESCE(SUM(pnl), 0) as total_pnl,
|
|
3253
|
+
COALESCE(AVG(pnl), 0) as avg_pnl,
|
|
3254
|
+
COALESCE(AVG(pnl_pct), 0) as avg_pnl_pct,
|
|
3255
|
+
COALESCE(AVG(EXTRACT(EPOCH FROM (exit_time - entry_time))), 0) as avg_holding_seconds
|
|
3256
|
+
FROM futures_trades
|
|
3257
|
+
WHERE strategy = $1 AND exit_time IS NOT NULL
|
|
3258
|
+
`;
|
|
3259
|
+
const values = [strategyName];
|
|
3260
|
+
if (variantName) {
|
|
3261
|
+
query += ' AND strategy_variant = $2';
|
|
3262
|
+
values.push(variantName);
|
|
3263
|
+
}
|
|
3264
|
+
const result = await this.pool.query(query, values);
|
|
3265
|
+
const row = result.rows[0];
|
|
3266
|
+
const totalTrades = parseInt(row.total_trades);
|
|
3267
|
+
const winningTrades = parseInt(row.winning_trades);
|
|
3268
|
+
const losingTrades = parseInt(row.losing_trades);
|
|
3269
|
+
return {
|
|
3270
|
+
strategyName,
|
|
3271
|
+
variantName,
|
|
3272
|
+
totalTrades,
|
|
3273
|
+
winningTrades,
|
|
3274
|
+
losingTrades,
|
|
3275
|
+
winRate: totalTrades > 0 ? (winningTrades / totalTrades) * 100 : 0,
|
|
3276
|
+
totalPnl: parseFloat(row.total_pnl),
|
|
3277
|
+
avgPnl: parseFloat(row.avg_pnl),
|
|
3278
|
+
avgPnlPct: parseFloat(row.avg_pnl_pct),
|
|
3279
|
+
maxDrawdown: 0, // Calculated separately if needed
|
|
3280
|
+
avgHoldingTime: parseFloat(row.avg_holding_seconds) / 60, // Convert to minutes
|
|
3281
|
+
};
|
|
3282
|
+
}
|
|
3283
|
+
async compareVariants(strategyName) {
|
|
3284
|
+
if (!this.pool)
|
|
3285
|
+
throw new Error('Database not connected');
|
|
3286
|
+
const result = await this.pool.query(`SELECT DISTINCT strategy_variant FROM futures_trades WHERE strategy = $1`, [strategyName]);
|
|
3287
|
+
const performances = await Promise.all(result.rows.map(row => this.getStrategyPerformance(strategyName, row.strategy_variant)));
|
|
3288
|
+
return performances.sort((a, b) => b.winRate - a.winRate);
|
|
3289
|
+
}
|
|
3290
|
+
async saveStrategyVariant(variant) {
|
|
3291
|
+
if (!this.pool)
|
|
3292
|
+
throw new Error('Database not connected');
|
|
3293
|
+
await this.pool.query(`INSERT INTO futures_strategy_variants (strategy_name, variant_name, variables, enabled)
|
|
3294
|
+
VALUES ($1, $2, $3, $4)
|
|
3295
|
+
ON CONFLICT (strategy_name, variant_name)
|
|
3296
|
+
DO UPDATE SET variables = $3, enabled = $4`, [variant.strategyName, variant.variantName, JSON.stringify(variant.variables), variant.enabled]);
|
|
3297
|
+
}
|
|
3298
|
+
async getStrategyVariants(strategyName) {
|
|
3299
|
+
if (!this.pool)
|
|
3300
|
+
throw new Error('Database not connected');
|
|
3301
|
+
const result = await this.pool.query(`SELECT * FROM futures_strategy_variants WHERE strategy_name = $1 AND enabled = true`, [strategyName]);
|
|
3302
|
+
return result.rows.map(row => ({
|
|
3303
|
+
strategyName: row.strategy_name,
|
|
3304
|
+
variantName: row.variant_name,
|
|
3305
|
+
variables: row.variables,
|
|
3306
|
+
enabled: row.enabled,
|
|
3307
|
+
}));
|
|
3308
|
+
}
|
|
3309
|
+
async disconnect() {
|
|
3310
|
+
if (this.pool) {
|
|
3311
|
+
await this.pool.end();
|
|
3312
|
+
this.pool = null;
|
|
3313
|
+
this.initialized = false;
|
|
3314
|
+
logger_1.logger.info('Disconnected from futures database');
|
|
3315
|
+
}
|
|
3316
|
+
}
|
|
3317
|
+
}
|
|
3318
|
+
exports.FuturesDatabase = FuturesDatabase;
|
|
3319
|
+
// =============================================================================
|
|
3320
|
+
// STRATEGY ENGINE
|
|
3321
|
+
// =============================================================================
|
|
3322
|
+
class StrategyEngine {
|
|
3323
|
+
strategies = new Map();
|
|
3324
|
+
variants = new Map();
|
|
3325
|
+
activePositions = new Map();
|
|
3326
|
+
db = null;
|
|
3327
|
+
service = null;
|
|
3328
|
+
registerStrategy(strategy) {
|
|
3329
|
+
this.strategies.set(strategy.name, strategy);
|
|
3330
|
+
logger_1.logger.info({ strategy: strategy.name, version: strategy.version }, 'Registered strategy');
|
|
3331
|
+
}
|
|
3332
|
+
addVariant(variant) {
|
|
3333
|
+
const variants = this.variants.get(variant.strategyName) || [];
|
|
3334
|
+
variants.push(variant);
|
|
3335
|
+
this.variants.set(variant.strategyName, variants);
|
|
3336
|
+
logger_1.logger.info({ strategy: variant.strategyName, variant: variant.variantName }, 'Added strategy variant');
|
|
3337
|
+
}
|
|
3338
|
+
async loadVariantsFromDb(db) {
|
|
3339
|
+
this.db = db;
|
|
3340
|
+
for (const strategyName of this.strategies.keys()) {
|
|
3341
|
+
const variants = await db.getStrategyVariants(strategyName);
|
|
3342
|
+
this.variants.set(strategyName, variants);
|
|
3343
|
+
}
|
|
3344
|
+
}
|
|
3345
|
+
connectService(service) {
|
|
3346
|
+
this.service = service;
|
|
3347
|
+
}
|
|
3348
|
+
getStrategies() {
|
|
3349
|
+
return Array.from(this.strategies.keys());
|
|
3350
|
+
}
|
|
3351
|
+
getVariants(strategyName) {
|
|
3352
|
+
return this.variants.get(strategyName) || [];
|
|
3353
|
+
}
|
|
3354
|
+
async evaluateEntry(exchange, market, strategyName, variantName) {
|
|
3355
|
+
const strategy = this.strategies.get(strategyName);
|
|
3356
|
+
if (!strategy)
|
|
3357
|
+
throw new Error(`Strategy ${strategyName} not found`);
|
|
3358
|
+
// Get variant variables or use defaults
|
|
3359
|
+
let variables = {};
|
|
3360
|
+
if (variantName) {
|
|
3361
|
+
const variants = this.variants.get(strategyName) || [];
|
|
3362
|
+
const variant = variants.find(v => v.variantName === variantName);
|
|
3363
|
+
if (variant) {
|
|
3364
|
+
variables = variant.variables;
|
|
3365
|
+
}
|
|
3366
|
+
}
|
|
3367
|
+
// Fill in defaults for missing variables
|
|
3368
|
+
for (const v of strategy.variables) {
|
|
3369
|
+
if (variables[v.name] === undefined && typeof v.default === 'number') {
|
|
3370
|
+
variables[v.name] = v.default;
|
|
3371
|
+
}
|
|
3372
|
+
}
|
|
3373
|
+
const signal = await strategy.entryCondition(market, variables);
|
|
3374
|
+
return { signal, variables };
|
|
3375
|
+
}
|
|
3376
|
+
async executeTrade(exchange, symbol, signal, strategyName, variantName, variables) {
|
|
3377
|
+
if (!this.service)
|
|
3378
|
+
throw new Error('FuturesService not connected');
|
|
3379
|
+
if (!this.db)
|
|
3380
|
+
throw new Error('Database not connected');
|
|
3381
|
+
const strategy = this.strategies.get(strategyName);
|
|
3382
|
+
if (!strategy)
|
|
3383
|
+
throw new Error(`Strategy ${strategyName} not found`);
|
|
3384
|
+
const balance = await this.service.getBalance(exchange);
|
|
3385
|
+
const markets = await this.service.getMarkets(exchange);
|
|
3386
|
+
const market = markets.find(m => m.symbol === symbol);
|
|
3387
|
+
if (!market)
|
|
3388
|
+
throw new Error(`Market ${symbol} not found`);
|
|
3389
|
+
const numVariables = variables;
|
|
3390
|
+
const size = strategy.calculateSize?.(balance, market, numVariables) || balance.available * 0.1 / market.markPrice;
|
|
3391
|
+
const leverage = strategy.calculateLeverage?.(market, numVariables) || 10;
|
|
3392
|
+
const order = signal === 'LONG'
|
|
3393
|
+
? await this.service.openLong(exchange, symbol, size, leverage)
|
|
3394
|
+
: await this.service.openShort(exchange, symbol, size, leverage);
|
|
3395
|
+
// Record trade in database
|
|
3396
|
+
const tradeId = await this.db.recordTrade({
|
|
3397
|
+
exchange,
|
|
3398
|
+
symbol,
|
|
3399
|
+
side: signal,
|
|
3400
|
+
entryPrice: order.avgFillPrice || market.markPrice,
|
|
3401
|
+
size: order.size,
|
|
3402
|
+
leverage,
|
|
3403
|
+
entryTime: new Date(),
|
|
3404
|
+
strategy: strategyName,
|
|
3405
|
+
strategyVariant: variantName,
|
|
3406
|
+
variables,
|
|
3407
|
+
});
|
|
3408
|
+
// Track active position
|
|
3409
|
+
const posKey = `${exchange}:${symbol}`;
|
|
3410
|
+
this.activePositions.set(posKey, { tradeId, strategy: strategyName, variant: variantName });
|
|
3411
|
+
logger_1.logger.info({
|
|
3412
|
+
tradeId,
|
|
3413
|
+
exchange,
|
|
3414
|
+
symbol,
|
|
3415
|
+
signal,
|
|
3416
|
+
strategy: strategyName,
|
|
3417
|
+
variant: variantName,
|
|
3418
|
+
variables,
|
|
3419
|
+
}, 'Executed strategy trade');
|
|
3420
|
+
return order;
|
|
3421
|
+
}
|
|
3422
|
+
async closeTrade(exchange, symbol, exitPrice) {
|
|
3423
|
+
if (!this.db)
|
|
3424
|
+
throw new Error('Database not connected');
|
|
3425
|
+
const posKey = `${exchange}:${symbol}`;
|
|
3426
|
+
const activePos = this.activePositions.get(posKey);
|
|
3427
|
+
if (!activePos)
|
|
3428
|
+
return;
|
|
3429
|
+
// Get original trade to calculate PnL
|
|
3430
|
+
const trades = await this.db.getTrades({ strategy: activePos.strategy, limit: 1 });
|
|
3431
|
+
const trade = trades.find(t => t.id === activePos.tradeId);
|
|
3432
|
+
if (!trade)
|
|
3433
|
+
return;
|
|
3434
|
+
const pnl = trade.side === 'LONG'
|
|
3435
|
+
? (exitPrice - trade.entryPrice) * trade.size
|
|
3436
|
+
: (trade.entryPrice - exitPrice) * trade.size;
|
|
3437
|
+
const pnlPct = (pnl / (trade.entryPrice * trade.size)) * 100 * trade.leverage;
|
|
3438
|
+
await this.db.updateTrade(activePos.tradeId, {
|
|
3439
|
+
exitPrice,
|
|
3440
|
+
exitTime: new Date(),
|
|
3441
|
+
pnl,
|
|
3442
|
+
pnlPct,
|
|
3443
|
+
});
|
|
3444
|
+
this.activePositions.delete(posKey);
|
|
3445
|
+
logger_1.logger.info({
|
|
3446
|
+
tradeId: activePos.tradeId,
|
|
3447
|
+
exchange,
|
|
3448
|
+
symbol,
|
|
3449
|
+
exitPrice,
|
|
3450
|
+
pnl,
|
|
3451
|
+
pnlPct: pnlPct.toFixed(2) + '%',
|
|
3452
|
+
}, 'Closed strategy trade');
|
|
3453
|
+
}
|
|
3454
|
+
async runABTest(exchange, symbol, strategyName, durationMinutes = 60) {
|
|
3455
|
+
const variants = this.variants.get(strategyName) || [];
|
|
3456
|
+
if (variants.length < 2) {
|
|
3457
|
+
throw new Error('Need at least 2 variants for A/B testing');
|
|
3458
|
+
}
|
|
3459
|
+
logger_1.logger.info({
|
|
3460
|
+
strategy: strategyName,
|
|
3461
|
+
variants: variants.map(v => v.variantName),
|
|
3462
|
+
duration: durationMinutes,
|
|
3463
|
+
}, 'Starting A/B test');
|
|
3464
|
+
// Rotate through variants
|
|
3465
|
+
let variantIndex = 0;
|
|
3466
|
+
const endTime = Date.now() + durationMinutes * 60 * 1000;
|
|
3467
|
+
while (Date.now() < endTime) {
|
|
3468
|
+
const variant = variants[variantIndex % variants.length];
|
|
3469
|
+
variantIndex++;
|
|
3470
|
+
if (!this.service)
|
|
3471
|
+
break;
|
|
3472
|
+
const markets = await this.service.getMarkets(exchange);
|
|
3473
|
+
const market = markets.find(m => m.symbol === symbol);
|
|
3474
|
+
if (!market)
|
|
3475
|
+
continue;
|
|
3476
|
+
const { signal, variables } = await this.evaluateEntry(exchange, market, strategyName, variant.variantName);
|
|
3477
|
+
if (signal) {
|
|
3478
|
+
await this.executeTrade(exchange, symbol, signal, strategyName, variant.variantName, variables);
|
|
3479
|
+
}
|
|
3480
|
+
// Wait before next evaluation
|
|
3481
|
+
await new Promise(resolve => setTimeout(resolve, 60000));
|
|
3482
|
+
}
|
|
3483
|
+
logger_1.logger.info({ strategy: strategyName }, 'A/B test completed');
|
|
3484
|
+
}
|
|
3485
|
+
}
|
|
3486
|
+
exports.StrategyEngine = StrategyEngine;
|
|
3487
|
+
// =============================================================================
|
|
3488
|
+
// UNIFIED FUTURES SERVICE
|
|
3489
|
+
// =============================================================================
|
|
3490
|
+
class FuturesService extends events_1.EventEmitter {
|
|
3491
|
+
clients = new Map();
|
|
3492
|
+
config;
|
|
3493
|
+
positionMonitorInterval = null;
|
|
3494
|
+
db = null;
|
|
3495
|
+
strategyEngine = null;
|
|
3496
|
+
hlPrefs = new Map();
|
|
3497
|
+
constructor(configs) {
|
|
3498
|
+
super();
|
|
3499
|
+
this.config = configs;
|
|
3500
|
+
for (const config of configs) {
|
|
3501
|
+
this.initClient(config);
|
|
3502
|
+
}
|
|
3503
|
+
}
|
|
3504
|
+
async connectDatabase(config) {
|
|
3505
|
+
this.db = new FuturesDatabase();
|
|
3506
|
+
await this.db.connect(config);
|
|
3507
|
+
await this.db.initialize();
|
|
3508
|
+
}
|
|
3509
|
+
enableStrategies() {
|
|
3510
|
+
if (!this.strategyEngine) {
|
|
3511
|
+
this.strategyEngine = new StrategyEngine();
|
|
3512
|
+
this.strategyEngine.connectService(this);
|
|
3513
|
+
if (this.db) {
|
|
3514
|
+
this.strategyEngine.loadVariantsFromDb(this.db);
|
|
3515
|
+
}
|
|
3516
|
+
}
|
|
3517
|
+
return this.strategyEngine;
|
|
3518
|
+
}
|
|
3519
|
+
getDatabase() {
|
|
3520
|
+
return this.db;
|
|
3521
|
+
}
|
|
3522
|
+
getStrategyEngine() {
|
|
3523
|
+
return this.strategyEngine;
|
|
3524
|
+
}
|
|
3525
|
+
initClient(config) {
|
|
3526
|
+
switch (config.exchange) {
|
|
3527
|
+
case 'binance':
|
|
3528
|
+
this.clients.set('binance', new BinanceFuturesClient(config.credentials, config.dryRun));
|
|
3529
|
+
break;
|
|
3530
|
+
case 'bybit':
|
|
3531
|
+
this.clients.set('bybit', new BybitFuturesClient(config.credentials, config.dryRun));
|
|
3532
|
+
break;
|
|
3533
|
+
case 'hyperliquid':
|
|
3534
|
+
this.clients.set('hyperliquid', new HyperliquidClient(config.credentials, config.dryRun));
|
|
3535
|
+
break;
|
|
3536
|
+
case 'mexc':
|
|
3537
|
+
this.clients.set('mexc', new MexcFuturesClient(config.credentials, config.dryRun));
|
|
3538
|
+
break;
|
|
3539
|
+
}
|
|
3540
|
+
logger_1.logger.info({ exchange: config.exchange }, 'Initialized futures client');
|
|
3541
|
+
}
|
|
3542
|
+
getClient(exchange) {
|
|
3543
|
+
const client = this.clients.get(exchange);
|
|
3544
|
+
if (!client) {
|
|
3545
|
+
throw new Error(`Exchange ${exchange} not configured`);
|
|
3546
|
+
}
|
|
3547
|
+
return client;
|
|
3548
|
+
}
|
|
3549
|
+
async getBalance(exchange) {
|
|
3550
|
+
return this.getClient(exchange).getBalance();
|
|
3551
|
+
}
|
|
3552
|
+
async getAllBalances() {
|
|
3553
|
+
const balances = await Promise.all(Array.from(this.clients.keys()).map(ex => this.getBalance(ex)));
|
|
3554
|
+
return balances;
|
|
3555
|
+
}
|
|
3556
|
+
async getPositions(exchange) {
|
|
3557
|
+
return this.getClient(exchange).getPositions();
|
|
3558
|
+
}
|
|
3559
|
+
async getAllPositions() {
|
|
3560
|
+
const positions = await Promise.all(Array.from(this.clients.keys()).map(ex => this.getPositions(ex)));
|
|
3561
|
+
return positions.flat();
|
|
3562
|
+
}
|
|
3563
|
+
async placeOrder(exchange, order) {
|
|
3564
|
+
const config = this.config.find(c => c.exchange === exchange);
|
|
3565
|
+
if (config?.maxLeverage && order.leverage && order.leverage > config.maxLeverage) {
|
|
3566
|
+
throw new Error(`Leverage ${order.leverage}x exceeds max ${config.maxLeverage}x`);
|
|
3567
|
+
}
|
|
3568
|
+
const result = await this.getClient(exchange).placeOrder(order);
|
|
3569
|
+
this.emit('order', result);
|
|
3570
|
+
logger_1.logger.info({
|
|
3571
|
+
exchange,
|
|
3572
|
+
symbol: order.symbol,
|
|
3573
|
+
side: order.side,
|
|
3574
|
+
size: order.size,
|
|
3575
|
+
leverage: order.leverage,
|
|
3576
|
+
}, 'Placed futures order');
|
|
3577
|
+
return result;
|
|
3578
|
+
}
|
|
3579
|
+
async openLong(exchange, symbol, size, leverage, options) {
|
|
3580
|
+
return this.placeOrder(exchange, {
|
|
3581
|
+
symbol,
|
|
3582
|
+
side: 'BUY',
|
|
3583
|
+
type: options?.price ? 'LIMIT' : 'MARKET',
|
|
3584
|
+
size,
|
|
3585
|
+
leverage,
|
|
3586
|
+
price: options?.price,
|
|
3587
|
+
takeProfit: options?.takeProfit,
|
|
3588
|
+
stopLoss: options?.stopLoss,
|
|
3589
|
+
});
|
|
3590
|
+
}
|
|
3591
|
+
async openShort(exchange, symbol, size, leverage, options) {
|
|
3592
|
+
return this.placeOrder(exchange, {
|
|
3593
|
+
symbol,
|
|
3594
|
+
side: 'SELL',
|
|
3595
|
+
type: options?.price ? 'LIMIT' : 'MARKET',
|
|
3596
|
+
size,
|
|
3597
|
+
leverage,
|
|
3598
|
+
price: options?.price,
|
|
3599
|
+
takeProfit: options?.takeProfit,
|
|
3600
|
+
stopLoss: options?.stopLoss,
|
|
3601
|
+
});
|
|
3602
|
+
}
|
|
3603
|
+
async closePosition(exchange, symbol) {
|
|
3604
|
+
const result = await this.getClient(exchange).closePosition(symbol);
|
|
3605
|
+
if (result) {
|
|
3606
|
+
this.emit('positionClosed', result);
|
|
3607
|
+
logger_1.logger.info({ exchange, symbol }, 'Closed futures position');
|
|
3608
|
+
}
|
|
3609
|
+
return result;
|
|
3610
|
+
}
|
|
3611
|
+
async closeAllPositions(exchange) {
|
|
3612
|
+
const positions = await this.getPositions(exchange);
|
|
3613
|
+
const results = await Promise.all(positions.map(p => this.closePosition(exchange, p.symbol)));
|
|
3614
|
+
return results.filter((r) => r !== null);
|
|
3615
|
+
}
|
|
3616
|
+
async cancelOrder(exchange, symbol, orderId) {
|
|
3617
|
+
await this.getClient(exchange).cancelOrder(symbol, orderId);
|
|
3618
|
+
this.emit('orderCanceled', { exchange, symbol, orderId });
|
|
3619
|
+
}
|
|
3620
|
+
async getMarkets(exchange) {
|
|
3621
|
+
return this.getClient(exchange).getMarkets();
|
|
3622
|
+
}
|
|
3623
|
+
async getFundingRate(exchange, symbol) {
|
|
3624
|
+
const client = this.getClient(exchange);
|
|
3625
|
+
if ('getFundingRate' in client) {
|
|
3626
|
+
return client.getFundingRate(symbol);
|
|
3627
|
+
}
|
|
3628
|
+
throw new Error(`getFundingRate not supported on ${exchange}`);
|
|
3629
|
+
}
|
|
3630
|
+
async getOpenOrders(exchange, symbol) {
|
|
3631
|
+
const client = this.getClient(exchange);
|
|
3632
|
+
if ('getOpenOrders' in client) {
|
|
3633
|
+
return client.getOpenOrders(symbol);
|
|
3634
|
+
}
|
|
3635
|
+
return [];
|
|
3636
|
+
}
|
|
3637
|
+
startPositionMonitor(intervalMs = 5000) {
|
|
3638
|
+
if (this.positionMonitorInterval)
|
|
3639
|
+
return;
|
|
3640
|
+
this.positionMonitorInterval = setInterval(async () => {
|
|
3641
|
+
try {
|
|
3642
|
+
const positions = await this.getAllPositions();
|
|
3643
|
+
for (const position of positions) {
|
|
3644
|
+
if (position.liquidationPrice <= 0)
|
|
3645
|
+
continue;
|
|
3646
|
+
const priceDiff = Math.abs(position.markPrice - position.liquidationPrice);
|
|
3647
|
+
const liqProximity = (priceDiff / position.markPrice) * 100;
|
|
3648
|
+
if (liqProximity < 5) {
|
|
3649
|
+
const level = liqProximity < 2 ? 'critical' : liqProximity < 3 ? 'danger' : 'warning';
|
|
3650
|
+
this.emit('liquidationWarning', {
|
|
3651
|
+
level,
|
|
3652
|
+
position,
|
|
3653
|
+
proximityPct: liqProximity,
|
|
3654
|
+
});
|
|
3655
|
+
logger_1.logger.warn({
|
|
3656
|
+
level,
|
|
3657
|
+
exchange: position.exchange,
|
|
3658
|
+
symbol: position.symbol,
|
|
3659
|
+
proximityPct: liqProximity.toFixed(2),
|
|
3660
|
+
}, 'Liquidation warning');
|
|
3661
|
+
}
|
|
3662
|
+
}
|
|
3663
|
+
}
|
|
3664
|
+
catch (err) {
|
|
3665
|
+
logger_1.logger.error({ err }, 'Position monitor error');
|
|
3666
|
+
}
|
|
3667
|
+
}, intervalMs);
|
|
3668
|
+
logger_1.logger.info({ intervalMs }, 'Started position monitor');
|
|
3669
|
+
}
|
|
3670
|
+
stopPositionMonitor() {
|
|
3671
|
+
if (this.positionMonitorInterval) {
|
|
3672
|
+
clearInterval(this.positionMonitorInterval);
|
|
3673
|
+
this.positionMonitorInterval = null;
|
|
3674
|
+
logger_1.logger.info('Stopped position monitor');
|
|
3675
|
+
}
|
|
3676
|
+
}
|
|
3677
|
+
getExchanges() {
|
|
3678
|
+
return Array.from(this.clients.keys());
|
|
3679
|
+
}
|
|
3680
|
+
async setMarginType(exchange, symbol, marginType) {
|
|
3681
|
+
const client = this.getClient(exchange);
|
|
3682
|
+
switch (exchange) {
|
|
3683
|
+
case 'binance':
|
|
3684
|
+
await client.setMarginType(symbol, marginType);
|
|
3685
|
+
break;
|
|
3686
|
+
case 'bybit': {
|
|
3687
|
+
// Bybit: 0 = cross, 1 = isolated
|
|
3688
|
+
const tradeMode = marginType === 'CROSS' ? 0 : 1;
|
|
3689
|
+
// Read current leverage from position to avoid resetting it
|
|
3690
|
+
const bybitClient = client;
|
|
3691
|
+
const bybitPositions = await bybitClient.getPositions();
|
|
3692
|
+
const bybitPos = bybitPositions.find(p => p.symbol === symbol);
|
|
3693
|
+
const bybitLeverage = bybitPos?.leverage || undefined;
|
|
3694
|
+
try {
|
|
3695
|
+
await bybitClient.setIsolatedMargin(symbol, tradeMode, bybitLeverage);
|
|
3696
|
+
}
|
|
3697
|
+
catch (err) {
|
|
3698
|
+
const msg = err.message;
|
|
3699
|
+
// Already set to this mode
|
|
3700
|
+
if (!msg.includes('not modified') && !msg.includes('same'))
|
|
3701
|
+
throw err;
|
|
3702
|
+
}
|
|
3703
|
+
break;
|
|
3704
|
+
}
|
|
3705
|
+
case 'hyperliquid': {
|
|
3706
|
+
// Get current leverage from position or local prefs
|
|
3707
|
+
const hlClient = client;
|
|
3708
|
+
const hlPositions = await hlClient.getPositions();
|
|
3709
|
+
const hlPos = hlPositions.find(p => p.symbol === symbol);
|
|
3710
|
+
const prefs = this.hlPrefs.get(symbol) || {};
|
|
3711
|
+
const currentLeverage = hlPos?.leverage || prefs.leverage || 10;
|
|
3712
|
+
prefs.marginType = marginType;
|
|
3713
|
+
this.hlPrefs.set(symbol, prefs);
|
|
3714
|
+
await hlClient.setLeverage(symbol, currentLeverage, marginType);
|
|
3715
|
+
break;
|
|
3716
|
+
}
|
|
3717
|
+
case 'mexc':
|
|
3718
|
+
// MEXC applies margin type per-order via openType param
|
|
3719
|
+
client.setMarginTypePreference(marginType);
|
|
3720
|
+
logger_1.logger.info({ symbol, marginType }, 'MEXC margin type set (applied to all future orders)');
|
|
3721
|
+
break;
|
|
3722
|
+
}
|
|
3723
|
+
}
|
|
3724
|
+
async setLeverage(exchange, symbol, leverage) {
|
|
3725
|
+
const client = this.getClient(exchange);
|
|
3726
|
+
if (exchange === 'hyperliquid') {
|
|
3727
|
+
// Preserve current margin type when setting leverage
|
|
3728
|
+
const hlClient = client;
|
|
3729
|
+
const positions = await hlClient.getPositions();
|
|
3730
|
+
const pos = positions.find(p => p.symbol === symbol);
|
|
3731
|
+
const prefs = this.hlPrefs.get(symbol) || {};
|
|
3732
|
+
const currentMarginType = pos?.marginType || prefs.marginType || 'CROSS';
|
|
3733
|
+
prefs.leverage = leverage;
|
|
3734
|
+
this.hlPrefs.set(symbol, prefs);
|
|
3735
|
+
await hlClient.setLeverage(symbol, leverage, currentMarginType);
|
|
3736
|
+
}
|
|
3737
|
+
else if ('setLeverage' in client) {
|
|
3738
|
+
await client.setLeverage(symbol, leverage);
|
|
3739
|
+
}
|
|
3740
|
+
}
|
|
3741
|
+
async getIncomeHistory(exchange, params) {
|
|
3742
|
+
const client = this.getClient(exchange);
|
|
3743
|
+
if (exchange === 'binance') {
|
|
3744
|
+
return client.getIncomeHistory(params?.symbol, undefined, params?.limit);
|
|
3745
|
+
}
|
|
3746
|
+
if (exchange === 'bybit') {
|
|
3747
|
+
return client.getIncomeHistory(params?.symbol, params?.limit);
|
|
3748
|
+
}
|
|
3749
|
+
if (exchange === 'mexc') {
|
|
3750
|
+
// MEXC uses position history for realized PnL
|
|
3751
|
+
const mexcClient = client;
|
|
3752
|
+
const history = await mexcClient.getPositionHistory(params?.symbol, params?.limit || 50);
|
|
3753
|
+
return history.map(h => ({
|
|
3754
|
+
symbol: h.symbol,
|
|
3755
|
+
incomeType: 'REALIZED_PNL',
|
|
3756
|
+
income: h.realizedPnl,
|
|
3757
|
+
asset: 'USDT',
|
|
3758
|
+
timestamp: h.closeTime,
|
|
3759
|
+
}));
|
|
3760
|
+
}
|
|
3761
|
+
if (exchange === 'hyperliquid') {
|
|
3762
|
+
// Hyperliquid uses trade fills with closedPnl
|
|
3763
|
+
const hlClient = client;
|
|
3764
|
+
const trades = await hlClient.getTradeHistory(params?.limit || 50);
|
|
3765
|
+
const filtered = params?.symbol
|
|
3766
|
+
? trades.filter(t => t.symbol === params.symbol)
|
|
3767
|
+
: trades;
|
|
3768
|
+
return filtered
|
|
3769
|
+
.filter(t => t.realizedPnl !== 0)
|
|
3770
|
+
.map(t => ({
|
|
3771
|
+
symbol: t.symbol,
|
|
3772
|
+
incomeType: 'REALIZED_PNL',
|
|
3773
|
+
income: t.realizedPnl,
|
|
3774
|
+
asset: 'USDC',
|
|
3775
|
+
timestamp: t.timestamp,
|
|
3776
|
+
}));
|
|
3777
|
+
}
|
|
3778
|
+
return [];
|
|
3779
|
+
}
|
|
3780
|
+
async getTradeHistory(exchange, symbol, limit) {
|
|
3781
|
+
const client = this.getClient(exchange);
|
|
3782
|
+
switch (exchange) {
|
|
3783
|
+
case 'binance': {
|
|
3784
|
+
if (!symbol)
|
|
3785
|
+
throw new Error('Binance requires symbol for trade history');
|
|
3786
|
+
return client.getTradeHistory(symbol, limit);
|
|
3787
|
+
}
|
|
3788
|
+
case 'bybit':
|
|
3789
|
+
return client.getTradeHistory(symbol, limit);
|
|
3790
|
+
case 'hyperliquid': {
|
|
3791
|
+
const trades = await client.getTradeHistory(limit);
|
|
3792
|
+
return symbol ? trades.filter(t => t.symbol === symbol) : trades;
|
|
3793
|
+
}
|
|
3794
|
+
case 'mexc':
|
|
3795
|
+
return client.getTradeHistory(symbol, limit);
|
|
3796
|
+
default:
|
|
3797
|
+
return [];
|
|
3798
|
+
}
|
|
3799
|
+
}
|
|
3800
|
+
async getOrderHistory(exchange, symbol, limit) {
|
|
3801
|
+
const client = this.getClient(exchange);
|
|
3802
|
+
switch (exchange) {
|
|
3803
|
+
case 'binance':
|
|
3804
|
+
return client.getOrderHistory(symbol, limit);
|
|
3805
|
+
case 'bybit':
|
|
3806
|
+
return client.getOrderHistory(symbol, limit);
|
|
3807
|
+
case 'hyperliquid': {
|
|
3808
|
+
const orders = await client.getOrderHistory();
|
|
3809
|
+
const filtered = symbol ? orders.filter(o => o.symbol === symbol) : orders;
|
|
3810
|
+
return limit ? filtered.slice(0, limit) : filtered;
|
|
3811
|
+
}
|
|
3812
|
+
case 'mexc':
|
|
3813
|
+
return client.getOrderHistory(symbol, limit);
|
|
3814
|
+
default:
|
|
3815
|
+
return [];
|
|
3816
|
+
}
|
|
3817
|
+
}
|
|
3818
|
+
async getAccountInfo(exchange) {
|
|
3819
|
+
const client = this.getClient(exchange);
|
|
3820
|
+
return client.getAccountInfo();
|
|
3821
|
+
}
|
|
3822
|
+
async getOrderBook(exchange, symbol, limit) {
|
|
3823
|
+
const client = this.getClient(exchange);
|
|
3824
|
+
if (exchange === 'hyperliquid') {
|
|
3825
|
+
return client.getOrderBook(symbol);
|
|
3826
|
+
}
|
|
3827
|
+
return client.getOrderBook(symbol, limit);
|
|
3828
|
+
}
|
|
3829
|
+
async getTickerPrice(exchange, symbol) {
|
|
3830
|
+
const client = this.getClient(exchange);
|
|
3831
|
+
if ('getTickerPrice' in client) {
|
|
3832
|
+
return client.getTickerPrice(symbol);
|
|
3833
|
+
}
|
|
3834
|
+
// Hyperliquid doesn't have a direct ticker API, use order book mid price
|
|
3835
|
+
if (symbol) {
|
|
3836
|
+
const book = await client.getOrderBook(symbol);
|
|
3837
|
+
if (book.bids.length > 0 && book.asks.length > 0) {
|
|
3838
|
+
const mid = (book.bids[0][0] + book.asks[0][0]) / 2;
|
|
3839
|
+
return [{ symbol, price: mid, timestamp: Date.now() }];
|
|
3840
|
+
}
|
|
3841
|
+
}
|
|
3842
|
+
return [];
|
|
3843
|
+
}
|
|
3844
|
+
}
|
|
3845
|
+
exports.FuturesService = FuturesService;
|
|
3846
|
+
// =============================================================================
|
|
3847
|
+
// FACTORY & EASY SETUP
|
|
3848
|
+
// =============================================================================
|
|
3849
|
+
function createFuturesService(configs) {
|
|
3850
|
+
return new FuturesService(configs);
|
|
3851
|
+
}
|
|
3852
|
+
/**
|
|
3853
|
+
* Easy setup from environment variables
|
|
3854
|
+
*
|
|
3855
|
+
* Required env vars (at least one exchange):
|
|
3856
|
+
* - BINANCE_API_KEY, BINANCE_API_SECRET
|
|
3857
|
+
* - BYBIT_API_KEY, BYBIT_API_SECRET
|
|
3858
|
+
* - HYPERLIQUID_WALLET, HYPERLIQUID_PRIVATE_KEY
|
|
3859
|
+
*
|
|
3860
|
+
* Optional:
|
|
3861
|
+
* - FUTURES_DATABASE_URL (for trade tracking)
|
|
3862
|
+
* - DRY_RUN=true (paper trading)
|
|
3863
|
+
*/
|
|
3864
|
+
async function setupFromEnv() {
|
|
3865
|
+
const configs = [];
|
|
3866
|
+
const dryRun = process.env.DRY_RUN === 'true';
|
|
3867
|
+
// Binance
|
|
3868
|
+
if (process.env.BINANCE_API_KEY && process.env.BINANCE_API_SECRET) {
|
|
3869
|
+
configs.push({
|
|
3870
|
+
exchange: 'binance',
|
|
3871
|
+
credentials: {
|
|
3872
|
+
apiKey: process.env.BINANCE_API_KEY,
|
|
3873
|
+
apiSecret: process.env.BINANCE_API_SECRET,
|
|
3874
|
+
testnet: process.env.BINANCE_TESTNET === 'true',
|
|
3875
|
+
},
|
|
3876
|
+
dryRun,
|
|
3877
|
+
maxLeverage: 125,
|
|
3878
|
+
});
|
|
3879
|
+
}
|
|
3880
|
+
// Bybit
|
|
3881
|
+
if (process.env.BYBIT_API_KEY && process.env.BYBIT_API_SECRET) {
|
|
3882
|
+
configs.push({
|
|
3883
|
+
exchange: 'bybit',
|
|
3884
|
+
credentials: {
|
|
3885
|
+
apiKey: process.env.BYBIT_API_KEY,
|
|
3886
|
+
apiSecret: process.env.BYBIT_API_SECRET,
|
|
3887
|
+
testnet: process.env.BYBIT_TESTNET === 'true',
|
|
3888
|
+
},
|
|
3889
|
+
dryRun,
|
|
3890
|
+
maxLeverage: 100,
|
|
3891
|
+
});
|
|
3892
|
+
}
|
|
3893
|
+
// Hyperliquid
|
|
3894
|
+
if (process.env.HYPERLIQUID_WALLET && process.env.HYPERLIQUID_PRIVATE_KEY) {
|
|
3895
|
+
configs.push({
|
|
3896
|
+
exchange: 'hyperliquid',
|
|
3897
|
+
credentials: {
|
|
3898
|
+
apiKey: process.env.HYPERLIQUID_WALLET,
|
|
3899
|
+
apiSecret: process.env.HYPERLIQUID_PRIVATE_KEY,
|
|
3900
|
+
},
|
|
3901
|
+
dryRun,
|
|
3902
|
+
maxLeverage: 50,
|
|
3903
|
+
});
|
|
3904
|
+
}
|
|
3905
|
+
// MEXC (No KYC for small amounts - up to 200x leverage)
|
|
3906
|
+
if (process.env.MEXC_API_KEY && process.env.MEXC_API_SECRET) {
|
|
3907
|
+
configs.push({
|
|
3908
|
+
exchange: 'mexc',
|
|
3909
|
+
credentials: {
|
|
3910
|
+
apiKey: process.env.MEXC_API_KEY,
|
|
3911
|
+
apiSecret: process.env.MEXC_API_SECRET,
|
|
3912
|
+
},
|
|
3913
|
+
dryRun,
|
|
3914
|
+
maxLeverage: 200,
|
|
3915
|
+
});
|
|
3916
|
+
}
|
|
3917
|
+
if (configs.length === 0) {
|
|
3918
|
+
throw new Error('No exchange credentials found in environment variables');
|
|
3919
|
+
}
|
|
3920
|
+
const service = new FuturesService(configs);
|
|
3921
|
+
// Connect database if configured
|
|
3922
|
+
let db = null;
|
|
3923
|
+
if (process.env.FUTURES_DATABASE_URL) {
|
|
3924
|
+
await service.connectDatabase({ connectionString: process.env.FUTURES_DATABASE_URL });
|
|
3925
|
+
db = service.getDatabase();
|
|
3926
|
+
}
|
|
3927
|
+
// Enable strategy engine
|
|
3928
|
+
const strategies = service.enableStrategies();
|
|
3929
|
+
return { service, db, strategies };
|
|
3930
|
+
}
|
|
3931
|
+
// =============================================================================
|
|
3932
|
+
// EXAMPLE STRATEGIES (Ready to use or customize)
|
|
3933
|
+
// =============================================================================
|
|
3934
|
+
/**
|
|
3935
|
+
* Simple momentum strategy
|
|
3936
|
+
* Buys when funding is negative (shorts paying longs)
|
|
3937
|
+
* Sells when funding is positive (longs paying shorts)
|
|
3938
|
+
*/
|
|
3939
|
+
exports.MomentumStrategy = {
|
|
3940
|
+
name: 'momentum',
|
|
3941
|
+
version: '1.0.0',
|
|
3942
|
+
description: 'Trade based on funding rate direction',
|
|
3943
|
+
variables: [
|
|
3944
|
+
{ name: 'fundingThreshold', type: 'number', default: 0.01, min: 0.001, max: 0.1, step: 0.001, description: 'Minimum funding rate to trigger' },
|
|
3945
|
+
{ name: 'leverage', type: 'number', default: 10, min: 1, max: 50, step: 1, description: 'Position leverage' },
|
|
3946
|
+
{ name: 'positionPct', type: 'number', default: 10, min: 1, max: 50, step: 1, description: 'Percentage of balance to use' },
|
|
3947
|
+
],
|
|
3948
|
+
entryCondition: async (market, variables) => {
|
|
3949
|
+
if (market.fundingRate < -variables.fundingThreshold)
|
|
3950
|
+
return 'LONG';
|
|
3951
|
+
if (market.fundingRate > variables.fundingThreshold)
|
|
3952
|
+
return 'SHORT';
|
|
3953
|
+
return null;
|
|
3954
|
+
},
|
|
3955
|
+
calculateSize: (balance, market, variables) => {
|
|
3956
|
+
return (balance.available * (variables.positionPct / 100)) / market.markPrice;
|
|
3957
|
+
},
|
|
3958
|
+
calculateLeverage: (_market, variables) => variables.leverage,
|
|
3959
|
+
};
|
|
3960
|
+
/**
|
|
3961
|
+
* Mean reversion strategy
|
|
3962
|
+
* Buys oversold, sells overbought based on price deviation
|
|
3963
|
+
*/
|
|
3964
|
+
exports.MeanReversionStrategy = {
|
|
3965
|
+
name: 'mean_reversion',
|
|
3966
|
+
version: '1.0.0',
|
|
3967
|
+
description: 'Trade reversions to mean price',
|
|
3968
|
+
variables: [
|
|
3969
|
+
{ name: 'deviationPct', type: 'number', default: 2, min: 0.5, max: 10, step: 0.5, description: 'Price deviation % to trigger' },
|
|
3970
|
+
{ name: 'leverage', type: 'number', default: 5, min: 1, max: 25, step: 1, description: 'Position leverage' },
|
|
3971
|
+
{ name: 'positionPct', type: 'number', default: 5, min: 1, max: 25, step: 1, description: 'Percentage of balance to use' },
|
|
3972
|
+
],
|
|
3973
|
+
entryCondition: async (market, variables) => {
|
|
3974
|
+
const deviation = ((market.markPrice - market.indexPrice) / market.indexPrice) * 100;
|
|
3975
|
+
if (deviation < -variables.deviationPct)
|
|
3976
|
+
return 'LONG'; // Oversold
|
|
3977
|
+
if (deviation > variables.deviationPct)
|
|
3978
|
+
return 'SHORT'; // Overbought
|
|
3979
|
+
return null;
|
|
3980
|
+
},
|
|
3981
|
+
calculateSize: (balance, market, variables) => {
|
|
3982
|
+
return (balance.available * (variables.positionPct / 100)) / market.markPrice;
|
|
3983
|
+
},
|
|
3984
|
+
calculateLeverage: (_market, variables) => variables.leverage,
|
|
3985
|
+
};
|
|
3986
|
+
/**
|
|
3987
|
+
* Grid trading strategy
|
|
3988
|
+
* Places orders at regular price intervals
|
|
3989
|
+
*/
|
|
3990
|
+
exports.GridStrategy = {
|
|
3991
|
+
name: 'grid',
|
|
3992
|
+
version: '1.0.0',
|
|
3993
|
+
description: 'Grid trading with price levels',
|
|
3994
|
+
variables: [
|
|
3995
|
+
{ name: 'gridSpacingPct', type: 'number', default: 1, min: 0.1, max: 5, step: 0.1, description: 'Grid spacing %' },
|
|
3996
|
+
{ name: 'gridLevels', type: 'number', default: 5, min: 2, max: 20, step: 1, description: 'Number of grid levels' },
|
|
3997
|
+
{ name: 'leverage', type: 'number', default: 3, min: 1, max: 10, step: 1, description: 'Position leverage' },
|
|
3998
|
+
{ name: 'positionPct', type: 'number', default: 20, min: 5, max: 50, step: 5, description: 'Total capital for grid' },
|
|
3999
|
+
],
|
|
4000
|
+
entryCondition: async (_market, _variables) => {
|
|
4001
|
+
// Grid strategy manages entries differently - always check for opportunities
|
|
4002
|
+
return null; // Managed by grid logic
|
|
4003
|
+
},
|
|
4004
|
+
calculateSize: (balance, market, variables) => {
|
|
4005
|
+
const totalCapital = balance.available * (variables.positionPct / 100);
|
|
4006
|
+
const perLevel = totalCapital / variables.gridLevels;
|
|
4007
|
+
return perLevel / market.markPrice;
|
|
4008
|
+
},
|
|
4009
|
+
calculateLeverage: (_market, variables) => variables.leverage,
|
|
4010
|
+
};
|
|
4011
|
+
//# sourceMappingURL=index.js.map
|