Coinbase Pro Market Orders
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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