Skip to content
Permalink
Browse files

Update Price Helper Method

  • Loading branch information...
piavgh committed Feb 12, 2019
1 parent 594617c commit c4470df04b175f7cabf24ab28dcfa36be466814c
Showing with 17 additions and 6 deletions.
  1. +17 −6 utils/price.js
@@ -3,10 +3,23 @@ import { utils } from 'ethers'
import { defaultOrderParams, minimumPriceStepChange } from '../config'
import { printBigNumberToString } from './print'

export const calculateBetterBid = (currentBestBid) => {
const amountMultipler = utils.bigNumberify(10).pow(18)
export const calculateBigNumberAmount = amount => {
const amountMultiplier = utils.bigNumberify(10).pow(18)

return utils.bigNumberify(amount).mul(amountMultiplier)
}

const defaultOrderAmount = utils.bigNumberify(defaultOrderParams.amount).mul(amountMultipler)
export const calculateCoinmarketcapPrice = price => {
// Get only 2 decimals from the price
const roundedPrice = Math.round(price * 1e2)

const priceMultiplier = utils.bigNumberify(10).pow(34) // Because we multiply by 1e2 above

return utils.bigNumberify(roundedPrice).mul(priceMultiplier).toString()
}

export const calculateBetterBid = (currentBestBid) => {
const defaultOrderAmount = calculateBigNumberAmount(defaultOrderParams.amount)

const newBidOrder = {
amount: printBigNumberToString(utils.bigNumberify(currentBestBid.amount).gt(defaultOrderAmount) ? defaultOrderAmount : utils.bigNumberify(currentBestBid.amount)),
@@ -17,9 +30,7 @@ export const calculateBetterBid = (currentBestBid) => {
}

export const calculateBetterAsk = (currentBestAsk) => {
const amountMultipler = utils.bigNumberify(10).pow(18)

const defaultOrderAmount = utils.bigNumberify(defaultOrderParams.amount).mul(amountMultipler)
const defaultOrderAmount = calculateBigNumberAmount(defaultOrderParams.amount)

const newAskOrder = {
amount: printBigNumberToString(utils.bigNumberify(currentBestAsk.amount).gt(defaultOrderAmount) ? defaultOrderAmount : utils.bigNumberify(currentBestAsk.amount)),

0 comments on commit c4470df

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