mirror of
https://github.com/aljazceru/bitfinex-api-py.git
synced 2025-12-19 14:54:21 +01:00
-) Use private host for auth-based requests
-) Updated examples
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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:
|
||||
"""
|
||||
|
||||
@@ -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():
|
||||
|
||||
@@ -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():
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -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():
|
||||
|
||||
@@ -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():
|
||||
|
||||
@@ -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():
|
||||
|
||||
@@ -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')
|
||||
|
||||
@@ -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')
|
||||
|
||||
@@ -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
|
||||
)
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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')
|
||||
|
||||
@@ -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')
|
||||
|
||||
@@ -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')
|
||||
|
||||
@@ -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')
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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')
|
||||
|
||||
@@ -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')
|
||||
|
||||
@@ -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')
|
||||
|
||||
@@ -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')
|
||||
|
||||
@@ -2,4 +2,4 @@
|
||||
This module contains the current version of the bfxapi lib
|
||||
"""
|
||||
|
||||
__version__ = '2.0.1'
|
||||
__version__ = '2.0.2'
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user