|
|
|
@ -25,7 +25,7 @@ class LBTC(util.Base):
|
|
|
|
|
Initialise the last_dash storage for detecting new trades.
|
|
|
|
|
"""
|
|
|
|
|
super().__init__()
|
|
|
|
|
self.lbtc = LocalBitcoins(settings.LocalBitcoins.Token)
|
|
|
|
|
self.lbtc = LocalBitcoins(settings.LocalBitcoins.Token, settings.LocalBitcoins.Secret)
|
|
|
|
|
|
|
|
|
|
# Cache for detecting new trades
|
|
|
|
|
self.last_dash = set()
|
|
|
|
@ -124,7 +124,16 @@ class LBTC(util.Base):
|
|
|
|
|
if not contact["data"]["is_selling"]:
|
|
|
|
|
continue
|
|
|
|
|
if reference not in self.last_dash:
|
|
|
|
|
reference = self.tx.new_trade("lbtc", asset, contact_id, buyer, currency, amount, amount_crypto, provider)
|
|
|
|
|
reference = self.tx.new_trade(
|
|
|
|
|
"lbtc",
|
|
|
|
|
asset,
|
|
|
|
|
contact_id,
|
|
|
|
|
buyer,
|
|
|
|
|
currency,
|
|
|
|
|
amount,
|
|
|
|
|
amount_crypto,
|
|
|
|
|
provider,
|
|
|
|
|
)
|
|
|
|
|
if reference:
|
|
|
|
|
if reference not in current_trades:
|
|
|
|
|
current_trades.append(reference)
|
|
|
|
@ -247,10 +256,10 @@ class LBTC(util.Base):
|
|
|
|
|
providers = ["REVOLUT"]
|
|
|
|
|
# buy-monero-online, buy-bitcoin-online
|
|
|
|
|
# Work around weirdness calling it bitcoins
|
|
|
|
|
# if len(providers) == 1:
|
|
|
|
|
# ads = self.lbtc._api_call(api_method=f"buy-{coin}-online/{currency}/{providers[0]}", query_values={"page": page})
|
|
|
|
|
# elif len(providers) > 1:
|
|
|
|
|
ads = self.lbtc._api_call(api_method=f"buy-bitcoins-online/{currency}", query_values={"page": page})
|
|
|
|
|
ads = self.lbtc._api_call(
|
|
|
|
|
api_method=f"buy-bitcoins-online/{currency}",
|
|
|
|
|
query_values={"page": page},
|
|
|
|
|
)
|
|
|
|
|
# with open("pub.json", "a") as f:
|
|
|
|
|
# import json
|
|
|
|
|
# f.write(json.dumps([page, currency, asset, ads])+"\n")
|
|
|
|
@ -414,8 +423,13 @@ class LBTC(util.Base):
|
|
|
|
|
return
|
|
|
|
|
if rtrn["response"]["error"]["error_code"] == 429:
|
|
|
|
|
throttled += 1
|
|
|
|
|
sleep_time = pow(throttled, float(settings.LocalBitcoins.SleepExponent))
|
|
|
|
|
self.log.info(f"Throttled {throttled} times while updating {ad_id}, sleeping for {sleep_time} seconds")
|
|
|
|
|
sleep_time = pow(
|
|
|
|
|
throttled,
|
|
|
|
|
float(settings.LocalBitcoins.SleepExponent),
|
|
|
|
|
)
|
|
|
|
|
self.log.info(
|
|
|
|
|
f"Throttled {throttled} times while updating {ad_id}, sleeping for {sleep_time} seconds"
|
|
|
|
|
)
|
|
|
|
|
# We're running in a thread, so this is fine
|
|
|
|
|
sleep(sleep_time)
|
|
|
|
|
self.log.error(f"Error updating ad {ad_id}: {rtrn['response']}")
|
|
|
|
@ -439,7 +453,17 @@ class LBTC(util.Base):
|
|
|
|
|
return all(return_ids)
|
|
|
|
|
|
|
|
|
|
@util.handle_exceptions
|
|
|
|
|
def create_ad(self, asset, countrycode, currency, provider, payment_details, visible=None, edit=False, ad_id=None):
|
|
|
|
|
def create_ad(
|
|
|
|
|
self,
|
|
|
|
|
asset,
|
|
|
|
|
countrycode,
|
|
|
|
|
currency,
|
|
|
|
|
provider,
|
|
|
|
|
payment_details,
|
|
|
|
|
visible=None,
|
|
|
|
|
edit=False,
|
|
|
|
|
ad_id=None,
|
|
|
|
|
):
|
|
|
|
|
"""
|
|
|
|
|
Post an ad with the given asset in a country with a given currency.
|
|
|
|
|
Convert the min and max amounts from settings to the given currency with CurrencyRates.
|
|
|
|
@ -498,14 +522,23 @@ class LBTC(util.Base):
|
|
|
|
|
"""
|
|
|
|
|
dist_list = list(self.markets.create_distribution_list(filter_asset))
|
|
|
|
|
our_ads = self.enum_ads()
|
|
|
|
|
supported_currencies, account_info = self.markets.get_valid_account_details()
|
|
|
|
|
(
|
|
|
|
|
supported_currencies,
|
|
|
|
|
account_info,
|
|
|
|
|
) = self.markets.get_valid_account_details()
|
|
|
|
|
# Let's get rid of the ad IDs and make it a tuple like dist_list
|
|
|
|
|
our_ads = [(x[0], x[2], x[3], x[4]) for x in our_ads]
|
|
|
|
|
for asset, countrycode, currency, provider in dist_list:
|
|
|
|
|
if (asset, countrycode, currency, provider) not in our_ads:
|
|
|
|
|
if currency in supported_currencies:
|
|
|
|
|
# Create the actual ad and pass in all the stuff
|
|
|
|
|
rtrn = self.create_ad(asset, countrycode, currency, provider, payment_details=account_info[currency])
|
|
|
|
|
rtrn = self.create_ad(
|
|
|
|
|
asset,
|
|
|
|
|
countrycode,
|
|
|
|
|
currency,
|
|
|
|
|
provider,
|
|
|
|
|
payment_details=account_info[currency],
|
|
|
|
|
)
|
|
|
|
|
# Bail on first error, let's not continue
|
|
|
|
|
if rtrn is False:
|
|
|
|
|
return False
|
|
|
|
@ -521,11 +554,20 @@ class LBTC(util.Base):
|
|
|
|
|
:rtype: bool or dict
|
|
|
|
|
"""
|
|
|
|
|
our_ads = self.enum_ads()
|
|
|
|
|
supported_currencies, account_info = self.markets.get_valid_account_details()
|
|
|
|
|
(
|
|
|
|
|
supported_currencies,
|
|
|
|
|
account_info,
|
|
|
|
|
) = self.markets.get_valid_account_details()
|
|
|
|
|
for asset, ad_id, countrycode, currency, provider in our_ads:
|
|
|
|
|
if currency in supported_currencies:
|
|
|
|
|
rtrn = self.create_ad(
|
|
|
|
|
asset, countrycode, currency, provider, payment_details=account_info[currency], edit=True, ad_id=ad_id
|
|
|
|
|
asset,
|
|
|
|
|
countrycode,
|
|
|
|
|
currency,
|
|
|
|
|
provider,
|
|
|
|
|
payment_details=account_info[currency],
|
|
|
|
|
edit=True,
|
|
|
|
|
ad_id=ad_id,
|
|
|
|
|
)
|
|
|
|
|
# Bail on first error, let's not continue
|
|
|
|
|
if rtrn is False:
|
|
|
|
@ -564,8 +606,15 @@ class LBTC(util.Base):
|
|
|
|
|
if settings.LocalBitcoins.Dummy == "1":
|
|
|
|
|
self.log.error(f"Running in dummy mode, not releasing funds for {contact_id}")
|
|
|
|
|
return
|
|
|
|
|
payload = {"tradeId": contact_id, "password": settings.LocalBitcoins.Pass}
|
|
|
|
|
rtrn = self.lbtc._api_call(api_method=f"contact_release/{contact_id}", http_method="POST", query_values=payload)
|
|
|
|
|
payload = {
|
|
|
|
|
"tradeId": contact_id,
|
|
|
|
|
"password": settings.LocalBitcoins.Pass,
|
|
|
|
|
}
|
|
|
|
|
rtrn = self.lbtc._api_call(
|
|
|
|
|
api_method=f"contact_release/{contact_id}",
|
|
|
|
|
http_method="POST",
|
|
|
|
|
query_values=payload,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
# Check if we can withdraw funds
|
|
|
|
|
self.withdraw_funds()
|
|
|
|
|