Skip to content

Instantly share code, notes, and snippets.

@VeryCB
Last active December 23, 2020 13:53
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save VeryCB/cf01e85e9ef70ac66dec07b2cd323b12 to your computer and use it in GitHub Desktop.
Save VeryCB/cf01e85e9ef70ac66dec07b2cd323b12 to your computer and use it in GitHub Desktop.
Monitor PEV prices in different pools
import requests
PEV_CONTRACT_ADDRESS = 'TUJrRXdbkHbKEVT8sRs9xdfsaEWe1XHEMC'
PEARL_CONTRACT_ADDRESS = 'TJydMBnDJUYccpBPbLqn6oBxaiaCAhxcFd'
TAI_CONTRACT_ADDRESS = 'TSdDVvLdt3Vu9TqyEH5m273pJxbpJoqAwR'
SAN_CONTRACT_ADDRESS = 'TUU9vEMbEndY4VBm6C6T35EHByvkaMQypc'
TOKEN_SYMBOLS = ['USDT', 'PEARL', 'TAI', 'SAN']
def fetch_token_balances(symbols, address):
API_URL = 'https://apilist.tronscan.io/api/account?address=%s' % address
res = requests.get(API_URL)
tokens = res.json()['trc20token_balances']
return {t['symbol'].upper(): float(t['balance']) / (10 ** t['decimals'])
for t in tokens if t['symbol'].upper() in symbols}
def get_token_price(symbol, address):
data = fetch_token_balances(['USDT', symbol], address)
return data['USDT'] / data[symbol]
if __name__ == '__main__':
try:
pev_data = fetch_token_balances(TOKEN_SYMBOLS, PEV_CONTRACT_ADDRESS)
prices = {}
sep = '=' * 10
print('%s PEV price in different pools %s' % (sep, sep))
price_in_usdt_pool = pev_data['USDT'] / 7500
prices['USDT'] = price_in_usdt_pool
print('USDT pool: 1 PEV = %.2f usdt' % price_in_usdt_pool)
config = [
('PEARL', PEARL_CONTRACT_ADDRESS, 1500),
('TAI', TAI_CONTRACT_ADDRESS, 500),
('SAN', SAN_CONTRACT_ADDRESS, 500),
]
for symbol, contract_address, share in config:
price = get_token_price(symbol, contract_address)
pev_price_in_pool = pev_data[symbol] * price / share
prices[symbol] = pev_price_in_pool
print('%s pool: 1 PEV = %.2f usdt. (%s Price: %.2f usdt)' % (
symbol, pev_price_in_pool, symbol, price))
print('=' * 50)
sorted_prices = sorted(prices.items(), key=lambda x: x[1])
print('The best choice is to buy from %s pool!' % sorted_prices[0][0])
print('=' * 50)
except KeyboardInterrupt:
print('You killed it.')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment