Skip to content
Open
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
c6aea17
Remove alpaca-trade-api from pyproject.toml
kuds Aug 30, 2025
b3a29e3
Replace 'alpaca_trade_api' with 'alpaca' import
kuds Aug 30, 2025
1d41361
Remove alpaca_trade_api from requirements.txt
kuds Aug 30, 2025
949d3d6
Change import from 'alpaca_trade_api' to 'alpaca'
kuds Aug 30, 2025
e8a95c1
Change import from alpaca_trade_api to alpaca
kuds Aug 30, 2025
d5820ac
Clean up imports in processor_alpaca.py
kuds Aug 30, 2025
c99b9fb
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 30, 2025
1e46a22
Clean up package installation commands in notebook
kuds Sep 5, 2025
decdadd
Clean up installation commands in demo notebook
kuds Sep 8, 2025
d810063
Update Alpaca API integration to use TradingClient
kuds Sep 8, 2025
d73afd7
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 8, 2025
47805eb
Update Colab link in PaperTrading demo notebook
kuds Sep 10, 2025
a65da26
Remove unused alpaca import from alpaca.py
kuds Sep 11, 2025
2f1aced
Update order retrieval to use new request method
kuds Sep 11, 2025
01548f1
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 11, 2025
ff36026
Update typing and replace old alpaca python sdk with new version
kuds Sep 11, 2025
d3b4066
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 11, 2025
151603f
Remove API_BASE_URL parameter from AlpacaProcessor
kuds Sep 11, 2025
169b6c9
Fix column reference for renaming in processor_alpaca
kuds Sep 11, 2025
3f5e153
Correct assignment of barset for data processing
kuds Sep 11, 2025
5634761
Refactor Alpaca API integration in paper trading
kuds Sep 11, 2025
ff6eeca
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 11, 2025
5d07950
Skip processing for single column DataFrame
kuds Sep 11, 2025
05951e5
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 11, 2025
934bd66
Refactor Alpaca API integration for portfolio history
kuds Sep 11, 2025
2dc4c3d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 11, 2025
2854b10
Fix elevation methods at the end to use new Aplaca-py sdk
kuds Sep 11, 2025
98ed7bf
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 11, 2025
cbbcc79
Update Colab link in PaperTrading demo notebook
kuds Sep 11, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3,706 changes: 1,819 additions & 1,887 deletions examples/FinRL_PaperTrading_Demo.ipynb

Large diffs are not rendered by default.

9 changes: 0 additions & 9 deletions examples/Stock_NeurIPS2018_SB3.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -224,15 +224,6 @@
],
"source": [
"## install required packages\n",
"\n",
"!pip install swig\n",
"!pip install wrds\n",
"!pip install pyportfolioopt\n",
"## install finrl library\n",
"!pip install -q condacolab\n",
"import condacolab\n",
"condacolab.install()\n",
"!apt-get update -y -qq && apt-get install -y -qq cmake libopenmpi-dev python3-dev zlib1g-dev libgl1-mesa-glx swig\n",
"!pip install git+https://github.com/AI4Finance-Foundation/FinRL.git"
]
},
Expand Down
2 changes: 0 additions & 2 deletions finrl/meta/data_processors/processor_alpaca.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
from alpaca.data.timeframe import TimeFrame
from stockstats import StockDataFrame as Sdf

# import alpaca_trade_api as tradeapi


class AlpacaProcessor:
def __init__(self, API_KEY=None, API_SECRET=None, API_BASE_URL=None, client=None):
Expand Down
2 changes: 1 addition & 1 deletion finrl/meta/env_stock_trading/env_stock_papertrading.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import threading
import time

import alpaca_trade_api as tradeapi
import alpaca as tradeapi
import gymnasium as gym
import numpy as np
import pandas as pd
Expand Down
23 changes: 16 additions & 7 deletions finrl/meta/paper_trading/alpaca.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@
import threading
import time

import alpaca_trade_api as tradeapi
import gym
import gymnasium as gym
import numpy as np
import pandas as pd
import torch
from alpaca.trading.client import TradingClient
from alpaca.trading.enums import OrderSide
from alpaca.trading.enums import QueryOrderStatus
from alpaca.trading.requests import GetOrdersRequest

from finrl.meta.data_processors.processor_alpaca import AlpacaProcessor
from finrl.meta.paper_trading.common import AgentPPO
Expand Down Expand Up @@ -94,7 +97,9 @@ def __init__(

# connect to Alpaca trading API
try:
self.alpaca = tradeapi.REST(API_KEY, API_SECRET, API_BASE_URL, "v2")
self.alpaca = TradingClient(
api_key=API_KEY, secret_key=SECRET_KEY, paper=True
)
except:
raise ValueError(
"Fail to connect Alpaca. Please check account info and internet connection."
Expand Down Expand Up @@ -145,7 +150,11 @@ def test_latency(self, test_times=10):
return latency

def run(self):
orders = self.alpaca.list_orders(status="open")
# params to filter orders by
request_params = GetOrdersRequest(status=QueryOrderStatus.OPEN)

# orders that satisfy params
orders = self.alpaca.get_orders(filter=request_params)
for order in orders:
self.alpaca.cancel_order(order.id)

Expand All @@ -168,7 +177,7 @@ def run(self):
print("Market closing soon. Closing positions.")

threads = []
positions = self.alpaca.list_positions()
positions = self.alpaca.get_all_positions()
for position in positions:
if position.side == "long":
orderSide = "sell"
Expand Down Expand Up @@ -280,7 +289,7 @@ def trade(self):

else: # sell all when turbulence
threads = []
positions = self.alpaca.list_positions()
positions = self.alpaca.get_all_positions()
for position in positions:
if position.side == "long":
orderSide = "sell"
Expand Down Expand Up @@ -313,7 +322,7 @@ def get_state(self):
).astype(np.float32)

tech = tech * 2**-7
positions = self.alpaca.list_positions()
positions = self.alpaca.get_all_positions()
stocks = [0] * len(self.stockUniverse)
for position in positions:
ind = self.stockUniverse.index(position.symbol)
Expand Down
2 changes: 1 addition & 1 deletion finrl/meta/paper_trading/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -798,7 +798,7 @@ def test(

# -----------------------------------------------------------------------------------------------------------------------------------------

import alpaca_trade_api as tradeapi
import alpaca as tradeapi
import pandas_market_calendars as tc
import numpy as np
import pandas as pd
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ github = "https://github.com/finrl/finrl-library"
[tool.poetry.dependencies]
python = "^3.7"
elegantrl = {git="https://github.com/AI4Finance-Foundation/ElegantRL.git#egg=elegantrl"}
alpaca-trade-api = "^3"
ccxt = "^3"
jqdatasdk = "^1"
pyfolio-reloaded = "^0.9"
Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
alpaca-py
alpaca_trade_api>=2.1.0
ccxt>=1.66.32
elegantrl

Expand Down