Merge pull request #193 from itsdeka/2.0.1

2.0.1
This commit is contained in:
Vigan Abdurrahmani
2022-01-31 14:51:05 +01:00
committed by GitHub
7 changed files with 162 additions and 11 deletions

View File

@@ -1,3 +1,9 @@
2.0.1
-) Added User Settings Write/Read/Delete endpoints (REST)
-) Added Balance Available for Orders/Offers endpoint (REST)
-) Added Alerts endpoints (REST)
-) Fixed trades handling error
2.0.0
-) Implemented Movement endpoints (REST)
-) Fixed unawaited stop

View File

@@ -20,6 +20,10 @@ def log_candle(candle):
def log_trade(trade):
print ("New trade: {}".format(trade))
@bfx.ws.on('new_user_trade')
def log_user_trade(trade):
print ("New user trade: {}".format(trade))
async def start():
await bfx.ws.subscribe('candles', 'tBTCUSD', timeframe='1m')
await bfx.ws.subscribe('trades', 'tBTCUSD')

View File

@@ -1005,6 +1005,123 @@ class BfxRest:
message = await self.post(endpoint, payload)
return message
async def get_alerts(self):
"""
Retrieve a list of active price alerts
"""
endpoint = f"auth/r/alerts"
message = await self.post(endpoint, {})
return message
async def set_alert(self, type, symbol, price):
"""
Sets up a price alert at the given value
# Attributes
@param type string
@param symbol string
@param price float
"""
endpoint = f"auth/w/alert/set"
payload = {
"type": type,
"symbol": symbol,
"price": price
}
message = await self.post(endpoint, payload)
return message
async def delete_alert(self, symbol, price):
"""
Delete an active alert
# Attributes
@param symbol string
@param price float
"""
endpoint = f"auth/w/alert/price:{symbol}:{price}/del"
payload = {
"symbol": symbol,
"price": price
}
message = await self.post(endpoint, payload)
return message
async def calc_order_avail(self, symbol, type, lev, dir=None, rate=None):
"""
Calculate the balance available for orders/offers
# Attributes
@param symbol str: Symbol (tBTCUSD, tBTCUST, fUSD, .... )
@param dir int: Direction of the order (1 for by, -1 for sell) (Mandator for EXCHANGE and MARGIN type, not used for FUNDING)
@param rate str: Order price (Mandator for EXCHANGE and MARGIN type, not used for FUNDING)
@param type str: Type of the order/offer EXCHANGE, MARGIN, DERIV, or FUNDING
@param lev str: Leverage that you want to use in calculating the max order amount (DERIV only)
"""
endpoint = f"auth/calc/order/avail"
payload = {
"symbol": symbol,
"type": type,
"lev": lev
}
if dir:
payload["dir"] = dir
if rate:
payload["rate"] = rate
message = await self.post(endpoint, payload)
return message
async def write_user_settings(self, settings):
"""
Allows you to create custom settings by creating key: value pairs
# Attributes
@param Settings object: object of keys and values to be set. Must follow regex pattern /^api:[A-Za-z0-9_-]*$/
"""
endpoint = f"auth/w/settings/set"
payload = {
"Settings": settings
}
message = await self.post(endpoint, payload)
return message
async def read_user_settings(self, keys):
"""
Allows you to read custom settings by providing a key
# Attributes
@param Keys array: the keys for which you wish to retrieve the values
"""
endpoint = f"auth/w/settings"
payload = {
"Keys": keys
}
message = await self.post(endpoint, payload)
return message
async def delete_user_settings(self, settings):
"""
Allows you to delete custom settings
# Attributes
@param settings object: object of keys to be deleted followed by value 1. Must follow regex pattern /^api:[A-Za-z0-9_-]*$/
"""
endpoint = f"auth/w/settings/del"
payload = {
"Settings": settings
}
message = await self.post(endpoint, payload)
return message
async def get_auth_pulse_hist(self, is_public=None):
"""
Allows you to retrieve your private pulse history or the public pulse history with an additional UID_LIKED field.

View File

@@ -2,4 +2,4 @@
This module contains the current version of the bfxapi lib
"""
__version__ = '2.0.0'
__version__ = '2.0.1'

View File

