Skip to main content

Python package, for communicating with Alpaca Markets REST API.

Project description

project-logo

PY-ALPACA-API

Empower Trading with Seamless Alpaca API Integration

GitHub Actions Workflow Status license last-commit repo-top-language repo-language-count

Python Poetry


Table of Contents

Overview

The py-alpaca-api project provides a comprehensive Python interface for seamless interaction with the Alpaca API, offering functionalities such as accessing account information, retrieving asset data, managing market details, executing orders, and analyzing stock performance. By encapsulating key components like account, asset, order, and market classes, this project facilitates efficient data retrieval, trading operations, and market analysis within the Alpaca ecosystem. Integrated with GitHub Actions for testing integrity, py-alpaca-api enhances developers capabilities in integrating Alpacas features into diverse projects, emphasizing simplicity and reliability in financial data processing and trading activities.


Features

Feature Description
⚙️ Architecture The project follows a modular architecture, with key components like account.py, asset.py, market.py, etc., encapsulating specific functionalities. This design enhances code organization and maintainability.
🔩 Code Quality The codebase maintains high quality and follows PEP8 style conventions. It leverages tools like black, flake8, and isort for consistent formatting and clean code practices.
📄 Documentation The project includes detailed documentation in pyproject.toml, outlining metadata, dependencies, and structure. Inline code comments and docstrings enhance readability and understanding for developers.
🔌 Integrations Key integrations include requests, pandas, numpy, etc., for data processing, HTTP requests, and financial analysis. External services like Alpaca API are seamlessly integrated for trading operations.
🧩 Modularity The codebase exhibits high modularity, allowing for code reuse and easy maintenance. Each module focuses on specific tasks, promoting separation of concerns and enhancing scalability.
🧪 Testing Testing frameworks such as pytest and pytest-mock are employed for unit testing. pre-commit ensures code quality checks before commits, maintaining robust test coverage.
⚡️ Performance The project emphasizes efficiency and resource optimization, ensuring swift data retrieval and processing. Performance tuning techniques are implemented to enhance speed and responsiveness.
🛡️ Security Security measures are in place for data protection and access control. Proper handling of API credentials and secure HTTP communication safeguard sensitive information.
📦 Dependencies Key dependencies include certifi, requests, pytz, etc., facilitating API interaction, data manipulation, and time zone handling. These libraries enhance the project's functionality.

Repository Structure

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
   ├── screener.py
   └── watchlist.py

Modules

