Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
FTX Limit Orders
import ftx
import json
YOUR_API_KEY = ""
YOUR_API_SECRET = ""
#change SYMBOL to 'ETH/USD' for ETH (etc)
SYMBOL = 'BTC/USD'
#Change USD_AMOUNT to dollar/fiat amount you want to buy/sell
USD_AMOUNT = 20
#change ORDER_TYPE to 'sell' for sells or 'buy' for buys
ORDER_TYPE = 'buy'
def lambda_handler(event, context):
client = ftx.FtxClient(api_key=YOUR_API_KEY, api_secret=YOUR_API_SECRET)
bid_price = client.get_orderbook(SYMBOL, 1)['bids'][0][0]
order_size = round(USD_AMOUNT/bid_price,4)
print(f"Bid Price: {bid_price}")
print(f"Order Size: {order_size}")
client.place_order(SYMBOL, ORDER_TYPE, bid_price, order_size)
return {
'statusCode': 200,
'body': json.dumps('Order sent!')
}
@rhettre
Copy link
Author

rhettre commented Jul 28, 2022

Buys/sells USD_AMOUNT of SYMBOL (20 USD of BTC in this case). Change symbol variable to ETH/USD (for example) to buy some other cryptocurrency. Needs your FTX US API key and FTX US API secret to run the code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment