Skip to content

Commit

Permalink
Merge pull request #19516 from Dan-krm/fetchLiquidations
Browse files Browse the repository at this point in the history
New unified methods: fetchLiquidations and fetchMyLiquidations

[ci skip]
  • Loading branch information
Travis CI committed Oct 13, 2023
1 parent a3f1ee5 commit a88b443
Show file tree
Hide file tree
Showing 188 changed files with 7,228 additions and 9 deletions.
907 changes: 907 additions & 0 deletions dist/ccxt.browser.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/ccxt.browser.min.js

Large diffs are not rendered by default.

907 changes: 907 additions & 0 deletions dist/ccxt.bundle.cjs

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dist/cjs/src/ace.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ class ace extends ace$1 {
'amount': this.parseNumber(this.parsePrecision(this.safeString(market, 'basePrecision'))),
},
'active': undefined,
'created': undefined,
'info': market,
});
}
Expand Down
1 change: 1 addition & 0 deletions dist/cjs/src/alpaca.js
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ class alpaca extends alpaca$1 {
'max': undefined,
},
},
'created': undefined,
'info': asset,
});
}
Expand Down
30 changes: 30 additions & 0 deletions dist/cjs/src/base/Exchange.js
Original file line number Diff line number Diff line change
Expand Up @@ -3276,6 +3276,12 @@ class Exchange {
async fetchMyTrades(symbol = undefined, since = undefined, limit = undefined, params = {}) {
throw new errors.NotSupported(this.id + ' fetchMyTrades() is not supported yet');
}
async fetchMyLiquidations(symbol = undefined, since = undefined, limit = undefined, params = {}) {
throw new errors.NotSupported(this.id + ' fetchMyLiquidations() is not supported yet');
}
async fetchLiquidations(symbol, since = undefined, limit = undefined, params = {}) {
throw new errors.NotSupported(this.id + ' fetchLiquidations() is not supported yet');
}
async fetchMyTradesWs(symbol = undefined, since = undefined, limit = undefined, params = {}) {
throw new errors.NotSupported(this.id + ' fetchMyTradesWs() is not supported yet');
}
Expand Down Expand Up @@ -4400,6 +4406,30 @@ class Exchange {
'info': this.safeValue(interest, 'info'),
});
}
parseLiquidation(liquidation, market = undefined) {
throw new errors.NotSupported(this.id + ' parseLiquidation () is not supported yet');
}
parseLiquidations(liquidations, market = undefined, since = undefined, limit = undefined) {
/**
* @ignore
* @method
* @description parses liquidation info from the exchange response
* @param {object[]} liquidations each item describes an instance of a liquidation event
* @param {object} market ccxt market
* @param {int} [since] when defined, the response items are filtered to only include items after this timestamp
* @param {int} [limit] limits the number of items in the response
* @returns {object[]} an array of [liquidation structures]{@link https://github.com/ccxt/ccxt/wiki/Manual#liquidation-structure}
*/
const result = [];
for (let i = 0; i < liquidations.length; i++) {
const entry = liquidations[i];
const parsed = this.parseLiquidation(entry, market);
result.push(parsed);
}
const sorted = this.sortBy(result, 'timestamp');
const symbol = this.safeString(market, 'symbol');
return this.filterBySymbolSinceLimit(sorted, symbol, since, limit);
}
}

