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(
|
bfx = Client(
|
||||||
API_KEY=API_KEY,
|
API_KEY=API_KEY,
|
||||||
API_SECRET=API_SECRET,
|
API_SECRET=API_SECRET,
|
||||||
logLevel='DEBUG',
|
logLevel='DEBUG'
|
||||||
rest_host='https://test.bitfinex.com/v2'
|
|
||||||
)
|
)
|
||||||
|
|
||||||
now = int(round(time.time() * 1000))
|
now = int(round(time.time() * 1000))
|
||||||
|
|||||||
@@ -38,12 +38,18 @@ async def log_mul_tickers():
|
|||||||
print ("Tickers:")
|
print ("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():
|
async def run():
|
||||||
await log_historical_candles()
|
await log_historical_candles()
|
||||||
await log_historical_trades()
|
await log_historical_trades()
|
||||||
await log_books()
|
await log_books()
|
||||||
await log_ticker()
|
await log_ticker()
|
||||||
await log_mul_tickers()
|
await log_mul_tickers()
|
||||||
|
await log_derivative_status()
|
||||||
|
|
||||||
t = asyncio.ensure_future(run())
|
t = asyncio.ensure_future(run())
|
||||||
asyncio.get_event_loop().run_until_complete(t)
|
asyncio.get_event_loop().run_until_complete(t)
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ class BfxRest:
|
|||||||
|
|
||||||
async def fetch(self, endpoint, params=""):
|
async def fetch(self, endpoint, params=""):
|
||||||
"""
|
"""
|
||||||
Fetch a GET request from the bitfinex host
|
Send a GET request to the bitfinex api
|
||||||
|
|
||||||
@return reponse
|
@return reponse
|
||||||
"""
|
"""
|
||||||
@@ -49,7 +49,7 @@ class BfxRest:
|
|||||||
|
|
||||||
async def post(self, endpoint, data={}, params=""):
|
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
|
@return response
|
||||||
"""
|
"""
|
||||||
@@ -151,7 +151,7 @@ class BfxRest:
|
|||||||
Get tickers for the given symbol. Tickers shows you the current best bid and ask,
|
Get tickers for the given symbol. Tickers shows you the current best bid and ask,
|
||||||
as well as the last trade price.
|
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,
|
@return Array [ SYMBOL, BID, BID_SIZE, ASK, ASK_SIZE, DAILY_CHANGE,
|
||||||
DAILY_CHANGE_PERC, LAST_PRICE, VOLUME, HIGH, LOW ]
|
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,
|
Get tickers for the given symbols. Tickers shows you the current best bid and ask,
|
||||||
as well as the last trade price.
|
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,
|
@return Array [ SYMBOL, BID, BID_SIZE, ASK, ASK_SIZE, DAILY_CHANGE, DAILY_CHANGE_PERC,
|
||||||
LAST_PRICE, VOLUME, HIGH, LOW ]
|
LAST_PRICE, VOLUME, HIGH, LOW ]
|
||||||
"""
|
"""
|
||||||
@@ -172,6 +172,31 @@ class BfxRest:
|
|||||||
ticker = await self.fetch(endpoint)
|
ticker = await self.fetch(endpoint)
|
||||||
return ticker
|
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 #
|
# Authenticated Data #
|
||||||
##################################################
|
##################################################
|
||||||
@@ -327,7 +352,7 @@ class BfxRest:
|
|||||||
return [FundingCredit.from_raw_credit(c) for c in credits]
|
return [FundingCredit.from_raw_credit(c) for c in credits]
|
||||||
|
|
||||||
##################################################
|
##################################################
|
||||||
# Orders #
|
# Orders #
|
||||||
##################################################
|
##################################################
|
||||||
|
|
||||||
async def __submit_order(self, symbol, amount, price, oType=Order.Type.LIMIT,
|
async def __submit_order(self, symbol, amount, price, oType=Order.Type.LIMIT,
|
||||||
@@ -368,3 +393,20 @@ class BfxRest:
|
|||||||
payload['sell_price_oco'] = stop_sell_price
|
payload['sell_price_oco'] = stop_sell_price
|
||||||
endpoint = 'order/new'
|
endpoint = 'order/new'
|
||||||
return await self.post(endpoint, data=payload)
|
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