From a4c141811323ee5e8a39869fe3700dc75d74c9a4 Mon Sep 17 00:00:00 2001 From: Davide Casale Date: Mon, 6 Mar 2023 16:36:56 +0100 Subject: [PATCH] Install and configure pylint. Add pylint to dev-requirements.txt. Start rewriting code to follow pylint's linting rules. --- .pylintrc | 11 +++++++ bfxapi/client.py | 30 ++++++++++-------- .../websocket/client/bfx_websocket_client.py | 4 +-- dev-requirements.txt | Bin 248 -> 600 bytes examples/rest/authenticated/claim_position.py | 6 ++-- examples/rest/authenticated/get_wallets.py | 6 ++-- .../set_derivative_position_collateral.py | 6 ++-- .../authenticated/submit_funding_offer.py | 6 ++-- examples/rest/authenticated/submit_order.py | 6 ++-- .../rest/authenticated/toggle_keep_funding.py | 6 ++-- examples/rest/merchant/settings.py | 6 ++-- examples/rest/merchant/submit_invoice.py | 6 ++-- examples/rest/public/book.py | 2 +- examples/rest/public/conf.py | 2 +- examples/rest/public/get_candles_hist.py | 2 +- examples/rest/public/pulse_endpoints.py | 2 +- .../rest/public/rest_calculation_endpoints.py | 2 +- examples/rest/public/trades.py | 2 +- .../websocket/authenticated/submit_order.py | 6 ++-- examples/websocket/authenticated/wallets.py | 6 ++-- .../websocket/public/derivatives_status.py | 2 +- examples/websocket/public/order_book.py | 2 +- examples/websocket/public/raw_order_book.py | 2 +- examples/websocket/public/ticker.py | 2 +- examples/websocket/public/trades.py | 2 +- requirements.txt | Bin 304 -> 300 bytes 26 files changed, 70 insertions(+), 57 deletions(-) create mode 100644 .pylintrc diff --git a/.pylintrc b/.pylintrc new file mode 100644 index 0000000..6f5760f --- /dev/null +++ b/.pylintrc @@ -0,0 +1,11 @@ +[MAIN] + +py-version = 3.8.0 + +ignore=examples + +[MESSAGES CONTROL] + +disable= + missing-docstring, + too-few-public-methods \ No newline at end of file diff --git a/bfxapi/client.py b/bfxapi/client.py index 757ee54..025ee08 100644 --- a/bfxapi/client.py +++ b/bfxapi/client.py @@ -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 - ) \ No newline at end of file + ) + \ No newline at end of file diff --git a/bfxapi/websocket/client/bfx_websocket_client.py b/bfxapi/websocket/client/bfx_websocket_client.py index 7b73db9..11cfa18 100644 --- a/bfxapi/websocket/client/bfx_websocket_client.py +++ b/bfxapi/websocket/client/bfx_websocket_client.py @@ -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)) diff --git a/dev-requirements.txt b/dev-requirements.txt index a6ffdb4b157564f93b3cf1a9e6046f9109245d6f..fff03cf052a26593c67097d8c3c4cd6ce90c4e5b 100644 GIT binary patch literal 600 zcmY*WTW-QY44m&u+@Ti;V#E8RhiL+p0$B)QQE3m~cE;X~R7DO%^YGaI{i!hGm371o z4|Mh~^6P?xJLY^pSu?y?MSNjkz42KP-SY|mkcwI<L6`sJHH@{p-?YtHCzpyD1kslj96s R&o}NOV diff --git a/examples/rest/authenticated/claim_position.py b/examples/rest/authenticated/claim_position.py index f3a91e4..0f8b385 100644 --- a/examples/rest/authenticated/claim_position.py +++ b/examples/rest/authenticated/claim_position.py @@ -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 diff --git a/examples/rest/authenticated/get_wallets.py b/examples/rest/authenticated/get_wallets.py index 00dc129..0ea1388 100644 --- a/examples/rest/authenticated/get_wallets.py +++ b/examples/rest/authenticated/get_wallets.py @@ -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 diff --git a/examples/rest/authenticated/set_derivative_position_collateral.py b/examples/rest/authenticated/set_derivative_position_collateral.py index c5f82d2..bb2100f 100644 --- a/examples/rest/authenticated/set_derivative_position_collateral.py +++ b/examples/rest/authenticated/set_derivative_position_collateral.py @@ -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( diff --git a/examples/rest/authenticated/submit_funding_offer.py b/examples/rest/authenticated/submit_funding_offer.py index bcaedcd..0230eb6 100644 --- a/examples/rest/authenticated/submit_funding_offer.py +++ b/examples/rest/authenticated/submit_funding_offer.py @@ -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 diff --git a/examples/rest/authenticated/submit_order.py b/examples/rest/authenticated/submit_order.py index b831c80..8c9fbb5 100644 --- a/examples/rest/authenticated/submit_order.py +++ b/examples/rest/authenticated/submit_order.py @@ -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 diff --git a/examples/rest/authenticated/toggle_keep_funding.py b/examples/rest/authenticated/toggle_keep_funding.py index 96304b7..b17405f 100644 --- a/examples/rest/authenticated/toggle_keep_funding.py +++ b/examples/rest/authenticated/toggle_keep_funding.py @@ -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") diff --git a/examples/rest/merchant/settings.py b/examples/rest/merchant/settings.py index 4afe06b..62c015b 100644 --- a/examples/rest/merchant/settings.py +++ b/examples/rest/merchant/settings.py @@ -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): diff --git a/examples/rest/merchant/submit_invoice.py b/examples/rest/merchant/submit_invoice.py index bec606e..907c4bf 100644 --- a/examples/rest/merchant/submit_invoice.py +++ b/examples/rest/merchant/submit_invoice.py @@ -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 = { diff --git a/examples/rest/public/book.py b/examples/rest/public/book.py index b5f1a64..9014835 100644 --- a/examples/rest/public/book.py +++ b/examples/rest/public/book.py @@ -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) diff --git a/examples/rest/public/conf.py b/examples/rest/public/conf.py index 8c04ae9..f4f6a55 100644 --- a/examples/rest/public/conf.py +++ b/examples/rest/public/conf.py @@ -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 ]) diff --git a/examples/rest/public/get_candles_hist.py b/examples/rest/public/get_candles_hist.py index a1a4e8f..8cb28b3 100644 --- a/examples/rest/public/get_candles_hist.py +++ b/examples/rest/public/get_candles_hist.py @@ -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')}") diff --git a/examples/rest/public/pulse_endpoints.py b/examples/rest/public/pulse_endpoints.py index 462c955..c1a079a 100644 --- a/examples/rest/public/pulse_endpoints.py +++ b/examples/rest/public/pulse_endpoints.py @@ -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 diff --git a/examples/rest/public/rest_calculation_endpoints.py b/examples/rest/public/rest_calculation_endpoints.py index 6022753..2317aea 100644 --- a/examples/rest/public/rest_calculation_endpoints.py +++ b/examples/rest/public/rest_calculation_endpoints.py @@ -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", diff --git a/examples/rest/public/trades.py b/examples/rest/public/trades.py index 4dbf77e..4428368 100644 --- a/examples/rest/public/trades.py +++ b/examples/rest/public/trades.py @@ -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) diff --git a/examples/websocket/authenticated/submit_order.py b/examples/websocket/authenticated/submit_order.py index ca671be..31965c7 100644 --- a/examples/websocket/authenticated/submit_order.py +++ b/examples/websocket/authenticated/submit_order.py @@ -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") diff --git a/examples/websocket/authenticated/wallets.py b/examples/websocket/authenticated/wallets.py index 039364a..da4815c 100644 --- a/examples/websocket/authenticated/wallets.py +++ b/examples/websocket/authenticated/wallets.py @@ -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") diff --git a/examples/websocket/public/derivatives_status.py b/examples/websocket/public/derivatives_status.py index 05a9556..dcb3c1d 100644 --- a/examples/websocket/public/derivatives_status.py +++ b/examples/websocket/public/derivatives_status.py @@ -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): diff --git a/examples/websocket/public/order_book.py b/examples/websocket/public/order_book.py index 536ce7c..705ec41 100644 --- a/examples/websocket/public/order_book.py +++ b/examples/websocket/public/order_book.py @@ -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): diff --git a/examples/websocket/public/raw_order_book.py b/examples/websocket/public/raw_order_book.py index 7909a61..9748abf 100644 --- a/examples/websocket/public/raw_order_book.py +++ b/examples/websocket/public/raw_order_book.py @@ -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): diff --git a/examples/websocket/public/ticker.py b/examples/websocket/public/ticker.py index b2eadc8..ff1120f 100644 --- a/examples/websocket/public/ticker.py +++ b/examples/websocket/public/ticker.py @@ -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): diff --git a/examples/websocket/public/trades.py b/examples/websocket/public/trades.py index 186c46b..ff178dc 100644 --- a/examples/websocket/public/trades.py +++ b/examples/websocket/public/trades.py @@ -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): diff --git a/requirements.txt b/requirements.txt index 2c5f864aae14843952137491e2ff4b912577b925..b2a3b7683962381e55063888496c3fa4478452d1 100644 GIT binary patch delta 7 OcmdnMw1#Pe4kG{xumU~+ delta 12 TcmZ3(w1H`Z4kHUM0~Z4T7CHi1