Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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