@exchanges/binance
Version:
Exchange provider for Binance API
34 lines • 1.56 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.responseUpdateXMBXUsedWeight = void 0;
const safe_parsing_1 = require("@berish/safe-parsing");
const clients_1 = require("../clients");
const info_1 = require("../info");
const utils_1 = require("../utils");
function responseUpdateXMBXUsedWeight(binanceClient) {
return (instance) => {
const id = instance.interceptors.response.use((response) => {
if (response && response.headers)
updateXMBXUsedWeight(binanceClient, Object.entries(response.headers));
return response;
}, (error) => {
if (error && error instanceof info_1.BinanceError)
updateXMBXUsedWeight(binanceClient, error.headers);
throw error;
});
return () => {
instance.interceptors.response.eject(id);
};
};
}
exports.responseUpdateXMBXUsedWeight = responseUpdateXMBXUsedWeight;
function updateXMBXUsedWeight(client, headers) {
if (!client)
throw new TypeError('updateXMBXUsedWeight client is empty');
if (!(client instanceof clients_1.BinanceClient))
throw new TypeError('updateXMBXUsedWeight client is not BinanceClient');
headers = (0, utils_1.resolveHeaders)(headers, [info_1.CONST.X_MBX_USED_WEIGHT_HEADER], 'strict');
const weight = (0, safe_parsing_1.parse)(headers[0] && headers[0][1], safe_parsing_1.numberParser);
client[info_1.CONST.SYMBOL_X_MBX_USED_WEIGHT] = weight || 0;
}
//# sourceMappingURL=responseUpdateXMBXUsedWeight.js.map