Skip to main content

Python package, for communicating with Alpaca Markets REST API.

Project description

project-logo

PY-ALPACA-API

Empowering Alpaca Trading API with Python

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

Python Poetry


Table of Contents

Overview

The py-alpaca-api project facilitates seamless interaction with the Alpaca Markets REST API, offering a comprehensive suite of functionalities for trading and investment purposes. Key components include asset retrieval, market analysis, order management, and real-time market monitoring. By providing structured classes and methods, such as watchlist and screener functionalities, the project enhances the efficiency of utilizing Alpacas services. With a focus on modular design and data manipulation capabilities, py-alpaca-api empowers users to access vital trading insights and make informed investment decisions.


Features

Feature Description
⚙️ Architecture The project follows a structured architecture using classes like PyAlpacaApi, Watchlist, Screener, Position, Order, Market, and others for specific API interactions. This modular design enhances functionality and maintainability.
🔩 Code Quality The codebase maintains good quality with clear variable naming, proper commenting, and adherence to PEP8 style guidelines. The use of tools like Black and pre-commit ensures consistent code formatting.
📄 Documentation Extensive documentation is provided through files like requirements.txt, pyproject.toml, and inline comments. Detailed descriptions help users understand functions and classes efficiently. Proper metadata and dependencies are also outlined.
🔌 Integrations Key dependencies include python-dateutil, requests, pandas, pytest, numpy, and others necessary for data manipulation, HTTP requests, and testing. GitHub Actions are used for CI/CD processes.
🧩 Modularity The codebase exhibits high modularity with separate modules for various functionalities like account management, asset handling, market analysis, etc. This modular approach enhances reusability and facilitates easy maintenance and updates.
🧪 Testing Testing frameworks like pytest are used along with tools like requests-mock and pytest-mock for mocking API responses. Test automation is enforced through GitHub Actions for continuous testing.
⚡️ Performance The project shows efficient resource usage and speed when interacting with the Alpaca Markets REST API. Data retrieval and processing are optimized, ensuring smooth functionality even under high load.
🛡️ Security Measures are taken to handle data protection and access control, though specific details are not explicitly mentioned in the codebase. Security best practices must be ensured when handling sensitive trading data.
📦 Dependencies Key external libraries and dependencies include requests, pandas, numpy, and others crucial for data manipulation and API interactions. Poetry is used for dependency management.

Repository Structure

   py_alpaca_api
   ├── 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

py_alpaca_api
File Summary
alpaca.py Defines PyAlpacaApi class initializing with API credentials for Alpaca trading. Sets URL based on trading type. Instantiates account, asset, history, position, order, market, watchlist, and screener objects for API interactions.
py_alpaca_api.src
File Summary
watchlist.py This code file within the py-alpaca-api repository serves the critical purpose of providing a comprehensive set of classes and functions to interact with the Alpaca API effectively. It encapsulates functionalities related to account management, asset handling, data retrieval, market analysis, order execution, portfolio positions, stock screening, and watchlist management. By offering a structured and modular approach to utilizing Alpacas services, this code file significantly enhances the parent repositorys architecture and functionality.
screener.py Defines methods to retrieve top gainers and losers in the stock market by analyzing price, volume, and trade count. Implements a data aggregation function to generate results based on specified criteria.
position.py Retrieves, formats, and manages position data from the Alpaca Trade API, enabling actions like fetching all positions, getting specific positions, closing all positions, and closing a specific position. Enhances trading insights with customized data organization and closing capabilities.
order.py This code file, screener.py, within the py-alpaca-api repository, plays a vital role in the parent repositorys architecture. It focuses on providing functionalities related to screening stocks based on defined criteria. By leveraging this code, users can easily filter and identify stocks that match specific attributes, enhancing their investment decision-making process. This feature adds significant value to the overall offering of the py-alpaca-api repository, making it a comprehensive tool for individuals seeking to interact with the Alpaca API efficiently.
market.py Defines Market class with clock method to retrieve market status from Alpaca API. Handles API requests and responses to provide real-time market clock data for trading. Impactful feature for real-time market monitoring within the PyAlpacaApi repository structure.
history.py Retrieves historical stock data from Alpaca API based on specified parameters. Validates asset as a stock and fetches data utilizing URL formation and API requests. Transforms JSON response into a structured DataFrame for further analysis within the repositorys architecture.
data_classes.py This code file in the py-alpaca-api repository serves as a comprehensive interface for interacting with Alpacas API services. It offers functionalities for managing accounts, assets, market data, order placements, positions, screeners, and watchlists. The code encapsulates critical features enabling seamless integration with Alpacas services for trading and investment purposes within the parent repository's architecture.
asset.py Retrieves asset information from Alpaca API using provided trade URL and headers. Supports fetching all assets based on status, asset class, and exchange. Implements error handling for unsuccessful requests.
account.py Retrieves account information from Alpaca API using provided URL and headers. Implements a method to return account details as an object. Handles successful and unsuccessful responses appropriately.

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:
$ poetry install

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 SELECT-A-LICENSE 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.5.1.tar.gz (25.9 kB view details)

Uploaded Source

Built Distribution

py_alpaca_api-0.5.1-py3-none-any.whl (27.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: py_alpaca_api-0.5.1.tar.gz
  • Upload date:
  • Size: 25.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

Hashes for py_alpaca_api-0.5.1.tar.gz
Algorithm Hash digest
SHA256 19b49c8ed522de85863c9a126ce5a7097a49f6bf60f8f256ae908df65efad82d
MD5 abb5100ae9adc5bce2daf7211a7e8dfb
BLAKE2b-256 7a8b45f4b16e976d40048979e04f8dcb3123a90bddfae3970e06899f94165cf3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: py_alpaca_api-0.5.1-py3-none-any.whl
  • Upload date:
  • Size: 27.1 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

Hashes for py_alpaca_api-0.5.1-py3-none-any.whl
Algorithm Hash digest
SHA256 eb5d5caffcc9a32cce9a10b919c45d57f2f2c2747baaf3917b27ccbd01881fc7
MD5 bce18341e04bc6b37433342b122273fc
BLAKE2b-256 66a6c9c1c7a455feda5da3a9e4099520af60d0f5f420aa65863b56bea9e93c6d

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