.
File Summary
pyproject.toml Defines dependencies and metadata for Python Alpaca API package.-Specifies version, description, authors, license, homepage, and repository.-Lists development, testing, and documentation dependencies.
requirements.txt Specifies Python package dependencies for the repository based on version compatibility. Essential libraries for API integration and data processing are outlined, ensuring proper functioning and alignment with specified Python versions.
py_alpaca_api
File Summary
alpaca.py Defines PyAlpacaApi class central to Alpaca API interaction. Initializes key components like account, asset, history, position, order, market, watchlist, and screener with API credentials and URLs for seamless data access and trading operations.
.github.workflows
File Summary
test-package.yml Verifies Python package build and tests integrity using GitHub Actions workflow test-package.yml in the py-alpaca-api repository.
py_alpaca_api.src
File Summary
account.py Retrieves account activities for a specific type, ensuring valid date usage. Fetches account information from Alpaca API and portfolio history data, transforming timestamps. Maintains DataFrame consistency and raises exceptions for failed requests.
asset.py Retrieves asset information from Alpaca API using given parameters. Utilizes requests to fetch data, then processes and returns it in a structured format. Maps API responses to custom AssetClass objects for ease of use.
data_classes.py This code file, alpaca.py, serves as a crucial component within the py-alpaca-api repository. It encapsulates functionalities related to interacting with the Alpaca API, including handling account information, managing assets, and executing orders. By providing a streamlined interface for accessing Alpacas services, this module enhances the overall capability of the repository, enabling seamless integration of Alpacas features into broader projects.
history.py Retrieves historical stock data, validates if an asset is a stock, and preprocesses data. Supports fetching data based on symbol, timeframe, and date range. Ensures data integrity and format consistency for analysis within the parent repositorys Alpaca API integration.
market.py Implements Market class with methods for retrieving calendar data and market clock status from Alpaca API. Provides functionalities to fetch, process, and return market-related information in a structured format.
order.py Watchlist.pyThe watchlist.pyfile in thepy-alpaca-api` repository is crucial for managing and tracking user-defined watchlists of assets within the Alpaca trading platform. It enables users to create, update, and retrieve custom watchlists, providing a streamlined approach to monitor specific assets of interest. By utilizing this module, users can easily curate and monitor their preferred assets, enhancing their trading experience on the Alpaca platform.
position.py Retrieves, processes, and manages Alpaca account positions, providing data in DataFrame format, individual position details, and options to close positions individually or all at once. Maintains accuracy and consistency in position-related actions within the Alpaca API ecosystem.
screener.py Analyzes stock winners and losers by filtering data based on preset criteria. Retrieves and ranks stock performances for the previous day, with options to customize filter thresholds. Requires asset and market context for accurate analysis.
watchlist.py Retrieval, creation, updating, deletion, and asset management. Encapsulates request handling, response processing, and error management. conforms to the parent repositorys architecture by structuring functionality into distinct modules.

Getting Started

System Requirements:

  • Python: version x.y.z

Installation

From source

  1. Clone the py-alpaca-api repository:
$ git clone https://github.com/TexasCoding/py-alpaca-api
  1. Change to the project directory:
$ cd py-alpaca-api
  1. Install the dependencies:
$ pip install -r requirements.txt

Usage

From source

Run py-alpaca-api using the command below:

$ python main.py

Tests

Run the test suite using the command below:

$ pytest

Contributing

Contributions are welcome! Here are several ways you can contribute:

Contributing Guidelines
  1. Fork the Repository: Start by forking the project repository to your github account.
  2. Clone Locally: Clone the forked repository to your local machine using a git client.
    git clone https://github.com/TexasCoding/py-alpaca-api
    
  3. Create a New Branch: Always work on a new branch, giving it a descriptive name.
    git checkout -b new-feature-x
    
  4. Make Your Changes: Develop and test your changes locally.
  5. Commit Your Changes: Commit with a clear message describing your updates.
    git commit -m 'Implemented new feature x.'
    
  6. Push to github: Push the changes to your forked repository.
    git push origin new-feature-x
    
  7. Submit a Pull Request: Create a PR against the original project repository. Clearly describe the changes and their motivations.
  8. Review: Once your PR is reviewed and approved, it will be merged into the main branch. Congratulations on your contribution!
Contributor Graph


License

This project is protected under the MIT License. For more details, refer to the LICENSE file.


Acknowledgments

  • List any resources, contributors, inspiration, etc. here.

Return


Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

py_alpaca_api-0.6.3.tar.gz (26.7 kB view details)

Uploaded Source

Built Distribution

py_alpaca_api-0.6.3-py3-none-any.whl (27.5 kB view details)

Uploaded Python 3

File details

Details for the file py_alpaca_api-0.6.3.tar.gz.

File metadata

  • Download URL: py_alpaca_api-0.6.3.tar.gz
  • Upload date:
  • Size: 26.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.3 Linux/6.9.2-arch1-1

File hashes

Hashes for py_alpaca_api-0.6.3.tar.gz
Algorithm Hash digest
SHA256 b96148920ec8d080eaf1f688e7f1c79d44d0426f3902b24b15162a1558dc57a9
MD5 20d4f890a913ea0c8c6fe08e92a94eca
BLAKE2b-256 87ba6fa4439cef5fcb24c4cf30f5a4cdf57bdb6613d1c4ea6d828a0902337200

See more details on using hashes here.

File details

Details for the file py_alpaca_api-0.6.3-py3-none-any.whl.

File metadata

  • Download URL: py_alpaca_api-0.6.3-py3-none-any.whl
  • Upload date:
  • Size: 27.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.3 Linux/6.9.2-arch1-1

File hashes

Hashes for py_alpaca_api-0.6.3-py3-none-any.whl
Algorithm Hash digest
SHA256 8658c34cd9de92ddc0f58282d09e0c32ece8fb415f7bf69b83e871238e226068
MD5 9df80b94f8e85ba7a7c30608d5635fb5
BLAKE2b-256 43d2c0cb30edbb8cf605ea800c4d4e7c6946fe5ae7260da8c6899a4a4d130a92

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page