{"id":31655510,"url":"https://github.com/quantum-encoding/zig-alpaca-trading","last_synced_at":"2025-10-07T13:15:02.394Z","repository":{"id":314790047,"uuid":"1054798320","full_name":"quantum-encoding/zig-alpaca-trading","owner":"quantum-encoding","description":"Production-grade Alpaca Markets API client for Zig. Build algorithmic trading systems with deterministic performance and zero GC pauses.","archived":false,"fork":false,"pushed_at":"2025-09-14T18:59:10.000Z","size":2807,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-09-14T20:47:11.297Z","etag":null,"topics":["algorithmic-trading","alpaca-markets","api-client","hft","quantitative-finance","trading-bot","zig"],"latest_commit_sha":null,"homepage":"https://quantumencoding.io","language":"Zig","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/quantum-encoding.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-09-11T10:48:07.000Z","updated_at":"2025-09-14T18:59:14.000Z","dependencies_parsed_at":"2025-09-14T20:47:12.975Z","dependency_job_id":"71bc86b3-b166-4090-816c-a290f3e009c5","html_url":"https://github.com/quantum-encoding/zig-alpaca-trading","commit_stats":null,"previous_names":["quantum-encoding/zig-alpaca-trading"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/quantum-encoding/zig-alpaca-trading","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/quantum-encoding%2Fzig-alpaca-trading","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/quantum-encoding%2Fzig-alpaca-trading/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/quantum-encoding%2Fzig-alpaca-trading/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/quantum-encoding%2Fzig-alpaca-trading/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/quantum-encoding","download_url":"https://codeload.github.com/quantum-encoding/zig-alpaca-trading/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/quantum-encoding%2Fzig-alpaca-trading/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278780080,"owners_count":26044494,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-07T02:00:06.786Z","response_time":59,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["algorithmic-trading","alpaca-markets","api-client","hft","quantitative-finance","trading-bot","zig"],"created_at":"2025-10-07T13:14:59.811Z","updated_at":"2025-10-07T13:15:02.379Z","avatar_url":"https://github.com/quantum-encoding.png","language":"Zig","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Quantum Alpaca Zig\n\nA high-performance, thread-safe Alpaca Markets API client for Zig 0.16.0, designed for algorithmic trading systems.\n\n## Features\n\n- **Complete API Coverage**: Account, positions, orders, and market data endpoints\n- **Thread-Safe Architecture**: Designed for concurrent trading strategies\n- **Type-Safe**: Strongly typed request/response structures\n- **High Performance**: Optimized for low-latency trading operations\n- **Memory Safe**: Automatic memory management with proper cleanup\n- **Production Ready**: Battle-tested in real trading environments\n\n## Installation\n\nAdd this library to your `build.zig.zon`:\n\n```zig\n.dependencies = .{\n    .quantum_alpaca = .{\n        .url = \"https://github.com/YOUR_USERNAME/quantum-alpaca-zig/archive/refs/tags/v1.0.0.tar.gz\",\n        .hash = \"YOUR_HASH_HERE\",\n    },\n},\n```\n\nThen in your `build.zig`:\n\n```zig\nconst quantum_alpaca = b.dependency(\"quantum_alpaca\", .{\n    .target = target,\n    .optimize = optimize,\n});\nexe.root_module.addImport(\"quantum-alpaca\", quantum_alpaca.module(\"quantum-alpaca\"));\n```\n\n## Production Deployment\n\n```zig\nconst std = @import(\"std\");\nconst AlpacaClient = @import(\"quantum-alpaca\").AlpacaClient;\n\npub fn main() !void {\n    var gpa = std.heap.GeneralPurposeAllocator(.{}){};\n    defer _ = gpa.deinit();\n    const allocator = gpa.allocator();\n\n    // Initialize client\n    var client = AlpacaClient.init(\n        allocator,\n        \"YOUR_API_KEY\",\n        \"YOUR_SECRET_KEY\",\n        .paper, // or .live for production\n    );\n    defer client.deinit();\n\n    // Get account info\n    var account = try client.getAccount();\n    defer account.deinit();\n    \n    // Submit an order\n    const order = AlpacaClient.OrderRequest{\n        .symbol = \"AAPL\",\n        .qty = 10,\n        .side = \"buy\",\n        .type = \"limit\",\n        .time_in_force = \"day\",\n        .limit_price = 150.00,\n    };\n    \n    var response = try client.submitOrder(order);\n    defer response.deinit();\n}\n```\n\n## API Reference\n\n### Client Initialization\n\n```zig\nvar client = AlpacaClient.init(allocator, api_key, secret_key, environment);\ndefer client.deinit();\n```\n\nEnvironments:\n- `.paper` - Paper trading (testing)\n- `.live` - Live trading (production)\n\n### Account Management\n\n```zig\n// Get account information\nvar response = try client.getAccount();\n\n// Get portfolio history\nvar response = try client.getPortfolioHistory(\"1M\", \"1D\");\n```\n\n### Position Management\n\n```zig\n// Get all positions\nvar response = try client.getPositions();\n\n// Get specific position\nvar response = try client.getPosition(\"AAPL\");\n\n// Close position\nvar response = try client.closePosition(\"AAPL\");\n\n// Close all positions\nvar response = try client.closeAllPositions();\n```\n\n### Order Management\n\n```zig\n// Submit order\nconst order = AlpacaClient.OrderRequest{\n    .symbol = \"AAPL\",\n    .qty = 10,\n    .side = \"buy\",\n    .type = \"limit\",\n    .time_in_force = \"day\",\n    .limit_price = 150.00,\n};\nvar response = try client.submitOrder(order);\n\n// Get all orders\nvar response = try client.getOrders();\n\n// Get specific order\nvar response = try client.getOrder(order_id);\n\n// Cancel order\nvar response = try client.cancelOrder(order_id);\n\n// Cancel all orders\nvar response = try client.cancelAllOrders();\n```\n\n### Market Data\n\n```zig\n// Get latest quote\nvar response = try client.getLatestQuote(\"AAPL\");\n\n// Get latest trade\nvar response = try client.getLatestTrade(\"AAPL\");\n\n// Get bars (candlestick data)\nvar response = try client.getBars(\"AAPL\", \"1Day\", \"2024-01-01\", \"2024-01-31\", 30);\n```\n\n### Market Hours\n\n```zig\n// Get market clock\nvar response = try client.getClock();\n\n// Get market calendar\nvar response = try client.getCalendar();\n```\n\n## Order Types\n\n### Production Market Order\n```zig\nconst order = AlpacaClient.OrderRequest{\n    .symbol = \"AAPL\",\n    .qty = 10,\n    .side = \"buy\",\n    .type = \"market\",\n    .time_in_force = \"day\",\n};\n```\n\n### Production Limit Order\n```zig\nconst order = AlpacaClient.OrderRequest{\n    .symbol = \"AAPL\",\n    .qty = 10,\n    .side = \"buy\",\n    .type = \"limit\",\n    .time_in_force = \"day\",\n    .limit_price = 150.00,\n};\n```\n\n### Production Stop Order\n```zig\nconst order = AlpacaClient.OrderRequest{\n    .symbol = \"AAPL\",\n    .qty = 10,\n    .side = \"sell\",\n    .type = \"stop\",\n    .time_in_force = \"day\",\n    .stop_price = 145.00,\n};\n```\n\n### Production Bracket Order\n```zig\nconst order = AlpacaClient.OrderRequest{\n    .symbol = \"AAPL\",\n    .qty = 10,\n    .side = \"buy\",\n    .type = \"limit\",\n    .time_in_force = \"day\",\n    .limit_price = 150.00,\n    .order_class = \"bracket\",\n    .take_profit = .{ .limit_price = 155.00 },\n    .stop_loss = .{ .stop_price = 145.00 },\n};\n```\n\n## Thread Safety\n\nEach thread should create its own `AlpacaClient` instance:\n\n```zig\nfn tradingThread(allocator: std.mem.Allocator, api_key: []const u8, secret: []const u8) void {\n    var client = AlpacaClient.init(allocator, api_key, secret, .paper);\n    defer client.deinit();\n    \n    // Trading logic here...\n}\n```\n\n## Environment Variables\n\nSet your API credentials as environment variables:\n\n```bash\nexport ALPACA_API_KEY=\"your_api_key\"\nexport ALPACA_SECRET_KEY=\"your_secret_key\"\n```\n\nThen in your code:\n```zig\nconst api_key = try std.process.getEnvVarOwned(allocator, \"ALPACA_API_KEY\");\nconst secret = try std.process.getEnvVarOwned(allocator, \"ALPACA_SECRET_KEY\");\n```\n\n## Error Handling\n\nAll methods return a `Response` that includes the HTTP status code:\n\n```zig\nvar response = try client.getAccount();\ndefer response.deinit();\n\nif (response.status == .ok) {\n    // Success\n    const account = try response.json(AlpacaClient.Account);\n    defer account.deinit();\n} else {\n    // Handle error\n    std.debug.print(\"Error: {}\\n\", .{response.status});\n}\n```\n\n## Rate Limiting\n\nAlpaca has rate limits. This client does not implement automatic retry logic, allowing you to implement your own strategy:\n\n- Trading API: 200 requests per minute\n- Data API: Variable based on subscription\n\n## Testing\n\nRun tests:\n```bash\nzig build test\n```\n\nRun examples (requires API keys):\n```bash\nexport ALPACA_API_KEY=\"your_key\"\nexport ALPACA_SECRET_KEY=\"your_secret\"\nzig build example\n```\n\n## Performance Notes\n\nThis client is optimized for:\n- Low-latency order submission\n- High-throughput data processing\n- Minimal memory allocations\n- Thread-safe concurrent operations\n\n## License\n\nMIT License - See LICENSE file for details\n\n## Disclaimer\n\nThis software is for educational and research purposes. Always test thoroughly with paper trading before using in production. The authors are not responsible for any financial losses incurred through the use of this software.\n\n## Acknowledgments\n\nBuilt for high-frequency trading systems where every microsecond counts.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fquantum-encoding%2Fzig-alpaca-trading","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fquantum-encoding%2Fzig-alpaca-trading","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fquantum-encoding%2Fzig-alpaca-trading/lists"}