Skip to content

Instantly share code, notes, and snippets.

@under0tech
Created September 26, 2022 18:12
Show Gist options
  • Save under0tech/731b2eb6ca1c246605874b65818c3d6d to your computer and use it in GitHub Desktop.
Save under0tech/731b2eb6ca1c246605874b65818c3d6d to your computer and use it in GitHub Desktop.
# Trade with STOP_LOSS and TAKE_PROFIT
def Trade(api, stock, operation, shares_to_trade, take_profit, stop_loss):
api.submit_order(symbol = stock, qty = shares_to_trade, side = operation, type = 'market',
order_class = 'bracket', time_in_force = 'day',
take_profit = {'limit_price': take_profit},
stop_loss = {'stop_price': stop_loss})
message = f'\n\t*{stock}*, qty _{shares_to_trade}_ \n\t\twere {operation}'
send_message(f'{TRADER_BOT_NAME}: we entered the market with:' + message)
return True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment