Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
2 changes: 1 addition & 1 deletion bfxapi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 1 addition & 5 deletions bfxapi/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,9 @@

# 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:
"""
Expand Down
4 changes: 4 additions & 0 deletions bfxapi/constants.py
Original file line number Diff line number Diff line change
@@ -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'
7 changes: 5 additions & 2 deletions bfxapi/examples/rest/create_funding.py
Original file line number Diff line number Diff line change
@@ -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():
Expand Down
6 changes: 5 additions & 1 deletion bfxapi/examples/rest/create_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,19 @@
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():
Expand Down
6 changes: 5 additions & 1 deletion bfxapi/examples/rest/get_authenticated_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,18 @@
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))
Expand Down
4 changes: 4 additions & 0 deletions bfxapi/examples/rest/get_public_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@
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))
Expand Down
6 changes: 5 additions & 1 deletion bfxapi/examples/rest/get_seed_trades.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@
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():
Expand Down
6 changes: 5 additions & 1 deletion bfxapi/examples/rest/merchant.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,18 @@
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():
Expand Down
7 changes: 5 additions & 2 deletions bfxapi/examples/rest/transfer_wallet.py
Original file line number Diff line number Diff line change
@@ -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():
Expand Down
6 changes: 5 additions & 1 deletion bfxapi/examples/ws/cancel_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,18 @@
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')
Expand Down
5 changes: 4 additions & 1 deletion bfxapi/examples/ws/connect.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
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')
Expand Down
5 changes: 4 additions & 1 deletion bfxapi/examples/ws/connect_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
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")
Expand All @@ -11,6 +12,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
)
Expand Down
7 changes: 5 additions & 2 deletions bfxapi/examples/ws/full_orderbook.py
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
5 changes: 2 additions & 3 deletions bfxapi/examples/ws/multiple_instances.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@
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

Expand All @@ -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

Expand Down
7 changes: 5 additions & 2 deletions bfxapi/examples/ws/resubscribe_orderbook.py
Original file line number Diff line number Diff line change
@@ -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')
Expand Down
6 changes: 5 additions & 1 deletion bfxapi/examples/ws/send_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,18 @@
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')
Expand Down
4 changes: 3 additions & 1 deletion bfxapi/examples/ws/start_stop_connection.py
Original file line number Diff line number Diff line change
@@ -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')
Expand Down
7 changes: 5 additions & 2 deletions bfxapi/examples/ws/subscribe_derivative_status.py
Original file line number Diff line number Diff line change
@@ -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')
Expand Down
4 changes: 4 additions & 0 deletions bfxapi/examples/ws/subscribe_orderbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@
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
Expand Down
7 changes: 5 additions & 2 deletions bfxapi/examples/ws/subscribe_tickers.py
Original file line number Diff line number Diff line change
@@ -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')
Expand Down
7 changes: 5 additions & 2 deletions bfxapi/examples/ws/subscribe_trades_candles.py
Original file line number Diff line number Diff line change
@@ -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')
Expand Down
Loading