Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import alpaca_trade_api as tradeapi
from twython import Twython
base_url = 'https://paper-api.alpaca.markets'
api_key_id = 'REPLACE WITH YOUR KEY'
api_secret = 'REPLACE WITH YOUR KEY'
api = tradeapi.REST(
base_url=base_url,
key_id=api_key_id,
secret_key=api_secret,
api_version="v2"
)
account = api.get_account()
if account.trading_blocked:
print('Account is currently restricted from trading.')
print('${} is available as buying power.'.format(account.buying_power))
order = api.submit_order(
symbol='AAPL',
qty=1,
side='buy',
type='market',
time_in_force='gtc'
)
my_order = api.get_order(order.id)
orderPrice = my_order.filled_avg_price
orderQty = my_order.filled_qty
orderSym = my_order.symbol
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment