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..1700f6c 100644 --- a/bfxapi/client.py +++ b/bfxapi/client.py @@ -5,13 +5,13 @@ 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' +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 c6213bb..8e4eeae 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 9c69a0c..ad5bc23 100644 --- a/bfxapi/examples/rest/create_order.py +++ b/bfxapi/examples/rest/create_order.py @@ -3,16 +3,19 @@ import sys 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 0efd74f..c5776a1 100644 --- a/bfxapi/examples/rest/get_authenticated_data.py +++ b/bfxapi/examples/rest/get_authenticated_data.py @@ -4,15 +4,18 @@ 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") +# 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..151ca0d 100644 --- a/bfxapi/examples/rest/get_public_data.py +++ b/bfxapi/examples/rest/get_public_data.py @@ -4,10 +4,13 @@ import asyncio 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 fb34dab..caffb19 100644 --- a/bfxapi/examples/rest/get_seed_trades.py +++ b/bfxapi/examples/rest/get_seed_trades.py @@ -3,10 +3,13 @@ import sys 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 91521fa..81c8fae 100644 --- a/bfxapi/examples/rest/merchant.py +++ b/bfxapi/examples/rest/merchant.py @@ -2,15 +2,18 @@ import os 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 631ea3b..84e5616 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 70511db..7d105f5 100644 --- a/bfxapi/examples/ws/cancel_order.py +++ b/bfxapi/examples/ws/cancel_order.py @@ -2,15 +2,18 @@ import os 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 4cb21bb..ffb28ac 100644 --- a/bfxapi/examples/ws/connect.py +++ b/bfxapi/examples/ws/connect.py @@ -2,10 +2,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' + 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..4e5db58 100644 --- a/bfxapi/examples/ws/connect_auth.py +++ b/bfxapi/examples/ws/connect_auth.py @@ -2,7 +2,7 @@ import os 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 @@ 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..49639b4 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 89fa677..9cb89ed 100644 --- a/bfxapi/examples/ws/multiple_instances.py +++ b/bfxapi/examples/ws/multiple_instances.py @@ -8,11 +8,9 @@ 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 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 ede112d..7bbfb20 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 6c30fd7..f26d670 100644 --- a/bfxapi/examples/ws/send_order.py +++ b/bfxapi/examples/ws/send_order.py @@ -2,15 +2,18 @@ import os 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 4e23469..59de479 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 3ddb7e5..52ca79d 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 7febcf3..bc06945 100644 --- a/bfxapi/examples/ws/subscribe_orderbook.py +++ b/bfxapi/examples/ws/subscribe_orderbook.py @@ -2,10 +2,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', + 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..2eb744f 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 d7135e6..1248dea 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 68df31e..936d1b6 100644 --- a/bfxapi/examples/ws/update_order.py +++ b/bfxapi/examples/ws/update_order.py @@ -2,15 +2,18 @@ import os 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 c46fa1e..731faa6 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 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..0afa60b 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