Package: alpaca-finance
Alpaca-Finance-PythonAn 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 TypesAutomated VaultsNOTE: Existing users please update to the latest version of the package before using, core functionality has changed in version 1+.Table of ContentsInstallationUsageUninstallationInstallationThis package is set up to be installed using thepippackage manager.Install the package using pip (you must use the git+url as this project is private and not listed on PyPi):pipinstall--upgradealpaca-financeAfter install, the package will be available to you in your local Python environment asalpaca_financeWhen 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.UsageHow to use the packageAutomated Vaults:Import the package into your Python script:fromalpaca_finance.automated_vaultimportAutomatedVaultPositionCreating anAutomatedVaultPositioninstance requires the following:Your position key (string)This key should match your position key on Alpaca Finance's webappYour 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 toapprove tokens:Tokens that have never been approved on the Alpaca web interface will need to be approved programmaticallyThe current options for token approval are as follows:Using theAutomatedVaultPosition.auto_token_approvalattribute:# Set to False by default# Tokens are only approved if the allowance is insufficent for the transactionposition.auto_token_approval=TrueUsing theAutomatedVaultPosition.do_approve_tokenmethod:See theapprove_token.ipynbexample fileUse your position instance to interact with Alpaca Finance:For reference, see the BEP20Token classdocumentationPlease view theusage examplesunderexamples/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<BEP20Tokenobject>)# 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:pipuninstallalpaca-financeContributions:Coming soon...