diff --git a/CHANGELOG b/CHANGELOG index 69a4b97..8563409 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 4ad4f80..5b6918e 100644 --- a/bfxapi/__init__.py +++ b/bfxapi/__init__.py @@ -3,7 +3,7 @@ This module is used to interact with the bitfinex api """ 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 fff114c..1d2d57c 100644 --- a/bfxapi/client.py +++ b/bfxapi/client.py @@ -5,13 +5,9 @@ a websocket client and a rest interface client # 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' +from .constants import * class Client: """ diff --git a/bfxapi/constants.py b/bfxapi/constants.py new file mode 100644 index 0000000..a0c6525 --- /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/examples/rest/create_funding.py b/bfxapi/examples/rest/create_funding.py index c6213bb..db16826 100644 --- a/bfxapi/examples/rest/create_funding.py +++ b/bfxapi/examples/rest/create_funding.py @@ -1,18 +1,21 @@ import os import sys import asyncio -import time sys.path.append('../../../') from bfxapi import Client +from bfxapi.constants import 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 9c69a0c..94e9640 100644 --- a/bfxapi/examples/rest/create_order.py +++ b/bfxapi/examples/rest/create_order.py @@ -4,15 +4,19 @@ import asyncio import time sys.path.append('../../../') from bfxapi import Client +from bfxapi.constants import 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 0efd74f..a557de2 100644 --- a/bfxapi/examples/rest/get_authenticated_data.py +++ b/bfxapi/examples/rest/get_authenticated_data.py @@ -5,14 +5,18 @@ import time sys.path.append('../../../') from bfxapi import Client +from bfxapi.constants import 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 eae9f94..6d1e246 100644 --- a/bfxapi/examples/rest/get_public_data.py +++ b/bfxapi/examples/rest/get_public_data.py @@ -5,9 +5,13 @@ import time sys.path.append('../../../') from bfxapi import Client +from bfxapi.constants import 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 fb34dab..6f9cbf8 100644 --- a/bfxapi/examples/rest/get_seed_trades.py +++ b/bfxapi/examples/rest/get_seed_trades.py @@ -4,9 +4,13 @@ import asyncio sys.path.append('../../../') from bfxapi import Client +from bfxapi.constants import 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 91521fa..5477588 100644 --- a/bfxapi/examples/rest/merchant.py +++ b/bfxapi/examples/rest/merchant.py @@ -3,14 +3,18 @@ import sys import asyncio sys.path.append('../../../') from bfxapi import Client +from bfxapi.constants import 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 631ea3b..a0c59ce 100644 --- a/bfxapi/examples/rest/transfer_wallet.py +++ b/bfxapi/examples/rest/transfer_wallet.py @@ -1,18 +1,21 @@ import os import sys import asyncio -import time sys.path.append('../../../') from bfxapi import Client +from bfxapi.constants import 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 70511db..e37ad00 100644 --- a/bfxapi/examples/ws/cancel_order.py +++ b/bfxapi/examples/ws/cancel_order.py @@ -3,14 +3,18 @@ import sys sys.path.append('../../../') 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") +# 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 4cb21bb..b63cd7d 100644 --- a/bfxapi/examples/ws/connect.py +++ b/bfxapi/examples/ws/connect.py @@ -3,9 +3,12 @@ import sys sys.path.append('../../../') from bfxapi import Client +from bfxapi.constants import 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 fac67e3..a01c6d3 100644 --- a/bfxapi/examples/ws/connect_auth.py +++ b/bfxapi/examples/ws/connect_auth.py @@ -2,7 +2,8 @@ import os import sys sys.path.append('../../../') -from bfxapi import Client, Order +from bfxapi import Client +from bfxapi.constants import WS_HOST, REST_HOST API_KEY=os.getenv("BFX_KEY") API_SECRET=os.getenv("BFX_SECRET") @@ -11,6 +12,8 @@ bfx = Client( 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 d8678e3..baac656 100644 --- a/bfxapi/examples/ws/full_orderbook.py +++ b/bfxapi/examples/ws/full_orderbook.py @@ -1,13 +1,16 @@ -import os import sys import time from collections import OrderedDict sys.path.append('../../../') from bfxapi import Client +from bfxapi.constants import 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 89fa677..cf1dc04 100644 --- a/bfxapi/examples/ws/multiple_instances.py +++ b/bfxapi/examples/ws/multiple_instances.py @@ -8,11 +8,10 @@ bfx ws instances to comply with the open subscriptions number constraint (max. 2 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.constants import PUB_WS_HOST, PUB_REST_HOST import math import random @@ -27,7 +26,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 ede112d..5e10277 100644 --- a/bfxapi/examples/ws/resubscribe_orderbook.py +++ b/bfxapi/examples/ws/resubscribe_orderbook.py @@ -1,11 +1,14 @@ -import os import sys sys.path.append('../../../') from bfxapi import Client +from bfxapi.constants import 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 6c30fd7..743934d 100644 --- a/bfxapi/examples/ws/send_order.py +++ b/bfxapi/examples/ws/send_order.py @@ -3,14 +3,18 @@ import sys sys.path.append('../../../') 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") +# 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 4e23469..4ddafbf 100644 --- a/bfxapi/examples/ws/start_stop_connection.py +++ b/bfxapi/examples/ws/start_stop_connection.py @@ -1,11 +1,13 @@ -import os import sys sys.path.append('../../../') from bfxapi import Client +from bfxapi.constants import 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 3ddb7e5..3c5a995 100644 --- a/bfxapi/examples/ws/subscribe_derivative_status.py +++ b/bfxapi/examples/ws/subscribe_derivative_status.py @@ -1,11 +1,14 @@ -import os import sys sys.path.append('../../../') from bfxapi import Client +from bfxapi.constants import 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 7febcf3..a9c44ab 100644 --- a/bfxapi/examples/ws/subscribe_orderbook.py +++ b/bfxapi/examples/ws/subscribe_orderbook.py @@ -3,9 +3,13 @@ import sys sys.path.append('../../../') from bfxapi import Client +from bfxapi.constants import 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 984fa47..616571e 100644 --- a/bfxapi/examples/ws/subscribe_tickers.py +++ b/bfxapi/examples/ws/subscribe_tickers.py @@ -1,11 +1,14 @@ -import os import sys sys.path.append('../../../') from bfxapi import Client +from bfxapi.constants import 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 d7135e6..024eb58 100644 --- a/bfxapi/examples/ws/subscribe_trades_candles.py +++ b/bfxapi/examples/ws/subscribe_trades_candles.py @@ -1,11 +1,14 @@ -import os import sys sys.path.append('../../../') from bfxapi import Client +from bfxapi.constants import 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 68df31e..8eb26ae 100644 --- a/bfxapi/examples/ws/update_order.py +++ b/bfxapi/examples/ws/update_order.py @@ -3,14 +3,18 @@ import sys sys.path.append('../../../') 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") +# 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 c46fa1e..f4af163 100644 --- a/bfxapi/examples/ws/wallet_balance.py +++ b/bfxapi/examples/ws/wallet_balance.py @@ -2,14 +2,18 @@ import os import sys sys.path.append('../../../') from bfxapi import Client +from bfxapi.constants import 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 f5a20c1..2b350b7 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 74c2371..451d975 100644 --- a/bfxapi/websockets/bfx_websocket.py +++ b/bfxapi/websockets/bfx_websocket.py @@ -14,6 +14,7 @@ from .order_manager import OrderManager 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 diff --git a/setup.py b/setup.py index af19bde..a5c1f42 100644 --- a/setup.py +++ b/setup.py @@ -11,7 +11,7 @@ from os import path 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',