@binance/fiat
Version:
Official Binance Fiat Connector - A lightweight library that provides a convenient interface to Binance's Fiat REST API.
413 lines (407 loc) • 20.2 kB
JavaScript
import { t as __export } from "./chunk.mjs";
import { BadRequestError, ConfigurationRestAPI, ConnectorClientError, FIAT_REST_API_PROD_URL, FIAT_REST_API_PROD_URL as FIAT_REST_API_PROD_URL$1, ForbiddenError, NetworkError, NotFoundError, RateLimitBanError, RequiredError, ServerError, TooManyRequestsError, UnauthorizedError, assertParamExists, buildUserAgent, sendRequest } from "@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) => {
assertParamExists("deposit", "currency", currency);
assertParamExists("deposit", "apiPaymentMethod", apiPaymentMethod);
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) => {
assertParamExists("fiatWithdraw", "currency", currency);
assertParamExists("fiatWithdraw", "apiPaymentMethod", apiPaymentMethod);
assertParamExists("fiatWithdraw", "amount", amount);
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) => {
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) => {
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) => {
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 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 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 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 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 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 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 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 = buildUserAgent(name, version);
if (config?.configurationRestAPI) {
const configRestAPI = new ConfigurationRestAPI(config.configurationRestAPI);
configRestAPI.basePath = configRestAPI.basePath || FIAT_REST_API_PROD_URL$1;
configRestAPI.baseOptions = configRestAPI.baseOptions || {};
configRestAPI.baseOptions.headers = {
...configRestAPI.baseOptions.headers || {},
"User-Agent": userAgent
};
this.restAPI = new RestAPI(configRestAPI);
}
}
};
//#endregion
export { BadRequestError, ConnectorClientError, FIAT_REST_API_PROD_URL, Fiat, rest_api_exports as FiatRestAPI, ForbiddenError, NetworkError, NotFoundError, RateLimitBanError, RequiredError, ServerError, TooManyRequestsError, UnauthorizedError };
//# sourceMappingURL=index.mjs.map