UNPKG

@rhino.fi/client-js

Version:
93 lines (81 loc) 1.83 kB
const P = require('@rhino.fi/aigle') const getPriceFromOrderBook = require( '../lib/util/getPriceFromOrderBook', ) const submitOrder = async (dvf, amount, price, symbol, starkPrivKey) => await dvf.submitOrder({ symbol, amount, price, starkPrivateKey: starkPrivKey, }) function executeOrders( dvf, amount, number, price, step, from, symbol, starkPrivKey, ) { P.timesSeries(number, async i => { const steppedPrice = price + (1 * step * (i + 1) + from) await submitOrder(dvf, amount, steppedPrice, symbol, starkPrivKey) }) } module.exports = async (dvf, { starkPrivKey, symbol = 'DAI:USDT', sells = 10, buys = 10, amount = false, spreadFrom = 0.1, spreadTo = 0.2, buyPrice = false, sellPrice = false, }) => { const spreadStepBuy = (spreadTo - spreadFrom) / buys const spreadStepSell = (spreadTo - spreadFrom) / sells const { tokenRegistry } = dvf.config const [cryptoSell, cryptoBuy] = symbol.split(':') let amountSell let amountBuy if (amount === false) { const amountSell = tokenRegistry[cryptoBuy].minOrderSize const amountBuy = tokenRegistry[cryptoSell].minOrderSize } else { amountSell = amount amountBuy = amount } if (buyPrice === false || sellPrice === false) { const tickersData = await dvf.getTickers(symbol) const orderBookPrice = getPriceFromOrderBook(tickersData) if (buyPrice === false) { buyPrice = orderBookPrice } if (sellPrice === false) { sellPrice = orderBookPrice } } await executeOrders( dvf, amountSell * -1, sells, sellPrice, -spreadStepSell, spreadFrom, symbol, starkPrivKey, ) await executeOrders( dvf, amountBuy, buys, buyPrice, spreadStepBuy, spreadFrom, symbol, starkPrivKey, ) }