Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(binance): fetchIsolatedBorrowRates #22206

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
4b1a02e
chore: new type IsolatedBorrowRate
samgermain Apr 19, 2024
a780e54
refactor: changed BorrowRate type to CrossBorrowRate
samgermain Apr 19, 2024
83dafa6
feat(base/exchange): parseIsolatedBorrowRates, parseIsolatedBorrowRate
samgermain Apr 19, 2024
c790c2d
feat: new types - CrossBorrowRate, IsolatedBorrowRate
samgermain Apr 19, 2024
5d12ed4
fetchCrossBorrowRate(s) return type
samgermain Apr 19, 2024
1314f60
feat(binance): fetchIsolatedBorrowRates
samgermain Apr 19, 2024
a170f57
fetch(Cross|Isolated)BorrowRate(s) return types
samgermain Apr 19, 2024
bd353a8
Merge branch 'master' into isolated-borrow-rate
samgermain Apr 19, 2024
d8b2d03
base/Exchange import CrossBorrowRate
samgermain Apr 19, 2024
89a803d
Exchange.ts removed BorrowRate type
samgermain Apr 20, 2024
adb64e0
types.py linting
samgermain Apr 20, 2024
df88471
fix crossborrowRates transpiling
carlosmiei Apr 20, 2024
6cd4aa8
Merge branch 'master' into isolated-borrow-rate
samgermain Apr 23, 2024
390782e
Merge branch 'isolated-borrow-rate' of https://github.com/samgermain/…
samgermain Apr 23, 2024
2767327
Merge branch 'master' into isolated-borrow-rate
samgermain Apr 23, 2024
90739bf
Merge branch 'isolated-borrow-rate' into binance-fetch-isolated-borro…
samgermain Apr 24, 2024
4ca4459
binance.fetchIsolatedBorrowRate update method signature and return type
samgermain Apr 24, 2024
54259f2
Merge branch 'master' into isolated-borrow-rate
samgermain Apr 25, 2024
4925561
Merge branch 'isolated-borrow-rate' into binance-fetch-isolated-borro…
samgermain Apr 25, 2024
850a60a
Merge branch 'master' into binance-fetch-isolated-borrow-rates
samgermain Apr 29, 2024
33d1d24
binance.parseIsolatedBorrowRate minor fix
samgermain May 2, 2024
ddf1c7e
add static tests
carlosmiei May 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
110 changes: 107 additions & 3 deletions ts/src/binance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import Exchange from './abstract/binance.js';
import { ExchangeError, ArgumentsRequired, OperationFailed, OperationRejected, InsufficientFunds, OrderNotFound, InvalidOrder, DDoSProtection, InvalidNonce, AuthenticationError, RateLimitExceeded, PermissionDenied, NotSupported, BadRequest, BadSymbol, AccountSuspended, OrderImmediatelyFillable, OnMaintenance, BadResponse, RequestTimeout, OrderNotFillable, MarginModeAlreadySet } from './base/errors.js';
import { Precise } from './base/Precise.js';
import type { TransferEntry, Int, OrderSide, Balances, OrderType, Trade, OHLCV, Order, FundingRateHistory, OpenInterest, Liquidation, OrderRequest, Str, Transaction, Ticker, OrderBook, Tickers, Market, Greeks, Strings, Currency, MarketInterface, MarginMode, MarginModes, Leverage, Leverages, Num, Option, MarginModification, TradingFeeInterface, Currencies, TradingFees, Conversion, CrossBorrowRate } from './base/types.js';
import type { TransferEntry, Int, OrderSide, Balances, OrderType, Trade, OHLCV, Order, FundingRateHistory, OpenInterest, Liquidation, OrderRequest, Str, Transaction, Ticker, OrderBook, Tickers, Market, Greeks, Strings, Currency, MarketInterface, MarginMode, MarginModes, Leverage, Leverages, Num, Option, MarginModification, TradingFeeInterface, Currencies, TradingFees, Conversion, CrossBorrowRate, IsolatedBorrowRates, IsolatedBorrowRate } from './base/types.js';
import { TRUNCATE, DECIMAL_PLACES } from './base/functions/number.js';
import { sha256 } from './static_dependencies/noble-hashes/sha256.js';
import { rsa } from './base/functions/rsa.js';
Expand Down Expand Up @@ -95,8 +95,8 @@ export default class binance extends Exchange {
'fetchFundingRates': true,
'fetchGreeks': true,
'fetchIndexOHLCV': true,
'fetchIsolatedBorrowRate': false,
'fetchIsolatedBorrowRates': false,
'fetchIsolatedBorrowRate': 'emulated',
'fetchIsolatedBorrowRates': true,
'fetchL3OrderBook': false,
'fetchLastPrices': true,
'fetchLedger': true,
Expand Down Expand Up @@ -11164,6 +11164,72 @@ export default class binance extends Exchange {
return this.parseBorrowRate (rate);
}

async fetchIsolatedBorrowRate (symbol: string, params = {}): Promise<IsolatedBorrowRate> {
/**
* @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) as IsolatedBorrowRate;
}

async fetchIsolatedBorrowRates (params = {}): Promise<IsolatedBorrowRates> {
/**
* @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: string, since: Int = undefined, limit: Int = undefined, params = {}) {
/**
* @method
Expand Down Expand Up @@ -11240,6 +11306,44 @@ export default class binance extends Exchange {
};
}

parseIsolatedBorrowRate (info, market: 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: string, amount, params = {}) {
/**
* @method
Expand Down
18 changes: 18 additions & 0 deletions ts/src/test/static/request/binance.json
Original file line number Diff line number Diff line change
Expand Up @@ -3077,6 +3077,24 @@
],
"output": "timestamp=1713536455384&quoteId=844f131de9994643a0b6ce7805d08cfb&recvWindow=10000&signature=39e6351a5061356643aa48f6e335b6d3c903710206f2543bd9443af07885948b"
}
],
"fetchIsolatedBorrowRate": [
{
"description": "fetchIsolatedBorrowRate",
"method": "fetchIsolatedBorrowRate",
"url": "https://api.binance.com/sapi/v1/margin/isolatedMarginData?timestamp=1714664548704&symbol=BTCUSDT&recvWindow=10000&signature=6bed3101b0139a52896c5ac2cba8c9c16371153e133ecdef782c7cd398bb470f",
"input": [
"BTC/USDT"
]
}
],
"fetchIsolatedBorrowRates": [
{
"description": "fetchIsolatedBorrowRates",
"method": "fetchIsolatedBorrowRates",
"url": "https://api.binance.com/sapi/v1/margin/isolatedMarginData?timestamp=1714664627834&recvWindow=10000&signature=9b4fa07568a385ee7a642e31375bb1c6e0640d1491508b2f5bbd4e36ce31f117",
"input": []
}
]
}
}