@upbit-official/upbit-sdk 0.9.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 +201 -0
- package/README.md +390 -0
- package/api-promise.d.mts +2 -0
- package/api-promise.d.mts.map +1 -0
- package/api-promise.d.ts +2 -0
- package/api-promise.d.ts.map +1 -0
- package/api-promise.js +6 -0
- package/api-promise.js.map +1 -0
- package/api-promise.mjs +2 -0
- package/api-promise.mjs.map +1 -0
- package/client.d.mts +261 -0
- package/client.d.mts.map +1 -0
- package/client.d.ts +261 -0
- package/client.d.ts.map +1 -0
- package/client.js +557 -0
- package/client.js.map +1 -0
- package/client.mjs +553 -0
- package/client.mjs.map +1 -0
- package/core/EventEmitter.d.mts +56 -0
- package/core/EventEmitter.d.mts.map +1 -0
- package/core/EventEmitter.d.ts +56 -0
- package/core/EventEmitter.d.ts.map +1 -0
- package/core/EventEmitter.js +93 -0
- package/core/EventEmitter.js.map +1 -0
- package/core/EventEmitter.mjs +88 -0
- package/core/EventEmitter.mjs.map +1 -0
- package/core/api-promise.d.mts +46 -0
- package/core/api-promise.d.mts.map +1 -0
- package/core/api-promise.d.ts +46 -0
- package/core/api-promise.d.ts.map +1 -0
- package/core/api-promise.js +73 -0
- package/core/api-promise.js.map +1 -0
- package/core/api-promise.mjs +69 -0
- package/core/api-promise.mjs.map +1 -0
- package/core/error.d.mts +51 -0
- package/core/error.d.mts.map +1 -0
- package/core/error.d.ts +51 -0
- package/core/error.d.ts.map +1 -0
- package/core/error.js +150 -0
- package/core/error.js.map +1 -0
- package/core/error.mjs +133 -0
- package/core/error.mjs.map +1 -0
- package/core/pagination.d.mts +63 -0
- package/core/pagination.d.mts.map +1 -0
- package/core/pagination.d.ts +63 -0
- package/core/pagination.d.ts.map +1 -0
- package/core/pagination.js +125 -0
- package/core/pagination.js.map +1 -0
- package/core/pagination.mjs +118 -0
- package/core/pagination.mjs.map +1 -0
- package/core/resource.d.mts +6 -0
- package/core/resource.d.mts.map +1 -0
- package/core/resource.d.ts +6 -0
- package/core/resource.d.ts.map +1 -0
- package/core/resource.js +10 -0
- package/core/resource.js.map +1 -0
- package/core/resource.mjs +6 -0
- package/core/resource.mjs.map +1 -0
- package/core/uploads.d.mts +3 -0
- package/core/uploads.d.mts.map +1 -0
- package/core/uploads.d.ts +3 -0
- package/core/uploads.d.ts.map +1 -0
- package/core/uploads.js +6 -0
- package/core/uploads.js.map +1 -0
- package/core/uploads.mjs +2 -0
- package/core/uploads.mjs.map +1 -0
- package/error.d.mts +2 -0
- package/error.d.mts.map +1 -0
- package/error.d.ts +2 -0
- package/error.d.ts.map +1 -0
- package/error.js +6 -0
- package/error.js.map +1 -0
- package/error.mjs +2 -0
- package/error.mjs.map +1 -0
- package/index.d.mts +8 -0
- package/index.d.mts.map +1 -0
- package/index.d.ts +8 -0
- package/index.d.ts.map +1 -0
- package/index.js +36 -0
- package/index.js.map +1 -0
- package/index.mjs +8 -0
- package/index.mjs.map +1 -0
- package/internal/builtin-types.d.mts +73 -0
- package/internal/builtin-types.d.mts.map +1 -0
- package/internal/builtin-types.d.ts +73 -0
- package/internal/builtin-types.d.ts.map +1 -0
- package/internal/builtin-types.js +3 -0
- package/internal/builtin-types.js.map +1 -0
- package/internal/builtin-types.mjs +2 -0
- package/internal/builtin-types.mjs.map +1 -0
- package/internal/errors.d.mts +3 -0
- package/internal/errors.d.mts.map +1 -0
- package/internal/errors.d.ts +3 -0
- package/internal/errors.d.ts.map +1 -0
- package/internal/errors.js +40 -0
- package/internal/errors.js.map +1 -0
- package/internal/errors.mjs +35 -0
- package/internal/errors.mjs.map +1 -0
- package/internal/headers.d.mts +20 -0
- package/internal/headers.d.mts.map +1 -0
- package/internal/headers.d.ts +20 -0
- package/internal/headers.d.ts.map +1 -0
- package/internal/headers.js +78 -0
- package/internal/headers.js.map +1 -0
- package/internal/headers.mjs +73 -0
- package/internal/headers.mjs.map +1 -0
- package/internal/parse.d.mts +12 -0
- package/internal/parse.d.mts.map +1 -0
- package/internal/parse.d.ts +12 -0
- package/internal/parse.d.ts.map +1 -0
- package/internal/parse.js +40 -0
- package/internal/parse.js.map +1 -0
- package/internal/parse.mjs +37 -0
- package/internal/parse.mjs.map +1 -0
- package/internal/qs/formats.d.mts +7 -0
- package/internal/qs/formats.d.mts.map +1 -0
- package/internal/qs/formats.d.ts +7 -0
- package/internal/qs/formats.d.ts.map +1 -0
- package/internal/qs/formats.js +13 -0
- package/internal/qs/formats.js.map +1 -0
- package/internal/qs/formats.mjs +9 -0
- package/internal/qs/formats.mjs.map +1 -0
- package/internal/qs/index.d.mts +10 -0
- package/internal/qs/index.d.mts.map +1 -0
- package/internal/qs/index.d.ts +10 -0
- package/internal/qs/index.d.ts.map +1 -0
- package/internal/qs/index.js +14 -0
- package/internal/qs/index.js.map +1 -0
- package/internal/qs/index.mjs +10 -0
- package/internal/qs/index.mjs.map +1 -0
- package/internal/qs/stringify.d.mts +3 -0
- package/internal/qs/stringify.d.mts.map +1 -0
- package/internal/qs/stringify.d.ts +3 -0
- package/internal/qs/stringify.d.ts.map +1 -0
- package/internal/qs/stringify.js +277 -0
- package/internal/qs/stringify.js.map +1 -0
- package/internal/qs/stringify.mjs +274 -0
- package/internal/qs/stringify.mjs.map +1 -0
- package/internal/qs/types.d.mts +57 -0
- package/internal/qs/types.d.mts.map +1 -0
- package/internal/qs/types.d.ts +57 -0
- package/internal/qs/types.d.ts.map +1 -0
- package/internal/qs/types.js +3 -0
- package/internal/qs/types.js.map +1 -0
- package/internal/qs/types.mjs +2 -0
- package/internal/qs/types.mjs.map +1 -0
- package/internal/qs/utils.d.mts +15 -0
- package/internal/qs/utils.d.mts.map +1 -0
- package/internal/qs/utils.d.ts +15 -0
- package/internal/qs/utils.d.ts.map +1 -0
- package/internal/qs/utils.js +230 -0
- package/internal/qs/utils.js.map +1 -0
- package/internal/qs/utils.mjs +217 -0
- package/internal/qs/utils.mjs.map +1 -0
- package/internal/request-options.d.mts +78 -0
- package/internal/request-options.d.mts.map +1 -0
- package/internal/request-options.d.ts +78 -0
- package/internal/request-options.d.ts.map +1 -0
- package/internal/request-options.js +13 -0
- package/internal/request-options.js.map +1 -0
- package/internal/request-options.mjs +9 -0
- package/internal/request-options.mjs.map +1 -0
- package/internal/shim-types.d.mts +17 -0
- package/internal/shim-types.d.mts.map +1 -0
- package/internal/shim-types.d.ts +17 -0
- package/internal/shim-types.d.ts.map +1 -0
- package/internal/shim-types.js +9 -0
- package/internal/shim-types.js.map +1 -0
- package/internal/shim-types.mjs +8 -0
- package/internal/shim-types.mjs.map +1 -0
- package/internal/shims.d.mts +26 -0
- package/internal/shims.d.mts.map +1 -0
- package/internal/shims.d.ts +26 -0
- package/internal/shims.d.ts.map +1 -0
- package/internal/shims.js +97 -0
- package/internal/shims.js.map +1 -0
- package/internal/shims.mjs +90 -0
- package/internal/shims.mjs.map +1 -0
- package/internal/to-file.d.mts +45 -0
- package/internal/to-file.d.mts.map +1 -0
- package/internal/to-file.d.ts +45 -0
- package/internal/to-file.d.ts.map +1 -0
- package/internal/to-file.js +91 -0
- package/internal/to-file.js.map +1 -0
- package/internal/to-file.mjs +88 -0
- package/internal/to-file.mjs.map +1 -0
- package/internal/tslib.js +81 -0
- package/internal/tslib.mjs +17 -0
- package/internal/types.d.mts +69 -0
- package/internal/types.d.mts.map +1 -0
- package/internal/types.d.ts +69 -0
- package/internal/types.d.ts.map +1 -0
- package/internal/types.js +3 -0
- package/internal/types.js.map +1 -0
- package/internal/types.mjs +2 -0
- package/internal/types.mjs.map +1 -0
- package/internal/uploads.d.mts +42 -0
- package/internal/uploads.d.mts.map +1 -0
- package/internal/uploads.d.ts +42 -0
- package/internal/uploads.d.ts.map +1 -0
- package/internal/uploads.js +141 -0
- package/internal/uploads.js.map +1 -0
- package/internal/uploads.mjs +131 -0
- package/internal/uploads.mjs.map +1 -0
- package/internal/utils/base64.d.mts +3 -0
- package/internal/utils/base64.d.mts.map +1 -0
- package/internal/utils/base64.d.ts +3 -0
- package/internal/utils/base64.d.ts.map +1 -0
- package/internal/utils/base64.js +37 -0
- package/internal/utils/base64.js.map +1 -0
- package/internal/utils/base64.mjs +32 -0
- package/internal/utils/base64.mjs.map +1 -0
- package/internal/utils/bytes.d.mts +4 -0
- package/internal/utils/bytes.d.mts.map +1 -0
- package/internal/utils/bytes.d.ts +4 -0
- package/internal/utils/bytes.d.ts.map +1 -0
- package/internal/utils/bytes.js +31 -0
- package/internal/utils/bytes.js.map +1 -0
- package/internal/utils/bytes.mjs +26 -0
- package/internal/utils/bytes.mjs.map +1 -0
- package/internal/utils/env.d.mts +9 -0
- package/internal/utils/env.d.mts.map +1 -0
- package/internal/utils/env.d.ts +9 -0
- package/internal/utils/env.d.ts.map +1 -0
- package/internal/utils/env.js +21 -0
- package/internal/utils/env.js.map +1 -0
- package/internal/utils/env.mjs +17 -0
- package/internal/utils/env.mjs.map +1 -0
- package/internal/utils/log.d.mts +37 -0
- package/internal/utils/log.d.mts.map +1 -0
- package/internal/utils/log.d.ts +37 -0
- package/internal/utils/log.d.ts.map +1 -0
- package/internal/utils/log.js +84 -0
- package/internal/utils/log.js.map +1 -0
- package/internal/utils/log.mjs +78 -0
- package/internal/utils/log.mjs.map +1 -0
- package/internal/utils/path.d.mts +15 -0
- package/internal/utils/path.d.mts.map +1 -0
- package/internal/utils/path.d.ts +15 -0
- package/internal/utils/path.d.ts.map +1 -0
- package/internal/utils/path.js +79 -0
- package/internal/utils/path.js.map +1 -0
- package/internal/utils/path.mjs +74 -0
- package/internal/utils/path.mjs.map +1 -0
- package/internal/utils/query.d.mts +2 -0
- package/internal/utils/query.d.mts.map +1 -0
- package/internal/utils/query.d.ts +2 -0
- package/internal/utils/query.d.ts.map +1 -0
- package/internal/utils/query.js +9 -0
- package/internal/utils/query.js.map +1 -0
- package/internal/utils/query.mjs +5 -0
- package/internal/utils/query.mjs.map +1 -0
- package/internal/utils/sleep.d.mts +2 -0
- package/internal/utils/sleep.d.mts.map +1 -0
- package/internal/utils/sleep.d.ts +2 -0
- package/internal/utils/sleep.d.ts.map +1 -0
- package/internal/utils/sleep.js +6 -0
- package/internal/utils/sleep.js.map +1 -0
- package/internal/utils/sleep.mjs +2 -0
- package/internal/utils/sleep.mjs.map +1 -0
- package/internal/utils/uuid.d.mts +5 -0
- package/internal/utils/uuid.d.mts.map +1 -0
- package/internal/utils/uuid.d.ts +5 -0
- package/internal/utils/uuid.d.ts.map +1 -0
- package/internal/utils/uuid.js +21 -0
- package/internal/utils/uuid.js.map +1 -0
- package/internal/utils/uuid.mjs +17 -0
- package/internal/utils/uuid.mjs.map +1 -0
- package/internal/utils/values.d.mts +18 -0
- package/internal/utils/values.d.mts.map +1 -0
- package/internal/utils/values.d.ts +18 -0
- package/internal/utils/values.d.ts.map +1 -0
- package/internal/utils/values.js +111 -0
- package/internal/utils/values.js.map +1 -0
- package/internal/utils/values.mjs +93 -0
- package/internal/utils/values.mjs.map +1 -0
- package/internal/utils.d.mts +8 -0
- package/internal/utils.d.mts.map +1 -0
- package/internal/utils.d.ts +8 -0
- package/internal/utils.d.ts.map +1 -0
- package/internal/utils.js +11 -0
- package/internal/utils.js.map +1 -0
- package/internal/utils.mjs +8 -0
- package/internal/utils.mjs.map +1 -0
- package/internal/ws.d.mts +31 -0
- package/internal/ws.d.mts.map +1 -0
- package/internal/ws.d.ts +31 -0
- package/internal/ws.d.ts.map +1 -0
- package/internal/ws.js +39 -0
- package/internal/ws.js.map +1 -0
- package/internal/ws.mjs +36 -0
- package/internal/ws.mjs.map +1 -0
- package/lib/index.d.mts +5 -0
- package/lib/index.d.mts.map +1 -0
- package/lib/index.d.ts +5 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +11 -0
- package/lib/index.js.map +1 -0
- package/lib/index.mjs +4 -0
- package/lib/index.mjs.map +1 -0
- package/lib/jsonParseFloat.d.mts +16 -0
- package/lib/jsonParseFloat.d.mts.map +1 -0
- package/lib/jsonParseFloat.d.ts +16 -0
- package/lib/jsonParseFloat.d.ts.map +1 -0
- package/lib/jsonParseFloat.js +77 -0
- package/lib/jsonParseFloat.js.map +1 -0
- package/lib/jsonParseFloat.mjs +74 -0
- package/lib/jsonParseFloat.mjs.map +1 -0
- package/lib/jwtAuth.d.mts +7 -0
- package/lib/jwtAuth.d.mts.map +1 -0
- package/lib/jwtAuth.d.ts +7 -0
- package/lib/jwtAuth.d.ts.map +1 -0
- package/lib/jwtAuth.js +33 -0
- package/lib/jwtAuth.js.map +1 -0
- package/lib/jwtAuth.mjs +30 -0
- package/lib/jwtAuth.mjs.map +1 -0
- package/lib/ws.d.mts +95 -0
- package/lib/ws.d.mts.map +1 -0
- package/lib/ws.d.ts +95 -0
- package/lib/ws.d.ts.map +1 -0
- package/lib/ws.js +229 -0
- package/lib/ws.js.map +1 -0
- package/lib/ws.mjs +223 -0
- package/lib/ws.mjs.map +1 -0
- package/package.json +169 -0
- package/pagination.d.mts +2 -0
- package/pagination.d.mts.map +1 -0
- package/pagination.d.ts +2 -0
- package/pagination.d.ts.map +1 -0
- package/pagination.js +6 -0
- package/pagination.js.map +1 -0
- package/pagination.mjs +2 -0
- package/pagination.mjs.map +1 -0
- package/resource.d.mts +2 -0
- package/resource.d.mts.map +1 -0
- package/resource.d.ts +2 -0
- package/resource.d.ts.map +1 -0
- package/resource.js +6 -0
- package/resource.js.map +1 -0
- package/resource.mjs +2 -0
- package/resource.mjs.map +1 -0
- package/resources/accounts.d.mts +48 -0
- package/resources/accounts.d.mts.map +1 -0
- package/resources/accounts.d.ts +48 -0
- package/resources/accounts.d.ts.map +1 -0
- package/resources/accounts.js +19 -0
- package/resources/accounts.js.map +1 -0
- package/resources/accounts.mjs +15 -0
- package/resources/accounts.mjs.map +1 -0
- package/resources/api-keys.d.mts +33 -0
- package/resources/api-keys.d.mts.map +1 -0
- package/resources/api-keys.d.ts +33 -0
- package/resources/api-keys.d.ts.map +1 -0
- package/resources/api-keys.js +19 -0
- package/resources/api-keys.js.map +1 -0
- package/resources/api-keys.mjs +15 -0
- package/resources/api-keys.mjs.map +1 -0
- package/resources/candles.d.mts +310 -0
- package/resources/candles.d.mts.map +1 -0
- package/resources/candles.d.ts +310 -0
- package/resources/candles.d.ts.map +1 -0
- package/resources/candles.js +117 -0
- package/resources/candles.js.map +1 -0
- package/resources/candles.mjs +113 -0
- package/resources/candles.mjs.map +1 -0
- package/resources/deposits.d.mts +373 -0
- package/resources/deposits.d.mts.map +1 -0
- package/resources/deposits.d.ts +373 -0
- package/resources/deposits.d.ts.map +1 -0
- package/resources/deposits.js +139 -0
- package/resources/deposits.js.map +1 -0
- package/resources/deposits.mjs +135 -0
- package/resources/deposits.mjs.map +1 -0
- package/resources/index.d.mts +15 -0
- package/resources/index.d.mts.map +1 -0
- package/resources/index.d.ts +15 -0
- package/resources/index.d.ts.map +1 -0
- package/resources/index.js +32 -0
- package/resources/index.js.map +1 -0
- package/resources/index.mjs +15 -0
- package/resources/index.mjs.map +1 -0
- package/resources/orderbooks.d.mts +134 -0
- package/resources/orderbooks.d.mts.map +1 -0
- package/resources/orderbooks.d.ts +134 -0
- package/resources/orderbooks.d.ts.map +1 -0
- package/resources/orderbooks.js +31 -0
- package/resources/orderbooks.js.map +1 -0
- package/resources/orderbooks.mjs +27 -0
- package/resources/orderbooks.mjs.map +1 -0
- package/resources/orders.d.mts +886 -0
- package/resources/orders.d.mts.map +1 -0
- package/resources/orders.d.ts +886 -0
- package/resources/orders.d.ts.map +1 -0
- package/resources/orders.js +250 -0
- package/resources/orders.js.map +1 -0
- package/resources/orders.mjs +246 -0
- package/resources/orders.mjs.map +1 -0
- package/resources/tickers.d.mts +184 -0
- package/resources/tickers.d.mts.map +1 -0
- package/resources/tickers.d.ts +184 -0
- package/resources/tickers.d.ts.map +1 -0
- package/resources/tickers.js +30 -0
- package/resources/tickers.js.map +1 -0
- package/resources/tickers.mjs +26 -0
- package/resources/tickers.mjs.map +1 -0
- package/resources/trades.d.mts +107 -0
- package/resources/trades.d.mts.map +1 -0
- package/resources/trades.d.ts +107 -0
- package/resources/trades.d.ts.map +1 -0
- package/resources/trades.js +19 -0
- package/resources/trades.js.map +1 -0
- package/resources/trades.mjs +15 -0
- package/resources/trades.mjs.map +1 -0
- package/resources/trading-pairs.d.mts +96 -0
- package/resources/trading-pairs.d.mts.map +1 -0
- package/resources/trading-pairs.d.ts +96 -0
- package/resources/trading-pairs.d.ts.map +1 -0
- package/resources/trading-pairs.js +19 -0
- package/resources/trading-pairs.js.map +1 -0
- package/resources/trading-pairs.mjs +15 -0
- package/resources/trading-pairs.mjs.map +1 -0
- package/resources/travel-rule.d.mts +139 -0
- package/resources/travel-rule.d.mts.map +1 -0
- package/resources/travel-rule.d.ts +139 -0
- package/resources/travel-rule.d.ts.map +1 -0
- package/resources/travel-rule.js +68 -0
- package/resources/travel-rule.js.map +1 -0
- package/resources/travel-rule.mjs +64 -0
- package/resources/travel-rule.mjs.map +1 -0
- package/resources/wallet-status.d.mts +74 -0
- package/resources/wallet-status.d.mts.map +1 -0
- package/resources/wallet-status.d.ts +74 -0
- package/resources/wallet-status.d.ts.map +1 -0
- package/resources/wallet-status.js +19 -0
- package/resources/wallet-status.js.map +1 -0
- package/resources/wallet-status.mjs +15 -0
- package/resources/wallet-status.mjs.map +1 -0
- package/resources/withdraws.d.mts +599 -0
- package/resources/withdraws.d.mts.map +1 -0
- package/resources/withdraws.d.ts +599 -0
- package/resources/withdraws.d.ts.map +1 -0
- package/resources/withdraws.js +139 -0
- package/resources/withdraws.js.map +1 -0
- package/resources/withdraws.mjs +135 -0
- package/resources/withdraws.mjs.map +1 -0
- package/resources/ws-private/index.d.mts +3 -0
- package/resources/ws-private/index.d.mts.map +1 -0
- package/resources/ws-private/index.d.ts +3 -0
- package/resources/ws-private/index.d.ts.map +1 -0
- package/resources/ws-private/index.js +6 -0
- package/resources/ws-private/index.js.map +1 -0
- package/resources/ws-private/index.mjs +2 -0
- package/resources/ws-private/index.mjs.map +1 -0
- package/resources/ws-private/internal-base.d.mts +58 -0
- package/resources/ws-private/internal-base.d.mts.map +1 -0
- package/resources/ws-private/internal-base.d.ts +58 -0
- package/resources/ws-private/internal-base.d.ts.map +1 -0
- package/resources/ws-private/internal-base.js +51 -0
- package/resources/ws-private/internal-base.js.map +1 -0
- package/resources/ws-private/internal-base.mjs +45 -0
- package/resources/ws-private/internal-base.mjs.map +1 -0
- package/resources/ws-private/ws-private.d.mts +224 -0
- package/resources/ws-private/ws-private.d.mts.map +1 -0
- package/resources/ws-private/ws-private.d.ts +224 -0
- package/resources/ws-private/ws-private.d.ts.map +1 -0
- package/resources/ws-private/ws-private.js +8 -0
- package/resources/ws-private/ws-private.js.map +1 -0
- package/resources/ws-private/ws-private.mjs +4 -0
- package/resources/ws-private/ws-private.mjs.map +1 -0
- package/resources/ws-private/ws.d.mts +85 -0
- package/resources/ws-private/ws.d.mts.map +1 -0
- package/resources/ws-private/ws.d.ts +85 -0
- package/resources/ws-private/ws.d.ts.map +1 -0
- package/resources/ws-private/ws.js +433 -0
- package/resources/ws-private/ws.js.map +1 -0
- package/resources/ws-private/ws.mjs +428 -0
- package/resources/ws-private/ws.mjs.map +1 -0
- package/resources/ws-private.d.mts +2 -0
- package/resources/ws-private.d.mts.map +1 -0
- package/resources/ws-private.d.ts +2 -0
- package/resources/ws-private.d.ts.map +1 -0
- package/resources/ws-private.js +5 -0
- package/resources/ws-private.js.map +1 -0
- package/resources/ws-private.mjs +2 -0
- package/resources/ws-private.mjs.map +1 -0
- package/resources/ws-public/index.d.mts +3 -0
- package/resources/ws-public/index.d.mts.map +1 -0
- package/resources/ws-public/index.d.ts +3 -0
- package/resources/ws-public/index.d.ts.map +1 -0
- package/resources/ws-public/index.js +6 -0
- package/resources/ws-public/index.js.map +1 -0
- package/resources/ws-public/index.mjs +2 -0
- package/resources/ws-public/index.mjs.map +1 -0
- package/resources/ws-public/internal-base.d.mts +58 -0
- package/resources/ws-public/internal-base.d.mts.map +1 -0
- package/resources/ws-public/internal-base.d.ts +58 -0
- package/resources/ws-public/internal-base.d.ts.map +1 -0
- package/resources/ws-public/internal-base.js +51 -0
- package/resources/ws-public/internal-base.js.map +1 -0
- package/resources/ws-public/internal-base.mjs +45 -0
- package/resources/ws-public/internal-base.mjs.map +1 -0
- package/resources/ws-public/ws-public.d.mts +427 -0
- package/resources/ws-public/ws-public.d.mts.map +1 -0
- package/resources/ws-public/ws-public.d.ts +427 -0
- package/resources/ws-public/ws-public.d.ts.map +1 -0
- package/resources/ws-public/ws-public.js +8 -0
- package/resources/ws-public/ws-public.js.map +1 -0
- package/resources/ws-public/ws-public.mjs +4 -0
- package/resources/ws-public/ws-public.mjs.map +1 -0
- package/resources/ws-public/ws.d.mts +85 -0
- package/resources/ws-public/ws.d.mts.map +1 -0
- package/resources/ws-public/ws.d.ts +85 -0
- package/resources/ws-public/ws.d.ts.map +1 -0
- package/resources/ws-public/ws.js +428 -0
- package/resources/ws-public/ws.js.map +1 -0
- package/resources/ws-public/ws.mjs +423 -0
- package/resources/ws-public/ws.mjs.map +1 -0
- package/resources/ws-public.d.mts +2 -0
- package/resources/ws-public.d.mts.map +1 -0
- package/resources/ws-public.d.ts +2 -0
- package/resources/ws-public.d.ts.map +1 -0
- package/resources/ws-public.js +5 -0
- package/resources/ws-public.js.map +1 -0
- package/resources/ws-public.mjs +2 -0
- package/resources/ws-public.mjs.map +1 -0
- package/resources.d.mts +2 -0
- package/resources.d.mts.map +1 -0
- package/resources.d.ts +2 -0
- package/resources.d.ts.map +1 -0
- package/resources.js +5 -0
- package/resources.js.map +1 -0
- package/resources.mjs +2 -0
- package/resources.mjs.map +1 -0
- package/src/api-promise.ts +2 -0
- package/src/client.ts +1112 -0
- package/src/core/EventEmitter.ts +114 -0
- package/src/core/README.md +3 -0
- package/src/core/api-promise.ts +91 -0
- package/src/core/error.ts +182 -0
- package/src/core/pagination.ts +195 -0
- package/src/core/resource.ts +10 -0
- package/src/core/uploads.ts +2 -0
- package/src/error.ts +2 -0
- package/src/index.ts +24 -0
- package/src/internal/README.md +3 -0
- package/src/internal/builtin-types.ts +92 -0
- package/src/internal/errors.ts +32 -0
- package/src/internal/headers.ts +96 -0
- package/src/internal/parse.ts +56 -0
- package/src/internal/qs/LICENSE.md +13 -0
- package/src/internal/qs/README.md +3 -0
- package/src/internal/qs/formats.ts +10 -0
- package/src/internal/qs/index.ts +13 -0
- package/src/internal/qs/stringify.ts +385 -0
- package/src/internal/qs/types.ts +71 -0
- package/src/internal/qs/utils.ts +265 -0
- package/src/internal/request-options.ts +92 -0
- package/src/internal/shim-types.ts +25 -0
- package/src/internal/shims.ts +106 -0
- package/src/internal/to-file.ts +154 -0
- package/src/internal/types.ts +94 -0
- package/src/internal/uploads.ts +187 -0
- package/src/internal/utils/base64.ts +39 -0
- package/src/internal/utils/bytes.ts +32 -0
- package/src/internal/utils/env.ts +17 -0
- package/src/internal/utils/log.ts +125 -0
- package/src/internal/utils/path.ts +88 -0
- package/src/internal/utils/query.ts +6 -0
- package/src/internal/utils/sleep.ts +2 -0
- package/src/internal/utils/uuid.ts +19 -0
- package/src/internal/utils/values.ts +104 -0
- package/src/internal/utils.ts +8 -0
- package/src/internal/ws.ts +68 -0
- package/src/lib/index.ts +4 -0
- package/src/lib/jsonParseFloat.ts +73 -0
- package/src/lib/jwtAuth.ts +39 -0
- package/src/lib/ws.ts +282 -0
- package/src/pagination.ts +2 -0
- package/src/resource.ts +2 -0
- package/src/resources/accounts.ts +59 -0
- package/src/resources/api-keys.ts +40 -0
- package/src/resources/candles.ts +392 -0
- package/src/resources/deposits.ts +484 -0
- package/src/resources/index.ts +102 -0
- package/src/resources/orderbooks.ts +170 -0
- package/src/resources/orders.ts +1102 -0
- package/src/resources/tickers.ts +233 -0
- package/src/resources/trades.ts +127 -0
- package/src/resources/trading-pairs.ts +120 -0
- package/src/resources/travel-rule.ts +181 -0
- package/src/resources/wallet-status.ts +87 -0
- package/src/resources/withdraws.ts +734 -0
- package/src/resources/ws-private/index.ts +3 -0
- package/src/resources/ws-private/internal-base.ts +99 -0
- package/src/resources/ws-private/ws-private.ts +283 -0
- package/src/resources/ws-private/ws.ts +529 -0
- package/src/resources/ws-private.ts +2 -0
- package/src/resources/ws-public/index.ts +3 -0
- package/src/resources/ws-public/internal-base.ts +99 -0
- package/src/resources/ws-public/ws-public.ts +561 -0
- package/src/resources/ws-public/ws.ts +525 -0
- package/src/resources/ws-public.ts +2 -0
- package/src/resources.ts +1 -0
- package/src/tsconfig.json +11 -0
- package/src/uploads.ts +2 -0
- package/src/version.ts +1 -0
- package/uploads.d.mts +2 -0
- package/uploads.d.mts.map +1 -0
- package/uploads.d.ts +2 -0
- package/uploads.d.ts.map +1 -0
- package/uploads.js +6 -0
- package/uploads.js.map +1 -0
- package/uploads.mjs +2 -0
- package/uploads.mjs.map +1 -0
- package/version.d.mts +2 -0
- package/version.d.mts.map +1 -0
- package/version.d.ts +2 -0
- package/version.d.ts.map +1 -0
- package/version.js +5 -0
- package/version.js.map +1 -0
- package/version.mjs +2 -0
- package/version.mjs.map +1 -0
|
@@ -0,0 +1,529 @@
|
|
|
1
|
+
|
|
2
|
+
import * as WS from 'ws';
|
|
3
|
+
import { WsPrivateEmitter, WsPrivateStreamMessage, WebSocketError, buildURL } from './internal-base';
|
|
4
|
+
import { InternalEventEmitter } from '../../core/EventEmitter';
|
|
5
|
+
import { sleep } from '../../internal/utils/sleep';
|
|
6
|
+
import { isRecoverableClose, type ReconnectingEvent, type ReconnectingOverrides } from '../../internal/ws';
|
|
7
|
+
import * as WsPrivateAPI from './ws-private';
|
|
8
|
+
import { Upbit } from '../../client';
|
|
9
|
+
import { jsonParseFloat } from '../../lib/jsonParseFloat';
|
|
10
|
+
import { createJwtToken } from '../../lib/jwtAuth';
|
|
11
|
+
|
|
12
|
+
export interface WsPrivateWSReconnectOptions {
|
|
13
|
+
/**
|
|
14
|
+
* Called before each reconnect attempt. Return an object with
|
|
15
|
+
* `parameters` to override query parameters for the next connection.
|
|
16
|
+
*/
|
|
17
|
+
onReconnecting(
|
|
18
|
+
event: ReconnectingEvent<Record<string, unknown>>,
|
|
19
|
+
): ReconnectingOverrides<Record<string, unknown>> | void;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Maximum number of reconnection attempts. Default: 5.
|
|
23
|
+
* Set to 0 to disable reconnection entirely.
|
|
24
|
+
*/
|
|
25
|
+
maxRetries?: number;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Initial backoff delay in milliseconds. Default: 500.
|
|
29
|
+
*/
|
|
30
|
+
initialDelay?: number;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Maximum backoff delay in milliseconds. Default: 8000.
|
|
34
|
+
*/
|
|
35
|
+
maxDelay?: number;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface WsPrivateWSClientOptions extends WS.ClientOptions {
|
|
39
|
+
/**
|
|
40
|
+
* Options for automatic reconnection on recoverable close codes.
|
|
41
|
+
* Automatic reconnection is only enabled when this has a non-null value.
|
|
42
|
+
*/
|
|
43
|
+
reconnect?: WsPrivateWSReconnectOptions | null;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export class WsPrivateWS extends WsPrivateEmitter {
|
|
47
|
+
url: URL;
|
|
48
|
+
socket: WS.WebSocket;
|
|
49
|
+
|
|
50
|
+
private _client: Upbit;
|
|
51
|
+
private _parameters: Record<string, unknown> | undefined;
|
|
52
|
+
private _wsOptions: WS.ClientOptions | null | undefined;
|
|
53
|
+
private _reconnectOptions: WsPrivateWSReconnectOptions | null;
|
|
54
|
+
private _sendQueue: string[] = [];
|
|
55
|
+
private _isReconnecting: boolean = false;
|
|
56
|
+
private _intentionallyClosed = false;
|
|
57
|
+
|
|
58
|
+
// Necessary to keep the public event interface clean while we manage reconnecting
|
|
59
|
+
private _internalEvents = new InternalEventEmitter<{
|
|
60
|
+
socketSwap: (oldSocket: WS.WebSocket, newSocket: WS.WebSocket) => void;
|
|
61
|
+
reconnecting: (event: ReconnectingEvent<Record<string, unknown>>) => void;
|
|
62
|
+
reconnected: () => void;
|
|
63
|
+
close: () => void;
|
|
64
|
+
}>();
|
|
65
|
+
|
|
66
|
+
constructor(
|
|
67
|
+
client: Upbit,
|
|
68
|
+
parameters?: Record<string, unknown> | undefined,
|
|
69
|
+
options?: WsPrivateWSClientOptions | null | undefined,
|
|
70
|
+
) {
|
|
71
|
+
super();
|
|
72
|
+
this._client = client;
|
|
73
|
+
this._parameters = undefined;
|
|
74
|
+
const { reconnect, ...wsOptions } = options ?? {};
|
|
75
|
+
this._wsOptions = wsOptions;
|
|
76
|
+
this._reconnectOptions = reconnect ?? null;
|
|
77
|
+
this.url = buildURL(client, parameters);
|
|
78
|
+
this.socket = this._connect();
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
send(event: WsPrivateAPI.ConnectPrivateClientEvent) {
|
|
82
|
+
if (this._isReconnecting || this.socket.readyState === WS.WebSocket.CONNECTING) {
|
|
83
|
+
this._sendQueue.push(JSON.stringify(event));
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
if (this.socket.readyState !== WS.WebSocket.OPEN) {
|
|
87
|
+
this._onError(null, 'cannot send on a closed WebSocket', undefined);
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
try {
|
|
91
|
+
this.socket.send(JSON.stringify(event));
|
|
92
|
+
} catch (err) {
|
|
93
|
+
this._onError(null, 'could not send data', err);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
close(props?: { code: number; reason: string }) {
|
|
98
|
+
this._intentionallyClosed = true;
|
|
99
|
+
try {
|
|
100
|
+
this.socket.close(props?.code ?? 1000, props?.reason ?? 'OK');
|
|
101
|
+
} catch (err) {
|
|
102
|
+
this._onError(null, 'could not close the connection', err);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Returns an async iterator over WebSocket lifecycle and message events,
|
|
108
|
+
* providing an alternative to the event-based `.on()` API.
|
|
109
|
+
* The iterator will exit if the socket closes but exiting the iterator
|
|
110
|
+
* does not close the socket.
|
|
111
|
+
*
|
|
112
|
+
* @example
|
|
113
|
+
* ```ts
|
|
114
|
+
* for await (const event of client.stream()) {
|
|
115
|
+
* switch (event.type) {
|
|
116
|
+
* case 'message':
|
|
117
|
+
* console.log('received:', event.message);
|
|
118
|
+
* break;
|
|
119
|
+
* case 'error':
|
|
120
|
+
* console.error(event.error);
|
|
121
|
+
* break;
|
|
122
|
+
* case 'close':
|
|
123
|
+
* console.log('connection closed');
|
|
124
|
+
* break;
|
|
125
|
+
* }
|
|
126
|
+
* }
|
|
127
|
+
* ```
|
|
128
|
+
*/
|
|
129
|
+
stream(): AsyncIterableIterator<WsPrivateStreamMessage> {
|
|
130
|
+
return this[Symbol.asyncIterator]();
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
[Symbol.asyncIterator](): AsyncIterableIterator<WsPrivateStreamMessage> {
|
|
134
|
+
// Two-queue async iterator: `queue` buffers incoming messages,
|
|
135
|
+
// `resolvers` buffers waiting next() calls. A push wakes the
|
|
136
|
+
// oldest next(); a next() drains the oldest message.
|
|
137
|
+
const queue: WsPrivateStreamMessage[] = [];
|
|
138
|
+
const resolvers: (() => void)[] = [];
|
|
139
|
+
let done = false;
|
|
140
|
+
let currentSocket = this.socket;
|
|
141
|
+
|
|
142
|
+
const push = (msg: WsPrivateStreamMessage) => {
|
|
143
|
+
queue.push(msg);
|
|
144
|
+
resolvers.shift()?.();
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
const onEvent = (event: WsPrivateAPI.ConnectPrivateServerEvent) => {
|
|
148
|
+
push({ type: 'message', message: event });
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
// All errors (API + socket) funnel through _onError → 'error' event
|
|
152
|
+
const onEmitterError = (err: WebSocketError) => {
|
|
153
|
+
push({ type: 'error', error: err });
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
const onOpen = () => {
|
|
157
|
+
push({ type: 'open' });
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
const onReconnecting = (evt: ReconnectingEvent<Record<string, unknown>>) => {
|
|
161
|
+
push({ type: 'reconnecting', reconnect: evt });
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
const onReconnected = () => {
|
|
165
|
+
push({ type: 'reconnected' });
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
const flushResolvers = () => {
|
|
169
|
+
for (let resolver = resolvers.shift(); resolver; resolver = resolvers.shift()) {
|
|
170
|
+
resolver();
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
const onClose = () => {
|
|
175
|
+
// Mid-reconnect; the swap handler will rebind us to the new socket
|
|
176
|
+
if (this._isReconnecting) return;
|
|
177
|
+
push({ type: 'close' });
|
|
178
|
+
done = true;
|
|
179
|
+
flushResolvers();
|
|
180
|
+
cleanup();
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
const onSocketSwap = (oldSocket: WS.WebSocket, newSocket: WS.WebSocket) => {
|
|
184
|
+
oldSocket.off('open', onOpen);
|
|
185
|
+
oldSocket.off('close', onClose);
|
|
186
|
+
newSocket.on('open', onOpen);
|
|
187
|
+
newSocket.on('close', onClose);
|
|
188
|
+
currentSocket = newSocket;
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
const cleanup = () => {
|
|
192
|
+
this.off('event', onEvent);
|
|
193
|
+
this.off('error', onEmitterError);
|
|
194
|
+
currentSocket.off('open', onOpen);
|
|
195
|
+
currentSocket.off('close', onClose);
|
|
196
|
+
this._internalEvents.off('socketSwap', onSocketSwap);
|
|
197
|
+
this._internalEvents.off('reconnecting', onReconnecting);
|
|
198
|
+
this._internalEvents.off('reconnected', onReconnected);
|
|
199
|
+
this._internalEvents.off('close', onClose);
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
this.on('event', onEvent);
|
|
203
|
+
this.on('error', onEmitterError);
|
|
204
|
+
this.socket.on('open', onOpen);
|
|
205
|
+
this.socket.on('close', onClose);
|
|
206
|
+
this._internalEvents.on('socketSwap', onSocketSwap);
|
|
207
|
+
this._internalEvents.on('reconnecting', onReconnecting);
|
|
208
|
+
this._internalEvents.on('reconnected', onReconnected);
|
|
209
|
+
this._internalEvents.on('close', onClose);
|
|
210
|
+
|
|
211
|
+
if (this._isReconnecting) {
|
|
212
|
+
// A reconnect is already in flight. The socket may be CLOSED but the
|
|
213
|
+
// instance is still alive. Emit 'reconnecting' so the iterator stays
|
|
214
|
+
// open and receives the upcoming reconnected/message events.
|
|
215
|
+
push({
|
|
216
|
+
type: 'reconnecting',
|
|
217
|
+
reconnect: { attempt: 0, maxAttempts: 0, delay: 0, closeCode: 0, parameters: undefined },
|
|
218
|
+
});
|
|
219
|
+
} else {
|
|
220
|
+
switch (this.socket.readyState) {
|
|
221
|
+
case WS.WebSocket.CONNECTING:
|
|
222
|
+
push({ type: 'connecting' });
|
|
223
|
+
break;
|
|
224
|
+
case WS.WebSocket.OPEN:
|
|
225
|
+
push({ type: 'open' });
|
|
226
|
+
break;
|
|
227
|
+
case WS.WebSocket.CLOSING:
|
|
228
|
+
push({ type: 'closing' });
|
|
229
|
+
break;
|
|
230
|
+
case WS.WebSocket.CLOSED:
|
|
231
|
+
push({ type: 'close' });
|
|
232
|
+
done = true;
|
|
233
|
+
cleanup();
|
|
234
|
+
break;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
const resolve = (res: (value: IteratorResult<WsPrivateStreamMessage>) => void) => {
|
|
239
|
+
if (queue.length > 0) {
|
|
240
|
+
res({ value: queue.shift()!, done: false });
|
|
241
|
+
} else if (done) {
|
|
242
|
+
res({ value: undefined, done: true });
|
|
243
|
+
} else {
|
|
244
|
+
return false;
|
|
245
|
+
}
|
|
246
|
+
return true;
|
|
247
|
+
};
|
|
248
|
+
|
|
249
|
+
const next = (): Promise<IteratorResult<WsPrivateStreamMessage>> =>
|
|
250
|
+
new Promise((res) => {
|
|
251
|
+
if (resolve(res)) return;
|
|
252
|
+
resolvers.push(() => {
|
|
253
|
+
resolve(res);
|
|
254
|
+
});
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
return {
|
|
258
|
+
next,
|
|
259
|
+
return: (): Promise<IteratorReturnResult<undefined>> => {
|
|
260
|
+
done = true;
|
|
261
|
+
cleanup();
|
|
262
|
+
flushResolvers();
|
|
263
|
+
return Promise.resolve({ value: undefined, done: true });
|
|
264
|
+
},
|
|
265
|
+
[Symbol.asyncIterator]() {
|
|
266
|
+
return this;
|
|
267
|
+
},
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
private _connect(): WS.WebSocket {
|
|
272
|
+
this.url = buildURL(this._client, this._parameters);
|
|
273
|
+
|
|
274
|
+
const socket = new WS.WebSocket(this.url, {
|
|
275
|
+
...this._wsOptions,
|
|
276
|
+
headers: {
|
|
277
|
+
...this._authHeaders(),
|
|
278
|
+
...this._wsOptions?.headers,
|
|
279
|
+
},
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
socket.on('message', (wsEvent) => {
|
|
283
|
+
const event = (() => {
|
|
284
|
+
try {
|
|
285
|
+
return jsonParseFloat(wsEvent.toString()) as WsPrivateAPI.ConnectPrivateServerEvent;
|
|
286
|
+
} catch (err) {
|
|
287
|
+
this._onError(null, 'could not parse websocket event', err);
|
|
288
|
+
return null;
|
|
289
|
+
}
|
|
290
|
+
})();
|
|
291
|
+
|
|
292
|
+
if (event) {
|
|
293
|
+
this._emit('event', event);
|
|
294
|
+
|
|
295
|
+
// @ts-ignore TS isn't smart enough to get the relationship right here
|
|
296
|
+
this._emit(event.type, event);
|
|
297
|
+
}
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
socket.on('error', (err) => {
|
|
301
|
+
// Suppress transient errors during reconnection — the retry loop
|
|
302
|
+
// already handles them and will surface a close if retries exhaust.
|
|
303
|
+
if (this._isReconnecting) return;
|
|
304
|
+
this._onError(null, err.message, err);
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
socket.on('open', () => {
|
|
308
|
+
this._flushSendQueue();
|
|
309
|
+
});
|
|
310
|
+
|
|
311
|
+
socket.on('close', (code: number) => {
|
|
312
|
+
// Ignore close events from superseded sockets — a stale socket's
|
|
313
|
+
// late close must not kick off a second reconnect loop.
|
|
314
|
+
if (socket !== this.socket) return;
|
|
315
|
+
|
|
316
|
+
if (!this._canReconnect(code)) {
|
|
317
|
+
if (!this._isReconnecting) {
|
|
318
|
+
this._emit('close');
|
|
319
|
+
}
|
|
320
|
+
return;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
this._reconnect(code);
|
|
324
|
+
});
|
|
325
|
+
|
|
326
|
+
return socket;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
// Reconnect is opt-in via onReconnecting so callers can pass
|
|
330
|
+
// state (e.g. session IDs) into the new connection.
|
|
331
|
+
private _canReconnect(code: number): boolean {
|
|
332
|
+
if (this._intentionallyClosed) return false;
|
|
333
|
+
if (!this._reconnectOptions) return false;
|
|
334
|
+
if (this._reconnectOptions.maxRetries === 0) return false;
|
|
335
|
+
if (!this._reconnectOptions.onReconnecting) return false;
|
|
336
|
+
return isRecoverableClose(code);
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
private async _reconnect(closeCode: number): Promise<void> {
|
|
340
|
+
if (this._isReconnecting || !this._reconnectOptions) return;
|
|
341
|
+
this._isReconnecting = true;
|
|
342
|
+
|
|
343
|
+
const maxRetries = this._reconnectOptions.maxRetries ?? 5;
|
|
344
|
+
const initialDelay = this._reconnectOptions.initialDelay ?? 500;
|
|
345
|
+
const maxDelay = this._reconnectOptions.maxDelay ?? 8000;
|
|
346
|
+
|
|
347
|
+
for (let attempt = 1; attempt <= maxRetries; attempt++) {
|
|
348
|
+
if (!this._canReconnect(closeCode)) {
|
|
349
|
+
this._isReconnecting = false;
|
|
350
|
+
if (!this._intentionallyClosed) {
|
|
351
|
+
this._onError(
|
|
352
|
+
null,
|
|
353
|
+
`WebSocket reconnect aborted: non-recoverable close code ${closeCode}`,
|
|
354
|
+
undefined,
|
|
355
|
+
);
|
|
356
|
+
}
|
|
357
|
+
this._emit('close');
|
|
358
|
+
this._internalEvents._emit('close');
|
|
359
|
+
return;
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
const baseDelay = Math.min(initialDelay * Math.pow(2, attempt - 1), maxDelay);
|
|
363
|
+
// Jitter: rand [0.75, 1.0] to spread out connection attempts without over-delaying
|
|
364
|
+
const jitter = 0.75 + Math.random() * 0.25;
|
|
365
|
+
const actualDelay = Math.round(baseDelay * jitter);
|
|
366
|
+
|
|
367
|
+
let reconnectingEvent: ReconnectingEvent<Record<string, unknown>> = {
|
|
368
|
+
attempt,
|
|
369
|
+
maxAttempts: maxRetries,
|
|
370
|
+
delay: actualDelay,
|
|
371
|
+
closeCode,
|
|
372
|
+
parameters: this._parameters ? { ...this._parameters } : undefined,
|
|
373
|
+
};
|
|
374
|
+
|
|
375
|
+
let overrides: ReconnectingOverrides<Record<string, unknown>> | void;
|
|
376
|
+
try {
|
|
377
|
+
overrides = this._reconnectOptions.onReconnecting(reconnectingEvent);
|
|
378
|
+
} catch (err) {
|
|
379
|
+
this._isReconnecting = false;
|
|
380
|
+
this._onError(null, 'onReconnecting callback threw', err);
|
|
381
|
+
this._emit('close');
|
|
382
|
+
this._internalEvents._emit('close');
|
|
383
|
+
return;
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
if (overrides && 'abort' in overrides && overrides.abort) {
|
|
387
|
+
this._isReconnecting = false;
|
|
388
|
+
this._emit('close');
|
|
389
|
+
this._internalEvents._emit('close');
|
|
390
|
+
return;
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
if (overrides && 'parameters' in overrides) {
|
|
394
|
+
this._parameters = overrides.parameters;
|
|
395
|
+
reconnectingEvent = { ...reconnectingEvent, parameters: this._parameters };
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
try {
|
|
399
|
+
this._emit('reconnecting', reconnectingEvent);
|
|
400
|
+
} catch (err) {
|
|
401
|
+
this._onError(null, 'onReconnecting callback threw', err);
|
|
402
|
+
}
|
|
403
|
+
this._internalEvents._emit('reconnecting', reconnectingEvent);
|
|
404
|
+
|
|
405
|
+
if (!this._canReconnect(closeCode)) {
|
|
406
|
+
this._isReconnecting = false;
|
|
407
|
+
if (!this._intentionallyClosed) {
|
|
408
|
+
this._onError(
|
|
409
|
+
null,
|
|
410
|
+
`WebSocket reconnect aborted: non-recoverable close code ${closeCode}`,
|
|
411
|
+
undefined,
|
|
412
|
+
);
|
|
413
|
+
}
|
|
414
|
+
this._emit('close');
|
|
415
|
+
this._internalEvents._emit('close');
|
|
416
|
+
return;
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
await sleep(actualDelay);
|
|
420
|
+
|
|
421
|
+
if (!this._canReconnect(closeCode)) {
|
|
422
|
+
this._isReconnecting = false;
|
|
423
|
+
if (!this._intentionallyClosed) {
|
|
424
|
+
this._onError(
|
|
425
|
+
null,
|
|
426
|
+
`WebSocket reconnect aborted: non-recoverable close code ${closeCode}`,
|
|
427
|
+
undefined,
|
|
428
|
+
);
|
|
429
|
+
}
|
|
430
|
+
this._emit('close');
|
|
431
|
+
this._internalEvents._emit('close');
|
|
432
|
+
return;
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
let closeCodePromise: Promise<number> | undefined;
|
|
436
|
+
try {
|
|
437
|
+
const oldSocket = this.socket;
|
|
438
|
+
this.socket = this._connect();
|
|
439
|
+
// Registered synchronously after _connect() and before any
|
|
440
|
+
// await so the code is captured even when ws emits 'close'
|
|
441
|
+
// in the same tick as 'error' (e.g. abortHandshake).
|
|
442
|
+
closeCodePromise = new Promise<number>((resolve) => {
|
|
443
|
+
this.socket.once('close', resolve);
|
|
444
|
+
});
|
|
445
|
+
|
|
446
|
+
await this._awaitOpen(this.socket);
|
|
447
|
+
|
|
448
|
+
this._internalEvents._emit('socketSwap', oldSocket, this.socket);
|
|
449
|
+
this._isReconnecting = false;
|
|
450
|
+
this._flushSendQueue();
|
|
451
|
+
this._emit('reconnected');
|
|
452
|
+
this._internalEvents._emit('reconnected');
|
|
453
|
+
return;
|
|
454
|
+
} catch {
|
|
455
|
+
if (closeCodePromise) {
|
|
456
|
+
// ws may emit 'error' before 'close', so await the code
|
|
457
|
+
// rather than reading it synchronously.
|
|
458
|
+
closeCode = await closeCodePromise;
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
// All retries exhausted — surface an error so consumers can
|
|
464
|
+
// distinguish retry failure from a clean close.
|
|
465
|
+
this._isReconnecting = false;
|
|
466
|
+
this._onError(
|
|
467
|
+
null,
|
|
468
|
+
`WebSocket reconnect failed after ${maxRetries} attempts (close code: ${closeCode})`,
|
|
469
|
+
undefined,
|
|
470
|
+
);
|
|
471
|
+
this._emit('close');
|
|
472
|
+
this._internalEvents._emit('close');
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
/**
|
|
476
|
+
* Resolves once the socket is open, rejects if it errors or closes first
|
|
477
|
+
*/
|
|
478
|
+
private _awaitOpen(socket: WS.WebSocket): Promise<void> {
|
|
479
|
+
return new Promise<void>((resolve, reject) => {
|
|
480
|
+
const cleanup = () => {
|
|
481
|
+
socket.off('open', onOpen);
|
|
482
|
+
socket.off('error', onError);
|
|
483
|
+
socket.off('close', onFail);
|
|
484
|
+
};
|
|
485
|
+
const onOpen = () => {
|
|
486
|
+
cleanup();
|
|
487
|
+
resolve();
|
|
488
|
+
};
|
|
489
|
+
const onError = (err: Error) => {
|
|
490
|
+
cleanup();
|
|
491
|
+
reject(err);
|
|
492
|
+
};
|
|
493
|
+
const onFail = () => {
|
|
494
|
+
cleanup();
|
|
495
|
+
reject(new Error('socket closed before open'));
|
|
496
|
+
};
|
|
497
|
+
socket.once('open', onOpen);
|
|
498
|
+
socket.once('error', onError);
|
|
499
|
+
socket.once('close', onFail);
|
|
500
|
+
});
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
private _flushSendQueue(): void {
|
|
504
|
+
const pending = this._sendQueue.splice(0);
|
|
505
|
+
for (let i = 0; i < pending.length; i++) {
|
|
506
|
+
try {
|
|
507
|
+
if (this.socket.readyState !== WS.WebSocket.OPEN) {
|
|
508
|
+
// Avoid dropping messages by sending them out over a closing socket
|
|
509
|
+
this._sendQueue.unshift(...pending.slice(i));
|
|
510
|
+
return;
|
|
511
|
+
} else {
|
|
512
|
+
this.socket.send(pending[i]!);
|
|
513
|
+
}
|
|
514
|
+
} catch (err) {
|
|
515
|
+
// Re-queue remaining for next open/reconnect
|
|
516
|
+
this._sendQueue.unshift(...pending.slice(i));
|
|
517
|
+
this._onError(null, 'could not send queued data', err);
|
|
518
|
+
return;
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
private _authHeaders(): Record<string, string> {
|
|
524
|
+
const { accessKey, secretKey } = this._client;
|
|
525
|
+
if (!accessKey || !secretKey) return {};
|
|
526
|
+
const token = createJwtToken(accessKey, secretKey);
|
|
527
|
+
return { Authorization: `Bearer ${token}` };
|
|
528
|
+
}
|
|
529
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
|
|
2
|
+
import * as WsPublicAPI from './ws-public';
|
|
3
|
+
import { Upbit } from '../../client';
|
|
4
|
+
import { EventEmitter } from '../../core/EventEmitter';
|
|
5
|
+
import { UpbitError } from '../../core/error';
|
|
6
|
+
import { stringifyQuery } from '../../internal/utils';
|
|
7
|
+
|
|
8
|
+
import type { ReconnectingEvent } from '../../internal/ws';
|
|
9
|
+
|
|
10
|
+
export type WsPublicStreamMessage =
|
|
11
|
+
| { type: 'connecting' | 'open' | 'closing' | 'close' }
|
|
12
|
+
| { type: 'reconnecting'; reconnect: ReconnectingEvent }
|
|
13
|
+
| { type: 'reconnected' }
|
|
14
|
+
| { type: 'message'; message: WsPublicAPI.ConnectPublicServerEvent }
|
|
15
|
+
| { type: 'error'; error: WebSocketError };
|
|
16
|
+
|
|
17
|
+
export class WebSocketError extends UpbitError {
|
|
18
|
+
/**
|
|
19
|
+
* The error data that the API sent back in an error event.
|
|
20
|
+
*/
|
|
21
|
+
error?: unknown | undefined;
|
|
22
|
+
|
|
23
|
+
constructor(message: string, event: unknown | null) {
|
|
24
|
+
super(message);
|
|
25
|
+
|
|
26
|
+
this.error = event ?? undefined;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
type Simplify<T> = { [KeyType in keyof T]: T[KeyType] } & {};
|
|
31
|
+
|
|
32
|
+
type WebSocketEvents = Simplify<
|
|
33
|
+
{
|
|
34
|
+
close: () => void;
|
|
35
|
+
event: (event: WsPublicAPI.ConnectPublicServerEvent) => void;
|
|
36
|
+
error: (error: WebSocketError) => void;
|
|
37
|
+
reconnecting: (event: ReconnectingEvent) => void;
|
|
38
|
+
reconnected: () => void;
|
|
39
|
+
} & {
|
|
40
|
+
[EventType in WsPublicAPI.ConnectPublicServerEvent['type']]: (
|
|
41
|
+
event: Extract<WsPublicAPI.ConnectPublicServerEvent, { type?: EventType }>,
|
|
42
|
+
) => unknown;
|
|
43
|
+
}
|
|
44
|
+
>;
|
|
45
|
+
|
|
46
|
+
export abstract class WsPublicEmitter extends EventEmitter<WebSocketEvents> {
|
|
47
|
+
/**
|
|
48
|
+
* Send an event to the API.
|
|
49
|
+
*/
|
|
50
|
+
abstract send(event: WsPublicAPI.ConnectPublicClientEvent): void;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Close the WebSocket connection.
|
|
54
|
+
*/
|
|
55
|
+
abstract close(props?: { code: number; reason: string }): void;
|
|
56
|
+
|
|
57
|
+
protected _onError(event: null, message: string, cause: any): void;
|
|
58
|
+
protected _onError(event: unknown, message?: string | undefined): void;
|
|
59
|
+
protected _onError(event: unknown | null, message?: string | undefined, cause?: any): void {
|
|
60
|
+
message = message ?? safeJSONStringify(event) ?? 'unknown error';
|
|
61
|
+
|
|
62
|
+
if (!this._hasListener('error')) {
|
|
63
|
+
const error = new WebSocketError(
|
|
64
|
+
message +
|
|
65
|
+
`\n\nTo resolve these unhandled rejection errors you should bind an \`error\` callback, e.g. \`ws.on('error', (error) => ...)\` `,
|
|
66
|
+
event,
|
|
67
|
+
);
|
|
68
|
+
// @ts-ignore
|
|
69
|
+
error.cause = cause;
|
|
70
|
+
Promise.reject(error);
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const error = new WebSocketError(message, event);
|
|
75
|
+
// @ts-ignore
|
|
76
|
+
error.cause = cause;
|
|
77
|
+
|
|
78
|
+
this._emit('error', error);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export function buildURL(client: Upbit, query?: object | null): URL {
|
|
83
|
+
const path = '/websocket/v1';
|
|
84
|
+
const baseURL = client.baseURL;
|
|
85
|
+
const url = new URL(baseURL + (baseURL.endsWith('/') ? path.slice(1) : path));
|
|
86
|
+
if (query) {
|
|
87
|
+
url.search = stringifyQuery(query);
|
|
88
|
+
}
|
|
89
|
+
url.protocol = url.protocol === 'http:' ? 'ws:' : 'wss:';
|
|
90
|
+
return url;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function safeJSONStringify(value: unknown): string | null {
|
|
94
|
+
try {
|
|
95
|
+
return JSON.stringify(value);
|
|
96
|
+
} catch {
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
}
|