changed selling mechanism to be same as buyer
This commit is contained in:
parent
dfeefa01d5
commit
12b95d4f72
1 changed files with 53 additions and 32 deletions
|
|
@ -1,7 +1,8 @@
|
||||||
from core import *
|
from core import *
|
||||||
|
|
||||||
# set config variables
|
# set config variables
|
||||||
sell_percent_diff_affection = 0
|
sell_percent_diff_pdai = 15
|
||||||
|
sell_percent_diff_pusdc = 25
|
||||||
sell_with_amount_affection = 200
|
sell_with_amount_affection = 200
|
||||||
slippage_percent = 5
|
slippage_percent = 5
|
||||||
wallet_min_pls = 20000
|
wallet_min_pls = 20000
|
||||||
|
|
@ -24,6 +25,10 @@ wpls_address = '0xA1077a294dDE1B09bB078844df40758a5D0f9a27'
|
||||||
wpls_info = get_token_info(wpls_address)
|
wpls_info = get_token_info(wpls_address)
|
||||||
wpls_contract = load_contract(wpls_address)
|
wpls_contract = load_contract(wpls_address)
|
||||||
|
|
||||||
|
# load contract addresses
|
||||||
|
pdai_address = '0x6B175474E89094C44Da98b954EedeAC495271d0F'
|
||||||
|
pusdc_address = '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
# log the wallet's pls balance
|
# log the wallet's pls balance
|
||||||
logging.info("PLS Balance: {:.15f}".format(get_pls_balance(account.address)))
|
logging.info("PLS Balance: {:.15f}".format(get_pls_balance(account.address)))
|
||||||
|
|
@ -53,29 +58,39 @@ while True:
|
||||||
log_end_loop(loop_delay)
|
log_end_loop(loop_delay)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# take a sample of the 1 affection to wpls price
|
# take samples of 1 pdai/pusdc/affection to wpls price
|
||||||
|
pdai_sample_result = sample_exchange_rate('PulseX_v2', pdai_address, wpls_address)
|
||||||
|
pusdc_sample_result = sample_exchange_rate('PulseX_v2', pusdc_address, wpls_address)
|
||||||
affection_sample_result = sample_exchange_rate('PulseX_v2', affection_address, wpls_address)
|
affection_sample_result = sample_exchange_rate('PulseX_v2', affection_address, wpls_address)
|
||||||
if not affection_sample_result_last:
|
|
||||||
affection_sample_result_last = affection_sample_result
|
|
||||||
|
|
||||||
# log the current rate
|
# log the current rates
|
||||||
|
logging.info("pDAI Rate: 1 = {} PLS".format(pdai_sample_result / 10 ** 18))
|
||||||
|
logging.info("pUSDC Rate: 1 = {} PLS".format(pusdc_sample_result / 10 ** 18))
|
||||||
logging.info("AFFECTION™ Rate: 1 = {} PLS".format(affection_sample_result / 10 ** 18))
|
logging.info("AFFECTION™ Rate: 1 = {} PLS".format(affection_sample_result / 10 ** 18))
|
||||||
logging.info("AFFECTION™ Balance: {:.15f}".format(affection_balance := get_token_balance(affection_address, wallet_c_address), 2))
|
|
||||||
# check if wallet c has at least 1 token to sell
|
# log the balance
|
||||||
|
affection_balance = get_token_balance(affection_address, wallet_c_address)
|
||||||
|
logging.info("AFFECTION™ Balance: {:.15f}".format(affection_balance))
|
||||||
|
|
||||||
|
# check if wallet c has at least 1 token
|
||||||
if affection_balance > 1:
|
if affection_balance > 1:
|
||||||
# check if the affection price spiked since last time
|
# get amounts of affection to sell
|
||||||
if not sell_percent_diff_affection or affection_sample_result > affection_sample_result_last:
|
sells = math.floor(affection_balance / sell_with_amount_affection)
|
||||||
# check the percent difference
|
selling_amounts = [sell_with_amount_affection] * sells
|
||||||
percent_diff = ((affection_sample_result_last - affection_sample_result) / affection_sample_result) * 100
|
selling_amounts.append(math.floor(affection_balance - sum(selling_amounts)))
|
||||||
# sell if percent is met
|
# start selling affection in different amounts
|
||||||
if not sell_percent_diff_affection or (percent_diff < 0 and abs(percent_diff) >= sell_percent_diff_affection):
|
logging.info("Selling {} AFFECTION™...".format(sum(selling_amounts)))
|
||||||
# get amounts of affection to sell
|
i = 0
|
||||||
sells = math.floor(affection_balance / sell_with_amount_affection)
|
while i < len(selling_amounts):
|
||||||
selling_amounts = [sell_with_amount_affection] * sells
|
amount = selling_amounts[i]
|
||||||
selling_amounts.append(math.floor(affection_balance - sum(selling_amounts)))
|
# check if the pdai/pusdc price is cheaper than affection price
|
||||||
# start selling affection in different amounts
|
if (pdai_sample_result < affection_sample_result
|
||||||
logging.info("Selling {} AFFECTION™...".format(sum(selling_amounts)))
|
or pusdc_sample_result < affection_sample_result):
|
||||||
for i, amount in enumerate(selling_amounts):
|
pdai_percent_diff = ((pdai_sample_result - affection_sample_result) / affection_sample_result) * 100
|
||||||
|
pusdc_percent_diff = ((pusdc_sample_result - affection_sample_result) / affection_sample_result) * 100
|
||||||
|
# pdai/pusdc price must be cheaper and over the diff threshold
|
||||||
|
if (pdai_percent_diff < 0 and abs(pdai_percent_diff) >= sell_percent_diff_pdai) \
|
||||||
|
or (pusdc_percent_diff < 0 and abs(pusdc_percent_diff) >= sell_percent_diff_pusdc):
|
||||||
estimated_swap_result = estimate_swap_result(
|
estimated_swap_result = estimate_swap_result(
|
||||||
'PulseX_v2',
|
'PulseX_v2',
|
||||||
affection_address,
|
affection_address,
|
||||||
|
|
@ -84,27 +99,33 @@ while True:
|
||||||
)
|
)
|
||||||
if estimated_swap_result:
|
if estimated_swap_result:
|
||||||
if swap_tokens(
|
if swap_tokens(
|
||||||
account,
|
account,
|
||||||
'PulseX_v2',
|
'PulseX_v2',
|
||||||
[affection_address, wpls_address],
|
[affection_address, wpls_address],
|
||||||
estimated_swap_result,
|
estimated_swap_result,
|
||||||
slippage_percent
|
slippage_percent
|
||||||
):
|
):
|
||||||
logging.info("Swapped {} AFFECTION™ to PLS".format(amount))
|
logging.info("Swapped {} AFFECTION™ to PLS".format(amount))
|
||||||
|
i += 1
|
||||||
else:
|
else:
|
||||||
logging.warning("No estimated swap result from RPC")
|
logging.warning("No estimated swap result from RPC")
|
||||||
break
|
break
|
||||||
# delay if amounts remain in the list
|
# delay if amounts remain in the list
|
||||||
if i + 1 != len(selling_amounts):
|
if i <= len(selling_amounts):
|
||||||
logging.info("Waiting for {} seconds...".format(loop_sell_delay))
|
logging.info("Waiting for {} seconds...".format(loop_sell_delay))
|
||||||
time.sleep(loop_sell_delay)
|
time.sleep(loop_sell_delay)
|
||||||
|
else:
|
||||||
|
break
|
||||||
|
# resample the prices
|
||||||
|
pdai_sample_result = sample_exchange_rate('PulseX_v2', pdai_address, wpls_address)
|
||||||
|
pusdc_sample_result = sample_exchange_rate('PulseX_v2', pusdc_address, wpls_address)
|
||||||
|
affection_sample_result = sample_exchange_rate('PulseX_v2', affection_address, wpls_address)
|
||||||
|
else:
|
||||||
|
logging.info("AFFECTION™ price is not within targeted range for selling")
|
||||||
|
break
|
||||||
else:
|
else:
|
||||||
logging.info("AFFECTION™ is not within range to sell yet ({}%)".format(sell_percent_diff_affection))
|
logging.info("AFFECTION™ price is too low")
|
||||||
else:
|
break
|
||||||
logging.info("AFFECTION™ price hasn't increased yet")
|
|
||||||
|
|
||||||
# save the last sample price
|
|
||||||
affection_sample_result_last = affection_sample_result
|
|
||||||
|
|
||||||
# wait before next loop
|
# wait before next loop
|
||||||
log_end_loop(loop_delay)
|
log_end_loop(loop_delay)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue