@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
package/src/client.ts
ADDED
|
@@ -0,0 +1,1112 @@
|
|
|
1
|
+
|
|
2
|
+
import type { RequestInit, RequestInfo, BodyInit } from './internal/builtin-types';
|
|
3
|
+
import type { HTTPMethod, PromiseOrValue, MergedRequestInit, FinalizedRequestInit } from './internal/types';
|
|
4
|
+
import { uuid4 } from './internal/utils/uuid';
|
|
5
|
+
import { validatePositiveInteger, isAbsoluteURL, safeJSON } from './internal/utils/values';
|
|
6
|
+
import { sleep } from './internal/utils/sleep';
|
|
7
|
+
export type { Logger, LogLevel } from './internal/utils/log';
|
|
8
|
+
import { castToError, isAbortError } from './internal/errors';
|
|
9
|
+
import type { APIResponseProps } from './internal/parse';
|
|
10
|
+
import * as Shims from './internal/shims';
|
|
11
|
+
import * as Opts from './internal/request-options';
|
|
12
|
+
import { stringifyQuery } from './internal/utils/query';
|
|
13
|
+
import { VERSION } from './version';
|
|
14
|
+
import * as Errors from './core/error';
|
|
15
|
+
import * as Pagination from './core/pagination';
|
|
16
|
+
import {
|
|
17
|
+
AbstractPage,
|
|
18
|
+
type PageNumberPageParams,
|
|
19
|
+
PageNumberPageResponse,
|
|
20
|
+
type UuidCursorIDPageParams,
|
|
21
|
+
UuidCursorIDPageResponse,
|
|
22
|
+
} from './core/pagination';
|
|
23
|
+
import * as Uploads from './core/uploads';
|
|
24
|
+
import * as API from './resources/index';
|
|
25
|
+
import { APIPromise } from './core/api-promise';
|
|
26
|
+
import { AccountListResponse, Accounts } from './resources/accounts';
|
|
27
|
+
import { APIKeyListResponse, APIKeys } from './resources/api-keys';
|
|
28
|
+
import {
|
|
29
|
+
Candle,
|
|
30
|
+
CandleListDaysParams,
|
|
31
|
+
CandleListDaysResponse,
|
|
32
|
+
CandleListMinutesParams,
|
|
33
|
+
CandleListMinutesResponse,
|
|
34
|
+
CandleListMonthsParams,
|
|
35
|
+
CandleListMonthsResponse,
|
|
36
|
+
CandleListSecondsParams,
|
|
37
|
+
CandleListSecondsResponse,
|
|
38
|
+
CandleListWeeksParams,
|
|
39
|
+
CandleListWeeksResponse,
|
|
40
|
+
CandleListYearsParams,
|
|
41
|
+
CandleListYearsResponse,
|
|
42
|
+
CandlePeriod,
|
|
43
|
+
Candles,
|
|
44
|
+
} from './resources/candles';
|
|
45
|
+
import {
|
|
46
|
+
Deposit,
|
|
47
|
+
DepositAddress,
|
|
48
|
+
DepositCreateCoinAddressParams,
|
|
49
|
+
DepositCreateCoinAddressResponse,
|
|
50
|
+
DepositDepositKrwParams,
|
|
51
|
+
DepositListCoinAddressesResponse,
|
|
52
|
+
DepositListParams,
|
|
53
|
+
DepositRetrieveChanceParams,
|
|
54
|
+
DepositRetrieveChanceResponse,
|
|
55
|
+
DepositRetrieveCoinAddressParams,
|
|
56
|
+
DepositRetrieveParams,
|
|
57
|
+
Deposits,
|
|
58
|
+
DepositsUuidCursorIDPage,
|
|
59
|
+
} from './resources/deposits';
|
|
60
|
+
import {
|
|
61
|
+
OrderbookListInstrumentsParams,
|
|
62
|
+
OrderbookListInstrumentsResponse,
|
|
63
|
+
OrderbookListParams,
|
|
64
|
+
OrderbookListResponse,
|
|
65
|
+
Orderbooks,
|
|
66
|
+
} from './resources/orderbooks';
|
|
67
|
+
import {
|
|
68
|
+
BatchCancelResult,
|
|
69
|
+
ClosedOrderState,
|
|
70
|
+
OpenOrderState,
|
|
71
|
+
OrdTypeEnum,
|
|
72
|
+
Order,
|
|
73
|
+
OrderCancelAndNewParams,
|
|
74
|
+
OrderCancelByUuidsParams,
|
|
75
|
+
OrderCancelOpenParams,
|
|
76
|
+
OrderCancelParams,
|
|
77
|
+
OrderCreateParams,
|
|
78
|
+
OrderListByUuidsParams,
|
|
79
|
+
OrderListByUuidsResponse,
|
|
80
|
+
OrderListClosedParams,
|
|
81
|
+
OrderListClosedResponse,
|
|
82
|
+
OrderListOpenParams,
|
|
83
|
+
OrderRetrieveChanceParams,
|
|
84
|
+
OrderRetrieveChanceResponse,
|
|
85
|
+
OrderRetrieveParams,
|
|
86
|
+
OrderTestCreateParams,
|
|
87
|
+
Orders,
|
|
88
|
+
OrdersPageNumberPage,
|
|
89
|
+
SideEnum,
|
|
90
|
+
SmpTypeEnum,
|
|
91
|
+
TimeInForceEnum,
|
|
92
|
+
} from './resources/orders';
|
|
93
|
+
import {
|
|
94
|
+
Ticker,
|
|
95
|
+
TickerListByQuoteCurrenciesParams,
|
|
96
|
+
TickerListByQuoteCurrenciesResponse,
|
|
97
|
+
TickerListByTradingPairsParams,
|
|
98
|
+
TickerListByTradingPairsResponse,
|
|
99
|
+
Tickers,
|
|
100
|
+
} from './resources/tickers';
|
|
101
|
+
import { TradeListParams, TradeListResponse, Trades } from './resources/trades';
|
|
102
|
+
import { TradingPairListParams, TradingPairListResponse, TradingPairs } from './resources/trading-pairs';
|
|
103
|
+
import {
|
|
104
|
+
TravelRule,
|
|
105
|
+
TravelRuleListVaspsResponse,
|
|
106
|
+
TravelRuleVerifyDepositByTxidParams,
|
|
107
|
+
TravelRuleVerifyDepositByUuidParams,
|
|
108
|
+
VerificationResult,
|
|
109
|
+
} from './resources/travel-rule';
|
|
110
|
+
import { WalletStatus, WalletStatusListResponse } from './resources/wallet-status';
|
|
111
|
+
import {
|
|
112
|
+
Withdraw,
|
|
113
|
+
WithdrawCancelWithdrawalParams,
|
|
114
|
+
WithdrawCreateKrwWithdrawalParams,
|
|
115
|
+
WithdrawCreateKrwWithdrawalResponse,
|
|
116
|
+
WithdrawCreateWithdrawalParams,
|
|
117
|
+
WithdrawListCoinAddressesResponse,
|
|
118
|
+
WithdrawListParams,
|
|
119
|
+
WithdrawRetrieveChanceParams,
|
|
120
|
+
WithdrawRetrieveChanceResponse,
|
|
121
|
+
WithdrawRetrieveParams,
|
|
122
|
+
Withdraws,
|
|
123
|
+
WithdrawsUuidCursorIDPage,
|
|
124
|
+
} from './resources/withdraws';
|
|
125
|
+
import {
|
|
126
|
+
ConnectPrivateClientEvent,
|
|
127
|
+
ConnectPrivateServerEvent,
|
|
128
|
+
WsPrivate,
|
|
129
|
+
} from './resources/ws-private/ws-private';
|
|
130
|
+
import {
|
|
131
|
+
ConnectPublicClientEvent,
|
|
132
|
+
ConnectPublicServerEvent,
|
|
133
|
+
WsPublic,
|
|
134
|
+
} from './resources/ws-public/ws-public';
|
|
135
|
+
import { type Fetch } from './internal/builtin-types';
|
|
136
|
+
import { HeadersLike, NullableHeaders, buildHeaders } from './internal/headers';
|
|
137
|
+
import { FinalRequestOptions, RequestOptions } from './internal/request-options';
|
|
138
|
+
import { readEnv } from './internal/utils/env';
|
|
139
|
+
import { createJwtToken } from './lib/jwtAuth';
|
|
140
|
+
import { WsStream } from './lib/ws';
|
|
141
|
+
import {
|
|
142
|
+
type LogLevel,
|
|
143
|
+
type Logger,
|
|
144
|
+
formatRequestDetails,
|
|
145
|
+
loggerFor,
|
|
146
|
+
parseLogLevel,
|
|
147
|
+
} from './internal/utils/log';
|
|
148
|
+
import { isEmptyObj } from './internal/utils/values';
|
|
149
|
+
|
|
150
|
+
const environments = {
|
|
151
|
+
kr: 'https://api.upbit.com',
|
|
152
|
+
sg: 'https://sg-api.upbit.com',
|
|
153
|
+
id: 'https://id-api.upbit.com',
|
|
154
|
+
th: 'https://th-api.upbit.com',
|
|
155
|
+
};
|
|
156
|
+
type Environment = keyof typeof environments;
|
|
157
|
+
|
|
158
|
+
export interface ClientOptions {
|
|
159
|
+
/**
|
|
160
|
+
* The access key provided by Upbit for API authentication.
|
|
161
|
+
* For more details, please refer to https://docs.upbit.com/reference/auth.
|
|
162
|
+
*
|
|
163
|
+
*/
|
|
164
|
+
accessKey?: string | null | undefined;
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* The secret key used to sign API requests for secure verification.
|
|
168
|
+
* For more details, please refer to https://docs.upbit.com/reference/auth.
|
|
169
|
+
*
|
|
170
|
+
*/
|
|
171
|
+
secretKey?: string | null | undefined;
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Specifies the environment to use for the API.
|
|
175
|
+
*
|
|
176
|
+
* Each environment maps to a different base URL:
|
|
177
|
+
* - `kr` corresponds to `https://api.upbit.com`
|
|
178
|
+
* - `sg` corresponds to `https://sg-api.upbit.com`
|
|
179
|
+
* - `id` corresponds to `https://id-api.upbit.com`
|
|
180
|
+
* - `th` corresponds to `https://th-api.upbit.com`
|
|
181
|
+
*/
|
|
182
|
+
environment?: Environment | undefined;
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Override the default base URL for the API, e.g., "https://api.example.com/v2/"
|
|
186
|
+
*
|
|
187
|
+
* Defaults to process.env['UPBIT_BASE_URL'].
|
|
188
|
+
*/
|
|
189
|
+
baseURL?: string | null | undefined;
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* The maximum amount of time (in milliseconds) that the client should wait for a response
|
|
193
|
+
* from the server before timing out a single request.
|
|
194
|
+
*
|
|
195
|
+
* Note that request timeouts are retried by default, so in a worst-case scenario you may wait
|
|
196
|
+
* much longer than this timeout before the promise succeeds or fails.
|
|
197
|
+
*
|
|
198
|
+
* @unit milliseconds
|
|
199
|
+
*/
|
|
200
|
+
timeout?: number | undefined;
|
|
201
|
+
/**
|
|
202
|
+
* Additional `RequestInit` options to be passed to `fetch` calls.
|
|
203
|
+
* Properties will be overridden by per-request `fetchOptions`.
|
|
204
|
+
*/
|
|
205
|
+
fetchOptions?: MergedRequestInit | undefined;
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Specify a custom `fetch` function implementation.
|
|
209
|
+
*
|
|
210
|
+
* If not provided, we expect that `fetch` is defined globally.
|
|
211
|
+
*/
|
|
212
|
+
fetch?: Fetch | undefined;
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* The maximum number of times that the client will retry a request in case of a
|
|
216
|
+
* temporary failure, like a network error or a 5XX error from the server.
|
|
217
|
+
*
|
|
218
|
+
* @default 2
|
|
219
|
+
*/
|
|
220
|
+
maxRetries?: number | undefined;
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* Default headers to include with every request to the API.
|
|
224
|
+
*
|
|
225
|
+
* These can be removed in individual requests by explicitly setting the
|
|
226
|
+
* header to `null` in request options.
|
|
227
|
+
*/
|
|
228
|
+
defaultHeaders?: HeadersLike | undefined;
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* Default query parameters to include with every request to the API.
|
|
232
|
+
*
|
|
233
|
+
* These can be removed in individual requests by explicitly setting the
|
|
234
|
+
* param to `undefined` in request options.
|
|
235
|
+
*/
|
|
236
|
+
defaultQuery?: Record<string, string | undefined> | undefined;
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* Set the log level.
|
|
240
|
+
*
|
|
241
|
+
* Defaults to process.env['UPBIT_LOG'] or 'warn' if it isn't set.
|
|
242
|
+
*/
|
|
243
|
+
logLevel?: LogLevel | undefined;
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* Set the logger.
|
|
247
|
+
*
|
|
248
|
+
* Defaults to globalThis.console.
|
|
249
|
+
*/
|
|
250
|
+
logger?: Logger | undefined;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* API Client for interfacing with the Upbit API.
|
|
255
|
+
*/
|
|
256
|
+
export class Upbit {
|
|
257
|
+
accessKey: string | null;
|
|
258
|
+
secretKey: string | null;
|
|
259
|
+
|
|
260
|
+
baseURL: string;
|
|
261
|
+
maxRetries: number;
|
|
262
|
+
timeout: number;
|
|
263
|
+
logger: Logger;
|
|
264
|
+
logLevel: LogLevel | undefined;
|
|
265
|
+
fetchOptions: MergedRequestInit | undefined;
|
|
266
|
+
|
|
267
|
+
private fetch: Fetch;
|
|
268
|
+
#encoder: Opts.RequestEncoder;
|
|
269
|
+
protected idempotencyHeader?: string;
|
|
270
|
+
private _options: ClientOptions;
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* API Client for interfacing with the Upbit API.
|
|
274
|
+
*
|
|
275
|
+
* @param {string | null | undefined} [opts.accessKey=process.env['UPBIT_ACCESS_KEY'] ?? null]
|
|
276
|
+
* @param {string | null | undefined} [opts.secretKey=process.env['UPBIT_SECRET_KEY'] ?? null]
|
|
277
|
+
* @param {Environment} [opts.environment=kr] - Specifies the environment URL to use for the API.
|
|
278
|
+
* @param {string} [opts.baseURL=process.env['UPBIT_BASE_URL'] ?? https://api.upbit.com] - Override the default base URL for the API.
|
|
279
|
+
* @param {number} [opts.timeout=1 minute] - The maximum amount of time (in milliseconds) the client will wait for a response before timing out.
|
|
280
|
+
* @param {MergedRequestInit} [opts.fetchOptions] - Additional `RequestInit` options to be passed to `fetch` calls.
|
|
281
|
+
* @param {Fetch} [opts.fetch] - Specify a custom `fetch` function implementation.
|
|
282
|
+
* @param {number} [opts.maxRetries=2] - The maximum number of times the client will retry a request.
|
|
283
|
+
* @param {HeadersLike} opts.defaultHeaders - Default headers to include with every request to the API.
|
|
284
|
+
* @param {Record<string, string | undefined>} opts.defaultQuery - Default query parameters to include with every request to the API.
|
|
285
|
+
*/
|
|
286
|
+
constructor({
|
|
287
|
+
baseURL = readEnv('UPBIT_BASE_URL'),
|
|
288
|
+
accessKey = readEnv('UPBIT_ACCESS_KEY') ?? null,
|
|
289
|
+
secretKey = readEnv('UPBIT_SECRET_KEY') ?? null,
|
|
290
|
+
...opts
|
|
291
|
+
}: ClientOptions = {}) {
|
|
292
|
+
const options: ClientOptions = {
|
|
293
|
+
accessKey,
|
|
294
|
+
secretKey,
|
|
295
|
+
...opts,
|
|
296
|
+
baseURL,
|
|
297
|
+
environment: opts.environment ?? 'kr',
|
|
298
|
+
};
|
|
299
|
+
|
|
300
|
+
if (baseURL && opts.environment) {
|
|
301
|
+
throw new Errors.UpbitError(
|
|
302
|
+
'Ambiguous URL; The `baseURL` option (or UPBIT_BASE_URL env var) and the `environment` option are given. If you want to use the environment you must pass baseURL: null',
|
|
303
|
+
);
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
this.baseURL = options.baseURL || environments[options.environment || 'kr'];
|
|
307
|
+
this.timeout = options.timeout ?? Upbit.DEFAULT_TIMEOUT /* 1 minute */;
|
|
308
|
+
this.logger = options.logger ?? console;
|
|
309
|
+
const defaultLogLevel = 'warn';
|
|
310
|
+
// Set default logLevel early so that we can log a warning in parseLogLevel.
|
|
311
|
+
this.logLevel = defaultLogLevel;
|
|
312
|
+
this.logLevel =
|
|
313
|
+
parseLogLevel(options.logLevel, 'ClientOptions.logLevel', this) ??
|
|
314
|
+
parseLogLevel(readEnv('UPBIT_LOG'), "process.env['UPBIT_LOG']", this) ??
|
|
315
|
+
defaultLogLevel;
|
|
316
|
+
this.fetchOptions = options.fetchOptions;
|
|
317
|
+
this.maxRetries = options.maxRetries ?? 2;
|
|
318
|
+
this.fetch = options.fetch ?? Shims.getDefaultFetch();
|
|
319
|
+
this.#encoder = Opts.FallbackEncoder;
|
|
320
|
+
|
|
321
|
+
this._options = options;
|
|
322
|
+
|
|
323
|
+
this.accessKey = accessKey;
|
|
324
|
+
this.secretKey = secretKey;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
/**
|
|
328
|
+
* Create a new client instance re-using the same options given to the current client with optional overriding.
|
|
329
|
+
*/
|
|
330
|
+
withOptions(options: Partial<ClientOptions>): this {
|
|
331
|
+
const client = new (this.constructor as any as new (props: ClientOptions) => typeof this)({
|
|
332
|
+
...this._options,
|
|
333
|
+
environment: options.environment ? options.environment : undefined,
|
|
334
|
+
baseURL: options.environment ? undefined : this.baseURL,
|
|
335
|
+
maxRetries: this.maxRetries,
|
|
336
|
+
timeout: this.timeout,
|
|
337
|
+
logger: this.logger,
|
|
338
|
+
logLevel: this.logLevel,
|
|
339
|
+
fetch: this.fetch,
|
|
340
|
+
fetchOptions: this.fetchOptions,
|
|
341
|
+
accessKey: this.accessKey,
|
|
342
|
+
secretKey: this.secretKey,
|
|
343
|
+
...options,
|
|
344
|
+
});
|
|
345
|
+
return client;
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
/**
|
|
349
|
+
* Check whether the base URL is set to its default.
|
|
350
|
+
*/
|
|
351
|
+
#baseURLOverridden(): boolean {
|
|
352
|
+
return this.baseURL !== environments[this._options.environment || 'kr'];
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
protected defaultQuery(): Record<string, string | undefined> | undefined {
|
|
356
|
+
return this._options.defaultQuery;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
protected validateHeaders({ values, nulls }: NullableHeaders) {
|
|
360
|
+
return;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
protected async authHeaders(
|
|
364
|
+
opts: FinalRequestOptions,
|
|
365
|
+
schemes: { bearerAuth?: boolean },
|
|
366
|
+
): Promise<NullableHeaders | undefined> {
|
|
367
|
+
return buildHeaders([schemes.bearerAuth ? await this.bearerAuth(opts) : null]);
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
protected async bearerAuth(opts: FinalRequestOptions): Promise<NullableHeaders | undefined> {
|
|
371
|
+
if (this.accessKey == null || this.secretKey == null) {
|
|
372
|
+
return undefined;
|
|
373
|
+
}
|
|
374
|
+
const queryParams =
|
|
375
|
+
(opts.query as Record<string, unknown> | null | undefined) ??
|
|
376
|
+
(opts.body != null && typeof opts.body === 'object' && !Array.isArray(opts.body) ?
|
|
377
|
+
(opts.body as Record<string, unknown>)
|
|
378
|
+
: null);
|
|
379
|
+
const token = createJwtToken(this.accessKey, this.secretKey, queryParams);
|
|
380
|
+
return buildHeaders([{ Authorization: `Bearer ${token}` }]);
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
protected stringifyQuery(query: object | Record<string, unknown>): string {
|
|
384
|
+
return stringifyQuery(query);
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
private getUserAgent(): string {
|
|
388
|
+
return `${this.constructor.name}/JS ${VERSION}`;
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
protected defaultIdempotencyKey(): string {
|
|
392
|
+
return `node-retry-${uuid4()}`;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
protected makeStatusError(
|
|
396
|
+
status: number,
|
|
397
|
+
error: Object,
|
|
398
|
+
message: string | undefined,
|
|
399
|
+
headers: Headers,
|
|
400
|
+
): Errors.APIError {
|
|
401
|
+
return Errors.APIError.generate(status, error, message, headers);
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
buildURL(
|
|
405
|
+
path: string,
|
|
406
|
+
query: Record<string, unknown> | null | undefined,
|
|
407
|
+
defaultBaseURL?: string | undefined,
|
|
408
|
+
): string {
|
|
409
|
+
const baseURL = (!this.#baseURLOverridden() && defaultBaseURL) || this.baseURL;
|
|
410
|
+
const url =
|
|
411
|
+
isAbsoluteURL(path) ?
|
|
412
|
+
new URL(path)
|
|
413
|
+
: new URL(baseURL + (baseURL.endsWith('/') && path.startsWith('/') ? path.slice(1) : path));
|
|
414
|
+
|
|
415
|
+
const defaultQuery = this.defaultQuery();
|
|
416
|
+
const pathQuery = Object.fromEntries(url.searchParams);
|
|
417
|
+
if (!isEmptyObj(defaultQuery) || !isEmptyObj(pathQuery)) {
|
|
418
|
+
query = { ...pathQuery, ...defaultQuery, ...query };
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
if (typeof query === 'object' && query && !Array.isArray(query)) {
|
|
422
|
+
url.search = this.stringifyQuery(query);
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
return url.toString();
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
/**
|
|
429
|
+
* Used as a callback for mutating the given `FinalRequestOptions` object.
|
|
430
|
+
*/
|
|
431
|
+
protected async prepareOptions(options: FinalRequestOptions): Promise<void> {}
|
|
432
|
+
|
|
433
|
+
/**
|
|
434
|
+
* Used as a callback for mutating the given `RequestInit` object.
|
|
435
|
+
*
|
|
436
|
+
* This is useful for cases where you want to add certain headers based off of
|
|
437
|
+
* the request properties, e.g. `method` or `url`.
|
|
438
|
+
*/
|
|
439
|
+
protected async prepareRequest(
|
|
440
|
+
request: RequestInit,
|
|
441
|
+
{ url, options }: { url: string; options: FinalRequestOptions },
|
|
442
|
+
): Promise<void> {}
|
|
443
|
+
|
|
444
|
+
get<Rsp>(path: string, opts?: PromiseOrValue<RequestOptions>): APIPromise<Rsp> {
|
|
445
|
+
return this.methodRequest('get', path, opts);
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
post<Rsp>(path: string, opts?: PromiseOrValue<RequestOptions>): APIPromise<Rsp> {
|
|
449
|
+
return this.methodRequest('post', path, opts);
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
patch<Rsp>(path: string, opts?: PromiseOrValue<RequestOptions>): APIPromise<Rsp> {
|
|
453
|
+
return this.methodRequest('patch', path, opts);
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
put<Rsp>(path: string, opts?: PromiseOrValue<RequestOptions>): APIPromise<Rsp> {
|
|
457
|
+
return this.methodRequest('put', path, opts);
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
delete<Rsp>(path: string, opts?: PromiseOrValue<RequestOptions>): APIPromise<Rsp> {
|
|
461
|
+
return this.methodRequest('delete', path, opts);
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
private methodRequest<Rsp>(
|
|
465
|
+
method: HTTPMethod,
|
|
466
|
+
path: string,
|
|
467
|
+
opts?: PromiseOrValue<RequestOptions>,
|
|
468
|
+
): APIPromise<Rsp> {
|
|
469
|
+
return this.request(
|
|
470
|
+
Promise.resolve(opts).then((opts) => {
|
|
471
|
+
return { method, path, ...opts };
|
|
472
|
+
}),
|
|
473
|
+
);
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
request<Rsp>(
|
|
477
|
+
options: PromiseOrValue<FinalRequestOptions>,
|
|
478
|
+
remainingRetries: number | null = null,
|
|
479
|
+
): APIPromise<Rsp> {
|
|
480
|
+
return new APIPromise(this, this.makeRequest(options, remainingRetries, undefined));
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
private async makeRequest(
|
|
484
|
+
optionsInput: PromiseOrValue<FinalRequestOptions>,
|
|
485
|
+
retriesRemaining: number | null,
|
|
486
|
+
retryOfRequestLogID: string | undefined,
|
|
487
|
+
): Promise<APIResponseProps> {
|
|
488
|
+
const options = await optionsInput;
|
|
489
|
+
const maxRetries = options.maxRetries ?? this.maxRetries;
|
|
490
|
+
if (retriesRemaining == null) {
|
|
491
|
+
retriesRemaining = maxRetries;
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
await this.prepareOptions(options);
|
|
495
|
+
|
|
496
|
+
const { req, url, timeout } = await this.buildRequest(options, {
|
|
497
|
+
retryCount: maxRetries - retriesRemaining,
|
|
498
|
+
});
|
|
499
|
+
|
|
500
|
+
await this.prepareRequest(req, { url, options });
|
|
501
|
+
|
|
502
|
+
/** Not an API request ID, just for correlating local log entries. */
|
|
503
|
+
const requestLogID = 'log_' + ((Math.random() * (1 << 24)) | 0).toString(16).padStart(6, '0');
|
|
504
|
+
const retryLogStr = retryOfRequestLogID === undefined ? '' : `, retryOf: ${retryOfRequestLogID}`;
|
|
505
|
+
const startTime = Date.now();
|
|
506
|
+
|
|
507
|
+
loggerFor(this).debug(
|
|
508
|
+
`[${requestLogID}] sending request`,
|
|
509
|
+
formatRequestDetails({
|
|
510
|
+
retryOfRequestLogID,
|
|
511
|
+
method: options.method,
|
|
512
|
+
url,
|
|
513
|
+
options,
|
|
514
|
+
headers: req.headers,
|
|
515
|
+
}),
|
|
516
|
+
);
|
|
517
|
+
|
|
518
|
+
if (options.signal?.aborted) {
|
|
519
|
+
throw new Errors.APIUserAbortError();
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
const controller = new AbortController();
|
|
523
|
+
const response = await this.fetchWithTimeout(url, req, timeout, controller).catch(castToError);
|
|
524
|
+
const headersTime = Date.now();
|
|
525
|
+
|
|
526
|
+
if (response instanceof globalThis.Error) {
|
|
527
|
+
const retryMessage = `retrying, ${retriesRemaining} attempts remaining`;
|
|
528
|
+
if (options.signal?.aborted) {
|
|
529
|
+
throw new Errors.APIUserAbortError();
|
|
530
|
+
}
|
|
531
|
+
// detect native connection timeout errors
|
|
532
|
+
// deno throws "TypeError: error sending request for url (https://example/): client error (Connect): tcp connect error: Operation timed out (os error 60): Operation timed out (os error 60)"
|
|
533
|
+
// undici throws "TypeError: fetch failed" with cause "ConnectTimeoutError: Connect Timeout Error (attempted address: example:443, timeout: 1ms)"
|
|
534
|
+
// others do not provide enough information to distinguish timeouts from other connection errors
|
|
535
|
+
const isTimeout =
|
|
536
|
+
isAbortError(response) ||
|
|
537
|
+
/timed? ?out/i.test(String(response) + ('cause' in response ? String(response.cause) : ''));
|
|
538
|
+
if (retriesRemaining) {
|
|
539
|
+
loggerFor(this).info(
|
|
540
|
+
`[${requestLogID}] connection ${isTimeout ? 'timed out' : 'failed'} - ${retryMessage}`,
|
|
541
|
+
);
|
|
542
|
+
loggerFor(this).debug(
|
|
543
|
+
`[${requestLogID}] connection ${isTimeout ? 'timed out' : 'failed'} (${retryMessage})`,
|
|
544
|
+
formatRequestDetails({
|
|
545
|
+
retryOfRequestLogID,
|
|
546
|
+
url,
|
|
547
|
+
durationMs: headersTime - startTime,
|
|
548
|
+
message: response.message,
|
|
549
|
+
}),
|
|
550
|
+
);
|
|
551
|
+
return this.retryRequest(options, retriesRemaining, retryOfRequestLogID ?? requestLogID);
|
|
552
|
+
}
|
|
553
|
+
loggerFor(this).info(
|
|
554
|
+
`[${requestLogID}] connection ${isTimeout ? 'timed out' : 'failed'} - error; no more retries left`,
|
|
555
|
+
);
|
|
556
|
+
loggerFor(this).debug(
|
|
557
|
+
`[${requestLogID}] connection ${isTimeout ? 'timed out' : 'failed'} (error; no more retries left)`,
|
|
558
|
+
formatRequestDetails({
|
|
559
|
+
retryOfRequestLogID,
|
|
560
|
+
url,
|
|
561
|
+
durationMs: headersTime - startTime,
|
|
562
|
+
message: response.message,
|
|
563
|
+
}),
|
|
564
|
+
);
|
|
565
|
+
if (isTimeout) {
|
|
566
|
+
throw new Errors.APIConnectionTimeoutError();
|
|
567
|
+
}
|
|
568
|
+
throw new Errors.APIConnectionError({ cause: response });
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
const responseInfo = `[${requestLogID}${retryLogStr}] ${req.method} ${url} ${
|
|
572
|
+
response.ok ? 'succeeded' : 'failed'
|
|
573
|
+
} with status ${response.status} in ${headersTime - startTime}ms`;
|
|
574
|
+
|
|
575
|
+
if (!response.ok) {
|
|
576
|
+
const shouldRetry = await this.shouldRetry(response);
|
|
577
|
+
if (retriesRemaining && shouldRetry) {
|
|
578
|
+
const retryMessage = `retrying, ${retriesRemaining} attempts remaining`;
|
|
579
|
+
|
|
580
|
+
// We don't need the body of this response.
|
|
581
|
+
await Shims.CancelReadableStream(response.body);
|
|
582
|
+
loggerFor(this).info(`${responseInfo} - ${retryMessage}`);
|
|
583
|
+
loggerFor(this).debug(
|
|
584
|
+
`[${requestLogID}] response error (${retryMessage})`,
|
|
585
|
+
formatRequestDetails({
|
|
586
|
+
retryOfRequestLogID,
|
|
587
|
+
url: response.url,
|
|
588
|
+
status: response.status,
|
|
589
|
+
headers: response.headers,
|
|
590
|
+
durationMs: headersTime - startTime,
|
|
591
|
+
}),
|
|
592
|
+
);
|
|
593
|
+
return this.retryRequest(
|
|
594
|
+
options,
|
|
595
|
+
retriesRemaining,
|
|
596
|
+
retryOfRequestLogID ?? requestLogID,
|
|
597
|
+
response.headers,
|
|
598
|
+
);
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
const retryMessage = shouldRetry ? `error; no more retries left` : `error; not retryable`;
|
|
602
|
+
|
|
603
|
+
loggerFor(this).info(`${responseInfo} - ${retryMessage}`);
|
|
604
|
+
|
|
605
|
+
const errText = await response.text().catch((err: any) => castToError(err).message);
|
|
606
|
+
const errJSON = safeJSON(errText) as any;
|
|
607
|
+
const errMessage = errJSON ? undefined : errText;
|
|
608
|
+
|
|
609
|
+
loggerFor(this).debug(
|
|
610
|
+
`[${requestLogID}] response error (${retryMessage})`,
|
|
611
|
+
formatRequestDetails({
|
|
612
|
+
retryOfRequestLogID,
|
|
613
|
+
url: response.url,
|
|
614
|
+
status: response.status,
|
|
615
|
+
headers: response.headers,
|
|
616
|
+
message: errMessage,
|
|
617
|
+
durationMs: Date.now() - startTime,
|
|
618
|
+
}),
|
|
619
|
+
);
|
|
620
|
+
|
|
621
|
+
const err = this.makeStatusError(response.status, errJSON, errMessage, response.headers);
|
|
622
|
+
throw err;
|
|
623
|
+
}
|
|
624
|
+
|
|
625
|
+
loggerFor(this).info(responseInfo);
|
|
626
|
+
loggerFor(this).debug(
|
|
627
|
+
`[${requestLogID}] response start`,
|
|
628
|
+
formatRequestDetails({
|
|
629
|
+
retryOfRequestLogID,
|
|
630
|
+
url: response.url,
|
|
631
|
+
status: response.status,
|
|
632
|
+
headers: response.headers,
|
|
633
|
+
durationMs: headersTime - startTime,
|
|
634
|
+
}),
|
|
635
|
+
);
|
|
636
|
+
|
|
637
|
+
return { response, options, controller, requestLogID, retryOfRequestLogID, startTime };
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
getAPIList<Item, PageClass extends Pagination.AbstractPage<Item> = Pagination.AbstractPage<Item>>(
|
|
641
|
+
path: string,
|
|
642
|
+
Page: new (...args: any[]) => PageClass,
|
|
643
|
+
opts?: PromiseOrValue<RequestOptions>,
|
|
644
|
+
): Pagination.PagePromise<PageClass, Item> {
|
|
645
|
+
return this.requestAPIList(
|
|
646
|
+
Page,
|
|
647
|
+
opts && 'then' in opts ?
|
|
648
|
+
opts.then((opts) => ({ method: 'get', path, ...opts }))
|
|
649
|
+
: { method: 'get', path, ...opts },
|
|
650
|
+
);
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
requestAPIList<
|
|
654
|
+
Item = unknown,
|
|
655
|
+
PageClass extends Pagination.AbstractPage<Item> = Pagination.AbstractPage<Item>,
|
|
656
|
+
>(
|
|
657
|
+
Page: new (...args: ConstructorParameters<typeof Pagination.AbstractPage>) => PageClass,
|
|
658
|
+
options: PromiseOrValue<FinalRequestOptions>,
|
|
659
|
+
): Pagination.PagePromise<PageClass, Item> {
|
|
660
|
+
const request = this.makeRequest(options, null, undefined);
|
|
661
|
+
return new Pagination.PagePromise<PageClass, Item>(this as any as Upbit, request, Page);
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
async fetchWithTimeout(
|
|
665
|
+
url: RequestInfo,
|
|
666
|
+
init: RequestInit | undefined,
|
|
667
|
+
ms: number,
|
|
668
|
+
controller: AbortController,
|
|
669
|
+
): Promise<Response> {
|
|
670
|
+
const { signal, method, ...options } = init || {};
|
|
671
|
+
const abort = this._makeAbort(controller);
|
|
672
|
+
if (signal) signal.addEventListener('abort', abort, { once: true });
|
|
673
|
+
|
|
674
|
+
const timeout = setTimeout(abort, ms);
|
|
675
|
+
|
|
676
|
+
const isReadableBody =
|
|
677
|
+
((globalThis as any).ReadableStream && options.body instanceof (globalThis as any).ReadableStream) ||
|
|
678
|
+
(typeof options.body === 'object' && options.body !== null && Symbol.asyncIterator in options.body);
|
|
679
|
+
|
|
680
|
+
const fetchOptions: RequestInit = {
|
|
681
|
+
signal: controller.signal as any,
|
|
682
|
+
...(isReadableBody ? { duplex: 'half' } : {}),
|
|
683
|
+
method: 'GET',
|
|
684
|
+
...options,
|
|
685
|
+
};
|
|
686
|
+
if (method) {
|
|
687
|
+
// Custom methods like 'patch' need to be uppercased
|
|
688
|
+
// See https://github.com/nodejs/undici/issues/2294
|
|
689
|
+
fetchOptions.method = method.toUpperCase();
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
try {
|
|
693
|
+
// use undefined this binding; fetch errors if bound to something else in browser/cloudflare
|
|
694
|
+
return await this.fetch.call(undefined, url, fetchOptions);
|
|
695
|
+
} finally {
|
|
696
|
+
clearTimeout(timeout);
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
private async shouldRetry(response: Response): Promise<boolean> {
|
|
701
|
+
// Note this is not a standard header.
|
|
702
|
+
const shouldRetryHeader = response.headers.get('x-should-retry');
|
|
703
|
+
|
|
704
|
+
// If the server explicitly says whether or not to retry, obey.
|
|
705
|
+
if (shouldRetryHeader === 'true') return true;
|
|
706
|
+
if (shouldRetryHeader === 'false') return false;
|
|
707
|
+
|
|
708
|
+
// Retry on request timeouts.
|
|
709
|
+
if (response.status === 408) return true;
|
|
710
|
+
|
|
711
|
+
// Retry on lock timeouts.
|
|
712
|
+
if (response.status === 409) return true;
|
|
713
|
+
|
|
714
|
+
// Retry on rate limits.
|
|
715
|
+
if (response.status === 429) return true;
|
|
716
|
+
|
|
717
|
+
// Retry internal errors.
|
|
718
|
+
if (response.status >= 500) return true;
|
|
719
|
+
|
|
720
|
+
return false;
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
private async retryRequest(
|
|
724
|
+
options: FinalRequestOptions,
|
|
725
|
+
retriesRemaining: number,
|
|
726
|
+
requestLogID: string,
|
|
727
|
+
responseHeaders?: Headers | undefined,
|
|
728
|
+
): Promise<APIResponseProps> {
|
|
729
|
+
let timeoutMillis: number | undefined;
|
|
730
|
+
|
|
731
|
+
// Note the `retry-after-ms` header may not be standard, but is a good idea and we'd like proactive support for it.
|
|
732
|
+
const retryAfterMillisHeader = responseHeaders?.get('retry-after-ms');
|
|
733
|
+
if (retryAfterMillisHeader) {
|
|
734
|
+
const timeoutMs = parseFloat(retryAfterMillisHeader);
|
|
735
|
+
if (!Number.isNaN(timeoutMs)) {
|
|
736
|
+
timeoutMillis = timeoutMs;
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
|
|
740
|
+
// About the Retry-After header: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Retry-After
|
|
741
|
+
const retryAfterHeader = responseHeaders?.get('retry-after');
|
|
742
|
+
if (retryAfterHeader && !timeoutMillis) {
|
|
743
|
+
const timeoutSeconds = parseFloat(retryAfterHeader);
|
|
744
|
+
if (!Number.isNaN(timeoutSeconds)) {
|
|
745
|
+
timeoutMillis = timeoutSeconds * 1000;
|
|
746
|
+
} else {
|
|
747
|
+
timeoutMillis = Date.parse(retryAfterHeader) - Date.now();
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
|
|
751
|
+
// If the API asks us to wait a certain amount of time, just do what it
|
|
752
|
+
// says, but otherwise calculate a default
|
|
753
|
+
if (timeoutMillis === undefined) {
|
|
754
|
+
const maxRetries = options.maxRetries ?? this.maxRetries;
|
|
755
|
+
timeoutMillis = this.calculateDefaultRetryTimeoutMillis(retriesRemaining, maxRetries);
|
|
756
|
+
}
|
|
757
|
+
await sleep(timeoutMillis);
|
|
758
|
+
|
|
759
|
+
return this.makeRequest(options, retriesRemaining - 1, requestLogID);
|
|
760
|
+
}
|
|
761
|
+
|
|
762
|
+
private calculateDefaultRetryTimeoutMillis(retriesRemaining: number, maxRetries: number): number {
|
|
763
|
+
const initialRetryDelay = 0.5;
|
|
764
|
+
const maxRetryDelay = 8.0;
|
|
765
|
+
|
|
766
|
+
const numRetries = maxRetries - retriesRemaining;
|
|
767
|
+
|
|
768
|
+
// Apply exponential backoff, but not more than the max.
|
|
769
|
+
const sleepSeconds = Math.min(initialRetryDelay * Math.pow(2, numRetries), maxRetryDelay);
|
|
770
|
+
|
|
771
|
+
// Apply some jitter, take up to at most 25 percent of the retry time.
|
|
772
|
+
const jitter = 1 - Math.random() * 0.25;
|
|
773
|
+
|
|
774
|
+
return sleepSeconds * jitter * 1000;
|
|
775
|
+
}
|
|
776
|
+
|
|
777
|
+
async buildRequest(
|
|
778
|
+
inputOptions: FinalRequestOptions,
|
|
779
|
+
{ retryCount = 0 }: { retryCount?: number } = {},
|
|
780
|
+
): Promise<{ req: FinalizedRequestInit; url: string; timeout: number }> {
|
|
781
|
+
const options = { ...inputOptions };
|
|
782
|
+
const { method, path, query, defaultBaseURL } = options;
|
|
783
|
+
|
|
784
|
+
const url = this.buildURL(path!, query as Record<string, unknown>, defaultBaseURL);
|
|
785
|
+
if ('timeout' in options) validatePositiveInteger('timeout', options.timeout);
|
|
786
|
+
options.timeout = options.timeout ?? this.timeout;
|
|
787
|
+
const { bodyHeaders, body } = this.buildBody({ options });
|
|
788
|
+
const reqHeaders = await this.buildHeaders({ options: inputOptions, method, bodyHeaders, retryCount });
|
|
789
|
+
|
|
790
|
+
const req: FinalizedRequestInit = {
|
|
791
|
+
method,
|
|
792
|
+
headers: reqHeaders,
|
|
793
|
+
...(options.signal && { signal: options.signal }),
|
|
794
|
+
...((globalThis as any).ReadableStream &&
|
|
795
|
+
body instanceof (globalThis as any).ReadableStream && { duplex: 'half' }),
|
|
796
|
+
...(body && { body }),
|
|
797
|
+
...((this.fetchOptions as any) ?? {}),
|
|
798
|
+
...((options.fetchOptions as any) ?? {}),
|
|
799
|
+
};
|
|
800
|
+
|
|
801
|
+
return { req, url, timeout: options.timeout };
|
|
802
|
+
}
|
|
803
|
+
|
|
804
|
+
private async buildHeaders({
|
|
805
|
+
options,
|
|
806
|
+
method,
|
|
807
|
+
bodyHeaders,
|
|
808
|
+
retryCount,
|
|
809
|
+
}: {
|
|
810
|
+
options: FinalRequestOptions;
|
|
811
|
+
method: HTTPMethod;
|
|
812
|
+
bodyHeaders: HeadersLike;
|
|
813
|
+
retryCount: number;
|
|
814
|
+
}): Promise<Headers> {
|
|
815
|
+
let idempotencyHeaders: HeadersLike = {};
|
|
816
|
+
if (this.idempotencyHeader && method !== 'get') {
|
|
817
|
+
if (!options.idempotencyKey) options.idempotencyKey = this.defaultIdempotencyKey();
|
|
818
|
+
idempotencyHeaders[this.idempotencyHeader] = options.idempotencyKey;
|
|
819
|
+
}
|
|
820
|
+
|
|
821
|
+
const headers = buildHeaders([
|
|
822
|
+
idempotencyHeaders,
|
|
823
|
+
{
|
|
824
|
+
Accept: 'application/json',
|
|
825
|
+
'User-Agent': this.getUserAgent(),
|
|
826
|
+
'X-Upbit-SDK-Lang': 'typescript',
|
|
827
|
+
'X-Upbit-SDK-Version': VERSION,
|
|
828
|
+
'X-Upbit-Runtime': getRuntimeName(),
|
|
829
|
+
'X-Upbit-Runtime-Version': getRuntimeVersion(),
|
|
830
|
+
},
|
|
831
|
+
await this.authHeaders(options, options.__security ?? { bearerAuth: true }),
|
|
832
|
+
this._options.defaultHeaders,
|
|
833
|
+
bodyHeaders,
|
|
834
|
+
options.headers,
|
|
835
|
+
]);
|
|
836
|
+
|
|
837
|
+
this.validateHeaders(headers);
|
|
838
|
+
|
|
839
|
+
return headers.values;
|
|
840
|
+
}
|
|
841
|
+
|
|
842
|
+
private _makeAbort(controller: AbortController) {
|
|
843
|
+
// note: we can't just inline this method inside `fetchWithTimeout()` because then the closure
|
|
844
|
+
// would capture all request options, and cause a memory leak.
|
|
845
|
+
return () => controller.abort();
|
|
846
|
+
}
|
|
847
|
+
|
|
848
|
+
private buildBody({ options: { body, headers: rawHeaders } }: { options: FinalRequestOptions }): {
|
|
849
|
+
bodyHeaders: HeadersLike;
|
|
850
|
+
body: BodyInit | undefined;
|
|
851
|
+
} {
|
|
852
|
+
if (!body) {
|
|
853
|
+
return { bodyHeaders: undefined, body: undefined };
|
|
854
|
+
}
|
|
855
|
+
const headers = buildHeaders([rawHeaders]);
|
|
856
|
+
if (
|
|
857
|
+
// Pass raw type verbatim
|
|
858
|
+
ArrayBuffer.isView(body) ||
|
|
859
|
+
body instanceof ArrayBuffer ||
|
|
860
|
+
body instanceof DataView ||
|
|
861
|
+
(typeof body === 'string' &&
|
|
862
|
+
// Preserve legacy string encoding behavior for now
|
|
863
|
+
headers.values.has('content-type')) ||
|
|
864
|
+
// `Blob` is superset of `File`
|
|
865
|
+
((globalThis as any).Blob && body instanceof (globalThis as any).Blob) ||
|
|
866
|
+
// `FormData` -> `multipart/form-data`
|
|
867
|
+
body instanceof FormData ||
|
|
868
|
+
// `URLSearchParams` -> `application/x-www-form-urlencoded`
|
|
869
|
+
body instanceof URLSearchParams ||
|
|
870
|
+
// Send chunked stream (each chunk has own `length`)
|
|
871
|
+
((globalThis as any).ReadableStream && body instanceof (globalThis as any).ReadableStream)
|
|
872
|
+
) {
|
|
873
|
+
return { bodyHeaders: undefined, body: body as BodyInit };
|
|
874
|
+
} else if (
|
|
875
|
+
typeof body === 'object' &&
|
|
876
|
+
(Symbol.asyncIterator in body ||
|
|
877
|
+
(Symbol.iterator in body && 'next' in body && typeof body.next === 'function'))
|
|
878
|
+
) {
|
|
879
|
+
return { bodyHeaders: undefined, body: Shims.ReadableStreamFrom(body as AsyncIterable<Uint8Array>) };
|
|
880
|
+
} else if (
|
|
881
|
+
typeof body === 'object' &&
|
|
882
|
+
headers.values.get('content-type') === 'application/x-www-form-urlencoded'
|
|
883
|
+
) {
|
|
884
|
+
return {
|
|
885
|
+
bodyHeaders: { 'content-type': 'application/x-www-form-urlencoded' },
|
|
886
|
+
body: this.stringifyQuery(body),
|
|
887
|
+
};
|
|
888
|
+
} else {
|
|
889
|
+
return this.#encoder({ body, headers });
|
|
890
|
+
}
|
|
891
|
+
}
|
|
892
|
+
|
|
893
|
+
private _wsStream: WsStream | undefined;
|
|
894
|
+
|
|
895
|
+
/** Convenience accessor for WebSocket streams. */
|
|
896
|
+
get wsStream(): WsStream {
|
|
897
|
+
return (this._wsStream ??= new WsStream(this));
|
|
898
|
+
}
|
|
899
|
+
|
|
900
|
+
static Upbit = this;
|
|
901
|
+
static DEFAULT_TIMEOUT = 60000; // 1 minute
|
|
902
|
+
|
|
903
|
+
static UpbitError = Errors.UpbitError;
|
|
904
|
+
static APIError = Errors.APIError;
|
|
905
|
+
static APIConnectionError = Errors.APIConnectionError;
|
|
906
|
+
static APIConnectionTimeoutError = Errors.APIConnectionTimeoutError;
|
|
907
|
+
static APIUserAbortError = Errors.APIUserAbortError;
|
|
908
|
+
static NotFoundError = Errors.NotFoundError;
|
|
909
|
+
static ConflictError = Errors.ConflictError;
|
|
910
|
+
static RateLimitError = Errors.RateLimitError;
|
|
911
|
+
static RateLimitPenaltyError = Errors.RateLimitPenaltyError;
|
|
912
|
+
static BadRequestError = Errors.BadRequestError;
|
|
913
|
+
static AuthenticationError = Errors.AuthenticationError;
|
|
914
|
+
static InternalServerError = Errors.InternalServerError;
|
|
915
|
+
static PermissionDeniedError = Errors.PermissionDeniedError;
|
|
916
|
+
static UnprocessableEntityError = Errors.UnprocessableEntityError;
|
|
917
|
+
|
|
918
|
+
static toFile = Uploads.toFile;
|
|
919
|
+
|
|
920
|
+
accounts: API.Accounts = new API.Accounts(this);
|
|
921
|
+
travelRule: API.TravelRule = new API.TravelRule(this);
|
|
922
|
+
walletStatus: API.WalletStatus = new API.WalletStatus(this);
|
|
923
|
+
apiKeys: API.APIKeys = new API.APIKeys(this);
|
|
924
|
+
orders: API.Orders = new API.Orders(this);
|
|
925
|
+
withdraws: API.Withdraws = new API.Withdraws(this);
|
|
926
|
+
deposits: API.Deposits = new API.Deposits(this);
|
|
927
|
+
tradingPairs: API.TradingPairs = new API.TradingPairs(this);
|
|
928
|
+
tickers: API.Tickers = new API.Tickers(this);
|
|
929
|
+
orderbooks: API.Orderbooks = new API.Orderbooks(this);
|
|
930
|
+
trades: API.Trades = new API.Trades(this);
|
|
931
|
+
candles: API.Candles = new API.Candles(this);
|
|
932
|
+
wsPublic: API.WsPublic = new API.WsPublic(this);
|
|
933
|
+
wsPrivate: API.WsPrivate = new API.WsPrivate(this);
|
|
934
|
+
}
|
|
935
|
+
|
|
936
|
+
Upbit.Accounts = Accounts;
|
|
937
|
+
Upbit.TravelRule = TravelRule;
|
|
938
|
+
Upbit.WalletStatus = WalletStatus;
|
|
939
|
+
Upbit.APIKeys = APIKeys;
|
|
940
|
+
Upbit.Orders = Orders;
|
|
941
|
+
Upbit.Withdraws = Withdraws;
|
|
942
|
+
Upbit.Deposits = Deposits;
|
|
943
|
+
Upbit.TradingPairs = TradingPairs;
|
|
944
|
+
Upbit.Tickers = Tickers;
|
|
945
|
+
Upbit.Orderbooks = Orderbooks;
|
|
946
|
+
Upbit.Trades = Trades;
|
|
947
|
+
Upbit.Candles = Candles;
|
|
948
|
+
Upbit.WsPublic = WsPublic;
|
|
949
|
+
Upbit.WsPrivate = WsPrivate;
|
|
950
|
+
|
|
951
|
+
export declare namespace Upbit {
|
|
952
|
+
export type RequestOptions = Opts.RequestOptions;
|
|
953
|
+
|
|
954
|
+
export import PageNumberPage = Pagination.PageNumberPage;
|
|
955
|
+
export {
|
|
956
|
+
type PageNumberPageParams as PageNumberPageParams,
|
|
957
|
+
type PageNumberPageResponse as PageNumberPageResponse,
|
|
958
|
+
};
|
|
959
|
+
|
|
960
|
+
export import UuidCursorIDPage = Pagination.UuidCursorIDPage;
|
|
961
|
+
export {
|
|
962
|
+
type UuidCursorIDPageParams as UuidCursorIDPageParams,
|
|
963
|
+
type UuidCursorIDPageResponse as UuidCursorIDPageResponse,
|
|
964
|
+
};
|
|
965
|
+
|
|
966
|
+
export { Accounts as Accounts, type AccountListResponse as AccountListResponse };
|
|
967
|
+
|
|
968
|
+
export {
|
|
969
|
+
TravelRule as TravelRule,
|
|
970
|
+
type VerificationResult as VerificationResult,
|
|
971
|
+
type TravelRuleListVaspsResponse as TravelRuleListVaspsResponse,
|
|
972
|
+
type TravelRuleVerifyDepositByTxidParams as TravelRuleVerifyDepositByTxidParams,
|
|
973
|
+
type TravelRuleVerifyDepositByUuidParams as TravelRuleVerifyDepositByUuidParams,
|
|
974
|
+
};
|
|
975
|
+
|
|
976
|
+
export { WalletStatus as WalletStatus, type WalletStatusListResponse as WalletStatusListResponse };
|
|
977
|
+
|
|
978
|
+
export { APIKeys as APIKeys, type APIKeyListResponse as APIKeyListResponse };
|
|
979
|
+
|
|
980
|
+
export {
|
|
981
|
+
Orders as Orders,
|
|
982
|
+
type BatchCancelResult as BatchCancelResult,
|
|
983
|
+
type ClosedOrderState as ClosedOrderState,
|
|
984
|
+
type OpenOrderState as OpenOrderState,
|
|
985
|
+
type OrdTypeEnum as OrdTypeEnum,
|
|
986
|
+
type Order as Order,
|
|
987
|
+
type SideEnum as SideEnum,
|
|
988
|
+
type SmpTypeEnum as SmpTypeEnum,
|
|
989
|
+
type TimeInForceEnum as TimeInForceEnum,
|
|
990
|
+
type OrderListByUuidsResponse as OrderListByUuidsResponse,
|
|
991
|
+
type OrderListClosedResponse as OrderListClosedResponse,
|
|
992
|
+
type OrderRetrieveChanceResponse as OrderRetrieveChanceResponse,
|
|
993
|
+
type OrdersPageNumberPage as OrdersPageNumberPage,
|
|
994
|
+
type OrderCreateParams as OrderCreateParams,
|
|
995
|
+
type OrderRetrieveParams as OrderRetrieveParams,
|
|
996
|
+
type OrderCancelParams as OrderCancelParams,
|
|
997
|
+
type OrderCancelAndNewParams as OrderCancelAndNewParams,
|
|
998
|
+
type OrderCancelByUuidsParams as OrderCancelByUuidsParams,
|
|
999
|
+
type OrderCancelOpenParams as OrderCancelOpenParams,
|
|
1000
|
+
type OrderListByUuidsParams as OrderListByUuidsParams,
|
|
1001
|
+
type OrderListClosedParams as OrderListClosedParams,
|
|
1002
|
+
type OrderListOpenParams as OrderListOpenParams,
|
|
1003
|
+
type OrderRetrieveChanceParams as OrderRetrieveChanceParams,
|
|
1004
|
+
type OrderTestCreateParams as OrderTestCreateParams,
|
|
1005
|
+
};
|
|
1006
|
+
|
|
1007
|
+
export {
|
|
1008
|
+
Withdraws as Withdraws,
|
|
1009
|
+
type Withdraw as Withdraw,
|
|
1010
|
+
type WithdrawCreateKrwWithdrawalResponse as WithdrawCreateKrwWithdrawalResponse,
|
|
1011
|
+
type WithdrawListCoinAddressesResponse as WithdrawListCoinAddressesResponse,
|
|
1012
|
+
type WithdrawRetrieveChanceResponse as WithdrawRetrieveChanceResponse,
|
|
1013
|
+
type WithdrawsUuidCursorIDPage as WithdrawsUuidCursorIDPage,
|
|
1014
|
+
type WithdrawRetrieveParams as WithdrawRetrieveParams,
|
|
1015
|
+
type WithdrawListParams as WithdrawListParams,
|
|
1016
|
+
type WithdrawCancelWithdrawalParams as WithdrawCancelWithdrawalParams,
|
|
1017
|
+
type WithdrawCreateKrwWithdrawalParams as WithdrawCreateKrwWithdrawalParams,
|
|
1018
|
+
type WithdrawCreateWithdrawalParams as WithdrawCreateWithdrawalParams,
|
|
1019
|
+
type WithdrawRetrieveChanceParams as WithdrawRetrieveChanceParams,
|
|
1020
|
+
};
|
|
1021
|
+
|
|
1022
|
+
export {
|
|
1023
|
+
Deposits as Deposits,
|
|
1024
|
+
type Deposit as Deposit,
|
|
1025
|
+
type DepositAddress as DepositAddress,
|
|
1026
|
+
type DepositCreateCoinAddressResponse as DepositCreateCoinAddressResponse,
|
|
1027
|
+
type DepositListCoinAddressesResponse as DepositListCoinAddressesResponse,
|
|
1028
|
+
type DepositRetrieveChanceResponse as DepositRetrieveChanceResponse,
|
|
1029
|
+
type DepositsUuidCursorIDPage as DepositsUuidCursorIDPage,
|
|
1030
|
+
type DepositRetrieveParams as DepositRetrieveParams,
|
|
1031
|
+
type DepositListParams as DepositListParams,
|
|
1032
|
+
type DepositCreateCoinAddressParams as DepositCreateCoinAddressParams,
|
|
1033
|
+
type DepositDepositKrwParams as DepositDepositKrwParams,
|
|
1034
|
+
type DepositRetrieveChanceParams as DepositRetrieveChanceParams,
|
|
1035
|
+
type DepositRetrieveCoinAddressParams as DepositRetrieveCoinAddressParams,
|
|
1036
|
+
};
|
|
1037
|
+
|
|
1038
|
+
export {
|
|
1039
|
+
TradingPairs as TradingPairs,
|
|
1040
|
+
type TradingPairListResponse as TradingPairListResponse,
|
|
1041
|
+
type TradingPairListParams as TradingPairListParams,
|
|
1042
|
+
};
|
|
1043
|
+
|
|
1044
|
+
export {
|
|
1045
|
+
Tickers as Tickers,
|
|
1046
|
+
type Ticker as Ticker,
|
|
1047
|
+
type TickerListByQuoteCurrenciesResponse as TickerListByQuoteCurrenciesResponse,
|
|
1048
|
+
type TickerListByTradingPairsResponse as TickerListByTradingPairsResponse,
|
|
1049
|
+
type TickerListByQuoteCurrenciesParams as TickerListByQuoteCurrenciesParams,
|
|
1050
|
+
type TickerListByTradingPairsParams as TickerListByTradingPairsParams,
|
|
1051
|
+
};
|
|
1052
|
+
|
|
1053
|
+
export {
|
|
1054
|
+
Orderbooks as Orderbooks,
|
|
1055
|
+
type OrderbookListResponse as OrderbookListResponse,
|
|
1056
|
+
type OrderbookListInstrumentsResponse as OrderbookListInstrumentsResponse,
|
|
1057
|
+
type OrderbookListParams as OrderbookListParams,
|
|
1058
|
+
type OrderbookListInstrumentsParams as OrderbookListInstrumentsParams,
|
|
1059
|
+
};
|
|
1060
|
+
|
|
1061
|
+
export {
|
|
1062
|
+
Trades as Trades,
|
|
1063
|
+
type TradeListResponse as TradeListResponse,
|
|
1064
|
+
type TradeListParams as TradeListParams,
|
|
1065
|
+
};
|
|
1066
|
+
|
|
1067
|
+
export {
|
|
1068
|
+
Candles as Candles,
|
|
1069
|
+
type Candle as Candle,
|
|
1070
|
+
type CandlePeriod as CandlePeriod,
|
|
1071
|
+
type CandleListDaysResponse as CandleListDaysResponse,
|
|
1072
|
+
type CandleListMinutesResponse as CandleListMinutesResponse,
|
|
1073
|
+
type CandleListMonthsResponse as CandleListMonthsResponse,
|
|
1074
|
+
type CandleListSecondsResponse as CandleListSecondsResponse,
|
|
1075
|
+
type CandleListWeeksResponse as CandleListWeeksResponse,
|
|
1076
|
+
type CandleListYearsResponse as CandleListYearsResponse,
|
|
1077
|
+
type CandleListDaysParams as CandleListDaysParams,
|
|
1078
|
+
type CandleListMinutesParams as CandleListMinutesParams,
|
|
1079
|
+
type CandleListMonthsParams as CandleListMonthsParams,
|
|
1080
|
+
type CandleListSecondsParams as CandleListSecondsParams,
|
|
1081
|
+
type CandleListWeeksParams as CandleListWeeksParams,
|
|
1082
|
+
type CandleListYearsParams as CandleListYearsParams,
|
|
1083
|
+
};
|
|
1084
|
+
|
|
1085
|
+
export {
|
|
1086
|
+
WsPublic as WsPublic,
|
|
1087
|
+
type ConnectPublicClientEvent as ConnectPublicClientEvent,
|
|
1088
|
+
type ConnectPublicServerEvent as ConnectPublicServerEvent,
|
|
1089
|
+
};
|
|
1090
|
+
|
|
1091
|
+
export {
|
|
1092
|
+
WsPrivate as WsPrivate,
|
|
1093
|
+
type ConnectPrivateClientEvent as ConnectPrivateClientEvent,
|
|
1094
|
+
type ConnectPrivateServerEvent as ConnectPrivateServerEvent,
|
|
1095
|
+
};
|
|
1096
|
+
}
|
|
1097
|
+
|
|
1098
|
+
function getRuntimeName(): string {
|
|
1099
|
+
if (typeof (globalThis as any).Bun !== 'undefined') return 'bun';
|
|
1100
|
+
if (typeof (globalThis as any).Deno !== 'undefined') return 'deno';
|
|
1101
|
+
return 'node';
|
|
1102
|
+
}
|
|
1103
|
+
|
|
1104
|
+
function getRuntimeVersion(): string {
|
|
1105
|
+
if (typeof (globalThis as any).Bun !== 'undefined') {
|
|
1106
|
+
return (globalThis as any).Bun.version ?? 'unknown';
|
|
1107
|
+
}
|
|
1108
|
+
if (typeof (globalThis as any).Deno !== 'undefined') {
|
|
1109
|
+
return (globalThis as any).Deno.version?.deno ?? 'unknown';
|
|
1110
|
+
}
|
|
1111
|
+
return typeof process !== 'undefined' ? process.version : 'unknown';
|
|
1112
|
+
}
|