mirror of
https://github.com/aljazceru/bitfinex-api-py.git
synced 2025-12-19 06:44:22 +01:00
Install and configure pylint. Add pylint to dev-requirements.txt. Start rewriting code to follow pylint's linting rules.
This commit is contained in:
11
.pylintrc
Normal file
11
.pylintrc
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
[MAIN]
|
||||||
|
|
||||||
|
py-version = 3.8.0
|
||||||
|
|
||||||
|
ignore=examples
|
||||||
|
|
||||||
|
[MESSAGES CONTROL]
|
||||||
|
|
||||||
|
disable=
|
||||||
|
missing-docstring,
|
||||||
|
too-few-public-methods
|
||||||
@@ -1,33 +1,35 @@
|
|||||||
|
from typing import List, Optional
|
||||||
|
|
||||||
from .rest import BfxRestInterface
|
from .rest import BfxRestInterface
|
||||||
from .websocket import BfxWebsocketClient
|
from .websocket import BfxWebsocketClient
|
||||||
from .urls import REST_HOST, WSS_HOST
|
from .urls import REST_HOST, WSS_HOST
|
||||||
|
|
||||||
from typing import List, Optional
|
class Client:
|
||||||
|
|
||||||
class Client(object):
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
REST_HOST: str = REST_HOST,
|
api_key: Optional[str] = None,
|
||||||
WSS_HOST: str = WSS_HOST,
|
api_secret: Optional[str] = None,
|
||||||
API_KEY: Optional[str] = None,
|
filters: Optional[List[str]] = None,
|
||||||
API_SECRET: Optional[str] = None,
|
*,
|
||||||
filter: Optional[List[str]] = None,
|
rest_host: str = REST_HOST,
|
||||||
|
wss_host: str = WSS_HOST,
|
||||||
log_filename: Optional[str] = None,
|
log_filename: Optional[str] = None,
|
||||||
log_level: str = "INFO"
|
log_level: str = "INFO"
|
||||||
):
|
):
|
||||||
credentials = None
|
credentials = None
|
||||||
|
|
||||||
if API_KEY and API_SECRET:
|
if api_key and api_secret:
|
||||||
credentials = { "API_KEY": API_KEY, "API_SECRET": API_SECRET, "filter": filter }
|
credentials = { "API_KEY": api_key, "API_SECRET": api_secret, "filters": filters }
|
||||||
|
|
||||||
self.rest = BfxRestInterface(
|
self.rest = BfxRestInterface(
|
||||||
host=REST_HOST,
|
host=rest_host,
|
||||||
credentials=credentials
|
credentials=credentials
|
||||||
)
|
)
|
||||||
|
|
||||||
self.wss = BfxWebsocketClient(
|
self.wss = BfxWebsocketClient(
|
||||||
host=WSS_HOST,
|
host=wss_host,
|
||||||
credentials=credentials,
|
credentials=credentials,
|
||||||
log_filename=log_filename,
|
log_filename=log_filename,
|
||||||
log_level=log_level
|
log_level=log_level
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -173,8 +173,8 @@ class BfxWebsocketClient(object):
|
|||||||
if reconnection.status == False:
|
if reconnection.status == False:
|
||||||
break
|
break
|
||||||
|
|
||||||
async def __authenticate(self, API_KEY, API_SECRET, filter=None):
|
async def __authenticate(self, API_KEY, API_SECRET, filters=None):
|
||||||
data = { "event": "auth", "filter": filter, "apiKey": API_KEY }
|
data = { "event": "auth", "filter": filters, "apiKey": API_KEY }
|
||||||
|
|
||||||
data["authNonce"] = str(round(time.time() * 1_000_000))
|
data["authNonce"] = str(round(time.time() * 1_000_000))
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
@@ -7,9 +7,9 @@ from bfxapi import Client, REST_HOST
|
|||||||
from bfxapi.rest.types import Notification, PositionClaim
|
from bfxapi.rest.types import Notification, PositionClaim
|
||||||
|
|
||||||
bfx = Client(
|
bfx = Client(
|
||||||
REST_HOST=REST_HOST,
|
rest_host=REST_HOST,
|
||||||
API_KEY=os.getenv("BFX_API_KEY"),
|
api_key=os.getenv("BFX_API_KEY"),
|
||||||
API_SECRET=os.getenv("BFX_API_SECRET")
|
api_secret=os.getenv("BFX_API_SECRET")
|
||||||
)
|
)
|
||||||
|
|
||||||
# Claims all active positions
|
# Claims all active positions
|
||||||
|
|||||||
@@ -9,9 +9,9 @@ from bfxapi.rest.types import List, Wallet, Transfer, \
|
|||||||
Notification
|
Notification
|
||||||
|
|
||||||
bfx = Client(
|
bfx = Client(
|
||||||
REST_HOST=REST_HOST,
|
rest_host=REST_HOST,
|
||||||
API_KEY=os.getenv("BFX_API_KEY"),
|
api_key=os.getenv("BFX_API_KEY"),
|
||||||
API_SECRET=os.getenv("BFX_API_SECRET")
|
api_secret=os.getenv("BFX_API_SECRET")
|
||||||
)
|
)
|
||||||
|
|
||||||
# Gets all user's available wallets
|
# Gets all user's available wallets
|
||||||
|
|||||||
@@ -7,9 +7,9 @@ from bfxapi import Client, REST_HOST
|
|||||||
from bfxapi.rest.types import DerivativePositionCollateral, DerivativePositionCollateralLimits
|
from bfxapi.rest.types import DerivativePositionCollateral, DerivativePositionCollateralLimits
|
||||||
|
|
||||||
bfx = Client(
|
bfx = Client(
|
||||||
REST_HOST=REST_HOST,
|
rest_host=REST_HOST,
|
||||||
API_KEY=os.getenv("BFX_API_KEY"),
|
api_key=os.getenv("BFX_API_KEY"),
|
||||||
API_SECRET=os.getenv("BFX_API_SECRET")
|
api_secret=os.getenv("BFX_API_SECRET")
|
||||||
)
|
)
|
||||||
|
|
||||||
submit_order_notification = bfx.rest.auth.submit_order(
|
submit_order_notification = bfx.rest.auth.submit_order(
|
||||||
|
|||||||
@@ -7,9 +7,9 @@ from bfxapi.enums import FundingOfferType, Flag
|
|||||||
from bfxapi.rest.types import Notification, FundingOffer
|
from bfxapi.rest.types import Notification, FundingOffer
|
||||||
|
|
||||||
bfx = Client(
|
bfx = Client(
|
||||||
REST_HOST=REST_HOST,
|
rest_host=REST_HOST,
|
||||||
API_KEY=os.getenv("BFX_API_KEY"),
|
api_key=os.getenv("BFX_API_KEY"),
|
||||||
API_SECRET=os.getenv("BFX_API_SECRET")
|
api_secret=os.getenv("BFX_API_SECRET")
|
||||||
)
|
)
|
||||||
|
|
||||||
# Submit a new funding offer
|
# Submit a new funding offer
|
||||||
|
|||||||
@@ -7,9 +7,9 @@ from bfxapi.enums import OrderType, Flag
|
|||||||
from bfxapi.rest.types import Notification, Order
|
from bfxapi.rest.types import Notification, Order
|
||||||
|
|
||||||
bfx = Client(
|
bfx = Client(
|
||||||
REST_HOST=REST_HOST,
|
rest_host=REST_HOST,
|
||||||
API_KEY=os.getenv("BFX_API_KEY"),
|
api_key=os.getenv("BFX_API_KEY"),
|
||||||
API_SECRET=os.getenv("BFX_API_SECRET")
|
api_secret=os.getenv("BFX_API_SECRET")
|
||||||
)
|
)
|
||||||
|
|
||||||
# Submit a new order
|
# Submit a new order
|
||||||
|
|||||||
@@ -7,9 +7,9 @@ from bfxapi import Client, REST_HOST
|
|||||||
from bfxapi.rest.types import List, FundingLoan, Notification
|
from bfxapi.rest.types import List, FundingLoan, Notification
|
||||||
|
|
||||||
bfx = Client(
|
bfx = Client(
|
||||||
REST_HOST=REST_HOST,
|
rest_host=REST_HOST,
|
||||||
API_KEY=os.getenv("BFX_API_KEY"),
|
api_key=os.getenv("BFX_API_KEY"),
|
||||||
API_SECRET=os.getenv("BFX_API_SECRET")
|
api_secret=os.getenv("BFX_API_SECRET")
|
||||||
)
|
)
|
||||||
|
|
||||||
loans: List[FundingLoan] = bfx.rest.auth.get_funding_loans(symbol="fUSD")
|
loans: List[FundingLoan] = bfx.rest.auth.get_funding_loans(symbol="fUSD")
|
||||||
|
|||||||
@@ -7,9 +7,9 @@ from bfxapi import Client, REST_HOST
|
|||||||
from bfxapi.rest.enums import MerchantSettingsKey
|
from bfxapi.rest.enums import MerchantSettingsKey
|
||||||
|
|
||||||
bfx = Client(
|
bfx = Client(
|
||||||
REST_HOST=REST_HOST,
|
rest_host=REST_HOST,
|
||||||
API_KEY=os.getenv("BFX_API_KEY"),
|
api_key=os.getenv("BFX_API_KEY"),
|
||||||
API_SECRET=os.getenv("BFX_API_SECRET")
|
api_secret=os.getenv("BFX_API_SECRET")
|
||||||
)
|
)
|
||||||
|
|
||||||
if not bfx.rest.merchant.set_merchant_settings(MerchantSettingsKey.RECOMMEND_STORE, 1):
|
if not bfx.rest.merchant.set_merchant_settings(MerchantSettingsKey.RECOMMEND_STORE, 1):
|
||||||
|
|||||||
@@ -7,9 +7,9 @@ from bfxapi import Client, REST_HOST
|
|||||||
from bfxapi.rest.types import InvoiceSubmission
|
from bfxapi.rest.types import InvoiceSubmission
|
||||||
|
|
||||||
bfx = Client(
|
bfx = Client(
|
||||||
REST_HOST=REST_HOST,
|
rest_host=REST_HOST,
|
||||||
API_KEY=os.getenv("BFX_API_KEY"),
|
api_key=os.getenv("BFX_API_KEY"),
|
||||||
API_SECRET=os.getenv("BFX_API_SECRET")
|
api_secret=os.getenv("BFX_API_SECRET")
|
||||||
)
|
)
|
||||||
|
|
||||||
customer_info = {
|
customer_info = {
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ from bfxapi import Client, PUB_REST_HOST
|
|||||||
from bfxapi.rest.types import List, TradingPairBook, TradingPairRawBook, \
|
from bfxapi.rest.types import List, TradingPairBook, TradingPairRawBook, \
|
||||||
FundingCurrencyBook, FundingCurrencyRawBook
|
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)
|
t_book: List[TradingPairBook] = bfx.rest.public.get_t_book("tBTCUSD", precision="P0", len=25)
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ from bfxapi import Client, PUB_REST_HOST
|
|||||||
|
|
||||||
from bfxapi.rest.enums import Config
|
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 ])
|
print("Available configs:", [ config.value for config in Config ])
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
from bfxapi import Client, PUB_REST_HOST
|
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')}")
|
print(f"Candles: {bfx.rest.public.get_candles_hist(symbol='tBTCUSD')}")
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ from bfxapi import Client, PUB_REST_HOST
|
|||||||
|
|
||||||
from bfxapi.rest.types import List, PulseMessage, PulseProfile
|
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/)
|
# POSIX timestamp in milliseconds (check https://currentmillis.com/)
|
||||||
end = datetime.datetime(2020, 5, 2).timestamp() * 1000
|
end = datetime.datetime(2020, 5, 2).timestamp() * 1000
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ from bfxapi import Client, PUB_REST_HOST
|
|||||||
|
|
||||||
from bfxapi.rest.types import TradingMarketAveragePrice, FundingMarketAveragePrice, FxRate
|
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(
|
trading_market_average_price: TradingMarketAveragePrice = bfx.rest.public.get_trading_market_average_price(
|
||||||
symbol="tBTCUSD",
|
symbol="tBTCUSD",
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ from bfxapi import Client, PUB_REST_HOST
|
|||||||
from bfxapi.rest.enums import Sort
|
from bfxapi.rest.enums import Sort
|
||||||
from bfxapi.rest.types import List, TradingPairTrade, FundingCurrencyTrade
|
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", \
|
t_trades: List[TradingPairTrade] = bfx.rest.public.get_t_trades("tBTCUSD", \
|
||||||
limit=15, sort=Sort.ASCENDING)
|
limit=15, sort=Sort.ASCENDING)
|
||||||
|
|||||||
@@ -7,9 +7,9 @@ from bfxapi.enums import Error, OrderType
|
|||||||
from bfxapi.websocket.types import Notification, Order
|
from bfxapi.websocket.types import Notification, Order
|
||||||
|
|
||||||
bfx = Client(
|
bfx = Client(
|
||||||
WSS_HOST=WSS_HOST,
|
wss_host=WSS_HOST,
|
||||||
API_KEY=os.getenv("BFX_API_KEY"),
|
api_key=os.getenv("BFX_API_KEY"),
|
||||||
API_SECRET=os.getenv("BFX_API_SECRET")
|
api_secret=os.getenv("BFX_API_SECRET")
|
||||||
)
|
)
|
||||||
|
|
||||||
@bfx.wss.on("wss-error")
|
@bfx.wss.on("wss-error")
|
||||||
|
|||||||
@@ -7,9 +7,9 @@ from bfxapi.enums import Error
|
|||||||
from bfxapi.websocket.types import List, Wallet
|
from bfxapi.websocket.types import List, Wallet
|
||||||
|
|
||||||
bfx = Client(
|
bfx = Client(
|
||||||
API_KEY=os.getenv("BFX_API_KEY"),
|
api_key=os.getenv("BFX_API_KEY"),
|
||||||
API_SECRET=os.getenv("BFX_API_SECRET"),
|
api_secret=os.getenv("BFX_API_SECRET"),
|
||||||
filter=["wallet"]
|
filters=["wallet"]
|
||||||
)
|
)
|
||||||
|
|
||||||
@bfx.wss.on("wss-error")
|
@bfx.wss.on("wss-error")
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ from bfxapi.websocket.types import DerivativesStatus
|
|||||||
|
|
||||||
from bfxapi.websocket import subscriptions
|
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")
|
@bfx.wss.on("derivatives_status_update")
|
||||||
def on_derivatives_status_update(subscription: subscriptions.Status, data: DerivativesStatus):
|
def on_derivatives_status_update(subscription: subscriptions.Status, data: DerivativesStatus):
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ SYMBOLS = [ "tBTCUSD", "tLTCUSD", "tLTCBTC", "tETHUSD", "tETHBTC" ]
|
|||||||
|
|
||||||
order_book = OrderBook(symbols=SYMBOLS)
|
order_book = OrderBook(symbols=SYMBOLS)
|
||||||
|
|
||||||
bfx = Client(WSS_HOST=PUB_WSS_HOST)
|
bfx = Client(wss_host=PUB_WSS_HOST)
|
||||||
|
|
||||||
@bfx.wss.on("wss-error")
|
@bfx.wss.on("wss-error")
|
||||||
def on_wss_error(code: Error, msg: str):
|
def on_wss_error(code: Error, msg: str):
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ SYMBOLS = [ "tBTCUSD", "tLTCUSD", "tLTCBTC", "tETHUSD", "tETHBTC" ]
|
|||||||
|
|
||||||
raw_order_book = RawOrderBook(symbols=SYMBOLS)
|
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")
|
@bfx.wss.on("wss-error")
|
||||||
def on_wss_error(code: Error, msg: str):
|
def on_wss_error(code: Error, msg: str):
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ from bfxapi.websocket import subscriptions
|
|||||||
from bfxapi.websocket.enums import Channel
|
from bfxapi.websocket.enums import Channel
|
||||||
from bfxapi.websocket.types import TradingPairTicker
|
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")
|
@bfx.wss.on("t_ticker_update")
|
||||||
def on_t_ticker_update(subscription: subscriptions.Ticker, data: TradingPairTicker):
|
def on_t_ticker_update(subscription: subscriptions.Ticker, data: TradingPairTicker):
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ from bfxapi.websocket.types import Candle, TradingPairTrade
|
|||||||
|
|
||||||
from bfxapi.websocket import subscriptions
|
from bfxapi.websocket import subscriptions
|
||||||
|
|
||||||
bfx = Client(WSS_HOST=PUB_WSS_HOST)
|
bfx = Client(wss_host=PUB_WSS_HOST)
|
||||||
|
|
||||||
@bfx.wss.on("candles_update")
|
@bfx.wss.on("candles_update")
|
||||||
def on_candles_update(subscription: subscriptions.Candles, candle: Candle):
|
def on_candles_update(subscription: subscriptions.Candles, candle: Candle):
|
||||||
|
|||||||
BIN
requirements.txt
BIN
requirements.txt
Binary file not shown.
Reference in New Issue
Block a user