kucoin-universal-sdk
Version:
Official KuCoin Universal SDK.
113 lines • 2.99 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.TransportOptionBuilder = exports.DEFAULT_TRANSPORT_OPTION = void 0;
/**
* Default values for TransportOption
*/
exports.DEFAULT_TRANSPORT_OPTION = {
timeout: 30000, // 30 seconds
keepAlive: true,
maxIdleConns: 100,
maxIdleConnsPerHost: 2,
maxConnsPerHost: 10,
idleConnTimeout: 90000, // 90 seconds
maxRetries: 3,
retryDelay: 2000, // 2 seconds
interceptors: [],
};
/**
* TransportOptionBuilder for creating and customizing TransportOption instances
*/
class TransportOptionBuilder {
constructor() {
this.option = { ...exports.DEFAULT_TRANSPORT_OPTION };
}
/**
* Set the request timeout duration (in milliseconds)
*/
setTimeout(timeout) {
this.option.timeout = timeout;
return this;
}
/**
* Set whether to enable keep-alive (persistent connection)
*/
setKeepAlive(keepAlive) {
this.option.keepAlive = keepAlive;
return this;
}
/**
* Set the maximum number of idle (keep-alive) connections across all hosts
*/
setMaxIdleConns(maxIdleConns) {
this.option.maxIdleConns = maxIdleConns;
return this;
}
/**
* Set the maximum idle connections per host
*/
setMaxIdleConnsPerHost(maxIdleConnsPerHost) {
this.option.maxIdleConnsPerHost = maxIdleConnsPerHost;
return this;
}
/**
* Set the total number of connections per host
*/
setMaxConnsPerHost(maxConnsPerHost) {
this.option.maxConnsPerHost = maxConnsPerHost;
return this;
}
/**
* Set the maximum time an idle connection will remain idle (in milliseconds)
*/
setIdleConnTimeout(idleConnTimeout) {
this.option.idleConnTimeout = idleConnTimeout;
return this;
}
/**
* Set the HTTP(s) proxy options
*/
setProxy(proxy) {
this.option.proxy = proxy;
return this;
}
/**
* Set the maximum number of retry attempts
*/
setMaxRetries(maxRetries) {
this.option.maxRetries = maxRetries;
return this;
}
/**
* Set the delay duration between retries (in milliseconds)
*/
setRetryDelay(retryDelay) {
this.option.retryDelay = retryDelay;
return this;
}
/**
* Set the HTTP interceptors
*/
setInterceptors(interceptors) {
this.option.interceptors = interceptors;
return this;
}
/**
* Add an HTTP interceptor
*/
addInterceptor(interceptor) {
if (!this.option.interceptors) {
this.option.interceptors = [];
}
this.option.interceptors.push(interceptor);
return this;
}
/**
* Build and return the TransportOption instance
*/
build() {
return this.option;
}
}
exports.TransportOptionBuilder = TransportOptionBuilder;
//# sourceMappingURL=transport_option.js.map