exports.Exchange = Exchange;
Expand Down
1 change: 1 addition & 0 deletions dist/cjs/src/bigone.js
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,7 @@ class bigone extends bigone$1 {
'max': this.safeNumber(market, 'max_quote_value'),
},
},
'created': undefined,
'info': market,
};
result.push(entry);
Expand Down
228 changes: 228 additions & 0 deletions dist/cjs/src/binance.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,11 @@ class binance extends binance$1 {
'fetchLedger': true,
'fetchLeverage': false,
'fetchLeverageTiers': true,
'fetchLiquidations': false,
'fetchMarketLeverageTiers': 'emulated',
'fetchMarkets': true,
'fetchMarkOHLCV': true,
'fetchMyLiquidations': true,
'fetchMySettlementHistory': true,
'fetchMyTrades': true,
'fetchOHLCV': true,
Expand Down Expand Up @@ -9219,6 +9221,232 @@ class binance extends binance$1 {
'info': interest,
}, market);
}
async fetchMyLiquidations(symbol = undefined, since = undefined, limit = undefined, params = {}) {
/**
* @method
* @name binance#fetchMyLiquidations
* @description retrieves the users liquidated positions
* @see https://binance-docs.github.io/apidocs/spot/en/#get-force-liquidation-record-user_data
* @see https://binance-docs.github.io/apidocs/futures/en/#user-39-s-force-orders-user_data
* @see https://binance-docs.github.io/apidocs/delivery/en/#user-39-s-force-orders-user_data
* @param {string} [symbol] unified CCXT market symbol
* @param {int} [since] the earliest time in ms to fetch liquidations for
* @param {int} [limit] the maximum number of liquidation structures to retrieve
* @param {object} [params] exchange specific parameters for the binance api endpoint
* @param {int} [params.until] timestamp in ms of the latest liquidation
* @param {boolean} [params.paginate] *spot only* default false, when true will automatically paginate by calling this endpoint multiple times. See in the docs all the [available parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
* @returns {object} an array of [liquidation structures]{@link https://github.com/ccxt/ccxt/wiki/Manual#liquidation-structure}
*/
await this.loadMarkets();
let paginate = false;
[paginate, params] = this.handleOptionAndParams(params, 'fetchMyLiquidations', 'paginate');
if (paginate) {
return await this.fetchPaginatedCallIncremental('fetchMyLiquidations', symbol, since, limit, params, 'current', 100);
}
let market = undefined;
if (symbol !== undefined) {
market = this.market(symbol);
}
let type = undefined;
[type, params] = this.handleMarketTypeAndParams('fetchMyLiquidations', market, params);
let subType = undefined;
[subType, params] = this.handleSubTypeAndParams('fetchMyLiquidations', market, params, 'linear');
let request = {};
if (type !== 'spot') {
request['autoCloseType'] = 'LIQUIDATION';
}
if (market !== undefined) {
const symbolKey = market['spot'] ? 'isolatedSymbol' : 'symbol';
request[symbolKey] = market['id'];
}
if (since !== undefined) {
request['startTime'] = since;
}
if (limit !== undefined) {
if (type === 'spot') {
request['size'] = limit;
}
else {
request['limit'] = limit;
}
}
[request, params] = this.handleUntilOption('endTime', request, params);
let response = undefined;
if (type === 'spot') {
response = await this.sapiGetMarginForceLiquidationRec(this.extend(request, params));
}
else if (subType === 'linear') {
response = await this.fapiPrivateGetForceOrders(this.extend(request, params));
}
else if (subType === 'inverse') {
response = await this.dapiPrivateGetForceOrders(this.extend(request, params));
}
else {
throw new errors.NotSupported(this.id + ' fetchMyLiquidations() does not support ' + market['type'] + ' markets');
}
//
// margin
//
// {
// "rows": [
// {
// "avgPrice": "0.00388359",
// "executedQty": "31.39000000",
// "orderId": 180015097,
// "price": "0.00388110",
// "qty": "31.39000000",
// "side": "SELL",
// "symbol": "BNBBTC",
// "timeInForce": "GTC",
// "isIsolated": true,
// "updatedTime": 1558941374745
// }
// ],
// "total": 1
// }
//
// linear
//
// [
// {
// "orderId": 6071832819,
// "symbol": "BTCUSDT",
// "status": "FILLED",
// "clientOrderId": "autoclose-1596107620040000020",
// "price": "10871.09",
// "avgPrice": "10913.21000",
// "origQty": "0.001",
// "executedQty": "0.001",
// "cumQuote": "10.91321",
// "timeInForce": "IOC",
// "type": "LIMIT",
// "reduceOnly": false,
// "closePosition": false,
// "side": "SELL",
// "positionSide": "BOTH",
// "stopPrice": "0",
// "workingType": "CONTRACT_PRICE",
// "origType": "LIMIT",
// "time": 1596107620044,
// "updateTime": 1596107620087
// },
// ]
//
// inverse
//
// [
// {
// "orderId": 165123080,
// "symbol": "BTCUSD_200925",
// "pair": "BTCUSD",
// "status": "FILLED",
// "clientOrderId": "autoclose-1596542005017000006",
// "price": "11326.9",
// "avgPrice": "11326.9",
// "origQty": "1",
// "executedQty": "1",
// "cumBase": "0.00882854",
// "timeInForce": "IOC",
// "type": "LIMIT",
// "reduceOnly": false,
// "closePosition": false,
// "side": "SELL",
// "positionSide": "BOTH",
// "stopPrice": "0",
// "workingType": "CONTRACT_PRICE",
// "priceProtect": false,
// "origType": "LIMIT",
// "time": 1596542005019,
// "updateTime": 1596542005050
// },
// ]
//
const liquidations = this.safeValue(response, 'rows', response);
return this.parseLiquidations(liquidations, market, since, limit);
}
parseLiquidation(liquidation, market = undefined) {
//
// margin
//
// {
// "avgPrice": "0.00388359",
// "executedQty": "31.39000000",
// "orderId": 180015097,
// "price": "0.00388110",
// "qty": "31.39000000",
// "side": "SELL",
// "symbol": "BNBBTC",
// "timeInForce": "GTC",
// "isIsolated": true,
// "updatedTime": 1558941374745
// }
//
// linear
//
// {
// "orderId": 6071832819,
// "symbol": "BTCUSDT",
// "status": "FILLED",
// "clientOrderId": "autoclose-1596107620040000020",
// "price": "10871.09",
// "avgPrice": "10913.21000",
// "origQty": "0.001",
// "executedQty": "0.001",
// "cumQuote": "10.91321",
// "timeInForce": "IOC",
// "type": "LIMIT",
// "reduceOnly": false,
// "closePosition": false,
// "side": "SELL",
// "positionSide": "BOTH",
// "stopPrice": "0",
// "workingType": "CONTRACT_PRICE",
// "origType": "LIMIT",
// "time": 1596107620044,
// "updateTime": 1596107620087
// }
//
// inverse
//
// {
// "orderId": 165123080,
// "symbol": "BTCUSD_200925",
// "pair": "BTCUSD",
// "status": "FILLED",
// "clientOrderId": "autoclose-1596542005017000006",
// "price": "11326.9",
// "avgPrice": "11326.9",
// "origQty": "1",
// "executedQty": "1",
// "cumBase": "0.00882854",
// "timeInForce": "IOC",
// "type": "LIMIT",
// "reduceOnly": false,
// "closePosition": false,
// "side": "SELL",
// "positionSide": "BOTH",
// "stopPrice": "0",
// "workingType": "CONTRACT_PRICE",
// "priceProtect": false,
// "origType": "LIMIT",
// "time": 1596542005019,
// "updateTime": 1596542005050
// }
//
const marketId = this.safeString(liquidation, 'symbol');
const timestamp = this.safeInteger2(liquidation, 'updatedTime', 'updateTime');
return {
'info': liquidation,
'symbol': this.safeSymbol(marketId, market),
'contracts': this.safeNumber(liquidation, 'executedQty'),
'contractSize': this.safeNumber(market, 'contractSize'),
'price': this.safeNumber(liquidation, 'avgPrice'),
'baseValue': this.safeNumber(liquidation, 'cumBase'),
'quoteValue': this.safeNumber(liquidation, 'cumQuote'),
'timestamp': timestamp,
'datetime': this.iso8601(timestamp),
};
}
}

