How to use the ccxt.InsufficientFunds 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
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 })
    }
  }
github magic8bot / magic8bot / src / seed / chaos.exchange.ts View on Github external
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 })
    }
  }
github magic8bot / magic8bot / src / engine / order.spec.ts View on Github external
mockPlaceOrder.mockImplementation(() => {
      throw new InsufficientFunds('no monies')
    })