Last active
April 22, 2022 03:01
-
-
Save priestc/3564426291c11db1d5527a4ea3e0e113 to your computer and use it in GitHub Desktop.
Automatically trade cryptocurrencies
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
from moneywagon import get_current_price, get_address_balance | |
from moneywagon.tx import Transaction | |
from bitcoin import privkey_to_address | |
data = [ | |
['btc', 'KwsccfDeJkrW6ZgMH6AJ7apNGncMVEagNWhTwq9MJnqoKp58i1MG'], | |
['ltc', 'T3ht4QWpi8q6sQKDpj7AKwMkDeFfZKbaBibiodmtsm1xqhcTJZT1'] | |
] | |
## DETERMINE IF TRADE IS NEEDED | |
current_rate = get_current_price(data[0][0], data[1][0]) | |
if current_rate > 150: | |
to_sell = data[0] # price is high, sell BTC | |
to_buy = data[1] | |
elif current_rate < 100: | |
to_sell = data[1] # price is low, buy BTC | |
to_buy = data[0] | |
else: | |
raise SystemExit() # no trade | |
amount_to_sell = get_address_balance(to_sell[0], privkey_to_address(to_sell[1])) / 4 | |
## MAKE TRADE | |
tx = Transaction(to_sell[0], verbose=True) | |
tx.add_inputs(to_sell[1]) | |
tx.onchain_exchange(to_buy[0], privkey_to_address(to_buy[1]), amount_to_sell) | |
tx.push() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment