# Analyze Data and Trade Stocks Through Your Browser Using Google Colab and Alpaca API

**URL:** <https://forum.alpaca.markets/t/analyze-data-and-trade-stocks-through-your-browser-using-google-colab-and-alpaca-api/196>\
**Category:** Examples\
**Created:** [August 27, 2019, 5:21pm UTC](https://forum.alpaca.markets/t/analyze-data-and-trade-stocks-through-your-browser-using-google-colab-and-alpaca-api/196 "2019-08-27T17:21:55Z")\
**Posts on this page:** 5\
**Page:** 2

<div class="post-metadata">

**Author:** ![Ianfinn1994](https://avatars.discourse-cdn.com/v4/letter/i/ecccb3/32.png) [@Ianfinn1994](https://forum.alpaca.markets/u/Ianfinn1994)\
**Post date:** [April 6, 2022, 12:47am UTC](https://forum.alpaca.markets/t/analyze-data-and-trade-stocks-through-your-browser-using-google-colab-and-alpaca-api/196/21 "2022-04-06T00:47:23Z")

</div>

\_bars = api.get\_bars(symbol=\_SPY, timeframe=_TimeFrame.Day, start=_“2022-03-28”)

print(\_bars)

File [“”](https://ati6k3pm9pp-496ff2e9c6d22116-0-colab.googleusercontent.com/outputframe.html?vrz=colab-20220401-060043-RC00_438786104#), line 1 \_bars = api.get\_bars(symbol=\_SPY, timeframe=_TimeFrame.Day, start=_“2022-03-28”) ^ SyntaxError: invalid syntax

Like I said bra, a coding noob. Lol my bad I’m sure its a simple fix.

---

<div class="post-metadata">

**Author:** ![maxks90](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.alpaca.markets/maxks90/32/3534_2.png) [@maxks90](https://forum.alpaca.markets/u/maxks90)\
**Post date:** [April 6, 2022, 11:23am UTC](https://forum.alpaca.markets/t/analyze-data-and-trade-stocks-through-your-browser-using-google-colab-and-alpaca-api/196/22 "2022-04-06T11:23:11Z")

</div>

No worries. I started teaching myself Python back in November, specifically to develop a trading bot for Alpaca. It’s been a journey!

I think you are getting that error because you need to specify the symbol as a string.  
`symbol=_SPY`

Either specify the string directly in the `get_bars` call, e.g.

```auto
_bars = api.get_bars(symbol= 'SPY', timeframe=TimeFrame.Day, start=“2022-03-28”)

```

or declare the symbol as a variable first:

```auto
_mySymbol = 'SPY' # Whichever ticker you want
_bars = api.get_bars(symbol=_mySymbol, timeframe=TimeFrame.Day, start=“2022-03-28”)

```

Bear in mind, if you haven’t already, you will need to include/import some libraries at the top of your code:

```auto
import alpaca_trade_api as alpaca
from alpaca_trade_api.rest import TimeFrame

```

---

<div class="post-metadata">

**Author:** ![Ianfinn1994](https://avatars.discourse-cdn.com/v4/letter/i/ecccb3/32.png) [@Ianfinn1994](https://forum.alpaca.markets/u/Ianfinn1994)\
**Post date:** [April 6, 2022, 11:37am UTC](https://forum.alpaca.markets/t/analyze-data-and-trade-stocks-through-your-browser-using-google-colab-and-alpaca-api/196/23 "2022-04-06T11:37:07Z")

</div>

Thank you man. I will log on and try to start this. I am learning for the same reason pretty much. 💯🔥

---

<div class="post-metadata">

**Author:** ![Igor\_Ivoilov](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.alpaca.markets/igor_ivoilov/32/5849_2.png) [@Igor\_Ivoilov](https://forum.alpaca.markets/u/Igor_Ivoilov)\
**Post date:** [February 13, 2024, 3:39pm UTC](https://forum.alpaca.markets/t/analyze-data-and-trade-stocks-through-your-browser-using-google-colab-and-alpaca-api/196/24 "2024-02-13T15:39:21Z")

</div>

Modern style to graph bars

```auto
import pandas as pd
import mplfinance as mpf

bars = api.get_bars('AAPL','1T',start='2024-02-13T09:30:00-05:00')
data = {
    'timestamp': [bar.t for bar in bars],
    'open': [bar.o for bar in bars],
    'high': [bar.h for bar in bars],
    'low': [bar.l for bar in bars],
    'close': [bar.c for bar in bars],
    'volume': [bar.v for bar in bars],
}
df = pd.DataFrame(data).set_index('timestamp')
mpf.plot(
    df,
    type='candle',
    # addplot=plots,
    figscale=2.0,
    figratio=(20,6),
    style='charles',
    warn_too_much_data=100_000,
)

```

 ![image](https://us1.discourse-cdn.com/flex020/uploads/alp/original/2X/3/3710fcff1e6195e35a11309f5913c0aee7951bd7.png)

---

<div class="post-metadata">

**Author:** ![Dan\_Whitnable\_Alpaca](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.alpaca.markets/dan_whitnable_alpaca/32/1658_2.png) [@Dan\_Whitnable\_Alpaca](https://forum.alpaca.markets/u/Dan_Whitnable_Alpaca)\
**Post date:** [February 15, 2024, 3:28pm UTC](https://forum.alpaca.markets/t/analyze-data-and-trade-stocks-through-your-browser-using-google-colab-and-alpaca-api/196/25 "2024-02-15T15:28:51Z")

</div>

@Igor_Ivoilov Looks nice! Thanks.

[Previous page](https://forum.alpaca.markets/t/analyze-data-and-trade-stocks-through-your-browser-using-google-colab-and-alpaca-api/196.md?page=1)
