Skip to content

Commit

Permalink
feat(binance): fetchIsolatedBorrowRates (ccxt#22206)
Browse files Browse the repository at this point in the history
* chore: new type IsolatedBorrowRate

* refactor: changed BorrowRate type to CrossBorrowRate

* feat(base/exchange): parseIsolatedBorrowRates, parseIsolatedBorrowRate

* feat: new types - CrossBorrowRate, IsolatedBorrowRate

* fetchCrossBorrowRate(s) return type

* feat(binance): fetchIsolatedBorrowRates

* fetch(Cross|Isolated)BorrowRate(s) return types

* base/Exchange import CrossBorrowRate

* Exchange.ts removed BorrowRate type

* types.py linting

* fix crossborrowRates transpiling

* binance.fetchIsolatedBorrowRate update method signature and return type

* binance.parseIsolatedBorrowRate minor fix

* add static tests

---------

Co-authored-by: carlosmiei <[email protected]>

[ci skip]
  • Loading branch information
Travis CI authored and DelAnt committed May 10, 2024
1 parent 95d45e9 commit 69baa0c
Show file tree
Hide file tree
Showing 11 changed files with 900 additions and 20 deletions.
114 changes: 112 additions & 2 deletions cs/ccxt/exchanges/binance.cs
Expand Up @@ -82,8 +82,8 @@ public override object describe()
{ "fetchFundingRates", true },
{ "fetchGreeks", true },
{ "fetchIndexOHLCV", true },
{ "fetchIsolatedBorrowRate", false },
{ "fetchIsolatedBorrowRates", false },
{ "fetchIsolatedBorrowRate", "emulated" },
{ "fetchIsolatedBorrowRates", true },
{ "fetchL3OrderBook", false },
{ "fetchLastPrices", true },
{ "fetchLedger", true },
Expand Down Expand Up @@ -12031,6 +12031,77 @@ public async override Task<object> fetchCrossBorrowRate(object code, object para
return this.parseBorrowRate(rate);
}

public async override Task<object> fetchIsolatedBorrowRate(object symbol, object parameters = null)
{
/**
* @method
* @name binance#fetchIsolatedBorrowRate
* @description fetch the rate of interest to borrow a currency for margin trading
* @see https://binance-docs.github.io/apidocs/spot/en/#query-isolated-margin-fee-data-user_data
* @param {string} symbol unified market symbol
* @param {object} [params] extra parameters specific to the exchange API endpoint
*
* EXCHANGE SPECIFIC PARAMETERS
* @param {object} [params.vipLevel] user's current specific margin data will be returned if viplevel is omitted
* @returns {object} an [isolated borrow rate structure]{@link https://docs.ccxt.com/#/?id=isolated-borrow-rate-structure}
*/
parameters ??= new Dictionary<string, object>();
object request = new Dictionary<string, object>() {
{ "symbol", symbol },
};
object borrowRates = await this.fetchIsolatedBorrowRates(this.extend(request, parameters));
return this.safeDict(borrowRates, symbol);
}

public async override Task<object> fetchIsolatedBorrowRates(object parameters = null)
{
/**
* @method
* @name binance#fetchIsolatedBorrowRates
* @description fetch the borrow interest rates of all currencies
* @see https://binance-docs.github.io/apidocs/spot/en/#query-isolated-margin-fee-data-user_data
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {object} [params.symbol] unified market symbol
*
* EXCHANGE SPECIFIC PARAMETERS
* @param {object} [params.vipLevel] user's current specific margin data will be returned if viplevel is omitted
* @returns {object} a [borrow rate structure]{@link https://docs.ccxt.com/#/?id=borrow-rate-structure}
*/
parameters ??= new Dictionary<string, object>();
await this.loadMarkets();
object request = new Dictionary<string, object>() {};
object symbol = this.safeString(parameters, "symbol");
parameters = this.omit(parameters, "symbol");
if (isTrue(!isEqual(symbol, null)))
{
object market = this.market(symbol);
((IDictionary<string,object>)request)["symbol"] = getValue(market, "id");
}
object response = await this.sapiGetMarginIsolatedMarginData(this.extend(request, parameters));
//
// [
// {
// "vipLevel": 0,
// "symbol": "BTCUSDT",
// "leverage": "10",
// "data": [
// {
// "coin": "BTC",
// "dailyInterest": "0.00026125",
// "borrowLimit": "270"
// },
// {
// "coin": "USDT",
// "dailyInterest": "0.000475",
// "borrowLimit": "2100000"
// }
// ]
// }
// ]
//
return this.parseIsolatedBorrowRates(response);
}

public async virtual Task<object> fetchBorrowRateHistory(object code, object since = null, object limit = null, object parameters = null)
{
/**
Expand Down Expand Up @@ -12114,6 +12185,45 @@ public virtual object parseBorrowRate(object info, object currency = null)
};
}

public override object parseIsolatedBorrowRate(object info, object market = null)
{
//
// {
// "vipLevel": 0,
// "symbol": "BTCUSDT",
// "leverage": "10",
// "data": [
// {
// "coin": "BTC",
// "dailyInterest": "0.00026125",
// "borrowLimit": "270"
// },
// {
// "coin": "USDT",
// "dailyInterest": "0.000475",
// "borrowLimit": "2100000"
// }
// ]
// }
//
object marketId = this.safeString(info, "symbol");
market = this.safeMarket(marketId, market, null, "spot");
object data = this.safeList(info, "data");
object baseInfo = this.safeDict(data, 0);
object quoteInfo = this.safeDict(data, 1);
return new Dictionary<string, object>() {
{ "info", info },
{ "symbol", this.safeString(market, "symbol") },
{ "base", this.safeString(baseInfo, "coin") },
{ "baseRate", this.safeNumber(baseInfo, "dailyInterest") },
{ "quote", this.safeString(quoteInfo, "coin") },
{ "quoteRate", this.safeNumber(quoteInfo, "dailyInterest") },
{ "period", 86400000 },
{ "timestamp", null },
{ "datetime", null },
};
}

public async virtual Task<object> createGiftCode(object code, object amount, object parameters = null)
{
/**
Expand Down
58 changes: 58 additions & 0 deletions cs/ccxt/wrappers/binance.cs
Expand Up @@ -2314,6 +2314,64 @@ public async Task<CrossBorrowRate> FetchCrossBorrowRate(string code, Dictionary<
return new CrossBorrowRate(res);
}
/// <summary>
/// fetch the rate of interest to borrow a currency for margin trading
/// </summary>
/// <remarks>
/// See <see href="https://binance-docs.github.io/apidocs/spot/en/#query-isolated-margin-fee-data-user_data"/> <br/>
/// <list type="table">
/// <item>
/// <term>params</term>
/// <description>
/// object : extra parameters specific to the exchange API endpoint
/// </description>
/// </item>
/// <item>
/// <term>params.vipLevel</term>
/// <description>
/// object : user's current specific margin data will be returned if viplevel is omitted
/// </description>
/// </item>
/// </list>
/// </remarks>
/// <returns> <term>object</term> an [isolated borrow rate structure]{@link https://docs.ccxt.com/#/?id=isolated-borrow-rate-structure}.</returns>
public async Task<IsolatedBorrowRate> FetchIsolatedBorrowRate(string symbol, Dictionary<string, object> parameters = null)
{
var res = await this.fetchIsolatedBorrowRate(symbol, parameters);
return new IsolatedBorrowRate(res);
}
/// <summary>
/// fetch the borrow interest rates of all currencies
/// </summary>
/// <remarks>
/// See <see href="https://binance-docs.github.io/apidocs/spot/en/#query-isolated-margin-fee-data-user_data"/> <br/>
/// <list type="table">
/// <item>
/// <term>params</term>
/// <description>
/// object : extra parameters specific to the exchange API endpoint
/// </description>
/// </item>
/// <item>
/// <term>params.symbol</term>
/// <description>
/// object : unified market symbol
/// </description>
/// </item>
/// <item>
/// <term>params.vipLevel</term>
/// <description>
/// object : user's current specific margin data will be returned if viplevel is omitted
/// </description>
/// </item>
/// </list>
/// </remarks>
/// <returns> <term>object</term> a [borrow rate structure]{@link https://docs.ccxt.com/#/?id=borrow-rate-structure}.</returns>
public async Task<IsolatedBorrowRates> FetchIsolatedBorrowRates(Dictionary<string, object> parameters = null)
{
var res = await this.fetchIsolatedBorrowRates(parameters);
return new IsolatedBorrowRates(res);
}
/// <summary>
/// retrieves a history of a currencies borrow interest rate at specific time slots
/// </summary>
/// <remarks>
Expand Down
105 changes: 103 additions & 2 deletions dist/ccxt.browser.js
Expand Up @@ -19171,8 +19171,8 @@ class binance extends _abstract_binance_js__WEBPACK_IMPORTED_MODULE_0__/* ["defa
'fetchFundingRates': true,
'fetchGreeks': true,
'fetchIndexOHLCV': true,
'fetchIsolatedBorrowRate': false,
'fetchIsolatedBorrowRates': false,
'fetchIsolatedBorrowRate': 'emulated',
'fetchIsolatedBorrowRates': true,
'fetchL3OrderBook': false,
'fetchLastPrices': true,
'fetchLedger': true,
Expand Down Expand Up @@ -30415,6 +30415,70 @@ class binance extends _abstract_binance_js__WEBPACK_IMPORTED_MODULE_0__/* ["defa
const rate = this.safeDict(response, 0);
return this.parseBorrowRate(rate);
}
async fetchIsolatedBorrowRate(symbol, params = {}) {
/**
* @method
* @name binance#fetchIsolatedBorrowRate
* @description fetch the rate of interest to borrow a currency for margin trading
* @see https://binance-docs.github.io/apidocs/spot/en/#query-isolated-margin-fee-data-user_data
* @param {string} symbol unified market symbol
* @param {object} [params] extra parameters specific to the exchange API endpoint
*
* EXCHANGE SPECIFIC PARAMETERS
* @param {object} [params.vipLevel] user's current specific margin data will be returned if viplevel is omitted
* @returns {object} an [isolated borrow rate structure]{@link https://docs.ccxt.com/#/?id=isolated-borrow-rate-structure}
*/
const request = {
'symbol': symbol,
};
const borrowRates = await this.fetchIsolatedBorrowRates(this.extend(request, params));
return this.safeDict(borrowRates, symbol);
}
async fetchIsolatedBorrowRates(params = {}) {
/**
* @method
* @name binance#fetchIsolatedBorrowRates
* @description fetch the borrow interest rates of all currencies
* @see https://binance-docs.github.io/apidocs/spot/en/#query-isolated-margin-fee-data-user_data
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {object} [params.symbol] unified market symbol
*
* EXCHANGE SPECIFIC PARAMETERS
* @param {object} [params.vipLevel] user's current specific margin data will be returned if viplevel is omitted
* @returns {object} a [borrow rate structure]{@link https://docs.ccxt.com/#/?id=borrow-rate-structure}
*/
await this.loadMarkets();
const request = {};
const symbol = this.safeString(params, 'symbol');
params = this.omit(params, 'symbol');
if (symbol !== undefined) {
const market = this.market(symbol);
request['symbol'] = market['id'];
}
const response = await this.sapiGetMarginIsolatedMarginData(this.extend(request, params));
//
// [
// {
// "vipLevel": 0,
// "symbol": "BTCUSDT",
// "leverage": "10",
// "data": [
// {
// "coin": "BTC",
// "dailyInterest": "0.00026125",
// "borrowLimit": "270"
// },
// {
// "coin": "USDT",
// "dailyInterest": "0.000475",
// "borrowLimit": "2100000"
// }
// ]
// }
// ]
//
return this.parseIsolatedBorrowRates(response);
}
async fetchBorrowRateHistory(code, since = undefined, limit = undefined, params = {}) {
/**
* @method
Expand Down Expand Up @@ -30489,6 +30553,43 @@ class binance extends _abstract_binance_js__WEBPACK_IMPORTED_MODULE_0__/* ["defa
'info': info,
};
}
parseIsolatedBorrowRate(info, market = undefined) {
//
// {
// "vipLevel": 0,
// "symbol": "BTCUSDT",
// "leverage": "10",
// "data": [
// {
// "coin": "BTC",
// "dailyInterest": "0.00026125",
// "borrowLimit": "270"
// },
// {
// "coin": "USDT",
// "dailyInterest": "0.000475",
// "borrowLimit": "2100000"
// }
// ]
// }
//
const marketId = this.safeString(info, 'symbol');
market = this.safeMarket(marketId, market, undefined, 'spot');
const data = this.safeList(info, 'data');
const baseInfo = this.safeDict(data, 0);
const quoteInfo = this.safeDict(data, 1);
return {
'info': info,
'symbol': this.safeString(market, 'symbol'),
'base': this.safeString(baseInfo, 'coin'),
'baseRate': this.safeNumber(baseInfo, 'dailyInterest'),
'quote': this.safeString(quoteInfo, 'coin'),
'quoteRate': this.safeNumber(quoteInfo, 'dailyInterest'),
'period': 86400000,
'timestamp': undefined,
'datetime': undefined,
};
}
async createGiftCode(code, amount, params = {}) {
/**
* @method
Expand Down
2 changes: 1 addition & 1 deletion dist/ccxt.browser.min.js

Large diffs are not rendered by default.

0 comments on commit 69baa0c

Please sign in to comment.