Created
October 4, 2020 15:06
-
-
Save VeryCB/37b2d23044d20f4c618b4ea966ed9843 to your computer and use it in GitHub Desktop.
Monitor PEV prices in different pools on sSwap
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
import requests | |
PEARL_PEV_CONTRACT_ADDRESS = 'TYCmYzi5c2X5FKhUBgD1FtgRCho8aiKd3j' | |
TAI_PEV_CONTRACT_ADDRESS = 'TNEgrJkG5S1t8p1xqFfqat3LsZaBbKJyVD' | |
SAN_PEV_CONTRACT_ADDRESS = 'TL5WhUrxfdi8G5WTuDDEB6Ai4GthiZ1jLK' | |
USDT_PEV_CONTRACT_ADDRESS = 'TSitoyPGTMb6pR3WrWM2jEtCis6b6QJcF1' | |
USDT_CONTRACT_ADDRESS = 'TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t' | |
PEV_CONTRACT_ADDRESS = 'TQQhxCErnhCQ4XG2fAqP2jG6ZwH5MBFv7X' | |
PEARL_CONTRACT_ADDRESS = 'TGbu32VEGpS4kDmjrmn5ZZJgUyHQiaweoq' | |
TAI_CONTRACT_ADDRESS = 'TRwS7apsNdRGzMBfhB2hVC4RhqfubUYZ8P' | |
SAN_CONTRACT_ADDRESS = 'TCMgrfpeHr49iGUBf9S22QAcFoynfqumhL' | |
PEARL_USDT_CONTRACT_ADDRESS = 'TJydMBnDJUYccpBPbLqn6oBxaiaCAhxcFd' | |
TAI_USDT_CONTRACT_ADDRESS = 'TSdDVvLdt3Vu9TqyEH5m273pJxbpJoqAwR' | |
SAN_USDT_CONTRACT_ADDRESS = 'TUU9vEMbEndY4VBm6C6T35EHByvkaMQypc' | |
def fetch_token_balances(token_addresses, pair_address): | |
API_URL = 'https://apilist.tronscan.io/api/account?address=%s' % pair_address | |
res = requests.get(API_URL) | |
tokens = res.json()['trc20token_balances'] | |
return {t['contract_address']: float(t['balance']) / (10 ** t['decimals']) | |
for t in tokens if t['contract_address'] in token_addresses} | |
if __name__ == '__main__': | |
try: | |
sep = '=' * 10 | |
print('%s PEV price in different pools %s' % (sep, sep)) | |
usdt_pev_data = fetch_token_balances([USDT_CONTRACT_ADDRESS, PEV_CONTRACT_ADDRESS], USDT_PEV_CONTRACT_ADDRESS) | |
pev_price_in_usdt = usdt_pev_data[USDT_CONTRACT_ADDRESS] / usdt_pev_data[PEV_CONTRACT_ADDRESS] | |
print('USDT pool: 1 PEV = %.2f usdt.' % pev_price_in_usdt) | |
config = [ | |
('PEARL', PEARL_CONTRACT_ADDRESS, PEARL_PEV_CONTRACT_ADDRESS, PEARL_USDT_CONTRACT_ADDRESS), | |
('TAI', TAI_CONTRACT_ADDRESS, TAI_PEV_CONTRACT_ADDRESS, TAI_USDT_CONTRACT_ADDRESS), | |
('SAN', SAN_CONTRACT_ADDRESS, SAN_PEV_CONTRACT_ADDRESS, SAN_USDT_CONTRACT_ADDRESS), | |
] | |
for symbol, token_address, pev_pair_address, usdt_pair_address in config: | |
pev_data = fetch_token_balances([PEV_CONTRACT_ADDRESS, token_address], pev_pair_address) | |
pev_price_in_token = pev_data[token_address] / pev_data[PEV_CONTRACT_ADDRESS] | |
token_usdt_data = fetch_token_balances([USDT_CONTRACT_ADDRESS, token_address], usdt_pair_address) | |
token_price_in_usdt = token_usdt_data[USDT_CONTRACT_ADDRESS] / token_usdt_data[token_address] | |
pev_usdt_price_in_token_pool = pev_price_in_token * token_price_in_usdt | |
print('%s pool: 1 PEV = %.2f usdt. (%s Price: %.2f usdt)' % ( | |
symbol, pev_usdt_price_in_token_pool, symbol, token_price_in_usdt)) | |
except KeyboardInterrupt: | |
print('You killed it.') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment