Reformat project
This commit is contained in:
@@ -1,9 +1,8 @@
|
||||
# Project imports
|
||||
# from settings import settings
|
||||
import util
|
||||
import sources.agora
|
||||
|
||||
import sources.localbitcoins
|
||||
import util
|
||||
|
||||
|
||||
class Sources(util.Base):
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
# Twisted/Klein imports
|
||||
from twisted.internet.defer import inlineCallbacks
|
||||
|
||||
import sources.local
|
||||
# Other library imports
|
||||
from pyotp import TOTP
|
||||
|
||||
# Project imports
|
||||
from settings import settings
|
||||
import sources.local
|
||||
from twisted.internet.defer import inlineCallbacks
|
||||
|
||||
|
||||
class Agora(sources.local.Local):
|
||||
@@ -42,7 +40,9 @@ class Agora(sources.local.Local):
|
||||
"""
|
||||
print("CALLING RELEASE FUNDS", contact_id)
|
||||
if self.sets.Dummy == "1":
|
||||
self.log.error(f"Running in dummy mode, not releasing funds for {contact_id}")
|
||||
self.log.error(
|
||||
f"Running in dummy mode, not releasing funds for {contact_id}"
|
||||
)
|
||||
return
|
||||
payload = {"tradeId": contact_id, "password": self.sets.Pass}
|
||||
rtrn = yield self.api._api_call(
|
||||
@@ -90,8 +90,12 @@ class Agora(sources.local.Local):
|
||||
|
||||
if not float(wallet_xmr) > profit_usd_in_xmr:
|
||||
# Not enough funds to withdraw
|
||||
self.log.error(f"Not enough funds to withdraw {profit_usd_in_xmr}, as wallet only contains {wallet_xmr}")
|
||||
self.irc.sendmsg(f"Not enough funds to withdraw {profit_usd_in_xmr}, as wallet only contains {wallet_xmr}")
|
||||
self.log.error(
|
||||
f"Not enough funds to withdraw {profit_usd_in_xmr}, as wallet only contains {wallet_xmr}"
|
||||
)
|
||||
self.irc.sendmsg(
|
||||
f"Not enough funds to withdraw {profit_usd_in_xmr}, as wallet only contains {wallet_xmr}"
|
||||
)
|
||||
self.ux.notify.notify_need_topup(profit_usd_in_xmr)
|
||||
return
|
||||
|
||||
|
||||
@@ -1,20 +1,18 @@
|
||||
# Twisted/Klein imports
|
||||
from twisted.internet.task import LoopingCall
|
||||
from twisted.internet.defer import inlineCallbacks
|
||||
|
||||
from datetime import datetime
|
||||
# Other library imports
|
||||
from json import loads
|
||||
from datetime import datetime
|
||||
from time import sleep # TODO: async
|
||||
|
||||
|
||||
# Project imports
|
||||
from settings import settings
|
||||
import db
|
||||
import util
|
||||
from lib.agoradesk_py import AgoraDesk
|
||||
from lib.localbitcoins_py import LocalBitcoins
|
||||
import db
|
||||
from lib.logstash import send_logstash
|
||||
# Project imports
|
||||
from settings import settings
|
||||
from twisted.internet.defer import inlineCallbacks
|
||||
from twisted.internet.task import LoopingCall
|
||||
|
||||
|
||||
class Local(util.Base):
|
||||
@@ -28,7 +26,9 @@ class Local(util.Base):
|
||||
self.api = AgoraDesk(settings.Agora.Token)
|
||||
self.sets = settings.Agora
|
||||
elif self.platform == "lbtc":
|
||||
self.api = LocalBitcoins(settings.LocalBitcoins.Token, settings.LocalBitcoins.Secret)
|
||||
self.api = LocalBitcoins(
|
||||
settings.LocalBitcoins.Token, settings.LocalBitcoins.Secret
|
||||
)
|
||||
self.sets = settings.LocalBitcoins
|
||||
else:
|
||||
self.log.error("Platform not defined.")
|
||||
@@ -49,7 +49,9 @@ class Local(util.Base):
|
||||
provider_map = {"NATIONAL_BANK": "national-bank-transfer"}
|
||||
if reverse:
|
||||
try:
|
||||
return next(key for key, value in provider_map.items() if value == provider)
|
||||
return next(
|
||||
key for key, value in provider_map.items() if value == provider
|
||||
)
|
||||
except StopIteration:
|
||||
return False
|
||||
else:
|
||||
@@ -221,13 +223,17 @@ class Local(util.Base):
|
||||
for user, message in messages_tmp[reference][::-1]:
|
||||
if reference in self.last_messages:
|
||||
if not [user, message] in self.last_messages[reference]:
|
||||
self.irc.sendmsg(f"[{reference}] ({self.platform}) <{user}> {message}")
|
||||
self.irc.sendmsg(
|
||||
f"[{reference}] ({self.platform}) <{user}> {message}"
|
||||
)
|
||||
# Append sent messages to last_messages so we don't send them again
|
||||
self.last_messages[reference].append([user, message])
|
||||
else:
|
||||
self.last_messages[reference] = [[user, message]]
|
||||
for x in messages_tmp[reference]:
|
||||
self.irc.sendmsg(f"[{reference}] ({self.platform}) <{user}> {message}")
|
||||
self.irc.sendmsg(
|
||||
f"[{reference}] ({self.platform}) <{user}> {message}"
|
||||
)
|
||||
|
||||
# Purge old trades from cache
|
||||
for ref in list(self.last_messages): # We're removing from the list on the fly
|
||||
@@ -419,10 +425,14 @@ class Local(util.Base):
|
||||
if not providers:
|
||||
providers = self.markets.get_all_providers(self.platform)
|
||||
sinks_currencies = self.sinks.currencies
|
||||
supported_currencies = [currency for currency in currencies if currency in sinks_currencies]
|
||||
supported_currencies = [
|
||||
currency for currency in currencies if currency in sinks_currencies
|
||||
]
|
||||
currencies = supported_currencies
|
||||
# We want to get the ads for each of these currencies and return the result
|
||||
rates = self.money.cg.get_price(ids=["monero", "bitcoin"], vs_currencies=currencies)
|
||||
rates = self.money.cg.get_price(
|
||||
ids=["monero", "bitcoin"], vs_currencies=currencies
|
||||
)
|
||||
for asset in assets:
|
||||
for currency in currencies:
|
||||
cg_asset_name = crypto_map[asset]
|
||||
@@ -493,7 +503,9 @@ class Local(util.Base):
|
||||
continue
|
||||
else:
|
||||
if "error_code" not in rtrn["response"]["error"]:
|
||||
self.log.error(f"Error code not in return for ad {ad_id}: {rtrn['response']}")
|
||||
self.log.error(
|
||||
f"Error code not in return for ad {ad_id}: {rtrn['response']}"
|
||||
)
|
||||
return
|
||||
if rtrn["response"]["error"]["error_code"] == 429:
|
||||
throttled += 1
|
||||
@@ -551,14 +563,20 @@ class Local(util.Base):
|
||||
"""
|
||||
|
||||
if payment_details:
|
||||
payment_details_text = self.markets.format_payment_details(currency, payment_details)
|
||||
payment_details_text = self.markets.format_payment_details(
|
||||
currency, payment_details
|
||||
)
|
||||
ad_text = self.markets.format_ad(asset, currency, payment_details_text)
|
||||
min_amount, max_amount = self.money.get_minmax(self.platform, asset, currency)
|
||||
min_amount, max_amount = self.money.get_minmax(
|
||||
self.platform, asset, currency
|
||||
)
|
||||
if self.platform == "lbtc":
|
||||
bank_name = payment_details["bank"]
|
||||
|
||||
if self.platform == "agora":
|
||||
price_formula = f"coingecko{asset.lower()}usd*usd{currency.lower()}*{self.sets.Margin}"
|
||||
price_formula = (
|
||||
f"coingecko{asset.lower()}usd*usd{currency.lower()}*{self.sets.Margin}"
|
||||
)
|
||||
elif self.platform == "lbtc":
|
||||
price_formula = f"btc_in_usd*{self.sets.Margin}*USD_in_{currency}"
|
||||
|
||||
@@ -605,7 +623,9 @@ class Local(util.Base):
|
||||
:return: False or dict with response
|
||||
:rtype: bool or dict
|
||||
"""
|
||||
dist_list = list(self.markets.create_distribution_list(self.platform, filter_asset))
|
||||
dist_list = list(
|
||||
self.markets.create_distribution_list(self.platform, filter_asset)
|
||||
)
|
||||
our_ads = yield self.enum_ads()
|
||||
(
|
||||
supported_currencies,
|
||||
@@ -683,7 +703,10 @@ class Local(util.Base):
|
||||
for i in range(_size):
|
||||
k = i + 1
|
||||
for j in range(k, _size):
|
||||
if existing_ads[i] == existing_ads[j] and existing_ads[i] not in repeated:
|
||||
if (
|
||||
existing_ads[i] == existing_ads[j]
|
||||
and existing_ads[i] not in repeated
|
||||
):
|
||||
repeated.append(existing_ads[i])
|
||||
|
||||
actioned = []
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
# Other library imports
|
||||
import sources.local
|
||||
import util
|
||||
from pyotp import TOTP
|
||||
|
||||
# Project imports
|
||||
from settings import settings
|
||||
import util
|
||||
import sources.local
|
||||
|
||||
|
||||
class LBTC(sources.local.Local):
|
||||
@@ -39,7 +38,9 @@ class LBTC(sources.local.Local):
|
||||
:rtype: dict
|
||||
"""
|
||||
if self.sets.Dummy == "1":
|
||||
self.log.error(f"Running in dummy mode, not releasing funds for {contact_id}")
|
||||
self.log.error(
|
||||
f"Running in dummy mode, not releasing funds for {contact_id}"
|
||||
)
|
||||
return
|
||||
payload = {
|
||||
"tradeId": contact_id,
|
||||
@@ -89,8 +90,12 @@ class LBTC(sources.local.Local):
|
||||
|
||||
if not float(wallet_xmr) > profit_usd_in_xmr:
|
||||
# Not enough funds to withdraw
|
||||
self.log.error(f"Not enough funds to withdraw {profit_usd_in_xmr}, as wallet only contains {wallet_xmr}")
|
||||
self.irc.sendmsg(f"Not enough funds to withdraw {profit_usd_in_xmr}, as wallet only contains {wallet_xmr}")
|
||||
self.log.error(
|
||||
f"Not enough funds to withdraw {profit_usd_in_xmr}, as wallet only contains {wallet_xmr}"
|
||||
)
|
||||
self.irc.sendmsg(
|
||||
f"Not enough funds to withdraw {profit_usd_in_xmr}, as wallet only contains {wallet_xmr}"
|
||||
)
|
||||
self.ux.notify.notify_need_topup(profit_usd_in_xmr)
|
||||
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user