Skip to content

Instantly share code, notes, and snippets.

@bacanadian
Created July 15, 2019 20:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bacanadian/238cae85f993bcbc94fea473598d8e05 to your computer and use it in GitHub Desktop.
Save bacanadian/238cae85f993bcbc94fea473598d8e05 to your computer and use it in GitHub Desktop.
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