module.exports = binance;
1 change: 1 addition & 0 deletions dist/cjs/src/bingx.js
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,7 @@ class bingx extends bingx$1 {
'max': this.safeNumber(market, 'maxNotional'),
},
},
'created': undefined,
'info': market,
};
return entry;
Expand Down
1 change: 1 addition & 0 deletions dist/cjs/src/bitbank.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ class bitbank extends bitbank$1 {
'max': undefined,
},
},
'created': undefined,
'info': entry,
});
}
Expand Down
1 change: 1 addition & 0 deletions dist/cjs/src/bitbns.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ class bitbns extends bitbns$1 {
'max': this.safeNumber(costLimits, 'max'),
},
},
'created': undefined,
'info': market,
});
}
Expand Down
1 change: 1 addition & 0 deletions dist/cjs/src/bitfinex.js
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,7 @@ class bitfinex extends bitfinex$1 {
'max': undefined,
},
},
'created': undefined,
'info': market,
});
}
Expand Down
1 change: 1 addition & 0 deletions dist/cjs/src/bitfinex2.js
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,7 @@ class bitfinex2 extends bitfinex2$1 {
'max': undefined,
},
},
'created': undefined,
'info': market,
});
}
Expand Down
1 change: 1 addition & 0 deletions dist/cjs/src/bitflyer.js
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ class bitflyer extends bitflyer$1 {
'max': undefined,
},
},
'created': undefined,
'info': market,
});
}
Expand Down
1 change: 1 addition & 0 deletions dist/cjs/src/bitforex.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ class bitforex extends bitforex$1 {
'max': undefined,
},
},
'created': undefined,
'info': market,
});
}
Expand Down
1 change: 1 addition & 0 deletions dist/cjs/src/bitget.js
Original file line number Diff line number Diff line change
Expand Up @@ -1474,6 +1474,7 @@ class bitget extends bitget$1 {
'max': undefined,
},
},
'created': undefined,
};
}
return result;
Expand Down
1 change: 1 addition & 0 deletions dist/cjs/src/bithumb.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ class bithumb extends bithumb$1 {
},
'cost': {}, // set via options
},
'created': undefined,
'info': market,
}, extension);
result.push(entry);
Expand Down
Loading

0 comments on commit a88b443

Please sign in to comment.