title: Nest JS resolving promises from Binance API
body: <p>I am trying to create an api that connects into the Binance API using node and in particular NestJs.</p>
  <p>In my controller I have <code>@Get('candles')</code> endpoint and call it by going to localhost:5000/candles. I am expecting it to return an object containing all the candleData retrieved from the Binance API. I am using the npm package node-binance-api.</p>
  <p>I know the <code>binance.candlesticks(&quot;BTCGBP&quot;, &quot;4h&quot;, async (error, ticks, symbol) = {...</code> I am using is getting the data as inside I log the data received and show candleData.length in the console and it returns 100 candles as requested.</p>
  <p>My issue is resolving the promise that this npm package returns so that I can return it via the /candles endpoint. I am used to angular and observables and I am getting a bit confused by async and await.</p>
  <p>app.controller.ts</p>
  <pre><code>// Endpoint to fetch the object.
  @Get('candles')
    public getCandleData() {
      console.log('Getting Candles');
   let binanceResponse = this.getBinanceCandles().then(
        (response) =&gt; {
          const result = response
          console.log('inside .then', result); // undefined
          this.candles = result
          return this.candles
        }
      );
  
      console.log('@Get binanceResponse', binanceResponse); // Promise { &lt;pending&gt; }
      return binanceResponse // undefined
  }
  
  // async function to retrieve data from Binance
  async getBinanceCandles() {
      let binanceResponse = await binance.candlesticks(&quot;BTCGBP&quot;, &quot;4h&quot;, async (error, ticks, symbol) =&gt; {
        if (error) return console.error(error);
        const candleData = await ticks.map(candle =&gt; ({
          time: candle[0],
          open: candle[1],
          high: candle[2],
          low: candle[3],
          close: candle[4]
        }))
        let last_tick = ticks[ticks.length - 1];
        let [time, open, high, low, close, volume] = last_tick;
        console.log('Length', candleData.length);
        console.info(symbol + &quot; last close: &quot; + close);
        return candleData
  } , { limit: 100 })
   return binanceResponse
  }
  </code></pre>
  <p>console output</p>
  <pre><code>Application is running on: http://[::1]:5000
  Getting Candles
  @Get binanceResponse Promise { &lt;pending&gt; }
  inside .then undefined
  Length 100
  BTCGBP last close: 41628.85000000
  </code></pre>
  <p>I am not sure if I am using the await keyword correctly but clearly the promise is returning unresolved. How do I get the endpoint localhost:5000/candles to return an object containing the 100 candles created in the getBinanceCandles() function?</p>