Created
July 15, 2019 20:38
-
-
Save bacanadian/238cae85f993bcbc94fea473598d8e05 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' | |
api_secret = 'REPLACE' | |
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) | |
twitter = Twython( | |
"REPLACE", | |
"REPLACE", | |
"REPLACE", | |
"REPLACE" | |
) | |
orderPrice = my_order.filled_avg_price | |
orderQty = my_order.filled_qty | |
orderSym = my_order.symbol | |
string = "Purchased " + str(orderQty) + " shares of " + str(orderSym) + " at $" + str(orderPrice) + "." | |
twitter.update_status(status=string) | |
print("Tweeted: %s" % string) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment