Install and configure pylint. Add pylint to dev-requirements.txt. Start rewriting code to follow pylint's linting rules.

This commit is contained in:
Davide Casale
2023-03-06 16:36:56 +01:00
parent 6c99d3aacf
commit a4c1418113
26 changed files with 70 additions and 57 deletions

11
.pylintrc Normal file
View File

@@ -0,0 +1,11 @@
[MAIN]
py-version = 3.8.0
ignore=examples
[MESSAGES CONTROL]
disable=
missing-docstring,
too-few-public-methods

View File

@@ -1,33 +1,35 @@
from typing import List, Optional
from .rest import BfxRestInterface
from .websocket import BfxWebsocketClient
from .urls import REST_HOST, WSS_HOST
from typing import List, Optional
class Client(object):
class Client:
def __init__(
self,
REST_HOST: str = REST_HOST,
WSS_HOST: str = WSS_HOST,
API_KEY: Optional[str] = None,
API_SECRET: Optional[str] = None,
filter: Optional[List[str]] = None,
api_key: Optional[str] = None,
api_secret: Optional[str] = None,
filters: Optional[List[str]] = None,
*,
rest_host: str = REST_HOST,
wss_host: str = WSS_HOST,
log_filename: Optional[str] = None,
log_level: str = "INFO"
):
credentials = None
if API_KEY and API_SECRET:
credentials = { "API_KEY": API_KEY, "API_SECRET": API_SECRET, "filter": filter }
if api_key and api_secret:
credentials = { "API_KEY": api_key, "API_SECRET": api_secret, "filters": filters }
self.rest = BfxRestInterface(
host=REST_HOST,
host=rest_host,
credentials=credentials
)
self.wss = BfxWebsocketClient(
host=WSS_HOST,
host=wss_host,
credentials=credentials,
log_filename=log_filename,
log_filename=log_filename,
log_level=log_level
)
)

View File

@@ -173,8 +173,8 @@ class BfxWebsocketClient(object):
if reconnection.status == False:
break
async def __authenticate(self, API_KEY, API_SECRET, filter=None):
data = { "event": "auth", "filter": filter, "apiKey": API_KEY }
async def __authenticate(self, API_KEY, API_SECRET, filters=None):
data = { "event": "auth", "filter": filters, "apiKey": API_KEY }
data["authNonce"] = str(round(time.time() * 1_000_000))

Binary file not shown.

View File

@@ -7,9 +7,9 @@ from bfxapi import Client, REST_HOST
from bfxapi.rest.types import Notification, PositionClaim
bfx = Client(
REST_HOST=REST_HOST,
API_KEY=os.getenv("BFX_API_KEY"),
API_SECRET=os.getenv("BFX_API_SECRET")
rest_host=REST_HOST,
api_key=os.getenv("BFX_API_KEY"),
api_secret=os.getenv("BFX_API_SECRET")
)
# Claims all active positions

View File

@@ -9,9 +9,9 @@ from bfxapi.rest.types import List, Wallet, Transfer, \
Notification
bfx = Client(
REST_HOST=REST_HOST,
API_KEY=os.getenv("BFX_API_KEY"),
API_SECRET=os.getenv("BFX_API_SECRET")
rest_host=REST_HOST,
api_key=os.getenv("BFX_API_KEY"),
api_secret=os.getenv("BFX_API_SECRET")
)
# Gets all user's available wallets

View File

