lighter-ts-sdk 1.0.8 → 1.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +743 -476
- package/dist/browser/index.html +20 -0
- package/dist/browser/lighter-ts-sdk.browser.js +33886 -0
- package/dist/browser/lighter-ts-sdk.browser.js.map +7 -0
- package/dist/cjs/api/account-api.d.ts +251 -0
- package/dist/cjs/api/account-api.d.ts.map +1 -0
- package/dist/cjs/api/account-api.js +203 -0
- package/dist/cjs/api/account-api.js.map +1 -0
- package/dist/cjs/api/announcement-api.d.ts.map +1 -0
- package/dist/cjs/api/announcement-api.js.map +1 -0
- package/dist/cjs/api/api-client.d.ts.map +1 -0
- package/dist/cjs/api/api-client.js +146 -0
- package/dist/cjs/api/api-client.js.map +1 -0
- package/dist/cjs/api/block-api.d.ts.map +1 -0
- package/dist/cjs/api/block-api.js.map +1 -0
- package/dist/{api → cjs/api}/bridge-api.d.ts +34 -0
- package/dist/cjs/api/bridge-api.d.ts.map +1 -0
- package/dist/cjs/api/bridge-api.js +173 -0
- package/dist/cjs/api/bridge-api.js.map +1 -0
- package/dist/{api → cjs/api}/candlestick-api.d.ts +3 -0
- package/dist/cjs/api/candlestick-api.d.ts.map +1 -0
- package/dist/cjs/api/candlestick-api.js +21 -0
- package/dist/cjs/api/candlestick-api.js.map +1 -0
- package/dist/cjs/api/explorer-api-client.d.ts +32 -0
- package/dist/cjs/api/explorer-api-client.d.ts.map +1 -0
- package/dist/cjs/api/explorer-api-client.js +138 -0
- package/dist/cjs/api/explorer-api-client.js.map +1 -0
- package/dist/cjs/api/funding-api.d.ts.map +1 -0
- package/dist/cjs/api/funding-api.js.map +1 -0
- package/dist/cjs/api/info-api.d.ts +43 -0
- package/dist/cjs/api/info-api.d.ts.map +1 -0
- package/dist/cjs/api/info-api.js +52 -0
- package/dist/cjs/api/info-api.js.map +1 -0
- package/dist/cjs/api/logs-api.d.ts +198 -0
- package/dist/cjs/api/logs-api.d.ts.map +1 -0
- package/dist/cjs/api/logs-api.js +256 -0
- package/dist/cjs/api/logs-api.js.map +1 -0
- package/dist/{api → cjs/api}/notification-api.d.ts +28 -0
- package/dist/cjs/api/notification-api.d.ts.map +1 -0
- package/dist/cjs/api/notification-api.js +108 -0
- package/dist/cjs/api/notification-api.js.map +1 -0
- package/dist/{api → cjs/api}/order-api.d.ts +22 -5
- package/dist/cjs/api/order-api.d.ts.map +1 -0
- package/dist/cjs/api/order-api.js +181 -0
- package/dist/cjs/api/order-api.js.map +1 -0
- package/dist/{api → cjs/api}/referral-api.d.ts +9 -0
- package/dist/cjs/api/referral-api.d.ts.map +1 -0
- package/dist/cjs/api/referral-api.js +53 -0
- package/dist/cjs/api/referral-api.js.map +1 -0
- package/dist/cjs/api/root-api.d.ts +15 -0
- package/dist/cjs/api/root-api.d.ts.map +1 -0
- package/dist/cjs/api/root-api.js +18 -0
- package/dist/cjs/api/root-api.js.map +1 -0
- package/dist/cjs/api/search-api.d.ts +211 -0
- package/dist/cjs/api/search-api.d.ts.map +1 -0
- package/dist/cjs/api/search-api.js +112 -0
- package/dist/cjs/api/search-api.js.map +1 -0
- package/dist/{api → cjs/api}/transaction-api.d.ts +4 -0
- package/dist/cjs/api/transaction-api.d.ts.map +1 -0
- package/dist/cjs/api/transaction-api.js +173 -0
- package/dist/cjs/api/transaction-api.js.map +1 -0
- package/dist/{api → cjs/api}/ws-client.d.ts +1 -0
- package/dist/cjs/api/ws-client.d.ts.map +1 -0
- package/dist/cjs/api/ws-client.js +139 -0
- package/dist/cjs/api/ws-client.js.map +1 -0
- package/dist/{api → cjs/api}/ws-order-client.d.ts +1 -0
- package/dist/cjs/api/ws-order-client.d.ts.map +1 -0
- package/dist/cjs/api/ws-order-client.js +451 -0
- package/dist/cjs/api/ws-order-client.js.map +1 -0
- package/dist/cjs/bridge/l1-bridge-client.d.ts.map +1 -0
- package/dist/cjs/bridge/l1-bridge-client.js.map +1 -0
- package/dist/{index.d.ts → cjs/index.d.ts} +19 -8
- package/dist/cjs/index.d.ts.map +1 -0
- package/dist/cjs/index.js +175 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/package.json +3 -0
- package/dist/{signer → cjs/signer}/wasm-signer-client.d.ts +91 -68
- package/dist/cjs/signer/wasm-signer-client.d.ts.map +1 -0
- package/dist/cjs/signer/wasm-signer-client.js +2263 -0
- package/dist/cjs/signer/wasm-signer-client.js.map +1 -0
- package/dist/{signer → cjs/signer}/wasm-signer.d.ts +8 -0
- package/dist/cjs/signer/wasm-signer.d.ts.map +1 -0
- package/dist/cjs/signer/wasm-signer.js +940 -0
- package/dist/cjs/signer/wasm-signer.js.map +1 -0
- package/dist/{types → cjs/types}/api.d.ts +13 -0
- package/dist/cjs/types/api.d.ts.map +1 -0
- package/dist/cjs/types/api.js.map +1 -0
- package/dist/cjs/types/config.d.ts.map +1 -0
- package/dist/cjs/types/config.js.map +1 -0
- package/dist/cjs/types/generated/openapi.d.ts.map +1 -0
- package/dist/cjs/types/generated/openapi.js.map +1 -0
- package/dist/cjs/types/index.d.ts.map +1 -0
- package/dist/cjs/types/index.js.map +1 -0
- package/dist/cjs/types/trading.d.ts.map +1 -0
- package/dist/cjs/types/trading.js.map +1 -0
- package/dist/cjs/types/transaction.d.ts.map +1 -0
- package/dist/cjs/types/transaction.js.map +1 -0
- package/dist/cjs/utils/configuration.d.ts.map +1 -0
- package/dist/cjs/utils/configuration.js.map +1 -0
- package/dist/cjs/utils/environment.d.ts +70 -0
- package/dist/cjs/utils/environment.d.ts.map +1 -0
- package/dist/cjs/utils/environment.js +214 -0
- package/dist/cjs/utils/environment.js.map +1 -0
- package/dist/cjs/utils/exceptions.d.ts.map +1 -0
- package/dist/cjs/utils/exceptions.js.map +1 -0
- package/dist/cjs/utils/index.d.ts.map +1 -0
- package/dist/cjs/utils/index.js.map +1 -0
- package/dist/cjs/utils/logger.d.ts.map +1 -0
- package/dist/cjs/utils/logger.js.map +1 -0
- package/dist/cjs/utils/market-helper.d.ts.map +1 -0
- package/dist/cjs/utils/market-helper.js.map +1 -0
- package/dist/cjs/utils/nonce-cache.d.ts.map +1 -0
- package/dist/cjs/utils/nonce-cache.js.map +1 -0
- package/dist/cjs/utils/nonce-manager.d.ts.map +1 -0
- package/dist/cjs/utils/nonce-manager.js.map +1 -0
- package/dist/cjs/utils/order-status-checker.d.ts.map +1 -0
- package/dist/cjs/utils/order-status-checker.js.map +1 -0
- package/dist/cjs/utils/price-utils.d.ts.map +1 -0
- package/dist/cjs/utils/price-utils.js.map +1 -0
- package/dist/cjs/utils/request-batcher.d.ts.map +1 -0
- package/dist/cjs/utils/request-batcher.js.map +1 -0
- package/dist/esm/api/account-api.d.ts +251 -0
- package/dist/esm/api/account-api.d.ts.map +1 -0
- package/dist/esm/api/account-api.js +199 -0
- package/dist/esm/api/account-api.js.map +1 -0
- package/dist/esm/api/announcement-api.d.ts +27 -0
- package/dist/esm/api/announcement-api.d.ts.map +1 -0
- package/dist/esm/api/announcement-api.js +21 -0
- package/dist/esm/api/announcement-api.js.map +1 -0
- package/dist/esm/api/api-client.d.ts +23 -0
- package/dist/esm/api/api-client.d.ts.map +1 -0
- package/dist/esm/api/api-client.js +139 -0
- package/dist/esm/api/api-client.js.map +1 -0
- package/dist/esm/api/block-api.d.ts +24 -0
- package/dist/esm/api/block-api.d.ts.map +1 -0
- package/dist/esm/api/block-api.js +18 -0
- package/dist/esm/api/block-api.js.map +1 -0
- package/dist/esm/api/bridge-api.d.ts +112 -0
- package/dist/esm/api/bridge-api.d.ts.map +1 -0
- package/dist/esm/api/bridge-api.js +169 -0
- package/dist/esm/api/bridge-api.js.map +1 -0
- package/dist/esm/api/candlestick-api.d.ts +30 -0
- package/dist/esm/api/candlestick-api.d.ts.map +1 -0
- package/dist/esm/api/candlestick-api.js +17 -0
- package/dist/esm/api/candlestick-api.js.map +1 -0
- package/dist/esm/api/explorer-api-client.d.ts +32 -0
- package/dist/esm/api/explorer-api-client.d.ts.map +1 -0
- package/dist/esm/api/explorer-api-client.js +131 -0
- package/dist/esm/api/explorer-api-client.js.map +1 -0
- package/dist/esm/api/funding-api.d.ts +28 -0
- package/dist/esm/api/funding-api.d.ts.map +1 -0
- package/dist/esm/api/funding-api.js +21 -0
- package/dist/esm/api/funding-api.js.map +1 -0
- package/dist/esm/api/info-api.d.ts +43 -0
- package/dist/esm/api/info-api.d.ts.map +1 -0
- package/dist/esm/api/info-api.js +48 -0
- package/dist/esm/api/info-api.js.map +1 -0
- package/dist/esm/api/logs-api.d.ts +198 -0
- package/dist/esm/api/logs-api.d.ts.map +1 -0
- package/dist/esm/api/logs-api.js +252 -0
- package/dist/esm/api/logs-api.js.map +1 -0
- package/dist/esm/api/notification-api.d.ts +55 -0
- package/dist/esm/api/notification-api.d.ts.map +1 -0
- package/dist/esm/api/notification-api.js +104 -0
- package/dist/esm/api/notification-api.js.map +1 -0
- package/dist/esm/api/order-api.d.ts +294 -0
- package/dist/esm/api/order-api.d.ts.map +1 -0
- package/dist/esm/api/order-api.js +177 -0
- package/dist/esm/api/order-api.js.map +1 -0
- package/dist/esm/api/referral-api.d.ts +46 -0
- package/dist/esm/api/referral-api.d.ts.map +1 -0
- package/dist/esm/api/referral-api.js +49 -0
- package/dist/esm/api/referral-api.js.map +1 -0
- package/dist/esm/api/root-api.d.ts +15 -0
- package/dist/esm/api/root-api.d.ts.map +1 -0
- package/dist/esm/api/root-api.js +14 -0
- package/dist/esm/api/root-api.js.map +1 -0
- package/dist/esm/api/search-api.d.ts +211 -0
- package/dist/esm/api/search-api.d.ts.map +1 -0
- package/dist/esm/api/search-api.js +108 -0
- package/dist/esm/api/search-api.js.map +1 -0
- package/dist/esm/api/transaction-api.d.ts +120 -0
- package/dist/esm/api/transaction-api.d.ts.map +1 -0
- package/dist/esm/api/transaction-api.js +169 -0
- package/dist/esm/api/transaction-api.js.map +1 -0
- package/dist/esm/api/ws-client.d.ts +22 -0
- package/dist/esm/api/ws-client.d.ts.map +1 -0
- package/dist/esm/api/ws-client.js +132 -0
- package/dist/esm/api/ws-client.js.map +1 -0
- package/dist/esm/api/ws-order-client.d.ts +84 -0
- package/dist/esm/api/ws-order-client.d.ts.map +1 -0
- package/dist/esm/api/ws-order-client.js +444 -0
- package/dist/esm/api/ws-order-client.js.map +1 -0
- package/dist/esm/bridge/l1-bridge-client.d.ts +49 -0
- package/dist/esm/bridge/l1-bridge-client.d.ts.map +1 -0
- package/dist/esm/bridge/l1-bridge-client.js +172 -0
- package/dist/esm/bridge/l1-bridge-client.js.map +1 -0
- package/dist/esm/browser-check.js +33637 -0
- package/dist/esm/index.d.ts +94 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +100 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/signer/wasm-signer-client.d.ts +593 -0
- package/dist/esm/signer/wasm-signer-client.d.ts.map +1 -0
- package/dist/esm/signer/wasm-signer-client.js +2236 -0
- package/dist/esm/signer/wasm-signer-client.js.map +1 -0
- package/dist/esm/signer/wasm-signer.d.ts +373 -0
- package/dist/esm/signer/wasm-signer.d.ts.map +1 -0
- package/dist/esm/signer/wasm-signer.js +935 -0
- package/dist/esm/signer/wasm-signer.js.map +1 -0
- package/dist/esm/types/api.d.ts +198 -0
- package/dist/esm/types/api.d.ts.map +1 -0
- package/dist/esm/types/api.js +6 -0
- package/dist/esm/types/api.js.map +1 -0
- package/dist/esm/types/config.d.ts +66 -0
- package/dist/esm/types/config.d.ts.map +1 -0
- package/dist/esm/types/config.js +6 -0
- package/dist/{types → esm/types}/config.js.map +1 -1
- package/dist/esm/types/generated/openapi.d.ts +5007 -0
- package/dist/esm/types/generated/openapi.d.ts.map +1 -0
- package/dist/esm/types/generated/openapi.js +6 -0
- package/dist/esm/types/generated/openapi.js.map +1 -0
- package/dist/esm/types/index.d.ts +32 -0
- package/dist/esm/types/index.d.ts.map +1 -0
- package/dist/esm/types/index.js +8 -0
- package/dist/esm/types/index.js.map +1 -0
- package/dist/esm/types/trading.d.ts +43 -0
- package/dist/esm/types/trading.d.ts.map +1 -0
- package/dist/esm/types/trading.js +22 -0
- package/dist/esm/types/trading.js.map +1 -0
- package/dist/esm/types/transaction.d.ts +57 -0
- package/dist/esm/types/transaction.d.ts.map +1 -0
- package/dist/esm/types/transaction.js +26 -0
- package/dist/esm/types/transaction.js.map +1 -0
- package/dist/esm/utils/configuration.d.ts +19 -0
- package/dist/esm/utils/configuration.d.ts.map +1 -0
- package/dist/esm/utils/configuration.js +51 -0
- package/dist/esm/utils/configuration.js.map +1 -0
- package/dist/esm/utils/environment.d.ts +70 -0
- package/dist/esm/utils/environment.d.ts.map +1 -0
- package/dist/esm/utils/environment.js +198 -0
- package/dist/esm/utils/environment.js.map +1 -0
- package/dist/esm/utils/exceptions.d.ts +57 -0
- package/dist/esm/utils/exceptions.d.ts.map +1 -0
- package/dist/esm/utils/exceptions.js +105 -0
- package/dist/esm/utils/exceptions.js.map +1 -0
- package/dist/esm/utils/index.d.ts +14 -0
- package/dist/esm/utils/index.d.ts.map +1 -0
- package/dist/esm/utils/index.js +22 -0
- package/dist/esm/utils/index.js.map +1 -0
- package/dist/esm/utils/logger.d.ts +35 -0
- package/dist/esm/utils/logger.d.ts.map +1 -0
- package/dist/esm/utils/logger.js +92 -0
- package/dist/esm/utils/logger.js.map +1 -0
- package/dist/esm/utils/market-helper.d.ts +62 -0
- package/dist/esm/utils/market-helper.d.ts.map +1 -0
- package/dist/esm/utils/market-helper.js +96 -0
- package/dist/esm/utils/market-helper.js.map +1 -0
- package/dist/esm/utils/nonce-cache.d.ts +37 -0
- package/dist/esm/utils/nonce-cache.d.ts.map +1 -0
- package/dist/esm/utils/nonce-cache.js +132 -0
- package/dist/esm/utils/nonce-cache.js.map +1 -0
- package/dist/esm/utils/nonce-manager.d.ts +79 -0
- package/dist/esm/utils/nonce-manager.d.ts.map +1 -0
- package/dist/esm/utils/nonce-manager.js +123 -0
- package/dist/esm/utils/nonce-manager.js.map +1 -0
- package/dist/esm/utils/order-status-checker.d.ts +29 -0
- package/dist/esm/utils/order-status-checker.d.ts.map +1 -0
- package/dist/esm/utils/order-status-checker.js +93 -0
- package/dist/esm/utils/order-status-checker.js.map +1 -0
- package/dist/esm/utils/price-utils.d.ts +86 -0
- package/dist/esm/utils/price-utils.d.ts.map +1 -0
- package/dist/esm/utils/price-utils.js +206 -0
- package/dist/esm/utils/price-utils.js.map +1 -0
- package/dist/esm/utils/request-batcher.d.ts +45 -0
- package/dist/esm/utils/request-batcher.d.ts.map +1 -0
- package/dist/esm/utils/request-batcher.js +161 -0
- package/dist/esm/utils/request-batcher.js.map +1 -0
- package/dist/examples/examples/cancel_order.js +90 -0
- package/dist/examples/examples/create_limit_order.js +213 -0
- package/dist/examples/examples/create_market_order.js +191 -0
- package/dist/examples/examples/explorer_logs_example.js +228 -0
- package/dist/examples/examples/explorer_search_example.js +196 -0
- package/dist/examples/examples/market_data.js +183 -0
- package/dist/examples/public_pool_deposit.js +67 -0
- package/dist/examples/public_pool_info.js +75 -0
- package/dist/{api → examples/src/api}/account-api.js +34 -3
- package/dist/examples/src/api/announcement-api.js +24 -0
- package/dist/{api → examples/src/api}/api-client.js +0 -1
- package/dist/examples/src/api/block-api.js +21 -0
- package/dist/{api → examples/src/api}/bridge-api.js +0 -1
- package/dist/{api → examples/src/api}/candlestick-api.js +5 -3
- package/dist/examples/src/api/explorer-api-client.js +127 -0
- package/dist/examples/src/api/funding-api.js +24 -0
- package/dist/examples/src/api/info-api.js +43 -0
- package/dist/examples/src/api/logs-api.js +255 -0
- package/dist/{api → examples/src/api}/notification-api.js +0 -1
- package/dist/{api → examples/src/api}/order-api.js +40 -7
- package/dist/{api → examples/src/api}/referral-api.js +0 -1
- package/dist/{api → examples/src/api}/root-api.js +4 -1
- package/dist/examples/src/api/search-api.js +111 -0
- package/dist/{api → examples/src/api}/transaction-api.js +7 -1
- package/dist/{api → examples/src/api}/ws-client.js +0 -1
- package/dist/{api → examples/src/api}/ws-order-client.js +1 -1
- package/dist/examples/src/bridge/l1-bridge-client.js +175 -0
- package/dist/{index.js → examples/src/index.js} +28 -3
- package/dist/{signer → examples/src/signer}/wasm-signer-client.js +52 -1
- package/dist/{signer → examples/src/signer}/wasm-signer.js +0 -1
- package/dist/examples/src/types/api.js +6 -0
- package/dist/examples/src/types/config.js +6 -0
- package/dist/examples/src/types/generated/openapi.js +6 -0
- package/dist/examples/src/types/index.js +23 -0
- package/dist/examples/src/types/trading.js +24 -0
- package/dist/examples/src/types/transaction.js +28 -0
- package/dist/examples/src/utils/configuration.js +54 -0
- package/dist/examples/src/utils/environment.js +213 -0
- package/dist/examples/src/utils/exceptions.js +122 -0
- package/dist/examples/src/utils/logger.js +95 -0
- package/dist/examples/src/utils/market-helper.js +99 -0
- package/dist/examples/src/utils/nonce-cache.js +135 -0
- package/dist/examples/src/utils/nonce-manager.js +129 -0
- package/dist/examples/src/utils/order-status-checker.js +98 -0
- package/dist/examples/src/utils/price-utils.js +228 -0
- package/dist/examples/src/utils/request-batcher.js +167 -0
- package/dist/umd/index.html +63 -0
- package/dist/umd/lighter-signer.wasm +0 -0
- package/dist/umd/lighter-ts-sdk.js +33894 -0
- package/dist/umd/lighter-ts-sdk.js.map +7 -0
- package/dist/umd/lighter-ts-sdk.min.js +25 -0
- package/dist/umd/lighter-ts-sdk.min.js.map +7 -0
- package/dist/umd/package.json +13 -0
- package/dist/umd/signer-import-check.html +29 -0
- package/dist/umd/signer-umd-check.html +29 -0
- package/dist/umd/wasm_exec.js +575 -0
- package/docs/API.md +191 -207
- package/docs/AccountApi.md +278 -278
- package/docs/ExplorerApi.md +536 -0
- package/docs/GettingStarted.md +388 -361
- package/docs/MarginManagement.md +628 -0
- package/docs/MarketHelper.md +1 -1
- package/docs/MigrationGuide.md +17 -14
- package/docs/OrderApi.md +353 -353
- package/docs/SignerClient.md +628 -626
- package/docs/TransactionApi.md +474 -474
- package/docs/TransactionMonitoring.md +520 -0
- package/docs/Utilities.md +9 -10
- package/docs/WsClient.md +1 -2
- package/docs/types/SignerConfig.md +40 -40
- package/docs/types/WasmSignerConfig.md +2 -2
- package/examples/README.md +247 -242
- package/examples/cancel_all_orders.ts +17 -4
- package/examples/cancel_order.ts +78 -76
- package/examples/close_all_positions.ts +405 -403
- package/examples/close_position.ts +166 -164
- package/examples/create_auth_token.ts +59 -57
- package/examples/create_grouped_ioc_with_attached_sl_tp.ts +180 -178
- package/examples/create_grouped_orders.ts +205 -203
- package/examples/create_limit_order.ts +23 -135
- package/examples/create_market_order.ts +124 -179
- package/examples/create_market_order_max_slippage.ts +121 -119
- package/examples/create_position_tied_sl_tp.ts +210 -208
- package/examples/create_subaccount.ts +3 -1
- package/examples/create_twap_order.ts +24 -41
- package/examples/create_with_multiple_keys.ts +35 -20
- package/examples/live_smoke.ts +253 -0
- package/examples/margin_eth_add_collateral_http.ts +75 -0
- package/examples/margin_eth_remove_collateral_http.ts +76 -0
- package/examples/market_data.ts +172 -175
- package/examples/modify_order.ts +22 -13
- package/examples/multi_client_advanced.ts +256 -254
- package/examples/onboarding.ts +455 -0
- package/examples/public_pool_deposit.ts +80 -0
- package/examples/public_pool_info.ts +83 -0
- package/examples/public_pool_operations.ts +152 -150
- package/examples/public_pool_withdraw.ts +78 -0
- package/examples/revoke_api_key.ts +132 -130
- package/examples/send_tx_batch.ts +110 -110
- package/examples/spot/README.md +99 -99
- package/examples/spot/cancel_spot_order.ts +89 -89
- package/examples/spot/create_market_spot_orders.ts +196 -259
- package/examples/spot/create_spot_limit_order.ts +122 -122
- package/examples/spot/create_spot_limit_order_with_sltp.ts +157 -193
- package/examples/spot/create_spot_twap_order.ts +110 -110
- package/examples/spot/modify_spot_order.ts +146 -146
- package/examples/spot_get_account_assets_http.ts +86 -0
- package/examples/system_setup.ts +225 -223
- package/examples/transfer_spot_perp.ts +167 -165
- package/examples/update_margin.ts +5 -3
- package/examples/update_margin_leverage.ts +2 -2
- package/examples/withdraw_fast.ts +198 -196
- package/examples/withdraw_to_l1.ts +3 -1
- package/package.json +29 -15
- package/wasm/wasm_exec.js +575 -575
- package/dist/api/account-api.d.ts +0 -124
- package/dist/api/account-api.d.ts.map +0 -1
- package/dist/api/account-api.js.map +0 -1
- package/dist/api/announcement-api.d.ts.map +0 -1
- package/dist/api/announcement-api.js.map +0 -1
- package/dist/api/api-client.d.ts.map +0 -1
- package/dist/api/api-client.js.map +0 -1
- package/dist/api/block-api.d.ts.map +0 -1
- package/dist/api/block-api.js.map +0 -1
- package/dist/api/bridge-api.d.ts.map +0 -1
- package/dist/api/bridge-api.js.map +0 -1
- package/dist/api/candlestick-api.d.ts.map +0 -1
- package/dist/api/candlestick-api.js.map +0 -1
- package/dist/api/funding-api.d.ts.map +0 -1
- package/dist/api/funding-api.js.map +0 -1
- package/dist/api/notification-api.d.ts.map +0 -1
- package/dist/api/notification-api.js.map +0 -1
- package/dist/api/order-api.d.ts.map +0 -1
- package/dist/api/order-api.js.map +0 -1
- package/dist/api/referral-api.d.ts.map +0 -1
- package/dist/api/referral-api.js.map +0 -1
- package/dist/api/root-api.d.ts +0 -8
- package/dist/api/root-api.d.ts.map +0 -1
- package/dist/api/root-api.js.map +0 -1
- package/dist/api/transaction-api.d.ts.map +0 -1
- package/dist/api/transaction-api.js.map +0 -1
- package/dist/api/ws-client.d.ts.map +0 -1
- package/dist/api/ws-client.js.map +0 -1
- package/dist/api/ws-order-client.d.ts.map +0 -1
- package/dist/api/ws-order-client.js.map +0 -1
- package/dist/bridge/l1-bridge-client.d.ts.map +0 -1
- package/dist/bridge/l1-bridge-client.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/signer/wasm-manager.d.ts +0 -29
- package/dist/signer/wasm-manager.d.ts.map +0 -1
- package/dist/signer/wasm-manager.js +0 -104
- package/dist/signer/wasm-manager.js.map +0 -1
- package/dist/signer/wasm-signer-client.d.ts.map +0 -1
- package/dist/signer/wasm-signer-client.js.map +0 -1
- package/dist/signer/wasm-signer.d.ts.map +0 -1
- package/dist/signer/wasm-signer.js.map +0 -1
- package/dist/types/api.d.ts.map +0 -1
- package/dist/types/api.js.map +0 -1
- package/dist/types/config.d.ts.map +0 -1
- package/dist/types/generated/openapi.d.ts.map +0 -1
- package/dist/types/generated/openapi.js.map +0 -1
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/index.js.map +0 -1
- package/dist/types/trading.d.ts.map +0 -1
- package/dist/types/trading.js.map +0 -1
- package/dist/types/transaction.d.ts.map +0 -1
- package/dist/types/transaction.js.map +0 -1
- package/dist/utils/configuration.d.ts.map +0 -1
- package/dist/utils/configuration.js.map +0 -1
- package/dist/utils/exceptions.d.ts.map +0 -1
- package/dist/utils/exceptions.js.map +0 -1
- package/dist/utils/index.d.ts.map +0 -1
- package/dist/utils/index.js.map +0 -1
- package/dist/utils/logger.d.ts.map +0 -1
- package/dist/utils/logger.js.map +0 -1
- package/dist/utils/market-helper.d.ts.map +0 -1
- package/dist/utils/market-helper.js.map +0 -1
- package/dist/utils/nonce-cache.d.ts.map +0 -1
- package/dist/utils/nonce-cache.js.map +0 -1
- package/dist/utils/nonce-manager.d.ts.map +0 -1
- package/dist/utils/nonce-manager.js.map +0 -1
- package/dist/utils/order-status-checker.d.ts.map +0 -1
- package/dist/utils/order-status-checker.js.map +0 -1
- package/dist/utils/price-utils.d.ts.map +0 -1
- package/dist/utils/price-utils.js.map +0 -1
- package/dist/utils/request-batcher.d.ts.map +0 -1
- package/dist/utils/request-batcher.js.map +0 -1
- package/examples/ws.ts +0 -50
- package/examples/ws_async.ts +0 -112
- package/examples/ws_ping_pong.ts +0 -267
- package/examples/ws_send_batch_tx.ts +0 -229
- package/examples/ws_send_tx.ts +0 -154
- /package/dist/{api → cjs/api}/announcement-api.d.ts +0 -0
- /package/dist/{api → cjs/api}/announcement-api.js +0 -0
- /package/dist/{api → cjs/api}/api-client.d.ts +0 -0
- /package/dist/{api → cjs/api}/block-api.d.ts +0 -0
- /package/dist/{api → cjs/api}/block-api.js +0 -0
- /package/dist/{api → cjs/api}/funding-api.d.ts +0 -0
- /package/dist/{api → cjs/api}/funding-api.js +0 -0
- /package/dist/{bridge → cjs/bridge}/l1-bridge-client.d.ts +0 -0
- /package/dist/{bridge → cjs/bridge}/l1-bridge-client.js +0 -0
- /package/dist/{types → cjs/types}/api.js +0 -0
- /package/dist/{types → cjs/types}/config.d.ts +0 -0
- /package/dist/{types → cjs/types}/config.js +0 -0
- /package/dist/{types → cjs/types}/generated/openapi.d.ts +0 -0
- /package/dist/{types → cjs/types}/generated/openapi.js +0 -0
- /package/dist/{types → cjs/types}/index.d.ts +0 -0
- /package/dist/{types → cjs/types}/index.js +0 -0
- /package/dist/{types → cjs/types}/trading.d.ts +0 -0
- /package/dist/{types → cjs/types}/trading.js +0 -0
- /package/dist/{types → cjs/types}/transaction.d.ts +0 -0
- /package/dist/{types → cjs/types}/transaction.js +0 -0
- /package/dist/{utils → cjs/utils}/configuration.d.ts +0 -0
- /package/dist/{utils → cjs/utils}/configuration.js +0 -0
- /package/dist/{utils → cjs/utils}/exceptions.d.ts +0 -0
- /package/dist/{utils → cjs/utils}/exceptions.js +0 -0
- /package/dist/{utils → cjs/utils}/index.d.ts +0 -0
- /package/dist/{utils → cjs/utils}/index.js +0 -0
- /package/dist/{utils → cjs/utils}/logger.d.ts +0 -0
- /package/dist/{utils → cjs/utils}/logger.js +0 -0
- /package/dist/{utils → cjs/utils}/market-helper.d.ts +0 -0
- /package/dist/{utils → cjs/utils}/market-helper.js +0 -0
- /package/dist/{utils → cjs/utils}/nonce-cache.d.ts +0 -0
- /package/dist/{utils → cjs/utils}/nonce-cache.js +0 -0
- /package/dist/{utils → cjs/utils}/nonce-manager.d.ts +0 -0
- /package/dist/{utils → cjs/utils}/nonce-manager.js +0 -0
- /package/dist/{utils → cjs/utils}/order-status-checker.d.ts +0 -0
- /package/dist/{utils → cjs/utils}/order-status-checker.js +0 -0
- /package/dist/{utils → cjs/utils}/price-utils.d.ts +0 -0
- /package/dist/{utils → cjs/utils}/price-utils.js +0 -0
- /package/dist/{utils → cjs/utils}/request-batcher.d.ts +0 -0
- /package/dist/{utils → cjs/utils}/request-batcher.js +0 -0
package/README.md
CHANGED
|
@@ -1,476 +1,743 @@
|
|
|
1
|
-
# Lighter Protocol TypeScript SDK
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
- ✅
|
|
13
|
-
- ✅
|
|
14
|
-
- ✅
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
- **
|
|
30
|
-
- **
|
|
31
|
-
- **
|
|
32
|
-
- **
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
```
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
takeProfit: {
|
|
100
|
-
triggerPrice: 420000, // Take profit at $4200
|
|
101
|
-
isLimit: false // Market TP
|
|
102
|
-
}
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
// Check if order succeeded
|
|
106
|
-
if (!result.
|
|
107
|
-
console.error('❌ Order failed:', result.
|
|
108
|
-
return;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
console.log('✅
|
|
112
|
-
console.log('
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
await signerClient.
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
//
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
OrderType.
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
**
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
//
|
|
208
|
-
|
|
209
|
-
await signerClient.
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
//
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
```
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
//
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
//
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
1
|
+
# Lighter Protocol TypeScript SDK
|
|
2
|
+
|
|
3
|
+
A complete TypeScript SDK for Lighter Protocol - trade perpetual futures with built-in stop-loss and take-profit orders, position management, and comprehensive error handling.
|
|
4
|
+
|
|
5
|
+
## 🔐 Signer Integration
|
|
6
|
+
|
|
7
|
+
This SDK uses a WASM signer for cryptographic operations. The signer is compiled during the build process.
|
|
8
|
+
|
|
9
|
+
**Key Features:**
|
|
10
|
+
- ✅ Uses a WASM signer for transaction signing
|
|
11
|
+
- ✅ Automatic error recovery and nonce management
|
|
12
|
+
- ✅ Support for all transaction types
|
|
13
|
+
- ✅ Multiple API key support
|
|
14
|
+
- ✅ Production-ready and battle-tested
|
|
15
|
+
|
|
16
|
+
## 📦 Installation
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
npm install lighter-ts-sdk
|
|
20
|
+
# or
|
|
21
|
+
yarn add lighter-ts-sdk
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## 🚀 What Does This SDK Do?
|
|
25
|
+
|
|
26
|
+
The Lighter TypeScript SDK provides everything you need to:
|
|
27
|
+
- **Trade perpetual futures and SPOT Markets** on Lighter Protocol
|
|
28
|
+
- **Create orders** (Market, Limit, TWAP) with automatic SL/TP
|
|
29
|
+
- **Manage positions** (open, close, update leverage)
|
|
30
|
+
- **Transfer funds** between accounts
|
|
31
|
+
- **Monitor transactions** with built-in status tracking
|
|
32
|
+
- **Handle errors** automatically with retry logic
|
|
33
|
+
|
|
34
|
+
## 🎯 Getting Started
|
|
35
|
+
|
|
36
|
+
### Step 1: Set Up Your Environment
|
|
37
|
+
|
|
38
|
+
Create a `.env` file in your project root:
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
# Required credentials
|
|
42
|
+
API_PRIVATE_KEY=your_private_key_here
|
|
43
|
+
ACCOUNT_INDEX=0
|
|
44
|
+
API_KEY_INDEX=0
|
|
45
|
+
BASE_URL=https://mainnet.zklighter.elliot.ai
|
|
46
|
+
|
|
47
|
+
# Optional: for specific examples
|
|
48
|
+
MARKET_ID=0
|
|
49
|
+
SUB_ACCOUNT_INDEX=1
|
|
50
|
+
DEPOSIT_AMOUNT=1
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### Step 2: Install the SDK
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
npm install lighter-ts-sdk
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### Step 3: Your First Trade
|
|
60
|
+
|
|
61
|
+
```typescript
|
|
62
|
+
import { SignerClient, OrderType } from 'lighter-ts-sdk';
|
|
63
|
+
import dotenv from 'dotenv';
|
|
64
|
+
|
|
65
|
+
dotenv.config();
|
|
66
|
+
|
|
67
|
+
async function placeOrder() {
|
|
68
|
+
// Initialize the client
|
|
69
|
+
const signerClient = new SignerClient({
|
|
70
|
+
url: process.env.BASE_URL!,
|
|
71
|
+
privateKey: process.env.API_PRIVATE_KEY!,
|
|
72
|
+
accountIndex: parseInt(process.env.ACCOUNT_INDEX!),
|
|
73
|
+
apiKeyIndex: parseInt(process.env.API_KEY_INDEX!)
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
// Initialize WASM signer (required)
|
|
77
|
+
await signerClient.initialize();
|
|
78
|
+
await signerClient.ensureWasmClient();
|
|
79
|
+
|
|
80
|
+
// Create a market order with SL/TP using OTOCO
|
|
81
|
+
const result = await signerClient.createOtocoOrder({
|
|
82
|
+
mainOrder: {
|
|
83
|
+
marketIndex: 0, // ETH market
|
|
84
|
+
clientOrderIndex: Date.now(), // Unique ID
|
|
85
|
+
baseAmount: 10000, // 0.01 ETH (scaled: 1 ETH = 1,000,000)
|
|
86
|
+
isAsk: false, // BUY (true = SELL)
|
|
87
|
+
orderType: OrderType.MARKET,
|
|
88
|
+
|
|
89
|
+
// Slippage protection
|
|
90
|
+
idealPrice: 400000, // Ideal price ($4000)
|
|
91
|
+
maxSlippage: 0.001 // Max 0.1% slippage
|
|
92
|
+
},
|
|
93
|
+
// Automatic stop-loss
|
|
94
|
+
stopLoss: {
|
|
95
|
+
triggerPrice: 380000, // Stop loss at $3800
|
|
96
|
+
isLimit: false // Market SL
|
|
97
|
+
},
|
|
98
|
+
// Automatic take-profit
|
|
99
|
+
takeProfit: {
|
|
100
|
+
triggerPrice: 420000, // Take profit at $4200
|
|
101
|
+
isLimit: false // Market TP
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
// Check if order succeeded
|
|
106
|
+
if (result.error || !result.hash) {
|
|
107
|
+
console.error('❌ Order failed:', result.error);
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
console.log('✅ OTOCO order created!');
|
|
112
|
+
console.log('Grouped order hash:', result.hash);
|
|
113
|
+
|
|
114
|
+
// Wait for transaction confirmation
|
|
115
|
+
await signerClient.waitForTransaction(result.hash, 30000);
|
|
116
|
+
|
|
117
|
+
await signerClient.close();
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
placeOrder().catch(console.error);
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
## 📚 Core Concepts
|
|
124
|
+
|
|
125
|
+
### Understanding Price Units
|
|
126
|
+
|
|
127
|
+
Lighter uses fixed decimal scaling:
|
|
128
|
+
- **ETH amounts**: 1 ETH = 1,000,000 units
|
|
129
|
+
- **Prices**: $1 = 100 units
|
|
130
|
+
|
|
131
|
+
```typescript
|
|
132
|
+
// To buy 0.01 ETH at $4000:
|
|
133
|
+
baseAmount: 10000 // 0.01 ETH (10,000 / 1,000,000)
|
|
134
|
+
price: 400000 // $4000 (400,000 / 100)
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
### Order Types
|
|
138
|
+
|
|
139
|
+
```typescript
|
|
140
|
+
OrderType.MARKET // Executes immediately at market price
|
|
141
|
+
OrderType.LIMIT // Executes at your specified price
|
|
142
|
+
OrderType.TWAP // Executes gradually over time
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
### Direction (isAsk)
|
|
146
|
+
|
|
147
|
+
```typescript
|
|
148
|
+
isAsk: false // BUY - You're buying ETH
|
|
149
|
+
isAsk: true // SELL - You're selling ETH
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
### Stop-Loss and Take-Profit
|
|
153
|
+
|
|
154
|
+
SL/TP orders are **automatically reduce-only** - they only close positions:
|
|
155
|
+
|
|
156
|
+
```typescript
|
|
157
|
+
stopLoss: {
|
|
158
|
+
triggerPrice: 380000, // When price hits this, close position
|
|
159
|
+
isLimit: false // false = market SL, true = limit SL
|
|
160
|
+
},
|
|
161
|
+
takeProfit: {
|
|
162
|
+
triggerPrice: 420000, // When price hits this, take profit
|
|
163
|
+
isLimit: false // false = market TP, true = limit TP
|
|
164
|
+
}
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
**Important**: SL/TP orders require an existing position. For Market orders, this works immediately. For Limit orders, SL/TP are created in the same batch.
|
|
168
|
+
|
|
169
|
+
**Note for TWAP orders**: TWAP orders execute over time, creating positions gradually. SL/TP cannot be created in the same batch as TWAP orders. You should create SL/TP orders separately after the TWAP has started creating positions.
|
|
170
|
+
|
|
171
|
+
## 🌐 Network-Aware Transaction Status Monitoring
|
|
172
|
+
|
|
173
|
+
Lighter Protocol transactions go through multiple network states. Use `waitForTransaction()` to monitor status changes with automatic error handling and recovery:
|
|
174
|
+
|
|
175
|
+
```typescript
|
|
176
|
+
// Transaction status constants
|
|
177
|
+
enum TransactionStatus {
|
|
178
|
+
PENDING = 0, // Initial state, not yet queued
|
|
179
|
+
QUEUED = 1, // Queued for processing
|
|
180
|
+
COMMITTED = 2, // Committed to block
|
|
181
|
+
EXECUTED = 3, // Successfully executed
|
|
182
|
+
FAILED = 4, // Execution failed
|
|
183
|
+
REJECTED = 5 // Transaction rejected
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// Monitor transaction with built-in retry logic
|
|
187
|
+
try {
|
|
188
|
+
const txResult = await signerClient.waitForTransaction(
|
|
189
|
+
txHash,
|
|
190
|
+
30000, // maxWaitTime: wait up to 30 seconds
|
|
191
|
+
2000 // pollInterval: check status every 2 seconds
|
|
192
|
+
);
|
|
193
|
+
|
|
194
|
+
console.log('Status:', txResult.status); // Will be EXECUTED (3) if successful
|
|
195
|
+
console.log('✅ Transaction confirmed on-chain');
|
|
196
|
+
} catch (error) {
|
|
197
|
+
// Error handling is centralized here
|
|
198
|
+
if (error.message.includes('timeout')) {
|
|
199
|
+
console.error('❌ Transaction didn\'t confirm within timeout');
|
|
200
|
+
} else if (error.message.includes('FAILED') || error.message.includes('REJECTED')) {
|
|
201
|
+
console.error('❌ Transaction failed:', error.message);
|
|
202
|
+
} else {
|
|
203
|
+
console.error('❌ Unexpected error:', error.message);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
// Advanced: Manual status polling for fine-grained control
|
|
208
|
+
const checkStatus = async (hash: string) => {
|
|
209
|
+
const txResult = await signerClient.getTransaction(hash);
|
|
210
|
+
|
|
211
|
+
switch (txResult.status) {
|
|
212
|
+
case SignerClient.TX_STATUS_PENDING:
|
|
213
|
+
console.log('⏳ Still pending...');
|
|
214
|
+
break;
|
|
215
|
+
case SignerClient.TX_STATUS_QUEUED:
|
|
216
|
+
console.log('📋 Queued for processing');
|
|
217
|
+
break;
|
|
218
|
+
case SignerClient.TX_STATUS_COMMITTED:
|
|
219
|
+
console.log('✍️ Committed to block');
|
|
220
|
+
break;
|
|
221
|
+
case SignerClient.TX_STATUS_EXECUTED:
|
|
222
|
+
console.log('✅ Transaction executed successfully');
|
|
223
|
+
break;
|
|
224
|
+
case SignerClient.TX_STATUS_FAILED:
|
|
225
|
+
console.error('❌ Transaction execution failed');
|
|
226
|
+
break;
|
|
227
|
+
case SignerClient.TX_STATUS_REJECTED:
|
|
228
|
+
console.error('❌ Transaction was rejected');
|
|
229
|
+
break;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
return txResult;
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
// Pattern: Fire-and-forget with error handling
|
|
236
|
+
const result = await signerClient.createOrder(orderParams);
|
|
237
|
+
if (result.hash) {
|
|
238
|
+
// Schedule async confirmation check (don't block)
|
|
239
|
+
signerClient.waitForTransaction(result.hash, 60000).catch(err => {
|
|
240
|
+
console.error('Transaction confirmation failed:', err);
|
|
241
|
+
// Handle error (alert user, retry, etc.)
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
**Key Points:**
|
|
247
|
+
- `waitForTransaction()` centralizes error handling and automatic retries
|
|
248
|
+
- No need to parse transaction status manually after wait
|
|
249
|
+
- Throw errors are detected and propagated with context
|
|
250
|
+
- Use timeout to prevent indefinite waits in production systems
|
|
251
|
+
|
|
252
|
+
## 💰 Margin Management with Direction Constants
|
|
253
|
+
|
|
254
|
+
Lighter Protocol supports both cross-margin and isolated-margin modes. Margin direction constants determine whether you're adding or removing collateral:
|
|
255
|
+
|
|
256
|
+
### Margin Mode Constants
|
|
257
|
+
|
|
258
|
+
```typescript
|
|
259
|
+
// Margin mode
|
|
260
|
+
SignerClient.CROSS_MARGIN_MODE = 0 // Shared collateral across markets
|
|
261
|
+
SignerClient.ISOLATED_MARGIN_MODE = 1 // Per-market collateral
|
|
262
|
+
|
|
263
|
+
// Margin direction (when updating isolated margin)
|
|
264
|
+
SignerClient.ISOLATED_MARGIN_REMOVE_COLLATERAL = 0 // Remove collateral from position
|
|
265
|
+
SignerClient.ISOLATED_MARGIN_ADD_COLLATERAL = 1 // Add collateral to position
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
### Adding Margin (Collateral) to Isolated Position
|
|
269
|
+
|
|
270
|
+
```typescript
|
|
271
|
+
// Add 100 USDC collateral to ETH position in isolated mode
|
|
272
|
+
const [marginInfo, txHash, error] = await signerClient.updateMargin(
|
|
273
|
+
0, // marketIndex: 0 = ETH/USDC
|
|
274
|
+
100, // usdcAmount: 100 USDC to add
|
|
275
|
+
SignerClient.ISOLATED_MARGIN_ADD_COLLATERAL // direction: 1
|
|
276
|
+
);
|
|
277
|
+
|
|
278
|
+
if (error) {
|
|
279
|
+
console.error('Failed to add margin:', error);
|
|
280
|
+
} else {
|
|
281
|
+
console.log('✅ Margin added:', txHash);
|
|
282
|
+
|
|
283
|
+
// Wait for confirmation
|
|
284
|
+
await signerClient.waitForTransaction(txHash, 30000);
|
|
285
|
+
console.log('✅ Margin update confirmed');
|
|
286
|
+
}
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
### Removing Margin (Collateral) from Isolated Position
|
|
290
|
+
|
|
291
|
+
```typescript
|
|
292
|
+
// Remove 50 USDC collateral from ETH position
|
|
293
|
+
const [marginInfo, txHash, error] = await signerClient.updateMargin(
|
|
294
|
+
0, // marketIndex: 0 = ETH/USDC
|
|
295
|
+
50, // usdcAmount: 50 USDC to remove
|
|
296
|
+
SignerClient.ISOLATED_MARGIN_REMOVE_COLLATERAL // direction: 0
|
|
297
|
+
);
|
|
298
|
+
|
|
299
|
+
if (error) {
|
|
300
|
+
console.error('Failed to remove margin:', error);
|
|
301
|
+
} else {
|
|
302
|
+
console.log('✅ Margin removed:', txHash);
|
|
303
|
+
|
|
304
|
+
// Wait for confirmation
|
|
305
|
+
await signerClient.waitForTransaction(txHash, 30000);
|
|
306
|
+
console.log('✅ Margin removal confirmed');
|
|
307
|
+
}
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
### Cross-Margin vs Isolated-Margin Workflows
|
|
311
|
+
|
|
312
|
+
```typescript
|
|
313
|
+
// === CROSS-MARGIN MODE ===
|
|
314
|
+
// Step 1: Update leverage to cross-margin
|
|
315
|
+
const [crossInfo1, crossHash1, crossErr1] = await signerClient.updateLeverage(
|
|
316
|
+
0, // marketIndex
|
|
317
|
+
SignerClient.CROSS_MARGIN_MODE, // mode: 0
|
|
318
|
+
5 // leverage: 5x
|
|
319
|
+
);
|
|
320
|
+
|
|
321
|
+
// Step 2: Create order (no margin updates needed - uses account balance)
|
|
322
|
+
const result = await signerClient.createMarketOrder({
|
|
323
|
+
marketIndex: 0,
|
|
324
|
+
baseAmount: 10000,
|
|
325
|
+
isAsk: false
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
// === ISOLATED-MARGIN MODE ===
|
|
329
|
+
// Step 1: Update leverage to isolated-margin
|
|
330
|
+
const [isolatedInfo1, isolatedHash1, isolatedErr1] = await signerClient.updateLeverage(
|
|
331
|
+
0, // marketIndex
|
|
332
|
+
SignerClient.ISOLATED_MARGIN_MODE, // mode: 1
|
|
333
|
+
20 // leverage: 20x (IMF = 10000/20 = 500)
|
|
334
|
+
);
|
|
335
|
+
|
|
336
|
+
// Step 2: Create order
|
|
337
|
+
const result = await signerClient.createMarketOrder({
|
|
338
|
+
marketIndex: 0,
|
|
339
|
+
baseAmount: 10000,
|
|
340
|
+
isAsk: false
|
|
341
|
+
});
|
|
342
|
+
|
|
343
|
+
// Step 3: Manage collateral dynamically
|
|
344
|
+
// Add more collateral if position grows risky
|
|
345
|
+
await signerClient.updateMargin(
|
|
346
|
+
0,
|
|
347
|
+
200, // Add 200 USDC
|
|
348
|
+
SignerClient.ISOLATED_MARGIN_ADD_COLLATERAL
|
|
349
|
+
);
|
|
350
|
+
|
|
351
|
+
// Remove collateral if position has buffer
|
|
352
|
+
await signerClient.updateMargin(
|
|
353
|
+
0,
|
|
354
|
+
100, // Remove 100 USDC
|
|
355
|
+
SignerClient.ISOLATED_MARGIN_REMOVE_COLLATERAL
|
|
356
|
+
);
|
|
357
|
+
```
|
|
358
|
+
|
|
359
|
+
**Important:**
|
|
360
|
+
- Cross-margin pools collateral across all markets
|
|
361
|
+
- Isolated margin requires explicit collateral management per-market
|
|
362
|
+
- `direction` parameter is only used for isolated-margin positions
|
|
363
|
+
- Always verify sufficient collateral before removing it
|
|
364
|
+
|
|
365
|
+
## �🔧 Common Operations
|
|
366
|
+
|
|
367
|
+
### Create a Market Order
|
|
368
|
+
|
|
369
|
+
```typescript
|
|
370
|
+
const [tx, hash, error] = await signerClient.createMarketOrder({
|
|
371
|
+
marketIndex: 0,
|
|
372
|
+
clientOrderIndex: Date.now(),
|
|
373
|
+
baseAmount: 10000, // Amount (0.01 ETH)
|
|
374
|
+
avgExecutionPrice: 400000, // Max execution price ($4000)
|
|
375
|
+
isAsk: false // BUY
|
|
376
|
+
});
|
|
377
|
+
|
|
378
|
+
if (error || !hash) {
|
|
379
|
+
console.error('Failed:', error);
|
|
380
|
+
return;
|
|
381
|
+
}
|
|
382
|
+
```
|
|
383
|
+
|
|
384
|
+
### Create a Limit Order
|
|
385
|
+
|
|
386
|
+
```typescript
|
|
387
|
+
const [tx, hash, error] = await signerClient.createOrder({
|
|
388
|
+
marketIndex: 0,
|
|
389
|
+
clientOrderIndex: Date.now(),
|
|
390
|
+
baseAmount: 10000, // Amount (0.01 ETH)
|
|
391
|
+
price: 400000, // Limit price ($4000)
|
|
392
|
+
isAsk: false, // BUY
|
|
393
|
+
orderType: OrderType.LIMIT,
|
|
394
|
+
orderExpiry: Date.now() + (60 * 60 * 1000) // Expires in 1 hour
|
|
395
|
+
});
|
|
396
|
+
|
|
397
|
+
if (error || !hash) {
|
|
398
|
+
console.error('Failed:', error);
|
|
399
|
+
return;
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
// Wait for it to fill
|
|
403
|
+
await signerClient.waitForTransaction(hash);
|
|
404
|
+
```
|
|
405
|
+
|
|
406
|
+
### Cancel an Order
|
|
407
|
+
|
|
408
|
+
```typescript
|
|
409
|
+
const [tx, hash, error] = await signerClient.cancelOrder({
|
|
410
|
+
marketIndex: 0,
|
|
411
|
+
orderIndex: 12345 // Your order's index
|
|
412
|
+
});
|
|
413
|
+
|
|
414
|
+
if (error) {
|
|
415
|
+
console.error('Cancel failed:', error);
|
|
416
|
+
return;
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
await signerClient.waitForTransaction(hash);
|
|
420
|
+
console.log('✅ Order cancelled');
|
|
421
|
+
```
|
|
422
|
+
|
|
423
|
+
### Close a Position
|
|
424
|
+
|
|
425
|
+
```typescript
|
|
426
|
+
const [tx, hash, error] = await signerClient.createMarketOrder({
|
|
427
|
+
marketIndex: 0,
|
|
428
|
+
clientOrderIndex: Date.now(),
|
|
429
|
+
baseAmount: 10000, // Position size to close
|
|
430
|
+
avgExecutionPrice: 400000,
|
|
431
|
+
isAsk: false, // Opposite of position
|
|
432
|
+
reduceOnly: true // IMPORTANT: Only closes, doesn't open new
|
|
433
|
+
});
|
|
434
|
+
|
|
435
|
+
if (error) {
|
|
436
|
+
console.error('Close failed:', error);
|
|
437
|
+
return;
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
await signerClient.waitForTransaction(hash);
|
|
441
|
+
console.log('✅ Position closed');
|
|
442
|
+
```
|
|
443
|
+
|
|
444
|
+
### Check Order Status
|
|
445
|
+
|
|
446
|
+
```typescript
|
|
447
|
+
const status = await signerClient.getTransaction(txHash);
|
|
448
|
+
console.log('Status:', status.status); // 0=pending, 1=queued, 2=committed, 3=executed
|
|
449
|
+
```
|
|
450
|
+
|
|
451
|
+
## 🛠️ API Reference
|
|
452
|
+
|
|
453
|
+
### SignerClient Methods
|
|
454
|
+
|
|
455
|
+
#### Order Management
|
|
456
|
+
```typescript
|
|
457
|
+
// Create an OTOCO order (entry + SL + TP)
|
|
458
|
+
createOtocoOrder(params) -> Promise<{ tx, hash, error }>
|
|
459
|
+
|
|
460
|
+
// Create an OCO order (one cancels other)
|
|
461
|
+
createOcoOrder(params) -> Promise<{ tx, hash, error }>
|
|
462
|
+
|
|
463
|
+
// Create a single order
|
|
464
|
+
createOrder(params) -> Promise<[txInfo, txHash, error]>
|
|
465
|
+
|
|
466
|
+
// Cancel a specific order
|
|
467
|
+
cancelOrder(params) -> Promise<[txInfo, txHash, error]>
|
|
468
|
+
|
|
469
|
+
// Cancel all orders
|
|
470
|
+
cancelAllOrders(timeInForce, time) -> Promise<[txInfo, txHash, error]>
|
|
471
|
+
```
|
|
472
|
+
|
|
473
|
+
#### Position Management
|
|
474
|
+
```typescript
|
|
475
|
+
// Close specific position
|
|
476
|
+
createMarketOrder({ reduceOnly: true }) -> Promise<[txInfo, txHash, error]>
|
|
477
|
+
|
|
478
|
+
// Close all positions
|
|
479
|
+
closeAllPositions() -> Promise<[txs[], responses[], errors[]]>
|
|
480
|
+
```
|
|
481
|
+
|
|
482
|
+
#### Transaction Monitoring
|
|
483
|
+
```typescript
|
|
484
|
+
// Get transaction details
|
|
485
|
+
getTransaction(txHash) -> Promise<Transaction>
|
|
486
|
+
|
|
487
|
+
// Wait for transaction (with timeout)
|
|
488
|
+
waitForTransaction(txHash, maxWaitTime, pollInterval) -> Promise<Transaction>
|
|
489
|
+
```
|
|
490
|
+
|
|
491
|
+
### Order Parameters
|
|
492
|
+
|
|
493
|
+
```typescript
|
|
494
|
+
// For OTOCO orders (entry + SL/TP)
|
|
495
|
+
interface OtocoOrderParams {
|
|
496
|
+
mainOrder: {
|
|
497
|
+
marketIndex: number; // Market ID (0 = ETH)
|
|
498
|
+
baseAmount: number; // Amount in units
|
|
499
|
+
isAsk: boolean; // true = SELL, false = BUY
|
|
500
|
+
orderType: OrderType.LIMIT | OrderType.MARKET;
|
|
501
|
+
price?: number; // For LIMIT orders
|
|
502
|
+
avgExecutionPrice?: number; // For MARKET orders
|
|
503
|
+
maxSlippage?: number; // Max slippage (0.001 = 0.1%)
|
|
504
|
+
idealPrice?: number; // Target price
|
|
505
|
+
};
|
|
506
|
+
stopLoss: {
|
|
507
|
+
triggerPrice: number;
|
|
508
|
+
price?: number;
|
|
509
|
+
isLimit?: boolean;
|
|
510
|
+
};
|
|
511
|
+
takeProfit: {
|
|
512
|
+
triggerPrice: number;
|
|
513
|
+
price?: number;
|
|
514
|
+
isLimit?: boolean;
|
|
515
|
+
};
|
|
516
|
+
nonce?: number;
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
// For single orders
|
|
520
|
+
interface CreateOrderParams {
|
|
521
|
+
marketIndex: number;
|
|
522
|
+
clientOrderIndex: number;
|
|
523
|
+
baseAmount: number;
|
|
524
|
+
price: number;
|
|
525
|
+
isAsk: boolean;
|
|
526
|
+
orderType?: OrderType;
|
|
527
|
+
timeInForce?: TimeInForce;
|
|
528
|
+
reduceOnly?: boolean;
|
|
529
|
+
orderExpiry?: number;
|
|
530
|
+
}
|
|
531
|
+
```
|
|
532
|
+
|
|
533
|
+
## 💡 Tips for Beginners
|
|
534
|
+
|
|
535
|
+
### 1. Always Use Environment Variables
|
|
536
|
+
|
|
537
|
+
```typescript
|
|
538
|
+
// ❌ DON'T hardcode credentials
|
|
539
|
+
const privateKey = '0xabc123...';
|
|
540
|
+
|
|
541
|
+
// ✅ DO use environment variables
|
|
542
|
+
const privateKey = process.env.API_PRIVATE_KEY;
|
|
543
|
+
```
|
|
544
|
+
|
|
545
|
+
### 2. Handle Errors Properly
|
|
546
|
+
|
|
547
|
+
```typescript
|
|
548
|
+
try {
|
|
549
|
+
const [tx, hash, error] = await signerClient.createOrder(params);
|
|
550
|
+
|
|
551
|
+
if (error || !hash) {
|
|
552
|
+
console.error('Order failed:', error);
|
|
553
|
+
return; // Exit early
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
// Success path
|
|
557
|
+
console.log('Order created:', hash);
|
|
558
|
+
} catch (error) {
|
|
559
|
+
console.error('Unexpected error:', error);
|
|
560
|
+
}
|
|
561
|
+
```
|
|
562
|
+
|
|
563
|
+
### 3. Check Transaction Status
|
|
564
|
+
|
|
565
|
+
```typescript
|
|
566
|
+
// Wait for transaction to be confirmed
|
|
567
|
+
try {
|
|
568
|
+
await signerClient.waitForTransaction(txHash, 30000, 2000);
|
|
569
|
+
console.log('✅ Transaction confirmed');
|
|
570
|
+
} catch (error) {
|
|
571
|
+
console.error('❌ Transaction failed:', error.message);
|
|
572
|
+
}
|
|
573
|
+
```
|
|
574
|
+
|
|
575
|
+
### 4. Close Resources
|
|
576
|
+
|
|
577
|
+
```typescript
|
|
578
|
+
try {
|
|
579
|
+
// ... use signerClient
|
|
580
|
+
} finally {
|
|
581
|
+
await signerClient.close(); // Always close when done
|
|
582
|
+
}
|
|
583
|
+
```
|
|
584
|
+
|
|
585
|
+
## 📖 Examples
|
|
586
|
+
|
|
587
|
+
The `examples/` directory contains working examples for every feature:
|
|
588
|
+
|
|
589
|
+
```bash
|
|
590
|
+
# Run examples
|
|
591
|
+
npx tsx examples/create_market_order.ts # Market order with SL/TP
|
|
592
|
+
npx tsx examples/create_limit_order.ts # Limit order with SL/TP
|
|
593
|
+
npx tsx examples/cancel_order.ts # Cancel orders
|
|
594
|
+
npx tsx examples/close_position.ts # Close positions
|
|
595
|
+
npx tsx examples/deposit_to_subaccount.ts # Fund transfers
|
|
596
|
+
```
|
|
597
|
+
|
|
598
|
+
## 🎓 Learning Path
|
|
599
|
+
|
|
600
|
+
1. **Start Here**: `examples/create_market_order.ts` - Simplest order creation
|
|
601
|
+
2. **Next**: `examples/create_limit_order.ts` - Learn about limit orders
|
|
602
|
+
3. **Then**: `examples/cancel_order.ts` - Learn about order management
|
|
603
|
+
4. **Advanced**: `examples/send_tx_batch.ts` - Batch transactions
|
|
604
|
+
|
|
605
|
+
## ✅ Live Executed Transactions (Testnet)
|
|
606
|
+
|
|
607
|
+
The SDK has been thoroughly tested with real transactions on Lighter Protocol testnet. Here are verified transaction hashes from live example execution:
|
|
608
|
+
|
|
609
|
+
### Real Transaction Examples
|
|
610
|
+
|
|
611
|
+
**1. Market Order with OTOCO (SL/TP)**
|
|
612
|
+
```
|
|
613
|
+
Transaction Hash: c622140d6d15760bbf5462e3f472a97b0eac8fb138becc00cb7ce24b223c19e352fe7e15098337c5
|
|
614
|
+
Example: examples/create_market_order.ts
|
|
615
|
+
Details: 60 ETH order with $2800 SL / $3100 TP
|
|
616
|
+
Status: ✅ Submitted to testnet
|
|
617
|
+
```
|
|
618
|
+
|
|
619
|
+
**2. Limit Order with Grouping**
|
|
620
|
+
```
|
|
621
|
+
Transaction Hash: 4349b469fa8d71161fc012a9d3224e1f4eda355527e91e83bb193ab9345bc19bfba22d7ab64721d1
|
|
622
|
+
Example: examples/create_limit_order.ts
|
|
623
|
+
Details: Limit entry with automatic SL/TP attachment
|
|
624
|
+
Status: ✅ Submitted to testnet
|
|
625
|
+
```
|
|
626
|
+
|
|
627
|
+
**3. Market Order with Max Slippage (1%)**
|
|
628
|
+
```
|
|
629
|
+
Transaction Hash: f1d2ab2ca65f77310502298961c6e738e21a2b9f2e8e4614a75d2bbf5a4168d225bec7708675cdca
|
|
630
|
+
Example: examples/create_market_order_max_slippage.ts
|
|
631
|
+
Details: Market order with 1% slippage protection
|
|
632
|
+
Status: ✅ Submitted to testnet
|
|
633
|
+
```
|
|
634
|
+
|
|
635
|
+
**4. IOC Order with Attached SL/TP**
|
|
636
|
+
```
|
|
637
|
+
Transaction Hash: 1d64b0bab34e2469a190558e53d13c8614ebd5075d4ed2eca079aab551a259b92343ad1c5d1fbed8
|
|
638
|
+
Example: examples/create_grouped_ioc_with_attached_sl_tp.ts
|
|
639
|
+
Details: Immediate-or-cancel with grouped exits
|
|
640
|
+
Status: ✅ Submitted to testnet
|
|
641
|
+
```
|
|
642
|
+
|
|
643
|
+
### Running Your Own Transactions
|
|
644
|
+
|
|
645
|
+
To execute transactions yourself:
|
|
646
|
+
|
|
647
|
+
```typescript
|
|
648
|
+
// All credentials loaded from .env
|
|
649
|
+
const signerClient = new SignerClient({
|
|
650
|
+
url: process.env.BASE_URL!,
|
|
651
|
+
privateKey: process.env.API_PRIVATE_KEY!,
|
|
652
|
+
accountIndex: parseInt(process.env.ACCOUNT_INDEX!),
|
|
653
|
+
apiKeyIndex: parseInt(process.env.API_KEY_INDEX!)
|
|
654
|
+
});
|
|
655
|
+
|
|
656
|
+
await signerClient.initialize();
|
|
657
|
+
await signerClient.ensureWasmClient();
|
|
658
|
+
|
|
659
|
+
// Create your order (any example will generate a real hash)
|
|
660
|
+
const result = await signerClient.createMarketOrder({...});
|
|
661
|
+
console.log('Your transaction hash:', result.hash);
|
|
662
|
+
```
|
|
663
|
+
|
|
664
|
+
All example files in `examples/` directory will generate valid transaction hashes when run with proper credentials.
|
|
665
|
+
|
|
666
|
+
## 🔒 Security
|
|
667
|
+
|
|
668
|
+
- ✅ Never commit `.env` files
|
|
669
|
+
- ✅ Use environment variables for all credentials
|
|
670
|
+
- ✅ Test with small amounts first
|
|
671
|
+
- ✅ Monitor all transactions
|
|
672
|
+
- ✅ Use proper error handling
|
|
673
|
+
|
|
674
|
+
## 🔧 Building from Source
|
|
675
|
+
|
|
676
|
+
If you want to build the SDK from source or rebuild the WASM signer:
|
|
677
|
+
|
|
678
|
+
```bash
|
|
679
|
+
# Clone the repository
|
|
680
|
+
git clone https://github.com/bvvvp009/lighter-ts.git
|
|
681
|
+
cd lighter-ts
|
|
682
|
+
|
|
683
|
+
# Install dependencies
|
|
684
|
+
npm install
|
|
685
|
+
|
|
686
|
+
# Build WASM signer assets
|
|
687
|
+
npm run build:wasm
|
|
688
|
+
|
|
689
|
+
# Build TypeScript
|
|
690
|
+
npm run build
|
|
691
|
+
```
|
|
692
|
+
|
|
693
|
+
**Note**: The build script automatically prepares and compiles WASM signer assets. No extra local signer repository is required.
|
|
694
|
+
|
|
695
|
+
## 🔄 Migration from Previous Versions
|
|
696
|
+
|
|
697
|
+
If you're upgrading from an older version that used `temp-lighter-go`:
|
|
698
|
+
|
|
699
|
+
### What Changed
|
|
700
|
+
|
|
701
|
+
- ✅ **Signer**: Uses the current WASM signer workflow instead of local `temp-lighter-go`
|
|
702
|
+
- ✅ **Build Process**: WASM is compiled directly from GitHub repo
|
|
703
|
+
- ✅ **Functions**: All transaction types are supported by the WASM signer flow
|
|
704
|
+
- ✅ **Error Handling**: Improved error recovery and nonce management
|
|
705
|
+
|
|
706
|
+
### Breaking Changes
|
|
707
|
+
|
|
708
|
+
**None!** The API remains the same. The change is internal to signer implementation.
|
|
709
|
+
|
|
710
|
+
### Removed Functions
|
|
711
|
+
|
|
712
|
+
These functions are no longer supported and have been removed:
|
|
713
|
+
- `getPublicKey()` - Use `generateAPIKey()` instead (returns both keys)
|
|
714
|
+
- `switchAPIKey()` - Use `createClient()` with different `apiKeyIndex` values instead
|
|
715
|
+
|
|
716
|
+
### Migration Steps
|
|
717
|
+
|
|
718
|
+
1. **Update your code** (if using removed functions):
|
|
719
|
+
```typescript
|
|
720
|
+
// Old (removed)
|
|
721
|
+
const publicKey = await client.getPublicKey(privateKey);
|
|
722
|
+
|
|
723
|
+
// New (use generateAPIKey)
|
|
724
|
+
const { privateKey, publicKey } = await client.generateAPIKey();
|
|
725
|
+
```
|
|
726
|
+
|
|
727
|
+
2. **Rebuild WASM** (if building from source):
|
|
728
|
+
```bash
|
|
729
|
+
npm run build:wasm
|
|
730
|
+
```
|
|
731
|
+
|
|
732
|
+
3. **Test your integration** - All existing code should work without changes.
|
|
733
|
+
|
|
734
|
+
## 📞 Getting Help
|
|
735
|
+
|
|
736
|
+
- Check the examples in `examples/` directory
|
|
737
|
+
- Read error messages carefully - they're informative
|
|
738
|
+
- Ensure environment variables are set correctly
|
|
739
|
+
- Start with `examples/create_market_order.ts`
|
|
740
|
+
|
|
741
|
+
## License
|
|
742
|
+
|
|
743
|
+
MIT License - see LICENSE file for details.
|