Skip to content

Instantly share code, notes, and snippets.

@priestc
Last active April 22, 2022 03:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save priestc/3564426291c11db1d5527a4ea3e0e113 to your computer and use it in GitHub Desktop.
Save priestc/3564426291c11db1d5527a4ea3e0e113 to your computer and use it in GitHub Desktop.
Automatically trade cryptocurrencies
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