A powerful integration between Alpaca and Zorro, enabling algorithmic trading with real-time market data, paper trading, and live trading capabilities.
- Features
- Installation
- Quick Start
- Configuration
- Usage Examples
- API Reference
- Building from Source
- Troubleshooting
- Contributing
- License
- âś… Real-time Market Data via Alpaca Market Data API V2
- âś… WebSocket Support with multi-instance connection sharing
- âś… Paper & Live Trading - Test strategies safely before going live
- âś… Multiple Order Types - Market, Limit, Stop, Stop-Limit
- âś… Time-in-Force Options - FOK, IOC, GTC, DAY, OPG, CLS
- âś… Fractional Shares - Trade fractional quantities (e.g., 0.001 shares)
- âś… Asset Types - Stocks, Options, Crypto
- âś… Historical Data - Download bars with adjustments (splits, dividends)
- âś… Runtime Configuration - F2 settings dialog for log level changes
- âś… x86 & x64 Support - Works with both 32-bit and 64-bit Zorro
The plugin includes ZorroWebsocketProxy, allowing multiple Zorro instances to share a single WebSocket connection:
- Lock-free design for high performance
- Automatic connection management
- Reduced API rate limits by sharing connections
- Note: High CPU usage is normal due to lock-free spinning design
- Zorro (version 2.30 or higher recommended)
- Alpaca account with API credentials
- Windows 10/11 (x86 or x64)
-
Download the latest release
-
Extract the downloaded ZIP file
-
Copy files to Zorro directory:
- For x86 (32-bit):
Alpaca.dll→<Zorro>/Plugin/websocket_proxy/→<Zorro>/Plugin/websocket_proxy/
- For x64 (64-bit):
Alpaca.dll→<Zorro>/Plugin64/websocket_proxy/→<Zorro>/Plugin/websocket_proxy/
- For x86 (32-bit):
-
Copy header file (optional, for advanced usage):
AlpacaBrokerCommands.h→<Zorro>/include/
- Sign up at Alpaca Markets
- Navigate to Paper Trading or Live Trading dashboard
- Generate API Key and Secret Key
- Launch Zorro
- Select Alpaca from the broker dropdown
- Enter credentials:
- User ID: Your Alpaca API Key
- Password: Your Alpaca Secret Key
- Press F2 to open settings dialog (optional)
// SimpleAlpacaStrategy.c
function run()
{
set(LOGFILE);
BarPeriod = 60; // 1-hour bars
asset("SPY");
if(crossOver(SMA(12), SMA(26))) {
enterLong();
}
else if(crossUnder(SMA(12), SMA(26))) {
enterShort();
}
}Add the following optional configurations to ZorroFix.ini (preferred) or Zorro.ini:
AlpacaPaidDataPlan = 1 # 0 = Basic (Free), 1 = Pro (Paid). Default: 1
AlpacaLogLevel = 0 # 0=OFF, 1=ERROR, 2=WARN, 3=INFO, 4=DEBUG, 5=TRACE. Default: 0
AlpacaUseWebsocket = 1 # 0 = REST API only, 1 = WebSocket. Default: 1
AlpacaFractionalLotAmount = 1.0 # Lot multiplier for fractional shares. Default: 1.0
AlpacaPassLogLevelToWebsocketProxy = 0 # Passing Log Level to WebsocketProxy. 0 = No, 1 = Yes. Default: 0| Parameter | Description | Values | Default |
|---|---|---|---|
| AlpacaPaidDataPlan | Market data plan tier | 0 = Basic (Free) 1 = Pro (Paid) |
1 |
| AlpacaLogLevel | Plugin logging verbosity | 0 = OFF 1 = ERROR 2 = WARNING 3 = INFO 4 = DEBUG 5 = TRACE |
0 |
| AlpacaLogType | Types of data to log | Bitmask value | ALL except WEB_SOCKET_DATA |
| AlpacaUseWebsocket | Real-time data method | 0 = REST polling 1 = WebSocket streaming |
1 |
| AlpacaFractionalLotAmount | Fractional trading multiplier | Any value < 1.0 enables fractional shares (e.g., 0.001 = 0.1% of 1 share) |
1.0 |
| AlpacaPassLogLevelToWebsocketProxy | WebSocket proxy log level | Same as AlpacaLogLevel | 0 |
Press F2 in Zorro to open the plugin settings dialog where you can:
- Adjust log levels without restarting
- View current configuration
- Test connection status
// Simple market orders
enterLong(5); // Buy 5 lots at market price
enterShort(5); // Sell 5 lots at market price// Place limit orders
OrderLimit = 100.00; // Set limit price
enterLong(5); // Buy 5 lots at $100.00 limit
OrderLimit = 200.00;
enterShort(3); // Sell 3 lots at $200.00 limitSupported TIF types: FOK (default), IOC, GTC, DAY, OPG, CLS
See Alpaca Orders Documentation for details.
#include <AlpacaBrokerCommands.h>
// Day order with limit price
brokerCommand(SET_ORDERTYPE, ORDERTYPE_DAY);
OrderLimit = 100.00;
enterShort(5); // Sell 5 lots, Day order at $100.00 limit
// Market-on-Close order
OrderLimit = 0; // Market order
brokerCommand(SET_ORDERTYPE, ORDERTYPE_CLS);
enterLong(5); // Buy 5 lots at market closeAvailable TIF Types:
ORDERTYPE_FOK- Fill-or-Kill (default)ORDERTYPE_IOC- Immediate-or-CancelORDERTYPE_GTC- Good-till-CanceledORDERTYPE_DAY- Day orderORDERTYPE_OPG- Market-on-OpenORDERTYPE_CLS- Market-on-Close
// Use Last Trade price (default is Last Quote)
brokerCommand(SET_PRICETYPE, 2); // Trades
brokerCommand(SET_PRICETYPE, 1); // Quotes (Ask/Bid)// ZorroFix.ini: AlpacaFractionalLotAmount = 0.001
#include <AlpacaBrokerCommands.h>
asset("TSLA");
brokerCommand(SET_ORDERTYPE, ORDERTYPE_DAY); // Required for fractional
LotAmount = 5;
enterLong(); // Buys 0.005 shares of TSLA (5 * 0.001)Note: Fractional trading only works with Market and Day order types.
// Add custom identifier to orders
brokerCommand(SET_ORDERTEXT, "MyStrategy_v1");
enterLong(5); // Order will have "MyStrategy_v1" in ClientOrderId// Get current position for specific asset
var position = brokerCommand(GET_POSITION, "AAPL");
printf("AAPL position: %.2f", position);#include <AlpacaBrokerCommands.h>
asset("GME");
// Check asset capabilities
int isFractionable = brokerCommand(IS_ASSET_FRACTIONABLE, Asset);
int isShortable = brokerCommand(IS_ASSET_SHORTABLE, Asset);
int isEasyToBorrow = brokerCommand(IS_ASSET_EASY_TO_BORROW, Asset);
int isMarginable = brokerCommand(IS_ASSET_MARGINABLE, Asset);
if(isFractionable) {
printf("GME supports fractional shares");
}#include <AlpacaBrokerCommands.h>
// Set adjustment type for historical bars
brokerCommand(SET_ADJUSTMENT, ADJUSTMENT_SPLIT); // Split-adjusted only
// Available adjustment types:
// ADJUSTMENT_RAW - 0 (no adjustments)
// ADJUSTMENT_SPLIT - 1 (split-adjusted)
// ADJUSTMENT_DIVIDEND - 2 (dividend-adjusted)
// ADJUSTMENT_ALL - 3 (both splits and dividends)#include <AlpacaBrokerCommands.h>
function main()
{
// Generate CSV for specific symbols
brokerCommand(CREATE_ASSETLIST, "SPY,AAPL,MSFT,TSLA");
// Or generate for all tradeable assets
// brokerCommand(CREATE_ASSETLIST, 0);
// Output: AssetAlpaca.csv in Log directory
}| Function | Description |
|---|---|
BrokerOpen |
Initialize broker connection |
BrokerHTTP |
HTTP communication with Alpaca API |
BrokerLogin |
Authenticate with API credentials |
BrokerTime |
Get current market time |
BrokerAsset |
Retrieve asset information |
BrokerHistory2 |
Download historical bar data |
BrokerBuy2 |
Place buy orders |
BrokerTrade |
Manage trade operations |
BrokerCommand |
Execute plugin-specific commands |
| Command | Description |
|---|---|
GET_COMPLIANCE |
Get NFA compiance |
GET_MAXTICKS |
Get max ticks per request |
GET_MAXREQUESTS |
Get max requests per period |
GET_LOCK |
Get resource lock |
GET_POSITION |
Get position for asset |
GET_PRICETYPE |
Get current price type |
GET_VOLTYPE |
Get volume type |
SET_ORDERTEXT |
Set custom order text |
SET_SYMBOL |
Set trading symbol |
SET_ORDERTYPE |
Set order TIF type |
SET_PRICETYPE |
Set price type (quote/trade) |
SET_DIAGNOSTICS |
Enable diagnostic mode |
SET_ADJUSTMENT |
Set historical data adjustment |
IS_ASSET_FRACTIONABLE |
Check if asset supports fractional shares |
IS_ASSET_SHORTABLE |
Check if asset is shortable |
IS_ASSET_EASY_TO_BORROW |
Check borrow availability |
IS_ASSET_MARGINABLE |
Check margin eligibility |
CREATE_ASSETLIST |
Generate asset list CSV |
See BUILD.md for detailed build instructions.
git clone https://github.com/kzhdev/alpaca_zorro_plugin.git
cd alpaca_zorro_plugin
cmake -B build -G "Visual Studio 17 2022" -A Win32
cmake --build build --config ReleaseProblem: Plugin doesn't load in Zorro
- Solution: Ensure DLL is in correct folder (
Plugin/for x86,Plugin64/for x64) - Verify
websocket_proxyfolder is also copied
Problem: WebSocket not connecting
- Solution: Check firewall settings
- Verify API credentials are correct
- Ensure
AlpacaUseWebsocket = 1in config
Problem: "Invalid API Key" error
- Solution: Regenerate API keys in Alpaca dashboard
- Ensure using Paper keys for paper trading, Live keys for live trading
Problem: High CPU usage
- Solution: This is normal for WebSocket Proxy (lock-free design)
- If problematic, disable WebSocket:
AlpacaUseWebsocket = 0
Problem: Orders not executing
- Solution: Check market hours
- Verify account has sufficient buying power
- Check if asset is tradeable (use
IS_ASSET_*commands)
Enable detailed logging to diagnose issues:
# In ZorroFix.ini
AlpacaLogLevel = 5 # TRACE levelLogs are saved to: <Zorro>/Log/
Contributions are welcome! Please see CONTRIBUTING.md for guidelines.
- Fork the repository
- Create a feature branch
- Make your changes
- Build and test thoroughly
- Submit a pull request
- Issues: GitHub Issues
- Discussions: GitHub Discussions
- Alpaca Docs: Alpaca Documentation
- Zorro Docs: Zorro Manual
This project is licensed under the MIT License - see the LICENSE file for details.
- Alpaca Markets for their excellent trading API
- Zorro for the algorithmic trading platform
- All contributors who have helped improve this plugin
Disclaimer: Trading involves risk. This plugin is provided as-is without warranties. Always test strategies thoroughly in paper trading before going live.