mirror of
https://github.com/discountry/ritmex-bot.git
synced 2026-09-09 08:18:07 +00:00
61 lines
2.4 KiB
JavaScript
61 lines
2.4 KiB
JavaScript
import ccxt from '../../js/ccxt.js';
|
|
|
|
console.log ('CCXT Version:', ccxt.version);
|
|
|
|
function getMaxLeverage (market, positionSize) {
|
|
/**
|
|
* @description Equation taken from https://www.delta.exchange/contracts/
|
|
* @param {object} market CCXT market
|
|
* @param {float} positionSize The value of the position in quote currency
|
|
* @returns The maximum leverage available for the market for the given position size
|
|
*/
|
|
const info = market['info'];
|
|
const maxLeverageNotional = Number (info['max_leverage_notional']);
|
|
const initialMarginScalingFactor = Number (info['initial_margin_scaling_factor']);
|
|
let initialMargin = Number (info['initial_margin']);
|
|
|
|
if (positionSize <= maxLeverageNotional) {
|
|
const initialMarginRatio = initialMargin / 100;
|
|
return 1 / initialMarginRatio;
|
|
} else {
|
|
initialMargin = initialMargin + (initialMarginScalingFactor * (positionSize - maxLeverageNotional));
|
|
const initialMarginRatio = initialMargin / 100;
|
|
return 1 / initialMarginRatio;
|
|
}
|
|
}
|
|
|
|
function getMaintenanceMarginRate (market, positionSize) {
|
|
/**
|
|
* @description Equation taken from https://www.delta.exchange/contracts/
|
|
* @param {object} market CCXT market
|
|
* @param {float} positionSize The value of the position in quote currency
|
|
* @returns The maintenance margin rate as a percentage for the market with the given position size
|
|
*/
|
|
const info = market['info'];
|
|
const maxLeverageNotional = Number (info['max_leverage_notional']);
|
|
const maintenanceMarginScalingFactor = Number (info['maintenance_margin_scaling_factor']);
|
|
const maintenanceMargin = Number (info['maintenance_margin']);
|
|
|
|
if (positionSize <= maxLeverageNotional) {
|
|
return maintenanceMargin;
|
|
} else {
|
|
return maintenanceMargin + (maintenanceMarginScalingFactor * (positionSize - maxLeverageNotional));
|
|
}
|
|
}
|
|
|
|
async function main () {
|
|
|
|
const exchange = new ccxt.delta();
|
|
await exchange.loadMarkets ();
|
|
|
|
const symbol = 'ADA/USDT:USDT';
|
|
const market = exchange.market (symbol);
|
|
|
|
// Gets the maximum leverage and maintenance margin rate for a position worth 100,000 USDT on the ADA/USDT:USDT market
|
|
const maxLeverage = getMaxLeverage(market, 100000);
|
|
const maintenanceMarginRate = getMaintenanceMarginRate(market, 100000);
|
|
console.log(maxLeverage, maintenanceMarginRate);
|
|
}
|
|
|
|
main ()
|