@binance/fiat
Version:
Official Binance Fiat Connector - A lightweight library that provides a convenient interface to Binance's Fiat REST API.
496 lines (489 loc) • 22.1 kB
JavaScript
//#region rolldown:runtime
var __defProp = Object.defineProperty;
var __export = (all) => {
let target = {};
for (var name$1 in all) __defProp(target, name$1, {
get: all[name$1],
enumerable: true
});
return target;
};
//#endregion
let __binance_common = require("@binance/common");
//#region package.json
var name = "@binance/fiat";
var version = "6.0.15";
//#endregion
//#region src/rest-api/modules/fiat-api.ts
/**
* Binance Fiat REST API
*
* OpenAPI Specification for the Binance Fiat REST API
*
* The version of the OpenAPI document: 1.0.0
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
/**
* FiatApi - axios parameter creator
*/
const FiatApiAxiosParamCreator = function(configuration) {
return {
deposit: async (currency, apiPaymentMethod, amount, recvWindow, ext) => {
(0, __binance_common.assertParamExists)("deposit", "currency", currency);
(0, __binance_common.assertParamExists)("deposit", "apiPaymentMethod", apiPaymentMethod);
(0, __binance_common.assertParamExists)("deposit", "amount", amount);
const localVarQueryParameter = {};
const localVarBodyParameter = {};
if (recvWindow !== void 0 && recvWindow !== null) localVarQueryParameter["recvWindow"] = recvWindow;
if (currency !== void 0 && currency !== null) localVarBodyParameter["currency"] = currency;
if (apiPaymentMethod !== void 0 && apiPaymentMethod !== null) localVarBodyParameter["apiPaymentMethod"] = apiPaymentMethod;
if (amount !== void 0 && amount !== null) localVarBodyParameter["amount"] = amount;
if (ext !== void 0 && ext !== null) localVarBodyParameter["ext"] = ext;
let _timeUnit;
if ("timeUnit" in configuration) _timeUnit = configuration.timeUnit;
return {
endpoint: "/sapi/v1/fiat/deposit",
method: "POST",
queryParams: localVarQueryParameter,
bodyParams: localVarBodyParameter,
timeUnit: _timeUnit
};
},
fiatWithdraw: async (currency, apiPaymentMethod, amount, accountInfo, recvWindow, ext) => {
(0, __binance_common.assertParamExists)("fiatWithdraw", "currency", currency);
(0, __binance_common.assertParamExists)("fiatWithdraw", "apiPaymentMethod", apiPaymentMethod);
(0, __binance_common.assertParamExists)("fiatWithdraw", "amount", amount);
(0, __binance_common.assertParamExists)("fiatWithdraw", "accountInfo", accountInfo);
const localVarQueryParameter = {};
const localVarBodyParameter = {};
if (recvWindow !== void 0 && recvWindow !== null) localVarQueryParameter["recvWindow"] = recvWindow;
if (currency !== void 0 && currency !== null) localVarBodyParameter["currency"] = currency;
if (apiPaymentMethod !== void 0 && apiPaymentMethod !== null) localVarBodyParameter["apiPaymentMethod"] = apiPaymentMethod;
if (amount !== void 0 && amount !== null) localVarBodyParameter["amount"] = amount;
if (accountInfo !== void 0 && accountInfo !== null) localVarBodyParameter["accountInfo"] = accountInfo;
if (ext !== void 0 && ext !== null) localVarBodyParameter["ext"] = ext;
let _timeUnit;
if ("timeUnit" in configuration) _timeUnit = configuration.timeUnit;
return {
endpoint: "/sapi/v2/fiat/withdraw",
method: "POST",
queryParams: localVarQueryParameter,
bodyParams: localVarBodyParameter,
timeUnit: _timeUnit
};
},
getFiatDepositWithdrawHistory: async (transactionType, beginTime, endTime, page, rows, recvWindow) => {
(0, __binance_common.assertParamExists)("getFiatDepositWithdrawHistory", "transactionType", transactionType);
const localVarQueryParameter = {};
const localVarBodyParameter = {};
if (transactionType !== void 0 && transactionType !== null) localVarQueryParameter["transactionType"] = transactionType;
if (beginTime !== void 0 && beginTime !== null) localVarQueryParameter["beginTime"] = beginTime;
if (endTime !== void 0 && endTime !== null) localVarQueryParameter["endTime"] = endTime;
if (page !== void 0 && page !== null) localVarQueryParameter["page"] = page;
if (rows !== void 0 && rows !== null) localVarQueryParameter["rows"] = rows;
if (recvWindow !== void 0 && recvWindow !== null) localVarQueryParameter["recvWindow"] = recvWindow;
let _timeUnit;
if ("timeUnit" in configuration) _timeUnit = configuration.timeUnit;
return {
endpoint: "/sapi/v1/fiat/orders",
method: "GET",
queryParams: localVarQueryParameter,
bodyParams: localVarBodyParameter,
timeUnit: _timeUnit
};
},
getFiatPaymentsHistory: async (transactionType, beginTime, endTime, page, rows, recvWindow) => {
(0, __binance_common.assertParamExists)("getFiatPaymentsHistory", "transactionType", transactionType);
const localVarQueryParameter = {};
const localVarBodyParameter = {};
if (transactionType !== void 0 && transactionType !== null) localVarQueryParameter["transactionType"] = transactionType;
if (beginTime !== void 0 && beginTime !== null) localVarQueryParameter["beginTime"] = beginTime;
if (endTime !== void 0 && endTime !== null) localVarQueryParameter["endTime"] = endTime;
if (page !== void 0 && page !== null) localVarQueryParameter["page"] = page;
if (rows !== void 0 && rows !== null) localVarQueryParameter["rows"] = rows;
if (recvWindow !== void 0 && recvWindow !== null) localVarQueryParameter["recvWindow"] = recvWindow;
let _timeUnit;
if ("timeUnit" in configuration) _timeUnit = configuration.timeUnit;
return {
endpoint: "/sapi/v1/fiat/payments",
method: "GET",
queryParams: localVarQueryParameter,
bodyParams: localVarBodyParameter,
timeUnit: _timeUnit
};
},
getOrderDetail: async (orderNo, recvWindow) => {
(0, __binance_common.assertParamExists)("getOrderDetail", "orderNo", orderNo);
const localVarQueryParameter = {};
const localVarBodyParameter = {};
if (orderNo !== void 0 && orderNo !== null) localVarQueryParameter["orderNo"] = orderNo;
if (recvWindow !== void 0 && recvWindow !== null) localVarQueryParameter["recvWindow"] = recvWindow;
let _timeUnit;
if ("timeUnit" in configuration) _timeUnit = configuration.timeUnit;
return {
endpoint: "/sapi/v1/fiat/get-order-detail",
method: "GET",
queryParams: localVarQueryParameter,
bodyParams: localVarBodyParameter,
timeUnit: _timeUnit
};
}
};
};
/**
* FiatApi - object-oriented interface
* @class FiatApi
*/
var FiatApi = class {
constructor(configuration) {
this.configuration = configuration;
this.localVarAxiosParamCreator = FiatApiAxiosParamCreator(configuration);
}
/**
* Submit deposit request, in this version, we only support BRL deposit via pix.
*
*
*
* For BRL deposit via pix, you need to place an order before making a transfer from your bank.
*
* Before calling this api, please make sure you have already completed your KYC or KYB, and already activated your fiat service on our website.
*
* Weight: 45000
*
* @summary Deposit(TRADE)
* @param {DepositRequest} requestParameters Request parameters.
* @returns {Promise<RestApiResponse<DepositResponse>>}
* @throws {RequiredError | ConnectorClientError | UnauthorizedError | ForbiddenError | TooManyRequestsError | RateLimitBanError | ServerError | NotFoundError | NetworkError | BadRequestError}
* @memberof FiatApi
* @see {@link https://developers.binance.com/docs/fiat/rest-api/Fiat-Deposit Binance API Documentation}
*/
async deposit(requestParameters) {
const localVarAxiosArgs = await this.localVarAxiosParamCreator.deposit(requestParameters?.currency, requestParameters?.apiPaymentMethod, requestParameters?.amount, requestParameters?.recvWindow, requestParameters?.ext);
return (0, __binance_common.sendRequest)(this.configuration, localVarAxiosArgs.endpoint, localVarAxiosArgs.method, localVarAxiosArgs.queryParams, localVarAxiosArgs.bodyParams, localVarAxiosArgs?.timeUnit, { isSigned: true });
}
/**
* Submit withdraw request, in this version, we support BRL,ARS,MXN withdrawal via bank_transfer.
*
* You need to call this api first, and call query order detail api in a loop to get the status of the order until this order is successful.
*
* Before calling this API, please ensure you have completed your KYC or KYB, activated your fiat service, and verified your destination bank account on our website.
*
* you need to bind your bank account on web/app before using the corresponding account number
*
* Weight: 45000
*
* @summary Fiat Withdraw(WITHDRAW)
* @param {FiatWithdrawRequest} requestParameters Request parameters.
* @returns {Promise<RestApiResponse<FiatWithdrawResponse>>}
* @throws {RequiredError | ConnectorClientError | UnauthorizedError | ForbiddenError | TooManyRequestsError | RateLimitBanError | ServerError | NotFoundError | NetworkError | BadRequestError}
* @memberof FiatApi
* @see {@link https://developers.binance.com/docs/fiat/rest-api/Fiat-Withdraw Binance API Documentation}
*/
async fiatWithdraw(requestParameters) {
const localVarAxiosArgs = await this.localVarAxiosParamCreator.fiatWithdraw(requestParameters?.currency, requestParameters?.apiPaymentMethod, requestParameters?.amount, requestParameters?.accountInfo, requestParameters?.recvWindow, requestParameters?.ext);
return (0, __binance_common.sendRequest)(this.configuration, localVarAxiosArgs.endpoint, localVarAxiosArgs.method, localVarAxiosArgs.queryParams, localVarAxiosArgs.bodyParams, localVarAxiosArgs?.timeUnit, { isSigned: true });
}
/**
* Get Fiat Deposit/Withdraw History
*
* If beginTime and endTime are not sent, the recent 30-day data will be returned.
*
* Weight: 45000
*
* @summary Get Fiat Deposit/Withdraw History (USER_DATA)
* @param {GetFiatDepositWithdrawHistoryRequest} requestParameters Request parameters.
* @returns {Promise<RestApiResponse<GetFiatDepositWithdrawHistoryResponse>>}
* @throws {RequiredError | ConnectorClientError | UnauthorizedError | ForbiddenError | TooManyRequestsError | RateLimitBanError | ServerError | NotFoundError | NetworkError | BadRequestError}
* @memberof FiatApi
* @see {@link https://developers.binance.com/docs/fiat/rest-api/Get-Fiat-Deposit-Withdraw-History Binance API Documentation}
*/
async getFiatDepositWithdrawHistory(requestParameters) {
const localVarAxiosArgs = await this.localVarAxiosParamCreator.getFiatDepositWithdrawHistory(requestParameters?.transactionType, requestParameters?.beginTime, requestParameters?.endTime, requestParameters?.page, requestParameters?.rows, requestParameters?.recvWindow);
return (0, __binance_common.sendRequest)(this.configuration, localVarAxiosArgs.endpoint, localVarAxiosArgs.method, localVarAxiosArgs.queryParams, localVarAxiosArgs.bodyParams, localVarAxiosArgs?.timeUnit, { isSigned: true });
}
/**
* Get Fiat Deposit/Withdraw History
*
* If beginTime and endTime are not sent, the recent 30-day data will be returned.
* paymentMethod: Only when requesting payments history for buy (transactionType=0), response contains paymentMethod representing the way of purchase. Now we have:
* Cash Balance
* Credit Card
* Online Banking
* Bank Transfer
*
* Weight: 1
*
* @summary Get Fiat Payments History (USER_DATA)
* @param {GetFiatPaymentsHistoryRequest} requestParameters Request parameters.
* @returns {Promise<RestApiResponse<GetFiatPaymentsHistoryResponse>>}
* @throws {RequiredError | ConnectorClientError | UnauthorizedError | ForbiddenError | TooManyRequestsError | RateLimitBanError | ServerError | NotFoundError | NetworkError | BadRequestError}
* @memberof FiatApi
* @see {@link https://developers.binance.com/docs/fiat/rest-api/Get-Fiat-Payments-History Binance API Documentation}
*/
async getFiatPaymentsHistory(requestParameters) {
const localVarAxiosArgs = await this.localVarAxiosParamCreator.getFiatPaymentsHistory(requestParameters?.transactionType, requestParameters?.beginTime, requestParameters?.endTime, requestParameters?.page, requestParameters?.rows, requestParameters?.recvWindow);
return (0, __binance_common.sendRequest)(this.configuration, localVarAxiosArgs.endpoint, localVarAxiosArgs.method, localVarAxiosArgs.queryParams, localVarAxiosArgs.bodyParams, localVarAxiosArgs?.timeUnit, { isSigned: true });
}
/**
* Get Order Detail
*
* Before calling this api, please make sure you have already completed your KYC or KYB, and already activated your fiat service on our website.
*
* Weight: 1
*
* @summary Get Order Detail(USER_DATA)
* @param {GetOrderDetailRequest} requestParameters Request parameters.
* @returns {Promise<RestApiResponse<GetOrderDetailResponse>>}
* @throws {RequiredError | ConnectorClientError | UnauthorizedError | ForbiddenError | TooManyRequestsError | RateLimitBanError | ServerError | NotFoundError | NetworkError | BadRequestError}
* @memberof FiatApi
* @see {@link https://developers.binance.com/docs/fiat/rest-api/Get-Order-Detail Binance API Documentation}
*/
async getOrderDetail(requestParameters) {
const localVarAxiosArgs = await this.localVarAxiosParamCreator.getOrderDetail(requestParameters?.orderNo, requestParameters?.recvWindow);
return (0, __binance_common.sendRequest)(this.configuration, localVarAxiosArgs.endpoint, localVarAxiosArgs.method, localVarAxiosArgs.queryParams, localVarAxiosArgs.bodyParams, localVarAxiosArgs?.timeUnit, { isSigned: true });
}
};
//#endregion
//#region src/rest-api/rest-api.ts
/**
* Binance Fiat REST API
*
* OpenAPI Specification for the Binance Fiat REST API
*
* The version of the OpenAPI document: 1.0.0
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
var RestAPI = class {
constructor(configuration) {
this.configuration = configuration;
this.fiatApi = new FiatApi(configuration);
}
/**
* Generic function to send a request.
* @param endpoint - The API endpoint to call.
* @param method - HTTP method to use (GET, POST, DELETE, etc.).
* @param queryParams - Query parameters for the request.
* @param bodyParams - Body parameters for the request.
*
* @returns A promise resolving to the response data object.
*/
sendRequest(endpoint, method, queryParams = {}, bodyParams = {}) {
return (0, __binance_common.sendRequest)(this.configuration, endpoint, method, queryParams, bodyParams, void 0);
}
/**
* Generic function to send a signed request.
* @param endpoint - The API endpoint to call.
* @param method - HTTP method to use (GET, POST, DELETE, etc.).
* @param queryParams - Query parameters for the request.
* @param bodyParams - Body parameters for the request.
*
* @returns A promise resolving to the response data object.
*/
sendSignedRequest(endpoint, method, queryParams = {}, bodyParams = {}) {
return (0, __binance_common.sendRequest)(this.configuration, endpoint, method, queryParams, bodyParams, void 0, { isSigned: true });
}
/**
* Submit deposit request, in this version, we only support BRL deposit via pix.
*
*
*
* For BRL deposit via pix, you need to place an order before making a transfer from your bank.
*
* Before calling this api, please make sure you have already completed your KYC or KYB, and already activated your fiat service on our website.
*
* Weight: 45000
*
* @summary Deposit(TRADE)
* @param {DepositRequest} requestParameters Request parameters.
*
* @returns {Promise<RestApiResponse<DepositResponse>>}
* @throws {RequiredError | ConnectorClientError | UnauthorizedError | ForbiddenError | TooManyRequestsError | RateLimitBanError | ServerError | NotFoundError | NetworkError | BadRequestError}
* @see {@link https://developers.binance.com/docs/fiat/rest-api/Fiat-Deposit Binance API Documentation}
*/
deposit(requestParameters) {
return this.fiatApi.deposit(requestParameters);
}
/**
* Submit withdraw request, in this version, we support BRL,ARS,MXN withdrawal via bank_transfer.
*
* You need to call this api first, and call query order detail api in a loop to get the status of the order until this order is successful.
*
* Before calling this API, please ensure you have completed your KYC or KYB, activated your fiat service, and verified your destination bank account on our website.
*
* you need to bind your bank account on web/app before using the corresponding account number
*
* Weight: 45000
*
* @summary Fiat Withdraw(WITHDRAW)
* @param {FiatWithdrawRequest} requestParameters Request parameters.
*
* @returns {Promise<RestApiResponse<FiatWithdrawResponse>>}
* @throws {RequiredError | ConnectorClientError | UnauthorizedError | ForbiddenError | TooManyRequestsError | RateLimitBanError | ServerError | NotFoundError | NetworkError | BadRequestError}
* @see {@link https://developers.binance.com/docs/fiat/rest-api/Fiat-Withdraw Binance API Documentation}
*/
fiatWithdraw(requestParameters) {
return this.fiatApi.fiatWithdraw(requestParameters);
}
/**
* Get Fiat Deposit/Withdraw History
*
* If beginTime and endTime are not sent, the recent 30-day data will be returned.
*
* Weight: 45000
*
* @summary Get Fiat Deposit/Withdraw History (USER_DATA)
* @param {GetFiatDepositWithdrawHistoryRequest} requestParameters Request parameters.
*
* @returns {Promise<RestApiResponse<GetFiatDepositWithdrawHistoryResponse>>}
* @throws {RequiredError | ConnectorClientError | UnauthorizedError | ForbiddenError | TooManyRequestsError | RateLimitBanError | ServerError | NotFoundError | NetworkError | BadRequestError}
* @see {@link https://developers.binance.com/docs/fiat/rest-api/Get-Fiat-Deposit-Withdraw-History Binance API Documentation}
*/
getFiatDepositWithdrawHistory(requestParameters) {
return this.fiatApi.getFiatDepositWithdrawHistory(requestParameters);
}
/**
* Get Fiat Deposit/Withdraw History
*
* If beginTime and endTime are not sent, the recent 30-day data will be returned.
* paymentMethod: Only when requesting payments history for buy (transactionType=0), response contains paymentMethod representing the way of purchase. Now we have:
* Cash Balance
* Credit Card
* Online Banking
* Bank Transfer
*
* Weight: 1
*
* @summary Get Fiat Payments History (USER_DATA)
* @param {GetFiatPaymentsHistoryRequest} requestParameters Request parameters.
*
* @returns {Promise<RestApiResponse<GetFiatPaymentsHistoryResponse>>}
* @throws {RequiredError | ConnectorClientError | UnauthorizedError | ForbiddenError | TooManyRequestsError | RateLimitBanError | ServerError | NotFoundError | NetworkError | BadRequestError}
* @see {@link https://developers.binance.com/docs/fiat/rest-api/Get-Fiat-Payments-History Binance API Documentation}
*/
getFiatPaymentsHistory(requestParameters) {
return this.fiatApi.getFiatPaymentsHistory(requestParameters);
}
/**
* Get Order Detail
*
* Before calling this api, please make sure you have already completed your KYC or KYB, and already activated your fiat service on our website.
*
* Weight: 1
*
* @summary Get Order Detail(USER_DATA)
* @param {GetOrderDetailRequest} requestParameters Request parameters.
*
* @returns {Promise<RestApiResponse<GetOrderDetailResponse>>}
* @throws {RequiredError | ConnectorClientError | UnauthorizedError | ForbiddenError | TooManyRequestsError | RateLimitBanError | ServerError | NotFoundError | NetworkError | BadRequestError}
* @see {@link https://developers.binance.com/docs/fiat/rest-api/Get-Order-Detail Binance API Documentation}
*/
getOrderDetail(requestParameters) {
return this.fiatApi.getOrderDetail(requestParameters);
}
};
//#endregion
//#region src/rest-api/index.ts
var rest_api_exports = /* @__PURE__ */ __export({
FiatApi: () => FiatApi,
RestAPI: () => RestAPI
});
//#endregion
//#region src/fiat.ts
var Fiat = class {
constructor(config) {
const userAgent = (0, __binance_common.buildUserAgent)(name, version);
if (config?.configurationRestAPI) {
const configRestAPI = new __binance_common.ConfigurationRestAPI(config.configurationRestAPI);
configRestAPI.basePath = configRestAPI.basePath || __binance_common.FIAT_REST_API_PROD_URL;
configRestAPI.baseOptions = configRestAPI.baseOptions || {};
configRestAPI.baseOptions.headers = {
...configRestAPI.baseOptions.headers || {},
"User-Agent": userAgent
};
this.restAPI = new RestAPI(configRestAPI);
}
}
};
//#endregion
Object.defineProperty(exports, 'BadRequestError', {
enumerable: true,
get: function () {
return __binance_common.BadRequestError;
}
});
Object.defineProperty(exports, 'ConnectorClientError', {
enumerable: true,
get: function () {
return __binance_common.ConnectorClientError;
}
});
Object.defineProperty(exports, 'FIAT_REST_API_PROD_URL', {
enumerable: true,
get: function () {
return __binance_common.FIAT_REST_API_PROD_URL;
}
});
exports.Fiat = Fiat;
Object.defineProperty(exports, 'FiatRestAPI', {
enumerable: true,
get: function () {
return rest_api_exports;
}
});
Object.defineProperty(exports, 'ForbiddenError', {
enumerable: true,
get: function () {
return __binance_common.ForbiddenError;
}
});
Object.defineProperty(exports, 'NetworkError', {
enumerable: true,
get: function () {
return __binance_common.NetworkError;
}
});
Object.defineProperty(exports, 'NotFoundError', {
enumerable: true,
get: function () {
return __binance_common.NotFoundError;
}
});
Object.defineProperty(exports, 'RateLimitBanError', {
enumerable: true,
get: function () {
return __binance_common.RateLimitBanError;
}
});
Object.defineProperty(exports, 'RequiredError', {
enumerable: true,
get: function () {
return __binance_common.RequiredError;
}
});
Object.defineProperty(exports, 'ServerError', {
enumerable: true,
get: function () {
return __binance_common.ServerError;
}
});
Object.defineProperty(exports, 'TooManyRequestsError', {
enumerable: true,
get: function () {
return __binance_common.TooManyRequestsError;
}
});
Object.defineProperty(exports, 'UnauthorizedError', {
enumerable: true,
get: function () {
return __binance_common.UnauthorizedError;
}
});
//# sourceMappingURL=index.js.map