Skip to main content

Python package, for communicating with Alpaca Markets REST API.

Project description

project-logo

PY-ALPACA-API

Unlock Alpacas Power with Seamless API Integration"

license last-commit repo-top-language repo-language-count


Table of Contents

Overview

The py-alpaca-api project is a Python library that simplifies interaction with the Alpaca API. It provides a robust interface, encapsulated in the PyAlpacaApi class, enabling developers to access Alpaca Market API trading functionalities effortlessly. By utilizing data classes for orders, assets, and accounts, the project abstracts away complexities, enhancing flexibility in processing API responses. With clear metadata management through Poetry, this project serves as a valuable tool for those looking to integrate Alpaca trading capabilities seamlessly into their applications.

This project is still in development. New functionality will be added and updated daily. Hopefully this project will help make communicating with Alpaca Markets API, much easier for some. Any input or help would be appreciated.


Features

Feature Description
⚙️ Architecture Designed with a clear separation of concerns, utilizing data classes for enhanced abstraction and maintainability. Follows a modular approach to interact with the Alpaca API efficiently.
🔩 Code Quality Maintains high code quality standards with consistent use of Python best practices. Codebase is well-formatted, follows PEP8 guidelines, and includes automated code formatting and linting with tools like black, flake8, and isort.
📄 Documentation Provides thorough documentation with a focus on API usage, setup instructions, and data class definitions. Utilizes Sphinx for generating documentation to support developers in understanding and integrating the project.
🔌 Integrations Relies on key external dependencies such as requests for handling HTTP requests and numpy for numerical computations. Also integrates with pre-commit for code quality checks and pytest for testing.
🧩 Modularity Emphasizes modularity and reusability with well-defined data classes that abstract API responses. Offers developers flexibility in handling different aspects of Alpaca trading functionalities.
🧪 Testing Utilizes pytest as the primary testing framework along with requests-mock for mocking API requests. Ensures reliable testing for validating the behavior of the PyAlpacaApi class.
⚡️ Performance Demonstrates efficiency in API communication and data processing. Optimizes speed by handling requests and responses effectively, contributing to overall performance.
🛡️ Security Implements secure data handling by requiring Alpaca API Key and Secret for authentication. Employs measures to protect sensitive information and control access to the Alpaca trading functionalities.
📦 Dependencies Depends on various libraries including requests, pandas, and numpy for API interactions, data processing, and numerical computations. Managed efficiently using Poetry for dependency management.
🚀 Scalability Shows potential for scalability with its modular design and efficient data processing. Capable of handling increased traffic and load by abstracting API interactions and ensuring maintainability.

Repository Structure

└── py-alpaca-api/
    ├── .github
       └── ISSUE_TEMPLATE
    ├── CODE_OF_CONDUCT.md
    ├── LICENSE
    ├── README.md
    ├── SECURITY.md
    ├── poetry.lock
    ├── py_alpaca_api
       ├── __init__.py
       ├── alpaca.py
       └── src
    ├── pyproject.toml
    └── tests
        ├── __init__.py
        └── test_alpaca.py

Modules

.
File Summary
pyproject.toml Defines metadata and dependencies for py-alpaca-api. Manages project details, such as name, version, description, homepage, repository, and dependencies like pandas, requests, and numpy. Organizes development and testing dependencies using Poetry.
py_alpaca_api
File Summary
alpaca.py The alpaca.py file in the py-alpaca-api repository contains a class called PyAlpacaApi, designed to interact with the Alpaca API. This class facilitates communication by handling API requests and responses, leveraging data classes for account, asset, and order information. The constructor requires the Alpaca API Key and Secret, with an option to specify the usage of the Alpaca Paper Trading API. This component serves as a fundamental interface for developers to access and manage Alpaca trading functionalities within the broader project architecture.
py_alpaca_api.src
File Summary
data_classes.py Defines data classes for Orders, Assets, and Accounts to map JSON data to Python objects. Abstracts data processing from API responses, enhancing flexibility and maintainability.

Getting Started

System Requirements:

  • Python: version 3.12.3

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: Recommended way is to use poetry, to install all dependencies including dev
$ poetry install

Using pip, this does not include -dev dependencies:

$ pip install -r requirements.txt

Usage

Include PyAlpacaAPI In Your App

from py_alpaca_api.alpaca import PyAlpacaApi

api_key = 'your_api_key'
api_secret = 'your_api_secret'

alpaca = PyAlpacaApi(api_key=api_key, api_secret=api_secret, api_paper=True)

asset = alpaca.get_asset('AAPL')

print(asset)

Tests

Run the test suite using the command below:

$ pytest

Project Roadmap

  • ► Adding all functionality from Alpaca's API

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

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.2.7.tar.gz (18.8 kB view hashes)

Uploaded Source

Built Distribution

py_alpaca_api-0.2.7-py3-none-any.whl (15.6 kB view hashes)

Uploaded Python 3

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