added price change mechanism

This commit is contained in:
Alexander 2024-07-09 11:43:31 -04:00
parent b8a7f0c355
commit f2aef7e590

View file

@ -63,34 +63,45 @@ while True:
logging.info("AFFECTION™ Balance: {:.15f}".format(affection_balance := get_token_balance(affection_address, wallet_c_address), 2)) 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 # check if wallet c has at least 1 token to sell
if affection_balance > 1: if affection_balance > 1:
# get amounts of affection to sell # check if the affection price spiked since last time
sells = math.floor(affection_balance / sell_with_amount_affection) if not sell_percent_diff_affection or affection_sample_result > affection_sample_result_last:
selling_amounts = [sell_with_amount_affection] * sells # check the percent difference
selling_amounts.append(math.floor(affection_balance - sum(selling_amounts))) percent_diff = ((affection_sample_result_last - affection_sample_result) / affection_sample_result) * 100
# start selling affection in different amounts # sell if percent is met
logging.info("Selling {} AFFECTION™...".format(sum(selling_amounts))) if not sell_percent_diff_affection or (percent_diff < 0 and abs(percent_diff) >= sell_percent_diff_affection):
for i, amount in enumerate(selling_amounts): # get amounts of affection to sell
estimated_swap_result = estimate_swap_result( sells = math.floor(affection_balance / sell_with_amount_affection)
'PulseX_v2', selling_amounts = [sell_with_amount_affection] * sells
affection_address, selling_amounts.append(math.floor(affection_balance - sum(selling_amounts)))
wpls_address, # start selling affection in different amounts
amount logging.info("Selling {} AFFECTION™...".format(sum(selling_amounts)))
) for i, amount in enumerate(selling_amounts):
if swap_tokens( estimated_swap_result = estimate_swap_result(
account, 'PulseX_v2',
'PulseX_v2', affection_address,
[affection_address, wpls_address], wpls_address,
estimated_swap_result, amount
slippage_percent )
): if swap_tokens(
logging.info("Swapped {} AFFECTION™ to PLS".format(amount)) account,
# delay if amounts remain in the list 'PulseX_v2',
if i + 1 != len(selling_amounts): [affection_address, wpls_address],
logging.info("Waiting for {} seconds...".format(loop_sell_delay)) estimated_swap_result,
time.sleep(loop_sell_delay) slippage_percent
):
logging.info("Swapped {} AFFECTION™ to PLS".format(amount))
# delay if amounts remain in the list
if i + 1 != len(selling_amounts):
logging.info("Waiting for {} seconds...".format(loop_sell_delay))
time.sleep(loop_sell_delay)
else:
logging.info("AFFECTION™ is not within range to sell yet ({}%)".format(sell_percent_diff_affection))
else:
logging.info("AFFECTION™ price hasn't increased yet")
# save the last sample price # save the last sample price
affection_sample_result_last = affection_sample_result 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)