Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save McKlayne/a52662330457f6dd05b0c1c41b71cc2f to your computer and use it in GitHub Desktop.
Save McKlayne/a52662330457f6dd05b0c1c41b71cc2f to your computer and use it in GitHub Desktop.
import os
import alpaca_trade_api as tradeapi
import requests
api_key = 'your_api_key'
api_secret = 'your_api_secret'
os.environ["APCA_API_BASE_URL"] = "https://paper-api.alpaca.markets"
api = tradeapi.REST(api_key, api_secret, api_version='v2') # or use ENV Vars shown below
#portfolio of stocks
symbols = ['FB','AMZN','AAPL','NFLX','GOOG']
#order paramaters
side = 'buy'
notional = True
amount = '20'
#paper account
endpoint = 'https://paper-api.alpaca.markets/v2/orders'
for symbol in symbols:
if api.get_asset(symbol).fractionable == True:
order_message = fractional_shares_order(symbol, side, notional, amount, api_key, api_secret, endpoint)
print(order_message)
else:
print(f'{symbol} is not available for fractional share orders')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment