Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
private async adjustBalance(symbol: string, price: number, amount: number, side: 'bid' | 'ask') {
const [a, c] = symbol.split('/')
if (side === 'bid') {
const cost = price * amount
const currency = this.balances.get(c)
if (cost > currency) throw new InsufficientFunds('You poor')
this.balances.set(c, currency - cost)
await this.balanceCollection.update({ name: a }, { amount: currency - cost })
} else {
const asset = this.balances.get(a)
if (amount > asset) throw new InsufficientFunds('You poor')
this.balances.set(a, asset - amount)
await this.balanceCollection.update({ name: c }, { amount: asset - amount })
}
}
private async adjustBalance(symbol: string, price: number, amount: number, side: 'bid' | 'ask') {
const [a, c] = symbol.split('/')
if (side === 'bid') {
const cost = price * amount
const currency = this.balances.get(c)
if (cost > currency) throw new InsufficientFunds('You poor')
this.balances.set(c, currency - cost)
await this.balanceCollection.update({ name: a }, { amount: currency - cost })
} else {
const asset = this.balances.get(a)
if (amount > asset) throw new InsufficientFunds('You poor')
this.balances.set(a, asset - amount)
await this.balanceCollection.update({ name: c }, { amount: asset - amount })
}
}
mockPlaceOrder.mockImplementation(() => {
throw new InsufficientFunds('no monies')
})