Skip to content

Commit

Permalink
add sell depth & buy depth
Browse files Browse the repository at this point in the history
  • Loading branch information
lehieuhust committed Aug 14, 2023
1 parent 56544ec commit 07d3061
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 15 deletions.
14 changes: 8 additions & 6 deletions packages/market-maker/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,23 @@ import {

const cancelPercentage = Number(process.env.CANCEL_PERCENTAGE || 1); // 100% cancel

const marketDepth = Number(process.env.MARKET_DEPTH);
const sellDepth = Number(process.env.SELL_DEPTH);
const buyDepth = Number(process.env.BUY_DEPTH);
const buyPercentage = Number(process.env.BUY_PERCENTAGE || 0.55);
const [spreadMin, spreadMax] = process.env.SPREAD_RANGE
? process.env.SPREAD_RANGE.split(",").map(Number)
: [0.003, 0.006];
: [0.001, 0.004];

const maxRepeat = 5;
const totalOrders = 10;
const totalOrders = 5;

const orderConfig: MakeOrderConfig = {
cancelPercentage,
buyPercentage,
spreadMax,
spreadMin,
marketDepth,
sellDepth,
buyDepth,
totalOrders
};
const [orderIntervalMin, orderIntervalMax] = process.env.ORDER_INTERVAL_RANGE
Expand All @@ -48,8 +50,8 @@ const [orderIntervalMin, orderIntervalMax] = process.env.ORDER_INTERVAL_RANGE
});
buyer = { client, address: "orai1hz4kkphvt0smw4wd9uusuxjwkp604u7m4akyzv" };
seller = { client, address: "orai18cgmaec32hgmd8ls8w44hjn25qzjwhannd9kpj" };
client.app.bank.setBalance(buyer.address, [coin(toDecimals(1000), "orai")]);
client.app.bank.setBalance(seller.address, [coin(toDecimals(1000), "orai")]);
client.app.bank.setBalance(buyer.address, [coin(toDecimals(100000), "orai")]);
client.app.bank.setBalance(seller.address, [coin(toDecimals(100000), "orai")]);
usdtToken = await deployToken(buyer.client, buyer.address, {
symbol: "USDT",
name: "USDT token"
Expand Down
2 changes: 1 addition & 1 deletion packages/market-maker/src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ export const deployToken = async (
symbol,
name,
mint: { minter: senderAddress },
initial_balances: [{ address: senderAddress, amount: "1000000000" }, ...initial_balances]
initial_balances: [{ address: senderAddress, amount: "100000000000" }, ...initial_balances]
}, "oraiswap_token", "oraiswap_token")
).contractAddress
);
Expand Down
18 changes: 10 additions & 8 deletions packages/market-maker/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ export type MakeOrderConfig = {
spreadMax: number;
buyPercentage: number;
cancelPercentage: number;
marketDepth: number;
sellDepth: number;
buyDepth: number;
totalOrders: number;
};

Expand All @@ -21,19 +22,20 @@ const getRandomSpread = (min: number, max: number) => {
return getRandomRange(min * atomic, max * atomic) / atomic;
};

const generateOrderMsg = (oraiPrice: number, usdtContractAddress: Addr, { spreadMin, spreadMax, buyPercentage, totalOrders, marketDepth, makeProfit }: MakeOrderConfig): OraiswapLimitOrderTypes.ExecuteMsg => {
const generateOrderMsg = (oraiPrice: number, usdtContractAddress: Addr, { spreadMin, spreadMax, buyPercentage, totalOrders, sellDepth, buyDepth, makeProfit }: MakeOrderConfig): OraiswapLimitOrderTypes.ExecuteMsg => {
const spread = getRandomSpread(spreadMin, spreadMax);
// buy percentage is 55%
const direction: OrderDirection = getRandomPercentage() < buyPercentage * 100 ? 'buy' : 'sell';
// if make profit then buy lower, sell higher than market
const oraiPriceEntry = getSpreadPrice(oraiPrice, spread * (direction === 'buy' ? 1 : -1) * (makeProfit ? -1 : 1));
const volumeMax = marketDepth / totalOrders;
const volumeMin = (marketDepth / totalOrders)*0.7;

const oraiVolume = getRandomRange(volumeMin, volumeMax);
console.log({oraiVolume})
const usdtVolume = (oraiPriceEntry * oraiVolume).toFixed(0);
const totalUsdtVolume = sellDepth + buyDepth;
console.log({totalVolume: totalUsdtVolume});

const usdtVolume = Math.round(totalUsdtVolume / totalOrders);
console.log({usdtVolume})
const oraiVolume = Math.round(usdtVolume / oraiPriceEntry);
console.log({oraiVolume})

return {
submit_order: {
Expand All @@ -48,7 +50,7 @@ const generateOrderMsg = (oraiPrice: number, usdtContractAddress: Addr, { spread
info: {
token: { contract_addr: usdtContractAddress }
},
amount: usdtVolume
amount: usdtVolume.toString()
}
],
direction
Expand Down

0 comments on commit 07d3061

Please sign in to comment.