Skip to content

Commit 022b2ce

Browse files
authored
My trades for the margin account by taboca
2 parents 7fbaf92 + 8c9c84f commit 022b2ce

File tree

2 files changed

+85
-0
lines changed

2 files changed

+85
-0
lines changed

README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1922,6 +1922,33 @@ For order operations, use `binance.mgCancel()`, `binance.mgCancelOrders()`, `bin
19221922
19231923
Usage and callbacks are the same as the 'regular account' counterparts.
19241924
1925+
#### Get your Trade History for the Margin account
1926+
Use `binance.mgTrades()` instead of `binance.trades()`.
1927+
1928+
```javascript
1929+
binance.mgTrades("ETHUSDT", (error, trades, symbol) => {
1930+
console.info(symbol+" trade history", trades);
1931+
});
1932+
```
1933+
<details>
1934+
<summary>View Response</summary>
1935+
1936+
```js
1937+
[ { symbol: 'ETHUSDT',
1938+
id: 9572,
1939+
orderId: 47884,
1940+
price: '2063.07',
1941+
qty: '1.44877',
1942+
commission: '2.98891392',
1943+
commissionAsset: 'USDT',
1944+
time: 1617900638521,
1945+
isBuyer: false,
1946+
isMaker: false,
1947+
isBestMatch: true,
1948+
isIsolated: true }]
1949+
```
1950+
</details>
1951+
19251952
#### Margin account details
19261953
```javascript
19271954
binance.mgAccount((error, response) => {

node-binance-api.js

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4649,6 +4649,35 @@ let api = function Binance( options = {} ) {
46494649
universalTransfer: (type, asset, amount, callback) =>
46504650
universalTransfer(type, asset, amount, callback),
46514651

4652+
/**
4653+
* Get trades for a given symbol - margin account
4654+
* @param {string} symbol - the symbol
4655+
* @param {function} callback - the callback function
4656+
* @param {object} options - additional options
4657+
* @return {promise or undefined} - omitting the callback returns a promise
4658+
*/
4659+
mgTrades: ( symbol, callback, options = {} ) => {
4660+
let parameters = Object.assign( { symbol: symbol }, options );
4661+
if ( !callback ) {
4662+
return new Promise( ( resolve, reject ) => {
4663+
callback = ( error, response ) => {
4664+
if ( error ) {
4665+
reject( error );
4666+
} else {
4667+
resolve( response );
4668+
}
4669+
}
4670+
signedRequest( sapi + 'v1/margin/myTrades', parameters, function ( error, data ) {
4671+
return callback.call( this, error, data, symbol );
4672+
} );
4673+
} )
4674+
} else {
4675+
signedRequest( sapi + 'v1/margin/myTrades', parameters, function ( error, data ) {
4676+
return callback.call( this, error, data, symbol );
4677+
} );
4678+
}
4679+
},
4680+
46524681
/**
46534682
* Transfer from main account to delivery account
46544683
* @param {string} asset - the asset
@@ -4724,6 +4753,34 @@ let api = function Binance( options = {} ) {
47244753
}, 'POST' );
47254754
},
47264755

4756+
/**
4757+
* Margin account borrow/loan
4758+
* @param {string} asset - the asset
4759+
* @param {object} options - additional options
4760+
* @param {function} callback - the callback function
4761+
* @return {undefined}
4762+
*/
4763+
mgQueryLoan: function ( asset, options, callback) {
4764+
let parameters = Object.assign( { asset: asset }, options );
4765+
signedRequest( sapi + 'v1/margin/loan', {...parameters}, function ( error, data ) {
4766+
if ( callback ) return callback( error, data );
4767+
}, 'GET' );
4768+
},
4769+
4770+
/**
4771+
* Margin account repay
4772+
* @param {string} asset - the asset
4773+
* @param {object} options - additional options
4774+
* @param {function} callback - the callback function
4775+
* @return {undefined}
4776+
*/
4777+
mgQueryRepay: function ( asset, options, callback ) {
4778+
let parameters = Object.assign( { asset: asset }, options );
4779+
signedRequest( sapi + 'v1/margin/repay', {...parameters}, function ( error, data ) {
4780+
if ( callback ) return callback( error, data );
4781+
}, 'GET' );
4782+
},
4783+
47274784
/**
47284785
* Margin account repay
47294786
* @param {string} asset - the asset
@@ -4744,6 +4801,7 @@ let api = function Binance( options = {} ) {
47444801
if ( callback ) return callback( error, data );
47454802
}, 'POST' );
47464803
},
4804+
47474805
/**
47484806
* Margin account details
47494807
* @param {function} callback - the callback function

0 commit comments

Comments
 (0)