mirror of
https://github.com/aljazceru/bitfinex-api-py.git
synced 2025-12-19 14:54:21 +01:00
rest: add derivative status and set collateral endpoints
This commit is contained in:
@@ -12,8 +12,7 @@ API_SECRET=os.getenv("BFX_SECRET")
|
||||
bfx = Client(
|
||||
API_KEY=API_KEY,
|
||||
API_SECRET=API_SECRET,
|
||||
logLevel='DEBUG',
|
||||
rest_host='https://test.bitfinex.com/v2'
|
||||
logLevel='DEBUG'
|
||||
)
|
||||
|
||||
now = int(round(time.time() * 1000))
|
||||
|
||||
@@ -38,12 +38,18 @@ async def log_mul_tickers():
|
||||
print ("Tickers:")
|
||||
print (tickers)
|
||||
|
||||
async def log_derivative_status():
|
||||
status = await bfx.rest.get_derivative_status('tBTCF0:USTF0')
|
||||
print ("Deriv status:")
|
||||
print (status)
|
||||
|
||||
async def run():
|
||||
await log_historical_candles()
|
||||
await log_historical_trades()
|
||||
await log_books()
|
||||
await log_ticker()
|
||||
await log_mul_tickers()
|
||||
await log_derivative_status()
|
||||
|
||||
t = asyncio.ensure_future(run())
|
||||
asyncio.get_event_loop().run_until_complete(t)
|
||||
|
||||
@@ -33,7 +33,7 @@ class BfxRest:
|
||||
|
||||
async def fetch(self, endpoint, params=""):
|
||||
"""
|
||||
Fetch a GET request from the bitfinex host
|
||||
Send a GET request to the bitfinex api
|
||||
|
||||
@return reponse
|
||||
"""
|
||||
@@ -49,7 +49,7 @@ class BfxRest:
|
||||
|
||||
async def post(self, endpoint, data={}, params=""):
|
||||
"""
|
||||
Request a POST to the bitfinex host
|
||||
Send a pre-signed POST request to the bitfinex api
|
||||
|
||||
@return response
|
||||
"""
|
||||
@@ -151,7 +151,7 @@ class BfxRest:
|
||||
Get tickers for the given symbol. Tickers shows you the current best bid and ask,
|
||||
as well as the last trade price.
|
||||
|
||||
@parms symbols symbol string: pair symbol i.e tBTCUSD
|
||||
@param symbols symbol string: pair symbol i.e tBTCUSD
|
||||
@return Array [ SYMBOL, BID, BID_SIZE, ASK, ASK_SIZE, DAILY_CHANGE,
|
||||
DAILY_CHANGE_PERC, LAST_PRICE, VOLUME, HIGH, LOW ]
|
||||
"""
|
||||
@@ -164,7 +164,7 @@ class BfxRest:
|
||||
Get tickers for the given symbols. Tickers shows you the current best bid and ask,
|
||||
as well as the last trade price.
|
||||
|
||||
@parms symbols Array<string>: array of symbols i.e [tBTCUSD, tETHUSD]
|
||||
@param symbols Array<string>: array of symbols i.e [tBTCUSD, tETHUSD]
|
||||
@return Array [ SYMBOL, BID, BID_SIZE, ASK, ASK_SIZE, DAILY_CHANGE, DAILY_CHANGE_PERC,
|
||||
LAST_PRICE, VOLUME, HIGH, LOW ]
|
||||
"""
|
||||
@@ -172,6 +172,31 @@ class BfxRest:
|
||||
ticker = await self.fetch(endpoint)
|
||||
return ticker
|
||||
|
||||
async def get_derivative_status(self, symbol):
|
||||
"""
|
||||
Gets platform information for derivative symbol.
|
||||
|
||||
@param derivativeSymbol string: i.e tBTCF0:USTF0
|
||||
@return [KEY/SYMBOL, MTS, PLACEHOLDER, DERIV_PRICE, SPOT_PRICE, PLACEHOLDER, INSURANCE_FUND_BALANCE4,
|
||||
PLACEHOLDER, PLACEHOLDER, FUNDING_ACCRUED, FUNDING_STEP, PLACEHOLDER]
|
||||
"""
|
||||
statuses = await self.get_derivative_statuses([symbol])
|
||||
if len(statuses) > 0:
|
||||
return statuses[0]
|
||||
return []
|
||||
|
||||
async def get_derivative_statuses(self, symbols):
|
||||
"""
|
||||
Gets platform information for a collection of derivative symbols.
|
||||
|
||||
@param derivativeSymbols Array<string>: array of symbols i.e [tBTCF0:USTF0 ...] or ["ALL"]
|
||||
@return [KEY/SYMBOL, MTS, PLACEHOLDER, DERIV_PRICE, SPOT_PRICE, PLACEHOLDER, INSURANCE_FUND_BALANCE4,
|
||||
PLACEHOLDER, PLACEHOLDER, FUNDING_ACCRUED, FUNDING_STEP, PLACEHOLDER]
|
||||
"""
|
||||
endpoint = "status/deriv?keys={}".format(','.join(symbols))
|
||||
status = await self.fetch(endpoint)
|
||||
return status
|
||||
|
||||
##################################################
|
||||
# Authenticated Data #
|
||||
##################################################
|
||||
@@ -368,3 +393,20 @@ class BfxRest:
|
||||
payload['sell_price_oco'] = stop_sell_price
|
||||
endpoint = 'order/new'
|
||||
return await self.post(endpoint, data=payload)
|
||||
|
||||
##################################################
|
||||
# Derivatives #
|
||||
##################################################
|
||||
|
||||
async def set_derivative_collateral(self, symbol, collateral):
|
||||
"""
|
||||
Update the amount of callateral used to back a derivative position.
|
||||
|
||||
@param symbol of the derivative i.e 'tBTCF0:USTF0'
|
||||
@param collateral: amount of collateral/value to apply to the open position
|
||||
"""
|
||||
endpoint = 'auth/w/deriv/collateral/set'
|
||||
payload = {}
|
||||
payload['symbol'] = symbol
|
||||
payload['collateral'] = collateral
|
||||
return await self.post(endpoint, data=payload)
|
||||
|
||||
Reference in New Issue
Block a user