# Live Trading Portfolio Value Error no attribute

**URL:** <https://forum.alpaca.markets/t/live-trading-portfolio-value-error-no-attribute/2809>\
**Category:** Getting Started with Alpaca\
**Created:** [September 29, 2020, 5:40pm UTC](https://forum.alpaca.markets/t/live-trading-portfolio-value-error-no-attribute/2809 "2020-09-29T17:40:01Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![algilama](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.alpaca.markets/algilama/32/1237_2.png) [@algilama](https://forum.alpaca.markets/u/algilama)\
**Post date:** [September 29, 2020, 5:40pm UTC](https://forum.alpaca.markets/t/live-trading-portfolio-value-error-no-attribute/2809/1 "2020-09-29T17:40:01Z")

</div>

I am trying to use Alpaca Backtrader API.

My account is saying $0 cash even though I have $1000 in there.

There is an error with portfolio\_value also.

```
            d = DataFactory(
            dataname=ticker,
            timeframe=bt.TimeFrame.Minutes,
            compression=minutes,
            backfill_start=True,
            historical=False
        )

print(cerebro.broker.cash)
print(cerebro.broker.getcash())

starting_value = ('Starting Portfolio Value: %.2f' % cerebro.broker.getvalue())

```

OUTPUT,

0.0  
0.0  
Traceback (most recent call last):  
File “C:/Users/Mochi/PycharmProjects/alpaca/hammer\_detect\_w\_alpaca\_data.py”, line 513, in   
starting\_value = (‘Starting Portfolio Value: %.2f’ % cerebro.broker.getvalue())  
File “C:\Users\Mochi\PycharmProjects\alpaca\venv\lib\site-packages\alpaca\_backtrader\_api\alpacabroker.py”, line 159, in getvalue  
self.value = float(self.o.oapi.get\_account().portfolio\_value)  
File “C:\Users\Mochi\PycharmProjects\alpaca\venv\lib\site-packages\alpaca\_trade\_api\entity.py”, line 29, in **getattr**  
return super(). **getattribute** (key)  
AttributeError: ‘Account’ object has no attribute ‘portfolio\_value’

---

<div class="post-metadata">

**Author:** ![Shlomik](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.alpaca.markets/shlomik/32/793_2.png) [@Shlomik](https://forum.alpaca.markets/u/Shlomik)\
**Post date:** [September 30, 2020, 12:48pm UTC](https://forum.alpaca.markets/t/live-trading-portfolio-value-error-no-attribute/2809/2 "2020-09-30T12:48:07Z")

</div>

Hi,  
are you using your paper account or your live account?

---

<div class="post-metadata">

**Author:** ![algilama](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.alpaca.markets/algilama/32/1237_2.png) [@algilama](https://forum.alpaca.markets/u/algilama)\
**Post date:** [September 30, 2020, 6:21pm UTC](https://forum.alpaca.markets/t/live-trading-portfolio-value-error-no-attribute/2809/3 "2020-09-30T18:21:58Z")

</div>

I am using my Live account with ‘[https://api.alpaca.markets](https://api.alpaca.markets)’

---

<div class="post-metadata">

**Author:** ![Shlomik](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.alpaca.markets/shlomik/32/793_2.png) [@Shlomik](https://forum.alpaca.markets/u/Shlomik)\
**Post date:** [September 30, 2020, 8:14pm UTC](https://forum.alpaca.markets/t/live-trading-portfolio-value-error-no-attribute/2809/4 "2020-09-30T20:14:12Z")

</div>

so, what happens here is the account that is returned from the server is a null account.  
my guess is that that the credentials are problematic  
so

1. make sure you are using the right credentials
2. what are the versions of the alpaca packages you are using?

---

<div class="post-metadata">

**Author:** ![algilama](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.alpaca.markets/algilama/32/1237_2.png) [@algilama](https://forum.alpaca.markets/u/algilama)\
**Post date:** [September 30, 2020, 10:06pm UTC](https://forum.alpaca.markets/t/live-trading-portfolio-value-error-no-attribute/2809/5 "2020-09-30T22:06:01Z")

</div>

was using alpaca backtrader - 0.9.5, just upgraded to 0.10.1

Got the same error.

I just regenerated an API key and secret again on the Overview page, [https://app.alpaca.markets/brokerage/dashboard/overview](https://app.alpaca.markets/brokerage/dashboard/overview)

Getting the same error.

---

<div class="post-metadata">

**Author:** ![algilama](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.alpaca.markets/algilama/32/1237_2.png) [@algilama](https://forum.alpaca.markets/u/algilama)\
**Post date:** [September 30, 2020, 10:16pm UTC](https://forum.alpaca.markets/t/live-trading-portfolio-value-error-no-attribute/2809/6 "2020-09-30T22:16:22Z")

</div>

I think my creds are good because when I use the same credentials with stream, I am authorized.

```
import websocket, json

from config import *

def on_open(ws):
    print("WEB SOCKET OPENED")
    auth_data = {
        "action": "authenticate",
        "data": {"key_id": APCA_API_KEY_ID, "secret_key": APCA_API_SECRET_KEY}
    }

# convert the python dict to json string and send to the web socket connection
ws.send(json.dumps(auth_data))

# streams can be a list of tickers
listen_msg = {"action": "listen",
              "data": {
                "streams": ["T.SPY"]}
              }

ws.send(json.dumps(listen_msg))

def on_close(ws):
    print("WEB SOCKET CLOSED")

def on_message(ws, msg):
    print("RECEIVED A WEB SOCKET MESSAGE")
    print(msg)

socket = "wss://data.alpaca.markets/stream"
ws = websocket.WebSocketApp(socket, on_open=on_open, on_message=on_message, on_close=on_close)
ws.run_forever()

```

Output,

WEB SOCKET OPENED  
RECEIVED A WEB SOCKET MESSAGE  
{“stream”:“authorization”,“data”:{“action”:“authenticate”,“status”:“authorized”}}  
RECEIVED A WEB SOCKET MESSAGE  
{“stream”:“listening”,“data”:{“streams”:[“T.SPY”]}}  
RECEIVED A WEB SOCKET MESSAGE  
{“stream”:“T.SPY”,“data”:{“ev”:“T”,“T”:“SPY”,“i”:“62879181326445”,“x”:2,“p”:335.15,“s”:100,“t”:1601504100522000000,“c”:[14,12,41],“z”:1}}

---

<div class="post-metadata">

**Author:** ![Shlomik](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.alpaca.markets/shlomik/32/793_2.png) [@Shlomik](https://forum.alpaca.markets/u/Shlomik)\
**Post date:** [October 6, 2020, 7:38am UTC](https://forum.alpaca.markets/t/live-trading-portfolio-value-error-no-attribute/2809/7 "2020-10-06T07:38:35Z")

</div>

does the paper trading work for you with no issues?

---

<div class="post-metadata">

**Author:** ![algilama](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.alpaca.markets/algilama/32/1237_2.png) [@algilama](https://forum.alpaca.markets/u/algilama)\
**Post date:** [October 11, 2020, 2:58am UTC](https://forum.alpaca.markets/t/live-trading-portfolio-value-error-no-attribute/2809/8 "2020-10-11T02:58:42Z")

</div>

yes paper trading works fine

---

<div class="post-metadata">

**Author:** ![Shlomik](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.alpaca.markets/shlomik/32/793_2.png) [@Shlomik](https://forum.alpaca.markets/u/Shlomik)\
**Post date:** [October 12, 2020, 6:30am UTC](https://forum.alpaca.markets/t/live-trading-portfolio-value-error-no-attribute/2809/9 "2020-10-12T06:30:05Z")

</div>

The default url used is the paper account url.  
do you pass the `paper=False` to the `AlpacaStore` object?

---

<div class="post-metadata">

**Author:** ![algilama](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.alpaca.markets/algilama/32/1237_2.png) [@algilama](https://forum.alpaca.markets/u/algilama)\
**Post date:** [October 12, 2020, 5:31pm UTC](https://forum.alpaca.markets/t/live-trading-portfolio-value-error-no-attribute/2809/10 "2020-10-12T17:31:53Z")

</div>

```
IS_BACKTEST = False
IS_LIVE = True

store = Alpaca.AlpacaStore(
    key_id=config.APCA_API_KEY_ID,
    secret_key=config.APCA_API_SECRET_KEY,
    paper=IS_LIVE
)
```

---

<div class="post-metadata">

**Author:** ![algilama](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.alpaca.markets/algilama/32/1237_2.png) [@algilama](https://forum.alpaca.markets/u/algilama)\
**Post date:** [October 12, 2020, 5:52pm UTC](https://forum.alpaca.markets/t/live-trading-portfolio-value-error-no-attribute/2809/11 "2020-10-12T17:52:10Z")

</div>

ha, that was it. Setting paper=false, fixed it.

Documentation in the example is misleading,

> <https://github.com/alpacahq/alpaca-backtrader-api/blob/master/sample/strategy_sma_crossover.py>

```
"""
You have 3 options: 
 - backtest (IS_BACKTEST=True, IS_LIVE=False)
 - paper trade (IS_BACKTEST=False, IS_LIVE=False) 
 - live trade (IS_BACKTEST=False, IS_LIVE=True) 
"""
```

---

<div class="post-metadata">

**Author:** ![Shlomik](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.alpaca.markets/shlomik/32/793_2.png) [@Shlomik](https://forum.alpaca.markets/u/Shlomik)\
**Post date:** [October 12, 2020, 7:26pm UTC](https://forum.alpaca.markets/t/live-trading-portfolio-value-error-no-attribute/2809/12 "2020-10-12T19:26:53Z")

</div>

yes I changed that a week ago, maybe you had a previous example code.  
I am now passing this in all examples:  
`paper = not IS_LIVE`

---

<div class="post-metadata">

**Author:** ![algilama](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.alpaca.markets/algilama/32/1237_2.png) [@algilama](https://forum.alpaca.markets/u/algilama)\
**Post date:** [October 12, 2020, 7:43pm UTC](https://forum.alpaca.markets/t/live-trading-portfolio-value-error-no-attribute/2809/13 "2020-10-12T19:43:18Z")

</div>

Thank You for the help Shlomik!
