Skip to content

Commit

Permalink
move getBalancesBinance in src/binance
Browse files Browse the repository at this point in the history
  • Loading branch information
fabcotech committed Jul 16, 2024
1 parent 0437caa commit 26942f4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 19 deletions.
25 changes: 6 additions & 19 deletions src/balances.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,14 @@
import querystring from 'node:querystring';

Check failure on line 1 in src/balances.ts

View workflow job for this annotation

GitHub Actions / lintandbuild

'querystring' is defined but never used
import { request } from 'undici';

Check failure on line 2 in src/balances.ts

View workflow job for this annotation

GitHub Actions / lintandbuild

'request' is defined but never used

import { getApiKey, getSingleProcessArgv, round4 } from './utils';
import {
getApiKey,

Check failure on line 5 in src/balances.ts

View workflow job for this annotation

GitHub Actions / lintandbuild

'getApiKey' is defined but never used
getSingleProcessArgv,
round4,
getBalancesBinance,
} from './utils';
import { signatureBinanceApi, getPriceTicker } from './binance';

Check failure on line 10 in src/balances.ts

View workflow job for this annotation

GitHub Actions / lintandbuild

'signatureBinanceApi' is defined but never used

const getBalancesBinance = async (): Promise<any> => {
const qs = querystring.stringify({
timestamp: new Date().getTime(),
omitZeroBalances: true,
});
const signature = signatureBinanceApi(qs);
const accountReq = await request(
`https://api1.binance.com/api/v3/account?${qs}&signature=${signature}`,
{
method: 'GET',
headers: {
'X-MBX-APIKEY': getApiKey(),
},
}
);
return await accountReq.body.json();
};

export const printBalances = async (symbols: string[], usdSymbol: string) => {
const obj: { [symbol: string]: any } = {};
let s = '';
Expand Down
18 changes: 18 additions & 0 deletions src/binance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,24 @@ export const signatureBinanceApi = (qs: string) => {
return crypto.createHmac('sha256', getSecretKey()).update(qs).digest('hex');
};

export const getBalancesBinance = async (): Promise<any> => {
const qs = querystring.stringify({
timestamp: new Date().getTime(),
omitZeroBalances: true,
});
const signature = signatureBinanceApi(qs);
const accountReq = await request(
`https://api1.binance.com/api/v3/account?${qs}&signature=${signature}`,
{
method: 'GET',
headers: {
'X-MBX-APIKEY': getApiKey(),
},
}
);
return await accountReq.body.json();
};

const getBalanceBinance = async (symbol: string) => {
const qs = querystring.stringify({
timestamp: new Date().getTime(),
Expand Down

0 comments on commit 26942f4

Please sign in to comment.