An unofficial Python3.9+ package that models positions on the Alpaca Finance platform to simplify interaction with their smart contracts in your Python projects.
Project description
Alpaca-Finance-Python
An unofficial Python3.9+ package that models Binance Smart Chain positions on the Alpaca Finance platform to simplify interaction with their smart contracts in your Python projects.
Supported Position Types
Automated VaultsNOTE: Existing users please update to the latest version of the package before using, core functionality has changed in version 1+.
Table of Contents
Installation
This package is set up to be installed using the pip
package manager.
-
Install the package using pip (you must use the git+url as this project is private and not listed on PyPi):
pip install --upgrade alpaca-finance
-
After install, the package will be available to you in your local Python environment as alpaca_finance
When updates are made to the package, the version will automatically be incremented so that in order to get the newest version on your end, you can simply use the same installation command and your pip will detect and update to the newest version.
Usage
How to use the package
Automated Vaults:
- Import the package into your Python script:
from alpaca_finance.automated_vault import AutomatedVaultPosition
-
Creating an AutomatedVaultPosition instance requires the following:
-
Your position key (string)
- This key should match your position key on Alpaca Finance's webapp
-
Your public wallet key (string)
-
(Optional) Your private wallet key (string)
- Your private key is required to sign transactions, but can be left as None if you are only going to be using the informational methods.
Once you've gathered all of these variables, you can create the position instance like this example below:
position = AutomatedVaultPosition(position_key="n3x-BNBBUSD-PCS1", owner_wallet_address="0x...", owner_private_key="123abc456efg789hij...")
-
-
How to approve tokens:
- Tokens that have never been approved on the Alpaca web interface will need to be approved programmatically
- The current options for token approval are as follows:
-
Using the
AutomatedVaultPosition.auto_token_approval
attribute:# Set to False by default # Tokens are only approved if the allowance is insufficent for the transaction position.auto_token_approval = True
-
Using the
AutomatedVaultPosition.do_approve_token
method:See the approve_token.ipynb example file
-
-
Use your position instance to interact with Alpaca Finance:
- For reference, see the BEP20Token class documentation
- Please view the usage examples under examples/automated_vault
""" Informational Methods (Private Key not Required) """ # Get the asset token or stable token for the vault (BEP20Token object) position.asset_token, position.stable_token # Get the current yields for the vault: position.yields() # Get the current vault TVL: position.tvl() # Get the current vault capacity: position.capacity() # Get the position's cost basis (entry price in USD): position.cost_basis() # Get the current position value (in USD): position.current_value() # Get the position profit/loss (PnL in USD): position.pnl() # Get the amount of shares held and the USD value of all shares held: position.shares() # get the full vault summary (See the documentation alpaca_fiance/position.py for more details): position.get_vault_summary() """ Transactional Methods (Private Key Required) """ # Approve a token for deposit to the vault (only required once if never approved): position.do_approve_token(<token_address> or <BEP20Token object>) # Approve the vault token for withdraw if using the "Convert All" strategy (only required once if never approved): position.do_approve_token(position.bep20_vault_token, _spender=position.gateway.address) # Invest the given amount of stable and asset token into the vault: position.do_invest(<stable_token_amt>, <asset_token_amt>) # Withdraw the given amount of shares from the vault: # Available strategies: "Minimize Trading" and "Convert All" (as shown on the webapp) # Using the "Minimize Trading" strategy (default, so not necessary to specify strategy): position.do_withdraw(<shares_amt>) # Using the "Convert All" strategy (must specify, and provide the percentage of stable token to receive): position.do_withdraw(<shares_amt>, <pct_stable_token>, strategy="Convert All") # Close a position (remove all shares): # (default) Using the "Minimize Trading" strategy: position.do_close() # Optionally specify the "Convert All" strategy: position.do_close(<pct_stable_token>, strategy="Convert All")
Uninstallation:
Uninstall the package like any other Python package using the pip uninstall command:
pip uninstall alpaca-finance
Contributions:
Coming soon...
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
File details
Details for the file alpaca_finance-1.1.3.tar.gz
.
File metadata
- Download URL: alpaca_finance-1.1.3.tar.gz
- Upload date:
- Size: 18.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6ed8d5521e89eb5c8d3376db0d83a28eb88f7ec195aa8fb0840b4c92d213d908 |
|
MD5 | 752763039c3fb0efce0d6298948b29f3 |
|
BLAKE2b-256 | 2283108e2a79277b785050aa1f9d8de4cf53621e9563cdd13081fd215f9d3513 |