@@ -66,7 +66,8 @@ def _parse_trade(tData, symbol):
'symbol': symbol
}
def _parse_account_trade(tData):
def _parse_user_trade(tData):
return {
'id': tData[0],
'symbol': tData[1],
@@ -81,7 +82,7 @@ def _parse_account_trade(tData):
}
def _parse_account_trade_update(tData):
def _parse_user_trade_update(tData):
return {
'id': tData[0],
'symbol': tData[1],
@@ -97,6 +98,7 @@ def _parse_account_trade_update(tData):
'cid': tData[11],
}
def _parse_deriv_status_update(sData, symbol):
return {
'symbol': symbol,
@@ -171,6 +173,7 @@ class BfxWebsocket(GenericWebsocket):
- `funding_credit_snapshot` (array): Opening funding credit balances
- `balance_update` (array): When the state of a balance is changed
- `new_trade` (array): A new trade on the market has been executed
- `new_user_trade` (array): A new - your - trade has been executed
- `new_ticker` (Ticker|FundingTicker): A new ticker update has been published
- `new_funding_ticker` (FundingTicker): A new funding ticker update has been published
- `new_trading_ticker` (Ticker): A new trading ticker update has been published
@@ -309,15 +312,29 @@ class BfxWebsocket(GenericWebsocket):
async def _trade_update_handler(self, data):
tData = data[2]
# [0,"tu",[738045455,"tTESTBTC:TESTUSD",1622169615771,66635385225,0.001,38175,"EXCHANGE LIMIT",39000,-1,-0.000002,"TESTBTC",1622169615685]]
tradeObj = _parse_account_trade_update(tData)
# [209, 'tu', [312372989, 1542303108930, 0.35, 5688.61834032]]
if self.subscriptionManager.is_subscribed(data[0]):
symbol = self.subscriptionManager.get(data[0]).symbol
tradeObj = _parse_trade(tData, symbol)
self._emit('trade_update', tradeObj)
else:
# user trade
# [0,"tu",[738045455,"tTESTBTC:TESTUSD",1622169615771,66635385225,0.001,38175,"EXCHANGE LIMIT",39000,-1,-0.000002,"TESTBTC",1622169615685]]
tradeObj = _parse_user_trade_update(tData)
self._emit('user_trade_update', tradeObj)
async def _trade_executed_handler(self, data):
tData = data[2]
# [0,"te",[738045455,"tTESTBTC:TESTUSD",1622169615771,66635385225,0.001,38175,"EXCHANGE LIMIT",39000,-1,null,null,1622169615685]]
tradeObj = _parse_account_trade(tData)
# [209, 'te', [312372989, 1542303108930, 0.35, 5688.61834032]]
if self.subscriptionManager.is_subscribed(data[0]):
symbol = self.subscriptionManager.get(data[0]).symbol
tradeObj = _parse_trade(tData, symbol)
self._emit('new_trade', tradeObj)
else:
# user trade
# [0, 'te', [37558151, 'tBTCUSD', 1643542688513, 1512164914, 0.0001, 30363, 'EXCHANGE MARKET', 100000, -1, None, None, 1643542688390]]
tradeObj = _parse_user_trade(tData)
self._emit('new_user_trade', tradeObj)
async def _wallet_update_handler(self, data):
# [0,"wu",["exchange","USD",89134.66933283,0]]
@@ -436,7 +453,12 @@ class BfxWebsocket(GenericWebsocket):
# connection
data.reverse()
for t in data:
trade = _parse_trade(t, symbol)
trade = {
'mts': t[1],
'amount': t[2],
'price': t[3],
'symbol': symbol
}
self._emit('seed_trade', trade)
async def _candle_handler(self, data):

View File

@@ -76,10 +76,12 @@ https://github.com/Crypto-toolbox/btfxwss
- `funding_credit_snapshot` (array): Opening funding credit balances
- `balance_update` (array): When the state of a balance is changed
- `new_trade` (array): A new trade on the market has been executed
- `new_user_trade` (array): A new - your - trade has been executed
- `new_ticker` (Ticker|FundingTicker): A new ticker update has been published
- `new_funding_ticker` (FundingTicker): A new funding ticker update has been published
- `new_trading_ticker` (Ticker): A new trading ticker update has been published
- `trade_update` (array): A trade on the market has been updated
- `user_trade_update` (array): A - your - trade has been updated
- `new_candle` (array): A new candle has been produced
- `margin_info_updates` (array): New margin information has been broadcasted
- `funding_info_updates` (array): New funding information has been broadcasted

View File

@@ -11,7 +11,7 @@ from os import path
here = path.abspath(path.dirname(__file__))
setup(
name='bitfinex-api-py',
version='2.0.0',
version='2.0.1',
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',