Skip to content

Instantly share code, notes, and snippets.

@rhettre
Created July 28, 2022 13:40
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/114eac7d372fdfebb7262ba79e9f37af to your computer and use it in GitHub Desktop.
Save rhettre/114eac7d372fdfebb7262ba79e9f37af to your computer and use it in GitHub Desktop.
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