Created
October 21, 2021 14:46
-
-
Save petabyt/f2fe7a1553c3223dc4267037af0e8c43 to your computer and use it in GitHub Desktop.
Trading script for ftx.us/ccxt
This file contains hidden or 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 ccxt | |
main_account_api_key = '' | |
main_account_secret = '' | |
exchange = ccxt.ftx({ | |
'apiKey': main_account_api_key, | |
'secret': main_account_secret, | |
'hostname': 'ftx.us', | |
'headers': { | |
} | |
}) | |
totalUsd = 0 | |
totalBtc = 0 | |
def stats(): | |
global totalBtc | |
global totalUsd | |
r = exchange.private_get_subaccounts_nickname_balances(params={'nickname': 'main'}) | |
for i in r["result"]: | |
print("Name: " + i["coin"]) | |
print("Total: " + str(i["total"])) | |
print("USD: " + str(i["usdValue"])) | |
print("----------------------") | |
if i["coin"] == "USD": | |
totalUsd = i["usdValue"] | |
if i["coin"] == "BTC": | |
totalBtc = i["total"] | |
def buy(): | |
global totalUsd | |
print("Buying", totalUsd) | |
r = exchange.private_post_otc_quotes(params={ | |
"fromCoin": "USD", | |
"toCoin": "BTC", | |
"size": totalUsd | |
}) | |
exchange.private_post_otc_quotes_quote_id_accept(params={ | |
"quote_id": r["result"]["quoteId"], | |
} | |
) | |
def sell(fro, to, m = 0): | |
global totalBtc | |
if m == 0: | |
m = totalBtc | |
print("Selling", totalBtc) | |
r = exchange.private_post_otc_quotes(params={ | |
"fromCoin": fro, | |
"toCoin": to, | |
"size": m | |
}) | |
exchange.private_post_otc_quotes_quote_id_accept(params={ | |
"quote_id": r["result"]["quoteId"], | |
} | |
) | |
stats() | |
sell("BTC", "USD", 0.000016) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment