From 87e7f9820edb71024a211d696037ba48465808cb Mon Sep 17 00:00:00 2001 From: itsdeka Date: Mon, 22 Aug 2022 19:31:16 +0200 Subject: [PATCH 1/5] -) Use private host for auth-based requests -) Updated examples --- CHANGELOG | 3 +++ bfxapi/__init__.py | 2 +- bfxapi/client.py | 8 ++++---- bfxapi/examples/rest/create_funding.py | 8 +++++--- bfxapi/examples/rest/create_order.py | 7 +++++-- bfxapi/examples/rest/get_authenticated_data.py | 7 +++++-- bfxapi/examples/rest/get_public_data.py | 5 ++++- bfxapi/examples/rest/get_seed_trades.py | 7 +++++-- bfxapi/examples/rest/merchant.py | 7 +++++-- bfxapi/examples/rest/transfer_wallet.py | 8 +++++--- bfxapi/examples/ws/cancel_order.py | 7 +++++-- bfxapi/examples/ws/connect.py | 6 ++++-- bfxapi/examples/ws/connect_auth.py | 4 +++- bfxapi/examples/ws/full_orderbook.py | 8 +++++--- bfxapi/examples/ws/multiple_instances.py | 6 ++---- bfxapi/examples/ws/resubscribe_orderbook.py | 8 +++++--- bfxapi/examples/ws/send_order.py | 7 +++++-- bfxapi/examples/ws/start_stop_connection.py | 5 +++-- bfxapi/examples/ws/subscribe_derivative_status.py | 8 +++++--- bfxapi/examples/ws/subscribe_orderbook.py | 5 ++++- bfxapi/examples/ws/subscribe_tickers.py | 8 +++++--- bfxapi/examples/ws/subscribe_trades_candles.py | 8 +++++--- bfxapi/examples/ws/update_order.py | 7 +++++-- bfxapi/examples/ws/wallet_balance.py | 7 +++++-- bfxapi/version.py | 2 +- bfxapi/websockets/bfx_websocket.py | 2 +- 26 files changed, 105 insertions(+), 55 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 69a4b97c..8563409f 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,6 @@ +2.0.2 +-) Use private host for auth-based requests + 2.0.1 -) Added User Settings Write/Read/Delete endpoints (REST) -) Added Balance Available for Orders/Offers endpoint (REST) diff --git a/bfxapi/__init__.py b/bfxapi/__init__.py index 4ad4f800..5b6918e2 100644 --- a/bfxapi/__init__.py +++ b/bfxapi/__init__.py @@ -3,7 +3,7 @@ """ from .version import __version__ -from .client import Client +from .client import Client, PUB_REST_HOST, PUB_WS_HOST, REST_HOST, WS_HOST from .models import (Order, Trade, OrderBook, Subscription, Wallet, Position, FundingLoan, FundingOffer, FundingCredit, Movement) diff --git a/bfxapi/client.py b/bfxapi/client.py index fff114c9..1700f6c1 100644 --- a/bfxapi/client.py +++ b/bfxapi/client.py @@ -5,13 +5,13 @@ # pylint: disable-all -import asyncio - from .websockets.bfx_websocket import BfxWebsocket from .rest.bfx_rest import BfxRest -REST_HOST = 'https://api-pub.bitfinex.com/v2' -WS_HOST = 'wss://api-pub.bitfinex.com/ws/2' +REST_HOST = 'https://api.bitfinex.com/v2' +WS_HOST = 'wss://api.bitfinex.com/ws/2' +PUB_REST_HOST = 'https://api-pub.bitfinex.com/v2' +PUB_WS_HOST = 'wss://api-pub.bitfinex.com/ws/2' class Client: """ diff --git a/bfxapi/examples/rest/create_funding.py b/bfxapi/examples/rest/create_funding.py index c6213bb2..8e4eeae1 100644 --- a/bfxapi/examples/rest/create_funding.py +++ b/bfxapi/examples/rest/create_funding.py @@ -1,18 +1,20 @@ import os import sys import asyncio -import time sys.path.append('../../../') -from bfxapi import Client +from bfxapi import Client, WS_HOST, REST_HOST API_KEY=os.getenv("BFX_KEY") API_SECRET=os.getenv("BFX_SECRET") +# Create funding requires private hosts bfx = Client( API_KEY=API_KEY, API_SECRET=API_SECRET, - logLevel='DEBUG' + logLevel='DEBUG', + ws_host=WS_HOST, + rest_host=REST_HOST ) async def create_funding(): diff --git a/bfxapi/examples/rest/create_order.py b/bfxapi/examples/rest/create_order.py index 9c69a0c0..ad5bc23f 100644 --- a/bfxapi/examples/rest/create_order.py +++ b/bfxapi/examples/rest/create_order.py @@ -3,16 +3,19 @@ import asyncio import time sys.path.append('../../../') -from bfxapi import Client +from bfxapi import Client, WS_HOST, REST_HOST from bfxapi.models import OrderType API_KEY=os.getenv("BFX_KEY") API_SECRET=os.getenv("BFX_SECRET") +# Create order requires private hosts bfx = Client( API_KEY=API_KEY, API_SECRET=API_SECRET, - logLevel='DEBUG' + logLevel='DEBUG', + ws_host=WS_HOST, + rest_host=REST_HOST ) async def create_order(): diff --git a/bfxapi/examples/rest/get_authenticated_data.py b/bfxapi/examples/rest/get_authenticated_data.py index 0efd74fc..c5776a1c 100644 --- a/bfxapi/examples/rest/get_authenticated_data.py +++ b/bfxapi/examples/rest/get_authenticated_data.py @@ -4,15 +4,18 @@ import time sys.path.append('../../../') -from bfxapi import Client +from bfxapi import Client, WS_HOST, REST_HOST API_KEY=os.getenv("BFX_KEY") API_SECRET=os.getenv("BFX_SECRET") +# Retrieving authenticated data requires private hosts bfx = Client( API_KEY=API_KEY, API_SECRET=API_SECRET, - logLevel='DEBUG' + logLevel='DEBUG', + ws_host=WS_HOST, + rest_host=REST_HOST ) now = int(round(time.time() * 1000)) diff --git a/bfxapi/examples/rest/get_public_data.py b/bfxapi/examples/rest/get_public_data.py index eae9f94c..151ca0d6 100644 --- a/bfxapi/examples/rest/get_public_data.py +++ b/bfxapi/examples/rest/get_public_data.py @@ -4,10 +4,13 @@ import time sys.path.append('../../../') -from bfxapi import Client +from bfxapi import Client, PUB_WS_HOST, PUB_REST_HOST +# Retrieving public data requires public hosts bfx = Client( logLevel='DEBUG', + ws_host=PUB_WS_HOST, + rest_host=PUB_REST_HOST ) now = int(round(time.time() * 1000)) diff --git a/bfxapi/examples/rest/get_seed_trades.py b/bfxapi/examples/rest/get_seed_trades.py index fb34dab5..caffb19e 100644 --- a/bfxapi/examples/rest/get_seed_trades.py +++ b/bfxapi/examples/rest/get_seed_trades.py @@ -3,10 +3,13 @@ import asyncio sys.path.append('../../../') -from bfxapi import Client +from bfxapi import Client, PUB_WS_HOST, PUB_REST_HOST +# Retrieving seed trades requires public hosts bfx = Client( - logLevel='INFO' + logLevel='INFO', + ws_host=PUB_WS_HOST, + rest_host=PUB_REST_HOST ) async def get_seeds(): diff --git a/bfxapi/examples/rest/merchant.py b/bfxapi/examples/rest/merchant.py index 91521fa9..81c8faed 100644 --- a/bfxapi/examples/rest/merchant.py +++ b/bfxapi/examples/rest/merchant.py @@ -2,15 +2,18 @@ import sys import asyncio sys.path.append('../../../') -from bfxapi import Client +from bfxapi import Client, WS_HOST, REST_HOST API_KEY=os.getenv("BFX_KEY") API_SECRET=os.getenv("BFX_SECRET") +# Submitting invoices requires private hosts bfx = Client( API_KEY=API_KEY, API_SECRET=API_SECRET, - logLevel='DEBUG' + logLevel='DEBUG', + ws_host=WS_HOST, + rest_host=REST_HOST ) async def run(): diff --git a/bfxapi/examples/rest/transfer_wallet.py b/bfxapi/examples/rest/transfer_wallet.py index 631ea3b0..84e5616e 100644 --- a/bfxapi/examples/rest/transfer_wallet.py +++ b/bfxapi/examples/rest/transfer_wallet.py @@ -1,18 +1,20 @@ import os import sys import asyncio -import time sys.path.append('../../../') -from bfxapi import Client +from bfxapi import Client, WS_HOST, REST_HOST API_KEY=os.getenv("BFX_KEY") API_SECRET=os.getenv("BFX_SECRET") +# Transfer wallet requires private hosts bfx = Client( API_KEY=API_KEY, API_SECRET=API_SECRET, - logLevel='DEBUG' + logLevel='DEBUG', + ws_host=WS_HOST, + rest_host=REST_HOST ) async def transfer_wallet(): diff --git a/bfxapi/examples/ws/cancel_order.py b/bfxapi/examples/ws/cancel_order.py index 70511dbf..7d105f50 100644 --- a/bfxapi/examples/ws/cancel_order.py +++ b/bfxapi/examples/ws/cancel_order.py @@ -2,15 +2,18 @@ import sys sys.path.append('../../../') -from bfxapi import Client, Order +from bfxapi import Client, WS_HOST, REST_HOST API_KEY=os.getenv("BFX_KEY") API_SECRET=os.getenv("BFX_SECRET") +# Canceling orders requires private hosts bfx = Client( API_KEY=API_KEY, API_SECRET=API_SECRET, - logLevel='DEBUG' + logLevel='DEBUG', + ws_host=WS_HOST, + rest_host=REST_HOST ) @bfx.ws.on('order_closed') diff --git a/bfxapi/examples/ws/connect.py b/bfxapi/examples/ws/connect.py index 4cb21bb9..ffb28ac3 100644 --- a/bfxapi/examples/ws/connect.py +++ b/bfxapi/examples/ws/connect.py @@ -2,10 +2,12 @@ import sys sys.path.append('../../../') -from bfxapi import Client +from bfxapi import Client, PUB_WS_HOST, PUB_REST_HOST bfx = Client( - logLevel='DEBUG' + logLevel='DEBUG', + ws_host=PUB_WS_HOST, + rest_host=PUB_REST_HOST ) @bfx.ws.on('error') diff --git a/bfxapi/examples/ws/connect_auth.py b/bfxapi/examples/ws/connect_auth.py index fac67e32..4e5db587 100644 --- a/bfxapi/examples/ws/connect_auth.py +++ b/bfxapi/examples/ws/connect_auth.py @@ -2,7 +2,7 @@ import sys sys.path.append('../../../') -from bfxapi import Client, Order +from bfxapi import Client, WS_HOST, REST_HOST API_KEY=os.getenv("BFX_KEY") API_SECRET=os.getenv("BFX_SECRET") @@ -11,6 +11,8 @@ API_KEY=API_KEY, API_SECRET=API_SECRET, logLevel='DEBUG', + ws_host=WS_HOST, + rest_host=REST_HOST, dead_man_switch=True, # <-- kill all orders if this connection drops channel_filter=['wallet'] # <-- only receive wallet updates ) diff --git a/bfxapi/examples/ws/full_orderbook.py b/bfxapi/examples/ws/full_orderbook.py index d8678e36..49639b45 100644 --- a/bfxapi/examples/ws/full_orderbook.py +++ b/bfxapi/examples/ws/full_orderbook.py @@ -1,13 +1,15 @@ -import os import sys import time from collections import OrderedDict sys.path.append('../../../') -from bfxapi import Client +from bfxapi import Client, PUB_WS_HOST, PUB_REST_HOST +# Retrieving orderbook requires public hosts bfx = Client( - manageOrderBooks=True + manageOrderBooks=True, + ws_host=PUB_WS_HOST, + rest_host=PUB_REST_HOST ) class OrderBook: diff --git a/bfxapi/examples/ws/multiple_instances.py b/bfxapi/examples/ws/multiple_instances.py index 89fa6777..9cb89ed3 100644 --- a/bfxapi/examples/ws/multiple_instances.py +++ b/bfxapi/examples/ws/multiple_instances.py @@ -8,11 +8,9 @@ import sys sys.path.append('../../../') import asyncio -import json -from datetime import datetime from functools import partial import websockets as ws -from bfxapi import Client +from bfxapi import Client, PUB_WS_HOST, PUB_REST_HOST import math import random @@ -27,7 +25,7 @@ def get_random_list_of_tickers(): class Instance: def __init__(self, _id): self.id = _id - self.bfx = Client(logLevel='INFO') + self.bfx = Client(logLevel='INFO', ws_host=PUB_WS_HOST, rest_host=PUB_REST_HOST) self.subscriptions = {'trades': {}, 'ticker': {}} self.is_ready = False diff --git a/bfxapi/examples/ws/resubscribe_orderbook.py b/bfxapi/examples/ws/resubscribe_orderbook.py index ede112dd..7bbfb20b 100644 --- a/bfxapi/examples/ws/resubscribe_orderbook.py +++ b/bfxapi/examples/ws/resubscribe_orderbook.py @@ -1,11 +1,13 @@ -import os import sys sys.path.append('../../../') -from bfxapi import Client +from bfxapi import Client, PUB_WS_HOST, PUB_REST_HOST +# Retrieving orderbook requires public hosts bfx = Client( - logLevel='INFO' + manageOrderBooks=True, + ws_host=PUB_WS_HOST, + rest_host=PUB_REST_HOST ) @bfx.ws.on('error') diff --git a/bfxapi/examples/ws/send_order.py b/bfxapi/examples/ws/send_order.py index 6c30fd77..f26d6707 100644 --- a/bfxapi/examples/ws/send_order.py +++ b/bfxapi/examples/ws/send_order.py @@ -2,15 +2,18 @@ import sys sys.path.append('../../../') -from bfxapi import Client, Order +from bfxapi import Client, Order, WS_HOST, REST_HOST API_KEY=os.getenv("BFX_KEY") API_SECRET=os.getenv("BFX_SECRET") +# Sending order requires private hosts bfx = Client( API_KEY=API_KEY, API_SECRET=API_SECRET, - logLevel='DEBUG' + logLevel='DEBUG', + ws_host=WS_HOST, + rest_host=REST_HOST ) @bfx.ws.on('order_snapshot') diff --git a/bfxapi/examples/ws/start_stop_connection.py b/bfxapi/examples/ws/start_stop_connection.py index 4e23469a..59de4792 100644 --- a/bfxapi/examples/ws/start_stop_connection.py +++ b/bfxapi/examples/ws/start_stop_connection.py @@ -1,11 +1,12 @@ -import os import sys sys.path.append('../../../') -from bfxapi import Client +from bfxapi import Client, PUB_WS_HOST, PUB_REST_HOST bfx = Client( logLevel='DEBUG', + ws_host=PUB_WS_HOST, + rest_host=PUB_REST_HOST ) @bfx.ws.on('order_book_snapshot') diff --git a/bfxapi/examples/ws/subscribe_derivative_status.py b/bfxapi/examples/ws/subscribe_derivative_status.py index 3ddb7e5c..52ca79d4 100644 --- a/bfxapi/examples/ws/subscribe_derivative_status.py +++ b/bfxapi/examples/ws/subscribe_derivative_status.py @@ -1,11 +1,13 @@ -import os import sys sys.path.append('../../../') -from bfxapi import Client +from bfxapi import Client, PUB_WS_HOST, PUB_REST_HOST +# Retrieving derivative status requires public hosts bfx = Client( - logLevel='INFO' + logLevel='DEBUG', + ws_host=PUB_WS_HOST, + rest_host=PUB_REST_HOST ) @bfx.ws.on('error') diff --git a/bfxapi/examples/ws/subscribe_orderbook.py b/bfxapi/examples/ws/subscribe_orderbook.py index 7febcf30..bc06945f 100644 --- a/bfxapi/examples/ws/subscribe_orderbook.py +++ b/bfxapi/examples/ws/subscribe_orderbook.py @@ -2,10 +2,13 @@ import sys sys.path.append('../../../') -from bfxapi import Client +from bfxapi import Client, PUB_WS_HOST, PUB_REST_HOST +# Retrieving trades/candles requires public hosts bfx = Client( logLevel='DEBUG', + ws_host=PUB_WS_HOST, + rest_host=PUB_REST_HOST, # Verifies that the local orderbook is up to date # with the bitfinex servers manageOrderBooks=True diff --git a/bfxapi/examples/ws/subscribe_tickers.py b/bfxapi/examples/ws/subscribe_tickers.py index 984fa470..2eb744fd 100644 --- a/bfxapi/examples/ws/subscribe_tickers.py +++ b/bfxapi/examples/ws/subscribe_tickers.py @@ -1,11 +1,13 @@ -import os import sys sys.path.append('../../../') -from bfxapi import Client +from bfxapi import Client, PUB_WS_HOST, PUB_REST_HOST +# Retrieving tickers requires public hosts bfx = Client( - logLevel='DEBUG' + logLevel='DEBUG', + ws_host=PUB_WS_HOST, + rest_host=PUB_REST_HOST ) @bfx.ws.on('error') diff --git a/bfxapi/examples/ws/subscribe_trades_candles.py b/bfxapi/examples/ws/subscribe_trades_candles.py index d7135e69..1248dea4 100644 --- a/bfxapi/examples/ws/subscribe_trades_candles.py +++ b/bfxapi/examples/ws/subscribe_trades_candles.py @@ -1,11 +1,13 @@ -import os import sys sys.path.append('../../../') -from bfxapi import Client +from bfxapi import Client, PUB_WS_HOST, PUB_REST_HOST +# Retrieving trades/candles requires public hosts bfx = Client( - logLevel='DEBUG' + logLevel='DEBUG', + ws_host=PUB_WS_HOST, + rest_host=PUB_REST_HOST ) @bfx.ws.on('error') diff --git a/bfxapi/examples/ws/update_order.py b/bfxapi/examples/ws/update_order.py index 68df31eb..936d1b61 100644 --- a/bfxapi/examples/ws/update_order.py +++ b/bfxapi/examples/ws/update_order.py @@ -2,15 +2,18 @@ import sys sys.path.append('../../../') -from bfxapi import Client, Order +from bfxapi import Client, Order, WS_HOST, REST_HOST API_KEY=os.getenv("BFX_KEY") API_SECRET=os.getenv("BFX_SECRET") +# Update order requires private hosts bfx = Client( API_KEY=API_KEY, API_SECRET=API_SECRET, - logLevel='DEBUG' + logLevel='INFO', + ws_host=WS_HOST, + rest_host=REST_HOST ) @bfx.ws.on('order_update') diff --git a/bfxapi/examples/ws/wallet_balance.py b/bfxapi/examples/ws/wallet_balance.py index c46fa1e8..731faa6a 100644 --- a/bfxapi/examples/ws/wallet_balance.py +++ b/bfxapi/examples/ws/wallet_balance.py @@ -1,15 +1,18 @@ import os import sys sys.path.append('../../../') -from bfxapi import Client +from bfxapi import Client, WS_HOST, REST_HOST API_KEY=os.getenv("BFX_KEY") API_SECRET=os.getenv("BFX_SECRET") +# Checking wallet balances requires private hosts bfx = Client( API_KEY=API_KEY, API_SECRET=API_SECRET, - logLevel='INFO' + logLevel='INFO', + ws_host=WS_HOST, + rest_host=REST_HOST ) @bfx.ws.on('wallet_snapshot') diff --git a/bfxapi/version.py b/bfxapi/version.py index f5a20c1c..2b350b75 100644 --- a/bfxapi/version.py +++ b/bfxapi/version.py @@ -2,4 +2,4 @@ This module contains the current version of the bfxapi lib """ -__version__ = '2.0.1' +__version__ = '2.0.2' diff --git a/bfxapi/websockets/bfx_websocket.py b/bfxapi/websockets/bfx_websocket.py index 74c23717..0afa60b4 100644 --- a/bfxapi/websockets/bfx_websocket.py +++ b/bfxapi/websockets/bfx_websocket.py @@ -187,7 +187,7 @@ class BfxWebsocket(GenericWebsocket): - `unsubscribed` (Subscription): A channel has been un-subscribed """ - def __init__(self, API_KEY=None, API_SECRET=None, host='wss://api-pub.bitfinex.com/ws/2', + def __init__(self, host, API_KEY=None, API_SECRET=None, manageOrderBooks=False, dead_man_switch=False, ws_capacity=25, logLevel='INFO', parse_float=float, channel_filter=[], *args, **kwargs): self.API_KEY = API_KEY From 26a5f509676ba11b6f5f5da877ff6aa08f20a777 Mon Sep 17 00:00:00 2001 From: itsdeka Date: Mon, 22 Aug 2022 19:36:09 +0200 Subject: [PATCH 2/5] fix cancel order updated version --- bfxapi/examples/ws/cancel_order.py | 2 +- setup.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bfxapi/examples/ws/cancel_order.py b/bfxapi/examples/ws/cancel_order.py index 7d105f50..6804c300 100644 --- a/bfxapi/examples/ws/cancel_order.py +++ b/bfxapi/examples/ws/cancel_order.py @@ -2,7 +2,7 @@ import sys sys.path.append('../../../') -from bfxapi import Client, WS_HOST, REST_HOST +from bfxapi import Client, Order, WS_HOST, REST_HOST API_KEY=os.getenv("BFX_KEY") API_SECRET=os.getenv("BFX_SECRET") diff --git a/setup.py b/setup.py index af19bde6..a5c1f428 100644 --- a/setup.py +++ b/setup.py @@ -11,7 +11,7 @@ here = path.abspath(path.dirname(__file__)) setup( name='bitfinex-api-py', - version='2.0.1', + version='2.0.2', description='Official Bitfinex Python API', long_description='A Python reference implementation of the Bitfinex API for both REST and websocket interaction', long_description_content_type='text/markdown', From b2460450c64b6257fc7853039f42f20ec10e97ef Mon Sep 17 00:00:00 2001 From: itsdeka Date: Tue, 23 Aug 2022 13:30:05 +0200 Subject: [PATCH 3/5] revert change --- bfxapi/websockets/bfx_websocket.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bfxapi/websockets/bfx_websocket.py b/bfxapi/websockets/bfx_websocket.py index 0afa60b4..74c23717 100644 --- a/bfxapi/websockets/bfx_websocket.py +++ b/bfxapi/websockets/bfx_websocket.py @@ -187,7 +187,7 @@ class BfxWebsocket(GenericWebsocket): - `unsubscribed` (Subscription): A channel has been un-subscribed """ - def __init__(self, host, API_KEY=None, API_SECRET=None, + def __init__(self, API_KEY=None, API_SECRET=None, host='wss://api-pub.bitfinex.com/ws/2', manageOrderBooks=False, dead_man_switch=False, ws_capacity=25, logLevel='INFO', parse_float=float, channel_filter=[], *args, **kwargs): self.API_KEY = API_KEY From 17646f9980239aa9e3857cb6cf8c825cc9aedb59 Mon Sep 17 00:00:00 2001 From: itsdeka Date: Sat, 27 Aug 2022 17:09:00 +0200 Subject: [PATCH 4/5] refactoring - moved hosts to constants.py --- bfxapi/client.py | 6 +----- bfxapi/constants.py | 4 ++++ bfxapi/websockets/bfx_websocket.py | 3 ++- 3 files changed, 7 insertions(+), 6 deletions(-) create mode 100644 bfxapi/constants.py diff --git a/bfxapi/client.py b/bfxapi/client.py index 1700f6c1..1d2d57c9 100644 --- a/bfxapi/client.py +++ b/bfxapi/client.py @@ -7,11 +7,7 @@ from .websockets.bfx_websocket import BfxWebsocket from .rest.bfx_rest import BfxRest - -REST_HOST = 'https://api.bitfinex.com/v2' -WS_HOST = 'wss://api.bitfinex.com/ws/2' -PUB_REST_HOST = 'https://api-pub.bitfinex.com/v2' -PUB_WS_HOST = 'wss://api-pub.bitfinex.com/ws/2' +from .constants import * class Client: """ diff --git a/bfxapi/constants.py b/bfxapi/constants.py new file mode 100644 index 00000000..a0c65251 --- /dev/null +++ b/bfxapi/constants.py @@ -0,0 +1,4 @@ +REST_HOST = 'https://api.bitfinex.com/v2' +WS_HOST = 'wss://api.bitfinex.com/ws/2' +PUB_REST_HOST = 'https://api-pub.bitfinex.com/v2' +PUB_WS_HOST = 'wss://api-pub.bitfinex.com/ws/2' \ No newline at end of file diff --git a/bfxapi/websockets/bfx_websocket.py b/bfxapi/websockets/bfx_websocket.py index 74c23717..451d9752 100644 --- a/bfxapi/websockets/bfx_websocket.py +++ b/bfxapi/websockets/bfx_websocket.py @@ -14,6 +14,7 @@ from ..utils.auth import generate_auth_payload from ..utils.decorators import handle_failure from ..models import Order, Trade, OrderBook, Ticker, FundingTicker +from ..constants import PUB_WS_HOST class Flags: @@ -187,7 +188,7 @@ class BfxWebsocket(GenericWebsocket): - `unsubscribed` (Subscription): A channel has been un-subscribed """ - def __init__(self, API_KEY=None, API_SECRET=None, host='wss://api-pub.bitfinex.com/ws/2', + def __init__(self, API_KEY=None, API_SECRET=None, host=PUB_WS_HOST, manageOrderBooks=False, dead_man_switch=False, ws_capacity=25, logLevel='INFO', parse_float=float, channel_filter=[], *args, **kwargs): self.API_KEY = API_KEY From 23c00e77a2d47342961aebadcb083a07bc8a03a7 Mon Sep 17 00:00:00 2001 From: itsdeka Date: Sat, 27 Aug 2022 17:17:13 +0200 Subject: [PATCH 5/5] refactoring - updated tests --- bfxapi/examples/rest/create_funding.py | 3 ++- bfxapi/examples/rest/create_order.py | 3 ++- bfxapi/examples/rest/get_authenticated_data.py | 3 ++- bfxapi/examples/rest/get_public_data.py | 3 ++- bfxapi/examples/rest/get_seed_trades.py | 3 ++- bfxapi/examples/rest/merchant.py | 3 ++- bfxapi/examples/rest/transfer_wallet.py | 3 ++- bfxapi/examples/ws/cancel_order.py | 3 ++- bfxapi/examples/ws/connect.py | 3 ++- bfxapi/examples/ws/connect_auth.py | 3 ++- bfxapi/examples/ws/full_orderbook.py | 3 ++- bfxapi/examples/ws/multiple_instances.py | 3 ++- bfxapi/examples/ws/resubscribe_orderbook.py | 3 ++- bfxapi/examples/ws/send_order.py | 3 ++- bfxapi/examples/ws/start_stop_connection.py | 3 ++- bfxapi/examples/ws/subscribe_derivative_status.py | 3 ++- bfxapi/examples/ws/subscribe_orderbook.py | 3 ++- bfxapi/examples/ws/subscribe_tickers.py | 3 ++- bfxapi/examples/ws/subscribe_trades_candles.py | 3 ++- bfxapi/examples/ws/update_order.py | 3 ++- bfxapi/examples/ws/wallet_balance.py | 3 ++- 21 files changed, 42 insertions(+), 21 deletions(-) diff --git a/bfxapi/examples/rest/create_funding.py b/bfxapi/examples/rest/create_funding.py index 8e4eeae1..db168260 100644 --- a/bfxapi/examples/rest/create_funding.py +++ b/bfxapi/examples/rest/create_funding.py @@ -3,7 +3,8 @@ import asyncio sys.path.append('../../../') -from bfxapi import Client, WS_HOST, REST_HOST +from bfxapi import Client +from bfxapi.constants import WS_HOST, REST_HOST API_KEY=os.getenv("BFX_KEY") API_SECRET=os.getenv("BFX_SECRET") diff --git a/bfxapi/examples/rest/create_order.py b/bfxapi/examples/rest/create_order.py index ad5bc23f..94e96407 100644 --- a/bfxapi/examples/rest/create_order.py +++ b/bfxapi/examples/rest/create_order.py @@ -3,7 +3,8 @@ import asyncio import time sys.path.append('../../../') -from bfxapi import Client, WS_HOST, REST_HOST +from bfxapi import Client +from bfxapi.constants import WS_HOST, REST_HOST from bfxapi.models import OrderType API_KEY=os.getenv("BFX_KEY") diff --git a/bfxapi/examples/rest/get_authenticated_data.py b/bfxapi/examples/rest/get_authenticated_data.py index c5776a1c..a557de26 100644 --- a/bfxapi/examples/rest/get_authenticated_data.py +++ b/bfxapi/examples/rest/get_authenticated_data.py @@ -4,7 +4,8 @@ import time sys.path.append('../../../') -from bfxapi import Client, WS_HOST, REST_HOST +from bfxapi import Client +from bfxapi.constants import WS_HOST, REST_HOST API_KEY=os.getenv("BFX_KEY") API_SECRET=os.getenv("BFX_SECRET") diff --git a/bfxapi/examples/rest/get_public_data.py b/bfxapi/examples/rest/get_public_data.py index 151ca0d6..6d1e246f 100644 --- a/bfxapi/examples/rest/get_public_data.py +++ b/bfxapi/examples/rest/get_public_data.py @@ -4,7 +4,8 @@ import time sys.path.append('../../../') -from bfxapi import Client, PUB_WS_HOST, PUB_REST_HOST +from bfxapi import Client +from bfxapi.constants import PUB_WS_HOST, PUB_REST_HOST # Retrieving public data requires public hosts bfx = Client( diff --git a/bfxapi/examples/rest/get_seed_trades.py b/bfxapi/examples/rest/get_seed_trades.py index caffb19e..6f9cbf80 100644 --- a/bfxapi/examples/rest/get_seed_trades.py +++ b/bfxapi/examples/rest/get_seed_trades.py @@ -3,7 +3,8 @@ import asyncio sys.path.append('../../../') -from bfxapi import Client, PUB_WS_HOST, PUB_REST_HOST +from bfxapi import Client +from bfxapi.constants import PUB_WS_HOST, PUB_REST_HOST # Retrieving seed trades requires public hosts bfx = Client( diff --git a/bfxapi/examples/rest/merchant.py b/bfxapi/examples/rest/merchant.py index 81c8faed..54775887 100644 --- a/bfxapi/examples/rest/merchant.py +++ b/bfxapi/examples/rest/merchant.py @@ -2,7 +2,8 @@ import sys import asyncio sys.path.append('../../../') -from bfxapi import Client, WS_HOST, REST_HOST +from bfxapi import Client +from bfxapi.constants import WS_HOST, REST_HOST API_KEY=os.getenv("BFX_KEY") API_SECRET=os.getenv("BFX_SECRET") diff --git a/bfxapi/examples/rest/transfer_wallet.py b/bfxapi/examples/rest/transfer_wallet.py index 84e5616e..a0c59ceb 100644 --- a/bfxapi/examples/rest/transfer_wallet.py +++ b/bfxapi/examples/rest/transfer_wallet.py @@ -3,7 +3,8 @@ import asyncio sys.path.append('../../../') -from bfxapi import Client, WS_HOST, REST_HOST +from bfxapi import Client +from bfxapi.constants import WS_HOST, REST_HOST API_KEY=os.getenv("BFX_KEY") API_SECRET=os.getenv("BFX_SECRET") diff --git a/bfxapi/examples/ws/cancel_order.py b/bfxapi/examples/ws/cancel_order.py index 6804c300..e37ad00c 100644 --- a/bfxapi/examples/ws/cancel_order.py +++ b/bfxapi/examples/ws/cancel_order.py @@ -2,7 +2,8 @@ import sys sys.path.append('../../../') -from bfxapi import Client, Order, WS_HOST, REST_HOST +from bfxapi import Client, Order +from bfxapi.constants import WS_HOST, REST_HOST API_KEY=os.getenv("BFX_KEY") API_SECRET=os.getenv("BFX_SECRET") diff --git a/bfxapi/examples/ws/connect.py b/bfxapi/examples/ws/connect.py index ffb28ac3..b63cd7d8 100644 --- a/bfxapi/examples/ws/connect.py +++ b/bfxapi/examples/ws/connect.py @@ -2,7 +2,8 @@ import sys sys.path.append('../../../') -from bfxapi import Client, PUB_WS_HOST, PUB_REST_HOST +from bfxapi import Client +from bfxapi.constants import PUB_WS_HOST, PUB_REST_HOST bfx = Client( logLevel='DEBUG', diff --git a/bfxapi/examples/ws/connect_auth.py b/bfxapi/examples/ws/connect_auth.py index 4e5db587..a01c6d36 100644 --- a/bfxapi/examples/ws/connect_auth.py +++ b/bfxapi/examples/ws/connect_auth.py @@ -2,7 +2,8 @@ import sys sys.path.append('../../../') -from bfxapi import Client, WS_HOST, REST_HOST +from bfxapi import Client +from bfxapi.constants import WS_HOST, REST_HOST API_KEY=os.getenv("BFX_KEY") API_SECRET=os.getenv("BFX_SECRET") diff --git a/bfxapi/examples/ws/full_orderbook.py b/bfxapi/examples/ws/full_orderbook.py index 49639b45..baac6568 100644 --- a/bfxapi/examples/ws/full_orderbook.py +++ b/bfxapi/examples/ws/full_orderbook.py @@ -3,7 +3,8 @@ from collections import OrderedDict sys.path.append('../../../') -from bfxapi import Client, PUB_WS_HOST, PUB_REST_HOST +from bfxapi import Client +from bfxapi.constants import PUB_WS_HOST, PUB_REST_HOST # Retrieving orderbook requires public hosts bfx = Client( diff --git a/bfxapi/examples/ws/multiple_instances.py b/bfxapi/examples/ws/multiple_instances.py index 9cb89ed3..cf1dc047 100644 --- a/bfxapi/examples/ws/multiple_instances.py +++ b/bfxapi/examples/ws/multiple_instances.py @@ -10,7 +10,8 @@ import asyncio from functools import partial import websockets as ws -from bfxapi import Client, PUB_WS_HOST, PUB_REST_HOST +from bfxapi import Client +from bfxapi.constants import PUB_WS_HOST, PUB_REST_HOST import math import random diff --git a/bfxapi/examples/ws/resubscribe_orderbook.py b/bfxapi/examples/ws/resubscribe_orderbook.py index 7bbfb20b..5e102770 100644 --- a/bfxapi/examples/ws/resubscribe_orderbook.py +++ b/bfxapi/examples/ws/resubscribe_orderbook.py @@ -1,7 +1,8 @@ import sys sys.path.append('../../../') -from bfxapi import Client, PUB_WS_HOST, PUB_REST_HOST +from bfxapi import Client +from bfxapi.constants import PUB_WS_HOST, PUB_REST_HOST # Retrieving orderbook requires public hosts bfx = Client( diff --git a/bfxapi/examples/ws/send_order.py b/bfxapi/examples/ws/send_order.py index f26d6707..743934d3 100644 --- a/bfxapi/examples/ws/send_order.py +++ b/bfxapi/examples/ws/send_order.py @@ -2,7 +2,8 @@ import sys sys.path.append('../../../') -from bfxapi import Client, Order, WS_HOST, REST_HOST +from bfxapi import Client, Order +from bfxapi.constants import WS_HOST, REST_HOST API_KEY=os.getenv("BFX_KEY") API_SECRET=os.getenv("BFX_SECRET") diff --git a/bfxapi/examples/ws/start_stop_connection.py b/bfxapi/examples/ws/start_stop_connection.py index 59de4792..4ddafbfd 100644 --- a/bfxapi/examples/ws/start_stop_connection.py +++ b/bfxapi/examples/ws/start_stop_connection.py @@ -1,7 +1,8 @@ import sys sys.path.append('../../../') -from bfxapi import Client, PUB_WS_HOST, PUB_REST_HOST +from bfxapi import Client +from bfxapi.constants import PUB_WS_HOST, PUB_REST_HOST bfx = Client( logLevel='DEBUG', diff --git a/bfxapi/examples/ws/subscribe_derivative_status.py b/bfxapi/examples/ws/subscribe_derivative_status.py index 52ca79d4..3c5a9954 100644 --- a/bfxapi/examples/ws/subscribe_derivative_status.py +++ b/bfxapi/examples/ws/subscribe_derivative_status.py @@ -1,7 +1,8 @@ import sys sys.path.append('../../../') -from bfxapi import Client, PUB_WS_HOST, PUB_REST_HOST +from bfxapi import Client +from bfxapi.constants import PUB_WS_HOST, PUB_REST_HOST # Retrieving derivative status requires public hosts bfx = Client( diff --git a/bfxapi/examples/ws/subscribe_orderbook.py b/bfxapi/examples/ws/subscribe_orderbook.py index bc06945f..a9c44ab1 100644 --- a/bfxapi/examples/ws/subscribe_orderbook.py +++ b/bfxapi/examples/ws/subscribe_orderbook.py @@ -2,7 +2,8 @@ import sys sys.path.append('../../../') -from bfxapi import Client, PUB_WS_HOST, PUB_REST_HOST +from bfxapi import Client +from bfxapi.constants import PUB_WS_HOST, PUB_REST_HOST # Retrieving trades/candles requires public hosts bfx = Client( diff --git a/bfxapi/examples/ws/subscribe_tickers.py b/bfxapi/examples/ws/subscribe_tickers.py index 2eb744fd..616571ed 100644 --- a/bfxapi/examples/ws/subscribe_tickers.py +++ b/bfxapi/examples/ws/subscribe_tickers.py @@ -1,7 +1,8 @@ import sys sys.path.append('../../../') -from bfxapi import Client, PUB_WS_HOST, PUB_REST_HOST +from bfxapi import Client +from bfxapi.constants import PUB_WS_HOST, PUB_REST_HOST # Retrieving tickers requires public hosts bfx = Client( diff --git a/bfxapi/examples/ws/subscribe_trades_candles.py b/bfxapi/examples/ws/subscribe_trades_candles.py index 1248dea4..024eb587 100644 --- a/bfxapi/examples/ws/subscribe_trades_candles.py +++ b/bfxapi/examples/ws/subscribe_trades_candles.py @@ -1,7 +1,8 @@ import sys sys.path.append('../../../') -from bfxapi import Client, PUB_WS_HOST, PUB_REST_HOST +from bfxapi import Client +from bfxapi.constants import PUB_WS_HOST, PUB_REST_HOST # Retrieving trades/candles requires public hosts bfx = Client( diff --git a/bfxapi/examples/ws/update_order.py b/bfxapi/examples/ws/update_order.py index 936d1b61..8eb26ae4 100644 --- a/bfxapi/examples/ws/update_order.py +++ b/bfxapi/examples/ws/update_order.py @@ -2,7 +2,8 @@ import sys sys.path.append('../../../') -from bfxapi import Client, Order, WS_HOST, REST_HOST +from bfxapi import Client, Order +from bfxapi.constants import WS_HOST, REST_HOST API_KEY=os.getenv("BFX_KEY") API_SECRET=os.getenv("BFX_SECRET") diff --git a/bfxapi/examples/ws/wallet_balance.py b/bfxapi/examples/ws/wallet_balance.py index 731faa6a..f4af1636 100644 --- a/bfxapi/examples/ws/wallet_balance.py +++ b/bfxapi/examples/ws/wallet_balance.py @@ -1,7 +1,8 @@ import os import sys sys.path.append('../../../') -from bfxapi import Client, WS_HOST, REST_HOST +from bfxapi import Client +from bfxapi.constants import WS_HOST, REST_HOST API_KEY=os.getenv("BFX_KEY") API_SECRET=os.getenv("BFX_SECRET")