Skip to content

Instantly share code, notes, and snippets.

@alg0trader
Last active July 19, 2020 23:58
Show Gist options
  • Save alg0trader/b8d2cc1021851f547a89260271ee5ade to your computer and use it in GitHub Desktop.
Save alg0trader/b8d2cc1021851f547a89260271ee5ade to your computer and use it in GitHub Desktop.
import os
import alpaca_trade_api as tradeapi
base_url = 'https://paper-api.alpaca.markets'
key_id = os.getenv("ALPCA_PAPER_KEY_ID")
secret_key = os.getenv("ALPCA_PAPER_KEY_SECRET")
api = tradeapi.REST(key_id, secret_key, base_url, api_version='v2')
account = api.get_account()
# Check if our account is restricted from trading
if account.trading_blocked:
print('Account is currently restricted from trading.')
# Check how much money we can use to open new positions
print('${} is available as buying power.'.format(account.buying_power))
print('Positions: %s' % api.list_positions())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment