Created
July 15, 2019 20:16
-
-
Save bacanadian/729f03db3029eeb9a462c5d386a9c03f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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