TypeScript
inline callbacks vs. external callbacks

by Benny Neugebauer

private async executeBuy(pair: CurrencyPair, quantity: string): Promise<coinbase.Buy> {
  return new Promise(async (resolve, reject) => {
    const account = await this.getAccount(pair.base);

    account.buy(
      {
        amount: quantity,
        currency: pair.base,
      },
      (error: Error, response: coinbase.Buy) => {
        if (error) {
          reject(error);
        } else {
          resolve(response);
        }
      }
    );
  });
}

private async executeBuy(pair: CurrencyPair, quantity: string): Promise<coinbase.Buy> {
  return new Promise(async (resolve, reject) => {
    const account = await this.getAccount(pair.base);

    const options = {
      amount: quantity,
      currency: pair.base,
    };

    const callback = (error: Error, response: coinbase.Buy) => {
      if (error) {
        reject(error);
      } else {
        resolve(response);
      }
    };

    account.buy(options, callback);
  });
}