# Example on viewing gain/loss of your portfolio

**URL:** <https://forum.alpaca.markets/t/example-on-viewing-gain-loss-of-your-portfolio/193>\
**Category:** Examples\
**Created:** [August 26, 2019, 10:01pm UTC](https://forum.alpaca.markets/t/example-on-viewing-gain-loss-of-your-portfolio/193 "2019-08-26T22:01:10Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![alpaca\_nancy](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.alpaca.markets/alpaca_nancy/32/45_2.png) [@alpaca\_nancy](https://forum.alpaca.markets/u/alpaca_nancy)\
**Post date:** [August 26, 2019, 10:01pm UTC](https://forum.alpaca.markets/t/example-on-viewing-gain-loss-of-your-portfolio/193/1 "2019-08-26T22:01:10Z")

</div>

You can use the information from the account endpoint to do things like calculating the daily profit or loss of your account.

**Example in python:**

```auto
import alpaca_trade_api as tradeapi

if __name__ == ' __main__':
    """
    With the Alpaca API, you can check on your daily profit or loss by
    comparing your current balance to yesterday's balance.
    """

    # First, open the API connection
    api = tradeapi.REST(
        'your_api_key_here',
        'your_api_secret_here',
        'https://paper-api.alpaca.markets'
    )

    # Get account info
    account = api.get_account()

    # Check our current balance vs. our balance at the last market close
    balance_change = float(account.equity) - float(account.last_equity)
    print(f'Today\'s portfolio balance change: ${balance_change}')

```

**You can view the full example in C# and python on our documentation site.**

> **[Documentation | Alpaca](https://docs.alpaca.markets/api-documentation/how-to/account/#view-gain-loss-of-portfolio)**
>
> Alpaca API lets you build and trade with real-time market data for free.

---

<div class="post-metadata">

**Author:** ![Michael2](https://avatars.discourse-cdn.com/v4/letter/m/3e96dc/32.png) [@Michael2](https://forum.alpaca.markets/u/Michael2)\
**Post date:** [June 29, 2023, 1:11am UTC](https://forum.alpaca.markets/t/example-on-viewing-gain-loss-of-your-portfolio/193/2 "2023-06-29T01:11:05Z")

</div>

I’ve tried several simple examples found in Alpaca documentation in order to get some data from the API, the above included. Below is a screenshot off the output of this build in Repl. I have also tried following the tutorial @ [Buying Crypto using Alpaca Snapshot and Crypto APIs](https://alpaca.markets/learn/buying-crypto-using-alpaca-snapshot-and-crypto-apis/) and other videos and getting similar results.

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