mirror of
https://github.com/ZigZagExchange/zksync-lite-market-maker.git
synced 2025-12-17 07:04:23 +01:00
Merge pull request #83 from TrooperCrypto/master
no need for splits under 1k
This commit is contained in:
@@ -34,7 +34,7 @@ node marketmaker.js
|
||||
|
||||
#### Fee Token
|
||||
|
||||
With the defualt setting the bot will pay the zkSync fee wiht the same token as the user (buy currency for the bot). You can chose to override that by a fixed fee token. Check if your tokens is avalible to pay fees on zkSync [here](https://zkscan.io/explorer/tokens).
|
||||
With the defualt setting the bot will pay the zkSync fee wiht the same token as the user (buy currency for the bot). You can chose to override that by a fixed fee token. Check if your tokens is available to pay fees on zkSync [here](https://zkscan.io/explorer/tokens).
|
||||
|
||||
```
|
||||
{
|
||||
@@ -85,11 +85,12 @@ Orders coming in below the `minSpread` from the price feed will not be filled. T
|
||||
|
||||
#### Price Feed
|
||||
|
||||
There are 3 modes available with a 4th on the way.
|
||||
There are 4 modes available with a 5th on the way.
|
||||
|
||||
* `cryptowatch`: Follows an external price oracle.
|
||||
* `chainlink` : Follows an external price oracle. Chainlink is WEB3 and might be slower then cryptowatch.
|
||||
* `constant`: Sets an fixed price and market makes around that price. Can be combined with single-sided liquidity to simulate limit orders.
|
||||
* `uniswapV3`: Reads prices on-chain from a specified uniswapV3 pool
|
||||
* `independent`: Under development. The price is set independent of a price feed.
|
||||
|
||||
**Warning:** Make sure your price feed is close to the price you see on zigzag. **Otherwise, your mm can lose money!**
|
||||
|
||||
@@ -105,10 +105,6 @@ try {
|
||||
// Update account state loop
|
||||
setInterval(updateAccountState, 900000);
|
||||
|
||||
// Log mm balance over all accounts
|
||||
logBalance();
|
||||
setInterval(logBalance, 3 * 60 * 60 * 1000); // 3h
|
||||
|
||||
let fillOrdersInterval, indicateLiquidityInterval;
|
||||
let zigzagws = new WebSocket(MM_CONFIG.zigzagWsUrl);
|
||||
zigzagws.on('open', onWsOpen);
|
||||
@@ -118,7 +114,7 @@ zigzagws.on('error', console.error);
|
||||
function onWsOpen() {
|
||||
zigzagws.on('message', handleMessage);
|
||||
fillOrdersInterval = setInterval(fillOpenOrders, 200);
|
||||
indicateLiquidityInterval = setInterval(indicateLiquidity, 5000);
|
||||
indicateLiquidityInterval = setInterval(indicateLiquidity, 12500);
|
||||
for (let market in MM_CONFIG.pairs) {
|
||||
if (MM_CONFIG.pairs[market].active) {
|
||||
const msg = {op:"subscribemarket", args:[CHAIN_ID, market]};
|
||||
@@ -748,15 +744,14 @@ function indicateLiquidity (pairs = MM_CONFIG.pairs) {
|
||||
const maxSellSize = Math.min(baseBalance, mmConfig.maxSize);
|
||||
const maxBuySize = Math.min(quoteBalance / midPrice, mmConfig.maxSize);
|
||||
|
||||
// default splits
|
||||
let buySplits = mmConfig.numOrdersIndicated || 10;
|
||||
let sellSplits = mmConfig.numOrdersIndicated || 10;
|
||||
|
||||
// check if balance passes the min liquidity size - 10 USD
|
||||
// dont do splits if under 1000 USD
|
||||
const usdBaseBalance = baseBalance * marketInfo.baseAsset.usdPrice;
|
||||
const usdQuoteBalance = quoteBalance * marketInfo.quoteAsset.usdPrice;
|
||||
if (usdBaseBalance < (10 * buySplits)) buySplits = Math.floor(usdBaseBalance / 10)
|
||||
if (usdQuoteBalance < (10 * sellSplits)) sellSplits = Math.floor(usdQuoteBalance / 10)
|
||||
let buySplits = (usdQuoteBalance < 1000) ? 1 : (mmConfig.numOrdersIndicated || 4);
|
||||
let sellSplits = (usdBaseBalance < 1000) ? 1 : (mmConfig.numOrdersIndicated || 4);
|
||||
|
||||
if (usdQuoteBalance < (10 * buySplits)) buySplits = Math.floor(usdQuoteBalance / 10)
|
||||
if (usdBaseBalance < (10 * sellSplits)) sellSplits = Math.floor(usdBaseBalance / 10)
|
||||
|
||||
const liquidity = [];
|
||||
for (let i=1; i <= buySplits; i++) {
|
||||
@@ -928,34 +923,3 @@ async function updateAccountState() {
|
||||
}
|
||||
}
|
||||
|
||||
async function logBalance() {
|
||||
try {
|
||||
await updateAccountState();
|
||||
// fetch all balances over all wallets per token
|
||||
const balance = {};
|
||||
Object.keys(WALLETS).forEach(accountId => {
|
||||
const committedBalaces = WALLETS[accountId]['account_state'].committed.balances;
|
||||
Object.keys(committedBalaces).forEach(token => {
|
||||
if(balance[token]) {
|
||||
balance[token] = balance[token] + parseInt(committedBalaces[token]);
|
||||
} else {
|
||||
balance[token] = parseInt(committedBalaces[token]);
|
||||
}
|
||||
});
|
||||
});
|
||||
// get token price and total in USD
|
||||
let sum = 0;
|
||||
await Promise.all(Object.keys(balance).map(async token => {
|
||||
const price = await syncProvider.getTokenPrice(token.toString());
|
||||
const tokenNumber = await syncProvider.tokenSet.formatToken(token, balance[token].toString())
|
||||
sum = sum + price * tokenNumber;
|
||||
}));
|
||||
|
||||
// log to CVS
|
||||
const date = new Date().toISOString();
|
||||
const content = date + ";" + sum.toFixed(2) + "\n";
|
||||
fs.writeFile('price_csv.txt', content, { flag: 'a+' }, err => {});
|
||||
} catch(err) {
|
||||
// pass
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user