Skip to content

Commit

Permalink
Borrow rate types and parsers (#22205)
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

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

* base/Exchange import CrossBorrowRate

* Exchange.ts removed BorrowRate type

* types.py linting

* fix crossborrowRates transpiling

* bybit minor fix

---------

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

[ci skip]
  • Loading branch information
Travis CI committed Apr 28, 2024
1 parent b0ce488 commit e8cc5f1
Show file tree
Hide file tree
Showing 79 changed files with 2,339 additions and 983 deletions.
18 changes: 18 additions & 0 deletions cs/ccxt/base/Exchange.BaseMethods.cs
Expand Up @@ -717,6 +717,11 @@ public virtual object parseBorrowInterest(object info, object market = null)
throw new NotSupported ((string)add(this.id, " parseBorrowInterest() is not supported yet")) ;
}

public virtual object parseIsolatedBorrowRate(object info, object market = null)
{
throw new NotSupported ((string)add(this.id, " parseIsolatedBorrowRate() is not supported yet")) ;
}

public virtual object parseWsTrade(object trade, object market = null)
{
throw new NotSupported ((string)add(this.id, " parseWsTrade() is not supported yet")) ;
Expand Down Expand Up @@ -5087,6 +5092,19 @@ public virtual object parseBorrowInterests(object response, object market = null
return interests;
}

public virtual object parseIsolatedBorrowRates(object info)
{
object result = new Dictionary<string, object>() {};
for (object i = 0; isLessThan(i, getArrayLength(info)); postFixIncrement(ref i))
{
object item = getValue(info, i);
object borrowRate = this.parseIsolatedBorrowRate(item);
object symbol = this.safeString(borrowRate, "symbol");
((IDictionary<string,object>)result)[(string)symbol] = borrowRate;
}
return ((object)result);
}

public virtual object parseFundingRateHistories(object response, object market = null, object since = null, object limit = null)
{
object rates = new List<object>() {};
Expand Down
16 changes: 8 additions & 8 deletions cs/ccxt/base/Exchange.Wrappers.cs
Expand Up @@ -128,15 +128,15 @@ public async Task<Int64> FetchTime(Dictionary<string, object> parameters = null)
var res = await this.fetchTradingLimits(symbols, parameters);
return ((Dictionary<string, object>)res);
}
public async Task<Dictionary<string, object>> FetchCrossBorrowRates(Dictionary<string, object> parameters = null)
public async Task<CrossBorrowRates> FetchCrossBorrowRates(Dictionary<string, object> parameters = null)
{
var res = await this.fetchCrossBorrowRates(parameters);
return ((Dictionary<string, object>)res);
return new CrossBorrowRates(res);
}
public async Task<Dictionary<string, object>> FetchIsolatedBorrowRates(Dictionary<string, object> parameters = null)
public async Task<IsolatedBorrowRates> FetchIsolatedBorrowRates(Dictionary<string, object> parameters = null)
{
var res = await this.fetchIsolatedBorrowRates(parameters);
return ((Dictionary<string, object>)res);
return new IsolatedBorrowRates(res);
}
public async Task<Dictionary<string, LeverageTier[]>> FetchLeverageTiers(List<string> symbols = null, Dictionary<string, object> parameters = null)
{
Expand Down Expand Up @@ -458,15 +458,15 @@ public async Task<DepositWithdrawFeeNetwork> FetchDepositWithdrawFee(string code
var res = await this.fetchDepositWithdrawFee(code, parameters);
return new DepositWithdrawFeeNetwork(res);
}
public async Task<Dictionary<string, object>> FetchCrossBorrowRate(string code, Dictionary<string, object> parameters = null)
public async Task<CrossBorrowRate> FetchCrossBorrowRate(string code, Dictionary<string, object> parameters = null)
{
var res = await this.fetchCrossBorrowRate(code, parameters);
return ((Dictionary<string, object>)res);
return new CrossBorrowRate(res);
}
public async Task<Dictionary<string, object>> FetchIsolatedBorrowRate(string symbol, Dictionary<string, object> parameters = null)
public async Task<IsolatedBorrowRate> FetchIsolatedBorrowRate(string symbol, Dictionary<string, object> parameters = null)
{
var res = await this.fetchIsolatedBorrowRate(symbol, parameters);
return ((Dictionary<string, object>)res);
return new IsolatedBorrowRate(res);
}
public async Task<Ticker> FetchTicker(string symbol, Dictionary<string, object> parameters = null)
{
Expand Down
2 changes: 1 addition & 1 deletion cs/ccxt/exchanges/bitget.cs
Expand Up @@ -8659,7 +8659,7 @@ public async override Task<object> fetchIsolatedBorrowRate(object symbol, object
return this.parseIsolatedBorrowRate(first, market);
}

public virtual object parseIsolatedBorrowRate(object info, object market = null)
public override object parseIsolatedBorrowRate(object info, object market = null)
{
//
// {
Expand Down
10 changes: 2 additions & 8 deletions cs/ccxt/exchanges/bitmart.cs
Expand Up @@ -3826,7 +3826,7 @@ public async override Task<object> fetchIsolatedBorrowRate(object symbol, object
return this.parseIsolatedBorrowRate(borrowRate, market);
}

public virtual object parseIsolatedBorrowRate(object info, object market = null)
public override object parseIsolatedBorrowRate(object info, object market = null)
{
//
// {
Expand Down Expand Up @@ -3917,13 +3917,7 @@ public async override Task<object> fetchIsolatedBorrowRates(object parameters =
//
object data = this.safeValue(response, "data", new Dictionary<string, object>() {});
object symbols = this.safeValue(data, "symbols", new List<object>() {});
object result = new List<object>() {};
for (object i = 0; isLessThan(i, getArrayLength(symbols)); postFixIncrement(ref i))
{
object symbol = this.safeValue(symbols, i);
((IList<object>)result).Add(this.parseIsolatedBorrowRate(symbol));
}
return result;
return this.parseIsolatedBorrowRates(symbols);
}

public async override Task<object> transfer(object code, object amount, object fromAccount, object toAccount, object parameters = null)
Expand Down
154 changes: 85 additions & 69 deletions cs/ccxt/exchanges/bybit.cs
Expand Up @@ -4261,50 +4261,10 @@ public async virtual Task<object> editUsdcOrder(object id, object symbol, object
return this.parseOrder(result, market);
}

public async override Task<object> editOrder(object id, object symbol, object type, object side, object amount = null, object price = null, object parameters = null)
public virtual object editOrderRequest(object id, object symbol, object type, object side, object amount = null, object price = null, object parameters = null)
{
/**
* @method
* @name bybit#editOrder
* @description edit a trade order
* @see https://bybit-exchange.github.io/docs/v5/order/amend-order
* @see https://bybit-exchange.github.io/docs/derivatives/unified/replace-order
* @see https://bybit-exchange.github.io/docs/api-explorer/derivatives/trade/contract/replace-order
* @param {string} id cancel order id
* @param {string} symbol unified symbol of the market to create an order in
* @param {string} type 'market' or 'limit'
* @param {string} side 'buy' or 'sell'
* @param {float} amount how much of currency you want to trade in units of base currency
* @param {float} price the price at which the order is to be fullfilled, in units of the base currency, ignored in market orders
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {float} [params.triggerPrice] The price that a trigger order is triggered at
* @param {float} [params.stopLossPrice] The price that a stop loss order is triggered at
* @param {float} [params.takeProfitPrice] The price that a take profit order is triggered at
* @param {object} [params.takeProfit] *takeProfit object in params* containing the triggerPrice that the attached take profit order will be triggered
* @param {float} [params.takeProfit.triggerPrice] take profit trigger price
* @param {object} [params.stopLoss] *stopLoss object in params* containing the triggerPrice that the attached stop loss order will be triggered
* @param {float} [params.stopLoss.triggerPrice] stop loss trigger price
* @param {string} [params.triggerBy] 'IndexPrice', 'MarkPrice' or 'LastPrice', default is 'LastPrice', required if no initial value for triggerPrice
* @param {string} [params.slTriggerBy] 'IndexPrice', 'MarkPrice' or 'LastPrice', default is 'LastPrice', required if no initial value for stopLoss
* @param {string} [params.tpTriggerby] 'IndexPrice', 'MarkPrice' or 'LastPrice', default is 'LastPrice', required if no initial value for takeProfit
* @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
*/
parameters ??= new Dictionary<string, object>();
if (isTrue(isEqual(symbol, null)))
{
throw new ArgumentsRequired ((string)add(this.id, " editOrder() requires a symbol argument")) ;
}
await this.loadMarkets();
object market = this.market(symbol);
var enableUnifiedMarginenableUnifiedAccountVariable = await this.isUnifiedEnabled();
var enableUnifiedMargin = ((IList<object>) enableUnifiedMarginenableUnifiedAccountVariable)[0];
var enableUnifiedAccount = ((IList<object>) enableUnifiedMarginenableUnifiedAccountVariable)[1];
object isUnifiedAccount = (isTrue(enableUnifiedMargin) || isTrue(enableUnifiedAccount));
object isUsdcSettled = isEqual(getValue(market, "settle"), "USDC");
if (isTrue(isTrue(isUsdcSettled) && !isTrue(isUnifiedAccount)))
{
return await this.editUsdcOrder(id, symbol, type, side, amount, price, parameters);
}
object request = new Dictionary<string, object>() {
{ "symbol", getValue(market, "id") },
{ "orderId", id },
Expand Down Expand Up @@ -4379,6 +4339,54 @@ public async override Task<object> editOrder(object id, object symbol, object ty
((IDictionary<string,object>)request)["orderLinkId"] = clientOrderId;
}
parameters = this.omit(parameters, new List<object>() {"stopPrice", "stopLossPrice", "takeProfitPrice", "triggerPrice", "clientOrderId", "stopLoss", "takeProfit"});
return request;
}

public async override Task<object> editOrder(object id, object symbol, object type, object side, object amount = null, object price = null, object parameters = null)
{
/**
* @method
* @name bybit#editOrder
* @description edit a trade order
* @see https://bybit-exchange.github.io/docs/v5/order/amend-order
* @see https://bybit-exchange.github.io/docs/derivatives/unified/replace-order
* @see https://bybit-exchange.github.io/docs/api-explorer/derivatives/trade/contract/replace-order
* @param {string} id cancel order id
* @param {string} symbol unified symbol of the market to create an order in
* @param {string} type 'market' or 'limit'
* @param {string} side 'buy' or 'sell'
* @param {float} amount how much of currency you want to trade in units of base currency
* @param {float} price the price at which the order is to be fullfilled, in units of the base currency, ignored in market orders
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {float} [params.triggerPrice] The price that a trigger order is triggered at
* @param {float} [params.stopLossPrice] The price that a stop loss order is triggered at
* @param {float} [params.takeProfitPrice] The price that a take profit order is triggered at
* @param {object} [params.takeProfit] *takeProfit object in params* containing the triggerPrice that the attached take profit order will be triggered
* @param {float} [params.takeProfit.triggerPrice] take profit trigger price
* @param {object} [params.stopLoss] *stopLoss object in params* containing the triggerPrice that the attached stop loss order will be triggered
* @param {float} [params.stopLoss.triggerPrice] stop loss trigger price
* @param {string} [params.triggerBy] 'IndexPrice', 'MarkPrice' or 'LastPrice', default is 'LastPrice', required if no initial value for triggerPrice
* @param {string} [params.slTriggerBy] 'IndexPrice', 'MarkPrice' or 'LastPrice', default is 'LastPrice', required if no initial value for stopLoss
* @param {string} [params.tpTriggerby] 'IndexPrice', 'MarkPrice' or 'LastPrice', default is 'LastPrice', required if no initial value for takeProfit
* @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
*/
parameters ??= new Dictionary<string, object>();
await this.loadMarkets();
if (isTrue(isEqual(symbol, null)))
{
throw new ArgumentsRequired ((string)add(this.id, " editOrder() requires a symbol argument")) ;
}
object market = this.market(symbol);
var enableUnifiedMarginenableUnifiedAccountVariable = await this.isUnifiedEnabled();
var enableUnifiedMargin = ((IList<object>) enableUnifiedMarginenableUnifiedAccountVariable)[0];
var enableUnifiedAccount = ((IList<object>) enableUnifiedMarginenableUnifiedAccountVariable)[1];
object isUnifiedAccount = (isTrue(enableUnifiedMargin) || isTrue(enableUnifiedAccount));
object isUsdcSettled = isEqual(getValue(market, "settle"), "USDC");
if (isTrue(isTrue(isUsdcSettled) && !isTrue(isUnifiedAccount)))
{
return await this.editUsdcOrder(id, symbol, type, side, amount, price, parameters);
}
object request = this.editOrderRequest(id, symbol, type, side, amount, price, parameters);
object response = await this.privatePostV5OrderAmend(this.extend(request, parameters));
//
// {
Expand Down Expand Up @@ -4443,6 +4451,40 @@ public async virtual Task<object> cancelUsdcOrder(object id, object symbol = nul
return this.parseOrder(result, market);
}

public virtual object cancelOrderRequest(object id, object symbol = null, object parameters = null)
{
parameters ??= new Dictionary<string, object>();
object market = this.market(symbol);
object request = new Dictionary<string, object>() {
{ "symbol", getValue(market, "id") },
};
if (isTrue(getValue(market, "spot")))
{
// only works for spot market
object isStop = this.safeBool2(parameters, "stop", "trigger", false);
parameters = this.omit(parameters, new List<object>() {"stop", "trigger"});
((IDictionary<string,object>)request)["orderFilter"] = ((bool) isTrue(isStop)) ? "StopOrder" : "Order";
}
if (isTrue(!isEqual(id, null)))
{
((IDictionary<string,object>)request)["orderId"] = id;
}
if (isTrue(getValue(market, "spot")))
{
((IDictionary<string,object>)request)["category"] = "spot";
} else if (isTrue(getValue(market, "linear")))
{
((IDictionary<string,object>)request)["category"] = "linear";
} else if (isTrue(getValue(market, "inverse")))
{
((IDictionary<string,object>)request)["category"] = "inverse";
} else if (isTrue(getValue(market, "option")))
{
((IDictionary<string,object>)request)["category"] = "option";
}
return this.extend(request, parameters);
}

public async override Task<object> cancelOrder(object id, object symbol = null, object parameters = null)
{
/**
Expand Down Expand Up @@ -4473,34 +4515,8 @@ public async override Task<object> cancelOrder(object id, object symbol = null,
{
return await this.cancelUsdcOrder(id, symbol, parameters);
}
object request = new Dictionary<string, object>() {
{ "symbol", getValue(market, "id") },
};
if (isTrue(getValue(market, "spot")))
{
// only works for spot market
object isStop = this.safeValue2(parameters, "stop", "trigger", false);
parameters = this.omit(parameters, new List<object>() {"stop", "trigger"});
((IDictionary<string,object>)request)["orderFilter"] = ((bool) isTrue(isStop)) ? "StopOrder" : "Order";
}
if (isTrue(!isEqual(id, null)))
{
((IDictionary<string,object>)request)["orderId"] = id;
}
if (isTrue(getValue(market, "spot")))
{
((IDictionary<string,object>)request)["category"] = "spot";
} else if (isTrue(getValue(market, "linear")))
{
((IDictionary<string,object>)request)["category"] = "linear";
} else if (isTrue(getValue(market, "inverse")))
{
((IDictionary<string,object>)request)["category"] = "inverse";
} else if (isTrue(getValue(market, "option")))
{
((IDictionary<string,object>)request)["category"] = "option";
}
object response = await this.privatePostV5OrderCancel(this.extend(request, parameters));
object requestExtended = this.cancelOrderRequest(id, symbol, parameters);
object response = await this.privatePostV5OrderCancel(requestExtended);
//
// {
// "retCode": 0,
Expand Down
9 changes: 2 additions & 7 deletions cs/ccxt/exchanges/coinex.cs
Expand Up @@ -5233,7 +5233,7 @@ public async override Task<object> fetchDeposits(object code = null, object sinc
return this.parseTransactions(data, currency, since, limit);
}

public virtual object parseIsolatedBorrowRate(object info, object market = null)
public override object parseIsolatedBorrowRate(object info, object market = null)
{
//
// {
Expand Down Expand Up @@ -5346,12 +5346,7 @@ public async override Task<object> fetchIsolatedBorrowRates(object parameters =
// }
//
object data = this.safeValue(response, "data", new List<object>() {});
object rates = new List<object>() {};
for (object i = 0; isLessThan(i, getArrayLength(data)); postFixIncrement(ref i))
{
((IList<object>)rates).Add(this.parseIsolatedBorrowRate(getValue(data, i)));
}
return rates;
return this.parseIsolatedBorrowRates(data);
}

public async override Task<object> fetchBorrowInterest(object code = null, object symbol = null, object since = null, object limit = null, object parameters = null)
Expand Down
9 changes: 2 additions & 7 deletions cs/ccxt/exchanges/htx.cs
Expand Up @@ -7029,15 +7029,10 @@ public async override Task<object> fetchIsolatedBorrowRates(object parameters =
// }
//
object data = this.safeValue(response, "data", new List<object>() {});
object rates = new List<object>() {};
for (object i = 0; isLessThan(i, getArrayLength(data)); postFixIncrement(ref i))
{
((IList<object>)rates).Add(this.parseIsolatedBorrowRate(getValue(data, i)));
}
return rates;
return this.parseIsolatedBorrowRates(data);
}

public virtual object parseIsolatedBorrowRate(object info, object market = null)
public override object parseIsolatedBorrowRate(object info, object market = null)
{
//
// {
Expand Down

0 comments on commit e8cc5f1

Please sign in to comment.