Skip to content

feat examples crypto: Add and refine example notebooks #589

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Apr 24, 2025

Conversation

idsts2670
Copy link
Contributor

@idsts2670 idsts2670 commented Apr 23, 2025

Focus review on commit f454485, 9ad7391, and a076992,

This pull request adds and refines several example notebooks in the examples/crypto directory:

  • Add btc-usd-swing-trade.ipynb demonstrating a BTC USD swing trading strategy and store it in the /crypto directory
  • Update the link for the “Open in Colab” widgets in crypto-trading-basic.ipynb, otpions-trading-basic.ipynb, options-trading-mleg.ipynb, stocks-trading-basic.ipynb

@idsts2670 idsts2670 requested a review from hiohiohio as a code owner April 23, 2025 02:58
Copy link
Contributor

@hiohiohio hiohiohio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall LGTM! Left small comments.


| Notebook | Open in Google Colab |
|:----------------------------------------------|:------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:|
| [BTC/USD Swing Trade](crypto-btc-usd-swing-trade.ipynb) | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/alpacahq/alpaca-py/blob/master/examples/crypto/crypto-btc-usd-swing-trade.ipynb.ipynb)|
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo

Suggested change
| [BTC/USD Swing Trade](crypto-btc-usd-swing-trade.ipynb) | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/alpacahq/alpaca-py/blob/master/examples/crypto/crypto-btc-usd-swing-trade.ipynb.ipynb)|
| [BTC/USD Swing Trade](crypto-btc-usd-swing-trade.ipynb) | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/alpacahq/alpaca-py/blob/master/examples/crypto/crypto-btc-usd-swing-trade.ipynb)|

@@ -11,7 +11,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/alpacahq/alpaca-py/blob/master/examples/crypto-trading-basic.ipynb)"
"[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/alpacahq/alpaca-py/blob/master/examples/crypto/crypto-trading-basic.ipynb)"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh good catch! Could you please also update stocks-trading-basic.ipynb / options-trading-basic.ipynb / options-trading-mleg.ipynb?

Comment on lines 42 to 68
"import pandas as pd\n",
"import pandas_ta as ta # The installment of pandas-ta may be tricky. Please find the pypi page here (https://pypi.org/project/pandas-ta/)\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"from datetime import datetime, timedelta\n",
"from zoneinfo import ZoneInfo\n",
"\n",
"import alpaca\n",
"from alpaca.data.timeframe import TimeFrame, TimeFrameUnit\n",
"from alpaca.data.historical.crypto import CryptoHistoricalDataClient\n",
"\n",
"from alpaca.data.requests import (\n",
" CryptoBarsRequest,\n",
" CryptoQuoteRequest,\n",
" CryptoTradesRequest,\n",
" CryptoLatestQuoteRequest\n",
" )\n",
"from alpaca.trading.client import TradingClient\n",
"from alpaca.trading.requests import MarketOrderRequest, LimitOrderRequest\n",
"from alpaca.trading.enums import (\n",
" AssetClass,\n",
" AssetStatus,\n",
" OrderSide,\n",
" OrderType,\n",
" TimeInForce,\n",
" QueryOrderStatus\n",
")"
Copy link
Contributor

@hiohiohio hiohiohio Apr 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor: How about applying isort?

Comment on lines 157 to 158
"df = bars_date.copy()\n",
"df.head()"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about adding a comment to explain the reason of using .copy() here?
In my understanding, if we copy here, we do not need to fetch data (i.e. bars_date) again within same session. It might make easy to change and check below codes if user want to tweak.

"metadata": {},
"outputs": [],
"source": [
"# Define EMA periods\n",
Copy link
Contributor

@hiohiohio hiohiohio Apr 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about adding explanation of abbreviation for EMA similar to SMA / ATR / ADX?

"metadata": {},
"outputs": [],
"source": [
"# Get the latest price of the underlying stock\n",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"# Get the latest price of the underlying stock\n",
"# Get the estimated buying cost of BTC/USD with given qty\n",

@idsts2670
Copy link
Contributor Author

Updated the notebooks and README.md per review

@hiohiohio hiohiohio merged commit 168c338 into alpacahq:master Apr 24, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants