Skip to content
Permalink
Browse files

Update Logic For The Market Maker

First we need to check the dense of bids and asks list. After that, we create new order for the list with less items.
  • Loading branch information...
piavgh committed Feb 12, 2019
1 parent f05d3fe commit b112b3fa8b50463832f3d96461184c30b761c389
Showing with 15 additions and 13 deletions.
  1. +15 −13 cron/index.js
@@ -7,20 +7,22 @@ import { calculateBetterBid, calculateBetterAsk } from '../utils/price'
const runMarketMaker = async () => {
try {
const orderBookData = await fetchOrderBook()
const bestBid = orderBookData.bids[0]
const bestAsk = orderBookData.asks[0]

let newBidOrder = calculateBetterBid(bestBid)
let newAskOrder = calculateBetterAsk(bestAsk)

newBidOrder = await prepareOrderParams(newBidOrder.amount, newBidOrder.price, 'BUY')
newAskOrder = await prepareOrderParams(newAskOrder.amount, newAskOrder.price, 'SELL')

// console.log(newBidOrder)
// console.log(newAskOrder)

await createOrder(newBidOrder)
await createOrder(newAskOrder)
if (orderBookData.bids.length <= orderBookData.asks.length) {
const bestBid = orderBookData.bids[0]
let newBidOrder = calculateBetterBid(bestBid)
newBidOrder = await prepareOrderParams(newBidOrder.amount, newBidOrder.price, 'BUY')
console.log(newBidOrder)

await createOrder(newBidOrder)
} else {
const bestAsk = orderBookData.asks[0]
let newAskOrder = calculateBetterAsk(bestAsk)
newAskOrder = await prepareOrderParams(newAskOrder.amount, newAskOrder.price, 'SELL')
console.log(newAskOrder)

await createOrder(newAskOrder)
}

} catch (err) {
console.log(err)

0 comments on commit b112b3f

Please sign in to comment.
You can’t perform that action at this time.