How to use the ccxt.OrderNotFound function in ccxt

To help you get started, we’ve selected a few ccxt examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github magic8bot / magic8bot / src / seed / chaos.exchange.ts View on Github external
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
github magic8bot / magic8bot / src / engine / order.spec.ts View on Github external
mockCancelOrder.mockImplementation(() => {
      throw new OrderNotFound('nope')
    })