@@ -7,9 +7,9 @@ from bfxapi import Client, REST_HOST
from bfxapi.rest.types import DerivativePositionCollateral, DerivativePositionCollateralLimits
bfx = Client(
REST_HOST=REST_HOST,
API_KEY=os.getenv("BFX_API_KEY"),
API_SECRET=os.getenv("BFX_API_SECRET")
rest_host=REST_HOST,
api_key=os.getenv("BFX_API_KEY"),
api_secret=os.getenv("BFX_API_SECRET")
)
submit_order_notification = bfx.rest.auth.submit_order(

View File

@@ -7,9 +7,9 @@ from bfxapi.enums import FundingOfferType, Flag
from bfxapi.rest.types import Notification, FundingOffer
bfx = Client(
REST_HOST=REST_HOST,
API_KEY=os.getenv("BFX_API_KEY"),
API_SECRET=os.getenv("BFX_API_SECRET")
rest_host=REST_HOST,
api_key=os.getenv("BFX_API_KEY"),
api_secret=os.getenv("BFX_API_SECRET")
)
# Submit a new funding offer

View File

@@ -7,9 +7,9 @@ from bfxapi.enums import OrderType, Flag
from bfxapi.rest.types import Notification, Order
bfx = Client(
REST_HOST=REST_HOST,
API_KEY=os.getenv("BFX_API_KEY"),
API_SECRET=os.getenv("BFX_API_SECRET")
rest_host=REST_HOST,
api_key=os.getenv("BFX_API_KEY"),
api_secret=os.getenv("BFX_API_SECRET")
)
# Submit a new order

View File

@@ -7,9 +7,9 @@ from bfxapi import Client, REST_HOST
from bfxapi.rest.types import List, FundingLoan, Notification
bfx = Client(
REST_HOST=REST_HOST,
API_KEY=os.getenv("BFX_API_KEY"),
API_SECRET=os.getenv("BFX_API_SECRET")
rest_host=REST_HOST,
api_key=os.getenv("BFX_API_KEY"),
api_secret=os.getenv("BFX_API_SECRET")
)
loans: List[FundingLoan] = bfx.rest.auth.get_funding_loans(symbol="fUSD")

View File

@@ -7,9 +7,9 @@ from bfxapi import Client, REST_HOST
from bfxapi.rest.enums import MerchantSettingsKey
bfx = Client(
REST_HOST=REST_HOST,
API_KEY=os.getenv("BFX_API_KEY"),
API_SECRET=os.getenv("BFX_API_SECRET")
rest_host=REST_HOST,
api_key=os.getenv("BFX_API_KEY"),
api_secret=os.getenv("BFX_API_SECRET")
)
if not bfx.rest.merchant.set_merchant_settings(MerchantSettingsKey.RECOMMEND_STORE, 1):

View File

@@ -7,9 +7,9 @@ from bfxapi import Client, REST_HOST
from bfxapi.rest.types import InvoiceSubmission
bfx = Client(
REST_HOST=REST_HOST,
API_KEY=os.getenv("BFX_API_KEY"),
API_SECRET=os.getenv("BFX_API_SECRET")
rest_host=REST_HOST,
api_key=os.getenv("BFX_API_KEY"),
api_secret=os.getenv("BFX_API_SECRET")
)
customer_info = {

View File

@@ -5,7 +5,7 @@ from bfxapi import Client, PUB_REST_HOST
from bfxapi.rest.types import List, TradingPairBook, TradingPairRawBook, \
FundingCurrencyBook, FundingCurrencyRawBook
bfx = Client(REST_HOST=PUB_REST_HOST)
bfx = Client(rest_host=PUB_REST_HOST)
t_book: List[TradingPairBook] = bfx.rest.public.get_t_book("tBTCUSD", precision="P0", len=25)

View File

@@ -4,7 +4,7 @@ from bfxapi import Client, PUB_REST_HOST
from bfxapi.rest.enums import Config
bfx = Client(REST_HOST=PUB_REST_HOST)
bfx = Client(rest_host=PUB_REST_HOST)
print("Available configs:", [ config.value for config in Config ])

View File

@@ -2,7 +2,7 @@
from bfxapi import Client, PUB_REST_HOST
bfx = Client(REST_HOST=PUB_REST_HOST)
bfx = Client(rest_host=PUB_REST_HOST)
print(f"Candles: {bfx.rest.public.get_candles_hist(symbol='tBTCUSD')}")

View File

@@ -6,7 +6,7 @@ from bfxapi import Client, PUB_REST_HOST
from bfxapi.rest.types import List, PulseMessage, PulseProfile
bfx = Client(REST_HOST=PUB_REST_HOST)
bfx = Client(rest_host=PUB_REST_HOST)
# POSIX timestamp in milliseconds (check https://currentmillis.com/)
end = datetime.datetime(2020, 5, 2).timestamp() * 1000

View File

@@ -4,7 +4,7 @@ from bfxapi import Client, PUB_REST_HOST
from bfxapi.rest.types import TradingMarketAveragePrice, FundingMarketAveragePrice, FxRate
bfx = Client(REST_HOST=PUB_REST_HOST)
bfx = Client(rest_host=PUB_REST_HOST)
trading_market_average_price: TradingMarketAveragePrice = bfx.rest.public.get_trading_market_average_price(
symbol="tBTCUSD",

View File

@@ -4,7 +4,7 @@ from bfxapi import Client, PUB_REST_HOST
from bfxapi.rest.enums import Sort
from bfxapi.rest.types import List, TradingPairTrade, FundingCurrencyTrade
bfx = Client(REST_HOST=PUB_REST_HOST)
bfx = Client(rest_host=PUB_REST_HOST)
t_trades: List[TradingPairTrade] = bfx.rest.public.get_t_trades("tBTCUSD", \
limit=15, sort=Sort.ASCENDING)

View File

@@ -7,9 +7,9 @@ from bfxapi.enums import Error, OrderType
from bfxapi.websocket.types import Notification, Order
bfx = Client(
WSS_HOST=WSS_HOST,
API_KEY=os.getenv("BFX_API_KEY"),
API_SECRET=os.getenv("BFX_API_SECRET")
wss_host=WSS_HOST,
api_key=os.getenv("BFX_API_KEY"),
api_secret=os.getenv("BFX_API_SECRET")
)
@bfx.wss.on("wss-error")

View File

@@ -7,9 +7,9 @@ from bfxapi.enums import Error
from bfxapi.websocket.types import List, Wallet
bfx = Client(
API_KEY=os.getenv("BFX_API_KEY"),
API_SECRET=os.getenv("BFX_API_SECRET"),
filter=["wallet"]
api_key=os.getenv("BFX_API_KEY"),
api_secret=os.getenv("BFX_API_SECRET"),
filters=["wallet"]
)
@bfx.wss.on("wss-error")

View File

@@ -6,7 +6,7 @@ from bfxapi.websocket.types import DerivativesStatus
from bfxapi.websocket import subscriptions
bfx = Client(WSS_HOST=PUB_WSS_HOST)
bfx = Client(wss_host=PUB_WSS_HOST)
@bfx.wss.on("derivatives_status_update")
def on_derivatives_status_update(subscription: subscriptions.Status, data: DerivativesStatus):

View File

@@ -38,7 +38,7 @@ SYMBOLS = [ "tBTCUSD", "tLTCUSD", "tLTCBTC", "tETHUSD", "tETHBTC" ]
order_book = OrderBook(symbols=SYMBOLS)
bfx = Client(WSS_HOST=PUB_WSS_HOST)
bfx = Client(wss_host=PUB_WSS_HOST)
@bfx.wss.on("wss-error")
def on_wss_error(code: Error, msg: str):

View File

@@ -38,7 +38,7 @@ SYMBOLS = [ "tBTCUSD", "tLTCUSD", "tLTCBTC", "tETHUSD", "tETHBTC" ]
raw_order_book = RawOrderBook(symbols=SYMBOLS)
bfx = Client(WSS_HOST=PUB_WSS_HOST)
bfx = Client(wss_host=PUB_WSS_HOST)
@bfx.wss.on("wss-error")
def on_wss_error(code: Error, msg: str):

View File

@@ -6,7 +6,7 @@ from bfxapi.websocket import subscriptions
from bfxapi.websocket.enums import Channel
from bfxapi.websocket.types import TradingPairTicker
bfx = Client(WSS_HOST=PUB_WSS_HOST)
bfx = Client(wss_host=PUB_WSS_HOST)
@bfx.wss.on("t_ticker_update")
def on_t_ticker_update(subscription: subscriptions.Ticker, data: TradingPairTicker):

View File

@@ -6,7 +6,7 @@ from bfxapi.websocket.types import Candle, TradingPairTrade
from bfxapi.websocket import subscriptions
bfx = Client(WSS_HOST=PUB_WSS_HOST)
bfx = Client(wss_host=PUB_WSS_HOST)
@bfx.wss.on("candles_update")
def on_candles_update(subscription: subscriptions.Candles, candle: Candle):

Binary file not shown.