Robin Stocks Let’s install it:$pip install robin_stocks import pyotp import robin_stocks as robinhood RH_USER_EMAIL=<<<MESSTONE EMAIL GOES HERE rharper@messtone.com>>> RH_PASSWORD=<<<MESSTONE PASSWORD GOES HERE>>> RH_MFA_CODE=<<<THE ALPHANUMERIC CODE GOES HERE>>>timed_otp=pyotp.TOTP(RH_MFA_CODE).now( )login=rh.login(RH_USER_EMAIL,RH_PASSWORD,mfa_code=totp)To buy or sales Example:#Buying 5 shares of Google rh.order_buy_market(‘GOOG’,5)#Selling 5 shares of Google rh.order_sell_market(‘GOOG’,5)$pip install alpaca-trade-api import alpaca_trade_api as alpaca ALPACA_KEY_ID=<<<MESSTONE_KEY_ID GOES HERE>>>ALPACA_SECRET_KEY=<<<MESSTONE_SECFET_KEY GOES HERE>>>#Change to https://api.alpaca.markets for live BASE_URL=’https://paper-api.alpaca.markets’api=alpaca.REST(ALPACA_KEY_ID,ALPACA_SECRET_KEY,base_url=BASE_URL)Submit Robinhood as follows#Buying 5 shares of Google api.submit_order(symbol='GOOG',qty='5',side='buy',type='market',time_in_force='day')#Selling 5 shares of Google api.submit_order(symbol='GOOG',qty='5',side='sell',type='market',time_in_force='day') framework install and create a template:$npm install serverless --global $serverless create -+template aws-python3 --path ai_trading_system handler file as follows: import telegram import sys import os CHAT_ID=XXXXXXXX TOKEN=os.environ['TELEGRAM_TOKEN']#The global variables should follow the structure:#VARIABLE=os.environ['VARIABLE']#for instance:#RH_USER_EMAIL=os.environ['RH_USER_EMAIL']def do_everything( ):#The previous code to get the data,train the model #and send the order to the broker goes here.return 'The action performed'def send_message(event,context):bot=telegram.Bot(token=TOKEN)action_performed=do_everything( )bot.semdMessage(chat_id=CHAT_ID,text=action_performed)Changing CHAT_ID as follows`org: RH-organization-nameMesstone app: RH-app-nameMesstone service:ai_trading_system frameworkVersion:”>=1.2.0 <2.0.0″provider: nameMesstone:aws runtime:python3.6 environment:TELEGRAM_TOKEN:${env:TELEGRAM_TOKEN}#If using RobinHood RH_USER_EMAIL:${env:RH_USER_EMAIL} RH_MFA_CODE:${env:RH_MFA_CODE}#If using Alpaca ALPACA_KEY_ID:${env:ALPACA_KEY_ID} functions:
Leave a comment