mirror of
https://github.com/basicswap/basicswap.git
synced 2024-12-22 03:29:34 +00:00
scripts: Remove incomplete feature.
This commit is contained in:
parent
31ead537c9
commit
128291a36a
2 changed files with 8 additions and 164 deletions
|
@ -133,8 +133,6 @@ def readConfig(args, known_coins):
|
|||
config["offers"] = []
|
||||
if "bids" not in config:
|
||||
config["bids"] = []
|
||||
if "stealthex" not in config:
|
||||
config["stealthex"] = []
|
||||
|
||||
if "min_seconds_between_offers" not in config:
|
||||
config["min_seconds_between_offers"] = 60
|
||||
|
@ -237,15 +235,6 @@ def readConfig(args, known_coins):
|
|||
bid_template["coin_to"] = findCoin(bid_template["coin_to"], known_coins)
|
||||
config["num_enabled_bids"] = num_enabled
|
||||
|
||||
num_enabled = 0
|
||||
stealthex_swaps = config["stealthex"]
|
||||
for i, swap in enumerate(stealthex_swaps):
|
||||
num_enabled += 1 if swap.get("enabled", True) else 0
|
||||
if swap.get("enabled", True) is False:
|
||||
continue
|
||||
swap["coin_from"] = findCoin(swap["coin_from"], known_coins)
|
||||
config["num_enabled_swaps"] = num_enabled
|
||||
|
||||
if num_changes > 0:
|
||||
shutil.copyfile(config_path, config_path + ".last")
|
||||
with open(config_path, "w") as fp:
|
||||
|
@ -342,9 +331,6 @@ def main():
|
|||
bid_templates = config["bids"]
|
||||
random.shuffle(bid_templates)
|
||||
|
||||
stealthex_swaps = config["stealthex"]
|
||||
random.shuffle(bid_templates)
|
||||
|
||||
# override wallet api calls for testing
|
||||
if "wallet_port_override" in config:
|
||||
wallet_api_port = int(config["wallet_port_override"])
|
||||
|
@ -823,110 +809,6 @@ def main():
|
|||
write_state(args.statefile, script_state)
|
||||
break # Create max one bid per iteration
|
||||
|
||||
if args.debug and len(stealthex_swaps) > 0:
|
||||
print(
|
||||
"Processing {} stealthex template{}".format(
|
||||
config["num_enabled_swaps"],
|
||||
"s" if config["num_enabled_swaps"] != 1 else "",
|
||||
)
|
||||
)
|
||||
for stealthex_swap in stealthex_swaps:
|
||||
if stealthex_swap.get("enabled", True) is False:
|
||||
continue
|
||||
coin_from_data = coins_map[stealthex_swap["coin_from"]]
|
||||
|
||||
wallet_from = read_json_api_wallet(
|
||||
"wallets/{}".format(coin_from_data["ticker"])
|
||||
)
|
||||
|
||||
current_balance = float(wallet_from["balance"])
|
||||
|
||||
min_balance_from = float(stealthex_swap["min_balance_from"])
|
||||
min_swap_amount = float(stealthex_swap["min_amount_tx"])
|
||||
max_swap_amount = float(stealthex_swap["max_amount_tx"])
|
||||
|
||||
# TODO: Check range limits
|
||||
|
||||
if current_balance >= min_balance_from + min_swap_amount:
|
||||
swap_amount = max_swap_amount
|
||||
if current_balance - swap_amount < min_balance_from:
|
||||
swap_amount = max(
|
||||
min_swap_amount, current_balance - min_balance_from
|
||||
)
|
||||
|
||||
estimate_url = "https://api.stealthex.io/api/v2/estimate/{}/{}?amount={}&api_key={}&fixed=true".format(
|
||||
coin_from_data["ticker"].lower(),
|
||||
stealthex_swap["coin_to"].lower(),
|
||||
swap_amount,
|
||||
stealthex_swap["api_key"],
|
||||
)
|
||||
if args.debug:
|
||||
print(f"Estimate URL: {estimate_url}")
|
||||
estimate_response = json.loads(post_req(estimate_url))
|
||||
|
||||
amount_to = float(estimate_response["estimated_amount"])
|
||||
rate = swap_amount / amount_to
|
||||
min_rate = float(stealthex_swap["min_rate"])
|
||||
if rate < min_rate:
|
||||
if args.debug:
|
||||
print(
|
||||
"Stealthex rate {} below minimum {} for {} to {}".format(
|
||||
rate,
|
||||
min_rate,
|
||||
coin_from_data["ticker"],
|
||||
stealthex_swap["coin_to"],
|
||||
)
|
||||
)
|
||||
continue
|
||||
|
||||
exchange_url = (
|
||||
"https://api.stealthex.io/api/v2/exchange?api_key={}".format(
|
||||
stealthex_swap["api_key"]
|
||||
)
|
||||
)
|
||||
|
||||
address_to = stealthex_swap.get("receive_address", "auto")
|
||||
if address_to == "auto":
|
||||
address_to = read_json_api(
|
||||
"wallets/{}/nextdepositaddr".format(
|
||||
stealthex_swap["coin_to"]
|
||||
)
|
||||
)
|
||||
|
||||
address_refund = stealthex_swap.get("refund_address", "auto")
|
||||
if address_refund == "auto":
|
||||
address_refund = read_json_api(
|
||||
"wallets/{}/nextdepositaddr".format(
|
||||
coin_from_data["ticker"]
|
||||
)
|
||||
)
|
||||
|
||||
exchange_data = {
|
||||
"currency_from": coin_from_data["ticker"].lower(),
|
||||
"currency_to": stealthex_swap["coin_to"].lower(),
|
||||
"address_to": address_to,
|
||||
"amount_from": swap_amount,
|
||||
"fixed": True,
|
||||
# 'extra_id_to':
|
||||
# 'referral':
|
||||
"refund_address": address_refund,
|
||||
# 'refund_extra_id':
|
||||
"rate_id": estimate_response["rate_id"],
|
||||
}
|
||||
|
||||
if args.debug:
|
||||
print(f"Exchange URL: {estimate_url}")
|
||||
print(f"Exchange data: {exchange_data}")
|
||||
|
||||
exchange_response = json.loads(
|
||||
post_req(exchange_url, exchange_data)
|
||||
)
|
||||
|
||||
if "Error" in exchange_response:
|
||||
raise ValueError("Exchange error " + exchange_response)
|
||||
|
||||
raise ValueError("TODO")
|
||||
|
||||
except Exception as e:
|
||||
print(f"Error: {e}.")
|
||||
|
||||
|
|
|
@ -284,19 +284,6 @@ class Test(unittest.TestCase):
|
|||
"min_coin_to_balance": -1,
|
||||
},
|
||||
],
|
||||
"stealthex": [
|
||||
{
|
||||
"coin_from": "XMR",
|
||||
"coin_to": "BTC",
|
||||
"min_balance_from": 1,
|
||||
"min_amount_tx": 1,
|
||||
"max_amount_tx": 5,
|
||||
"min_rate": 0.01,
|
||||
"refund_address": "auto",
|
||||
"receive_address": "auto",
|
||||
"api_key": "API_KEY_HERE",
|
||||
}
|
||||
],
|
||||
}
|
||||
with open(self.node0_configfile, "w") as fp:
|
||||
json.dump(node0_test_config, fp, indent=4)
|
||||
|
@ -305,12 +292,10 @@ class Test(unittest.TestCase):
|
|||
rv_stdout = result.stdout.decode().split("\n")
|
||||
assert count_lines_with(rv_stdout, "Processing 1 offer template") == 1
|
||||
assert count_lines_with(rv_stdout, "Processing 1 bid template") == 1
|
||||
assert count_lines_with(rv_stdout, "Processing 1 stealthex template") == 1
|
||||
|
||||
# Test that disabled templates are not processed
|
||||
node0_test_config["offers"][0]["enabled"] = False
|
||||
node0_test_config["bids"][0]["enabled"] = False
|
||||
node0_test_config["stealthex"][0]["enabled"] = False
|
||||
with open(self.node0_configfile, "w") as fp:
|
||||
json.dump(node0_test_config, fp, indent=4)
|
||||
|
||||
|
@ -318,7 +303,6 @@ class Test(unittest.TestCase):
|
|||
rv_stdout = result.stdout.decode().split("\n")
|
||||
assert count_lines_with(rv_stdout, "Processing 0 offer templates") == 1
|
||||
assert count_lines_with(rv_stdout, "Processing 0 bid templates") == 1
|
||||
assert count_lines_with(rv_stdout, "Processing 0 stealthex templates") == 1
|
||||
|
||||
def test_offers(self):
|
||||
|
||||
|
@ -583,30 +567,6 @@ class Test(unittest.TestCase):
|
|||
assert len(get_possible_bids(get_possible_bids(rv_stdout))) == 0
|
||||
assert count_lines_with(rv_stdout, "too many failed bids") == 1
|
||||
|
||||
"""
|
||||
TODO
|
||||
node0_test1_config['stealthex'] = [
|
||||
{
|
||||
'coin_from': 'XMR',
|
||||
'coin_to': 'BTC',
|
||||
'min_balance_from': 1,
|
||||
'min_amount_tx': 1,
|
||||
'max_amount_tx': 5,
|
||||
'min_rate': 0.01,
|
||||
'refund_address': 'auto',
|
||||
'receive_address': 'auto',
|
||||
'api_key': 'API_KEY_HERE'
|
||||
}
|
||||
]
|
||||
node0_test1_config['wallet_port_override'] = 12699
|
||||
node0_test1_config['test_mode'] = True
|
||||
with open(self.node0_configfile, 'w') as fp:
|
||||
json.dump(node0_test1_config, fp, indent=4)
|
||||
|
||||
result = subprocess.run(self.node0_args, stdout=subprocess.PIPE)
|
||||
rv_stdout = result.stdout.decode().split('\n')
|
||||
"""
|
||||
|
||||
def test_offer_amount_step(self):
|
||||
waitForServer(self.delay_event, UI_PORT + 0)
|
||||
waitForServer(self.delay_event, UI_PORT + 1)
|
||||
|
@ -981,7 +941,7 @@ class Test(unittest.TestCase):
|
|||
if final_completed is not None:
|
||||
# bids should complete
|
||||
|
||||
logging.info("Waiting for bids to settle")
|
||||
logging.info("Waiting for bids to complete")
|
||||
for i in range(50):
|
||||
|
||||
delay_event.wait(5)
|
||||
|
@ -990,7 +950,6 @@ class Test(unittest.TestCase):
|
|||
if any(bid["bid_state"] == "Receiving" for bid in bids):
|
||||
continue
|
||||
|
||||
logging.info(f"[rm] bids {bids}")
|
||||
num_active_state = 0
|
||||
num_completed = 0
|
||||
for bid in bids:
|
||||
|
@ -1012,7 +971,6 @@ class Test(unittest.TestCase):
|
|||
if any(bid["bid_state"] == "Receiving" for bid in bids):
|
||||
continue
|
||||
|
||||
logging.info(f"[rm] bids {bids}")
|
||||
break
|
||||
|
||||
num_active_state = 0
|
||||
|
@ -1021,13 +979,17 @@ class Test(unittest.TestCase):
|
|||
num_active_state += 1
|
||||
assert num_active_state == max_active
|
||||
|
||||
# Bids with a combined value less than the offer value should both be accepted
|
||||
logging.info(
|
||||
"Bids with a combined value less than the offer value should both be accepted"
|
||||
)
|
||||
test_bid_pair(1.1, 1.2, 2, self.delay_event)
|
||||
|
||||
# Only one bid of bids with a combined value greater than the offer value should be accepted
|
||||
logging.info(
|
||||
"Only one bid of bids with a combined value greater than the offer value should be accepted"
|
||||
)
|
||||
test_bid_pair(1.1, 9.2, 1, self.delay_event)
|
||||
|
||||
logging.debug("Change max_concurrent_bids to 1")
|
||||
logging.debug("Change max_concurrent_bids to 1. Only one bid should be active")
|
||||
try:
|
||||
json_rv = read_json_api(UI_PORT + 0, "automationstrategies/1")
|
||||
assert json_rv["data"]["max_concurrent_bids"] == 5
|
||||
|
|
Loading…
Reference in a new issue