Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
public async cancelOrder(orderId: string) {
const order = this.orders.get(Number(orderId))
if (!order) return null
if (order.status === 'canceled' || order.status === 'closed') throw new OrderNotFound('Nah.')
await this.checkOrderCompletion(order)
const updatedOrder = this.orders.get(Number(orderId))
if (updatedOrder.status === 'closed') throw new OrderNotFound('Nah.')
const [a, c] = updatedOrder.symbol.split('/')
if (updatedOrder.side === 'bid') {
const cost = updatedOrder.remaining * order.price
const currency = this.balances.get(c)
this.balances.set(c, currency + cost)
} else {
const asset = this.balances.get(a)
this.balances.set(a, asset + updatedOrder.remaining)
}
const canceledOrder: Order = { ...updatedOrder, status: 'canceled' }
this.orders.set(order.id, canceledOrder)
// @ts-ignore
mockCancelOrder.mockImplementation(() => {
throw new OrderNotFound('nope')
})