Python package, for communicating with Alpaca Markets REST API.
Project description
PY-ALPACA-API
Empowering traders with precision and control.
Table of Contents
Overview
Py-alpaca-api is a robust Python library facilitating seamless interaction with the Alpaca Markets REST API. It empowers developers to manage accounts, assets, market data, orders, and positions efficiently. By leveraging key modules like position, order, and history, users can access historical market data, analyze trends, and make informed trading decisions. With a focus on modularity and ease of use, this open-source project delivers essential functionalities for enhancing trading platforms and enabling strategic decision-making within the financial realm.
Features
Feature | Description | |
---|---|---|
โ๏ธ | Architecture | The project follows a modular architecture design, allowing for separate components such as Account, Asset, Market, and Order handling. It initializes with API Key, Secret, and Paper Trading options. |
๐ฉ | Code Quality | The codebase maintains good code quality with consistent style and formatting. It integrates tools like Black for code formatting and Flake8 for linting. |
๐ | Documentation | The project has extensive documentation covering various modules such as Account, Asset, and History. It provides detailed explanations of methods, parameters, and usage instructions. |
๐ | Integrations | Key integrations include requests for HTTP requests, pandas for data manipulation, and pytest for testing. It also leverages Alpaca Markets REST API for financial data interaction. |
๐งฉ | Modularity | The codebase is highly modular, with separate modules for different functionalities like Position, Order, and Market data retrieval. This promotes code reusability and maintainability. |
๐งช | Testing | The project utilizes pytest for unit testing and requests-mock for mocking HTTP requests. GitHub Actions automate testing workflows for ensuring code integrity. |
โก๏ธ | Performance | The codebase efficiently handles data retrieval and processing, ensuring smooth interaction with the Alpaca API endpoints. Performance optimizations are achieved through streamlined historical data retrieval and market status updates. |
๐ก๏ธ | Security | Security measures include handling authentication securely through API Key and Secret. The project emphasizes data protection and access control by managing account and asset information securely. |
๐ฆ | Dependencies | Key external libraries and dependencies include requests, pandas, numpy for data manipulation, and pytest for testing. Additional tools like pre-commit and poetry enhance development workflows. |
Repository Structure
โโโ py-alpaca-api/
โโโ .github
โ โโโ ISSUE_TEMPLATE
โ โ โโโ bug_report.md
โ โ โโโ custom.md
โ โ โโโ feature_request.md
โ โโโ workflows
โ โโโ test-package.yml
โโโ CODE_OF_CONDUCT.md
โโโ CONTRIBUTING.md
โโโ LICENSE
โโโ README.md
โโโ SECURITY.md
โโโ docs
โ โโโ Makefile
โ โโโ make.bat
โ โโโ rtd_requirements.txt
โ โโโ source
โ โโโ conf.py
โ โโโ index.md
โ โโโ notebooks
โโโ poetry.lock
โโโ py_alpaca_api
โ โโโ __init__.py
โ โโโ alpaca.py
โ โโโ src
โ โโโ __init__.py
โ โโโ account.py
โ โโโ asset.py
โ โโโ data_classes.py
โ โโโ history.py
โ โโโ market.py
โ โโโ order.py
โ โโโ position.py
โโโ pyproject.toml
โโโ requirements.txt
โโโ tests
โโโ __init__.py
โโโ test_account.py
โโโ test_alpaca.py
โโโ test_asset.py
โโโ test_historical_data.py
โโโ test_market.py
โโโ test_orders.py
โโโ test_positions.py
Modules
.
File | Summary |
---|---|
requirements.txt | Ensures Python dependencies are managed for the repository, restricting versions to specific ranges. Facilitates compatibility and stable functioning by defining required packages for the Alpaca API project. |
pyproject.toml | Enables interaction with Alpaca Markets REST API. Manages account, asset, market data, orders, and positions. Supports Python 3.12, pandas, requests, and numpy. Integrates testing, linting, and documentation tools. |
py_alpaca_api
File | Summary |
---|---|
alpaca.py | Defines PyAlpacaApi class, initializing with API Key, Secret, and Paper Trading option. Sets URLs based on trading mode and initializes Account, Asset, History, Position, Order, and Market objects for interacting with Alpaca API endpoints. |
py_alpaca_api.src
File | Summary |
---|---|
position.py | Retrieves and processes account positions from Alpaca API. Includes functions to get all positions as a DataFrame, retrieve a specific position, close all positions, and close a specific position by symbol or ID. |
order.py | SummaryThis code file, history.py , plays a crucial role in the py-alpaca-api repository by providing essential functionalities related to historical market data retrieval and analysis within the Alpaca API ecosystem. By leveraging this module, developers can efficiently access and process historical data for strategic decision-making, enhancing the overall capabilities of the trading platform. |
market.py | Retrieves market clock status via HTTP GET request, handling successful and failed responses. Integrated with Alpaca API for real-time market data. |
history.py | Retrieve historical stock data from Alpaca API based on specified parameters. Validates asset information, handles timeframe conversions, sends API request with required parameters, and converts response to a structured DataFrame. Ensures error handling for data availability, asset validation, and API response. |
data_classes.py | This code file, data_classes.py , plays a critical role in defining the data structures and classes essential for modeling various financial assets and market data within the py-alpaca-api repository. By encapsulating the core data elements and relationships, this module sets the foundation for consistent and organized representation of data throughout the project. |
asset.py | Retrieves asset information from the Alpaca API based on the provided symbol. Parses the response into an AssetClass object containing essential details like ID, exchange, status, and more. Signals errors if retrieval fails. |
account.py | Retrieves account information from Alpaca API, mapping it to an AccountClass object in JSON format. Handles successful and failed responses gracefully within the repositorys modular architecture. |
.github.workflows
File | Summary |
---|---|
test-package.yml | Tests package dependencies and ensures code integrity through automated workflows. Orchestrates testing for account, asset, historical data, market, orders, and positions modules. Facilitates CI/CD integration for robust repository maintenance. |
Getting Started
System Requirements:
- Python:
version x.y.z
Installation
From source
- Clone the py-alpaca-api repository:
$ git clone https://github.com/TexasCoding/py-alpaca-api
- Change to the project directory:
$ cd py-alpaca-api
- Install the dependencies:
$ poetry install
Usage
From source
Run py-alpaca-api using the command below:
from py_alpaca_api import PyAlpacaApi api = PyAlpacaApi(api_key='YOUR_KEY', api_secret='YOUR_SECRET', api_paper=True) positions = api.position.get_all() orders = api.order.get_all() # Create new order order = api.order.market(symbol='AAPL', qty=1.034, side='buy')
Tests
Run the test suite using the command below:
$ pytest
Project Roadmap
-
โบ Create functionality for all Alpaca API resources
Contributing
Contributions are welcome! Here are several ways you can contribute:
- Report Issues: Submit bugs found or log feature requests for the
py-alpaca-api
project. - Submit Pull Requests: Review open PRs, and submit your own PRs.
- Join the Discussions: Share your insights, provide feedback, or ask questions.
Contributing Guidelines
- Fork the Repository: Start by forking the project repository to your github account.
- Clone Locally: Clone the forked repository to your local machine using a git client.
git clone https://github.com/TexasCoding/py-alpaca-api
- Create a New Branch: Always work on a new branch, giving it a descriptive name.
git checkout -b new-feature-x
- Make Your Changes: Develop and test your changes locally.
- Commit Your Changes: Commit with a clear message describing your updates.
git commit -m 'Implemented new feature x.'
- Push to github: Push the changes to your forked repository.
git push origin new-feature-x
- Submit a Pull Request: Create a PR against the original project repository. Clearly describe the changes and their motivations.
- Review: Once your PR is reviewed and approved, it will be merged into the main branch. Congratulations on your contribution!
License
This project is protected under the SELECT-A-LICENSE License. For more details, refer to the LICENSE file.
Acknowledgments
- List any resources, contributors, inspiration, etc. here.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file py_alpaca_api-0.4.4.tar.gz
.
File metadata
- Download URL: py_alpaca_api-0.4.4.tar.gz
- Upload date:
- Size: 24.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.2 CPython/3.12.3 Linux/5.15.146.1-microsoft-standard-WSL2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c732e29bc977a1d661137a0ab5ccbcc2312e8635656671a27b1410fc45e21a46 |
|
MD5 | d8551a889caae87cb68cc0d7c610b6bb |
|
BLAKE2b-256 | 7d99edc1728807fef4ef44090313ddb003e2170c6ddd4e92b76119500b2b0f3a |
File details
Details for the file py_alpaca_api-0.4.4-py3-none-any.whl
.
File metadata
- Download URL: py_alpaca_api-0.4.4-py3-none-any.whl
- Upload date:
- Size: 26.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.2 CPython/3.12.3 Linux/5.15.146.1-microsoft-standard-WSL2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 57c0d90d643695cd48d7b8138f17bcde01919146d3a377153bd76b189a764f52 |
|
MD5 | 708f3532b13dc157ac1428fe34e39873 |
|
BLAKE2b-256 | 05a8f022235b317585962f8c0a99aa11f331777b4bd315b9b8090e171c110a52 |