Skip to content

Commit

Permalink
fix(binance): remove filtering from account positions (ccxt#22009)
Browse files Browse the repository at this point in the history
* fix(binance): remove filtering from account positions

* revert

* add filterClosed option

* add static test
  • Loading branch information
carlosmiei authored Apr 1, 2024
1 parent 49f888f commit df68484
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
12 changes: 8 additions & 4 deletions ts/src/binance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9009,7 +9009,7 @@ export default class binance extends Exchange {
};
}

parseAccountPositions (account) {
parseAccountPositions (account, filterClosed = false) {
const positions = this.safeList (account, 'positions');
const assets = this.safeList (account, 'assets', []);
const balances = {};
Expand All @@ -9032,7 +9032,8 @@ export default class binance extends Exchange {
const code = market['linear'] ? market['quote'] : market['base'];
const maintenanceMargin = this.safeString (position, 'maintMargin');
// check for maintenance margin so empty positions are not returned
if ((maintenanceMargin !== '0') && (maintenanceMargin !== '0.00000000')) {
const isPositionOpen = (maintenanceMargin !== '0') && (maintenanceMargin !== '0.00000000');
if (!filterClosed || isPositionOpen) {
// sometimes not all the codes are correctly returned...
if (code in balances) {
const parsed = this.parseAccountPosition (this.extend (position, {
Expand Down Expand Up @@ -9862,10 +9863,11 @@ export default class binance extends Exchange {
* @see https://binance-docs.github.io/apidocs/delivery/en/#account-information-user_data
* @see https://binance-docs.github.io/apidocs/pm/en/#get-um-account-detail-user_data
* @see https://binance-docs.github.io/apidocs/pm/en/#get-cm-account-detail-user_data
* @param {string[]|undefined} symbols list of unified market symbols
* @param {string[]} [symbols] list of unified market symbols
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {boolean} [params.portfolioMargin] set to true if you would like to fetch positions in a portfolio margin account
* @param {string} [params.subType] "linear" or "inverse"
* @param {boolean} [params.filterClosed] set to true if you would like to filter out closed positions, default is false
* @returns {object} data on account positions
*/
if (symbols !== undefined) {
Expand Down Expand Up @@ -9898,7 +9900,9 @@ export default class binance extends Exchange {
} else {
throw new NotSupported (this.id + ' fetchPositions() supports linear and inverse contracts only');
}
const result = this.parseAccountPositions (response);
let filterClosed = undefined;
[ filterClosed, params ] = this.handleOptionAndParams (params, 'fetchAccountPositions', 'filterClosed', false);
const result = this.parseAccountPositions (response, filterClosed);
symbols = this.marketSymbols (symbols);
return this.filterByArrayPositions (result, 'symbol', symbols, false);
}
Expand Down
11 changes: 11 additions & 0 deletions ts/src/test/static/request/binance.json
Original file line number Diff line number Diff line change
Expand Up @@ -2280,6 +2280,17 @@
"subType": "inverse"
}
]
},
{
"description": "account positions with filterClosed option",
"method": "fetchAccountPositions",
"url": "https://testnet.binancefuture.com/fapi/v2/account?timestamp=1711968805532&filterClosed=true&recvWindow=10000&signature=d70e7146e12dff30106d51e77574cda0b75aa353c505746b1a78a5c086a7ac19",
"input": [
null,
{
"filterClosed": true
}
]
}
],
"fetchOpenInterest": [
Expand Down

0 comments on commit df68484

Please sign in to comment.