Skip to content

Instantly share code, notes, and snippets.

@rhettre
Last active July 28, 2022 03:12
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 rhettre/194c8e1749614c4cb7d7c5f4bfe38a74 to your computer and use it in GitHub Desktop.
Save rhettre/194c8e1749614c4cb7d7c5f4bfe38a74 to your computer and use it in GitHub Desktop.
Coinbase Pro Market Orders
import cbpro
import json
#Insert your API key, secret, and passphrase from Coinbase Pro
my_key = ""
my_secret = ""
my_passphrase = ""
#Replace symbol with whatever currencypair you want to trade - list of currency pairs available on Notion
symbol = "BTC-USD"
#Replace buy size with amount you want to buy/sell
buy_size = 20
#Order = "sell" for a sell order and "buy" for a buy order
order = "buy"
def _makeOrder(buy_size, cb_key, cb_secret, cb_passphrase):
auth_client = cbpro.AuthenticatedClient(cb_key, cb_secret, cb_passphrase)
market_order = auth_client.place_market_order(symbol,order,funds=buy_size)
print(market_order)
return buy_size
def lambda_handler(event, context):
amount = _makeOrder(buy_size,my_key,my_secret,my_passphrase)
return {
'statusCode': 200,
'body': json.dumps(f"You bought {amount} {symbol.split('-')[1]} of {symbol.split('-')[0]}!")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment