This commit is contained in:
Trooper
2022-06-19 20:18:57 +02:00
parent 9a7f83582e
commit 02ccfd1138

View File

@@ -89,9 +89,11 @@ try {
console.log(signKeyResult); console.log(signKeyResult);
} }
let accountId = await syncWallet.getAccountId(); let accountId = await syncWallet.getAccountId();
let account_state = await syncWallet.getAccountState();
WALLETS[accountId] = { WALLETS[accountId] = {
'ethWallet': ethWallet, 'ethWallet': ethWallet,
'syncWallet': syncWallet, 'syncWallet': syncWallet,
'account_state': account_state,
'ORDER_BROADCASTING': false, 'ORDER_BROADCASTING': false,
} }
} }
@@ -101,8 +103,7 @@ try {
} }
// Update account state loop // Update account state loop
await updateAccountState(); setInterval(updateAccountState, 900000);
setInterval(updateAccountState, 150000);
let fillOrdersInterval, indicateLiquidityInterval; let fillOrdersInterval, indicateLiquidityInterval;
let zigzagws = new WebSocket(MM_CONFIG.zigzagWsUrl); let zigzagws = new WebSocket(MM_CONFIG.zigzagWsUrl);
@@ -911,23 +912,14 @@ function rememberOrder(chainId, marketId, orderId, price, sellSymbol, sellQuanti
} }
async function updateAccountState() { async function updateAccountState() {
let lowBalance = false;
try { try {
const promise = Object.keys(WALLETS).map(accountId => { Object.keys(WALLETS).forEach(accountId => {
const accountState = WALLETS[accountId].syncWallet.getAccountState(); (WALLETS[accountId]['syncWallet']).getAccountState().then((state) => {
const ethBalance = accountState?.committed?.balances?.ETH WALLETS[accountId]['account_state'] = state;
? ethers.utils.formatEther(accountState.committed.balances.ETH).toNumber() })
: 0
if (ethBalance < 0.01) {
lowBalance = true;
return;
}
WALLETS[accountId]['account_state'] = accountState;
}); });
await Promise.all(promise);
} catch(err) { } catch(err) {
// pass // pass
} }
if (lowBalance) throw new Error('Your ETH balance is to low to run the marketmaker bot. You need at least 0.01 ETH!')
} }