bfxapi/rest: add submit/cancel funding

This commit is contained in:
Jacob Plaster
2019-09-11 12:45:13 +01:00
committed by Jacob Plaster
parent dfabb438de
commit edfd4fc280
3 changed files with 61 additions and 2 deletions

View File

@@ -2,6 +2,12 @@
Module used to describe all of the different data types Module used to describe all of the different data types
""" """
class FundingOfferTypes:
"""
Enum used to define the different funding offer types
"""
LIMIT = 'LIMIT'
FRR_DELTA = 'FRRDELTAVAR'
class FundingOfferModel: class FundingOfferModel:
""" """
@@ -41,6 +47,8 @@ class FundingOffer:
RENEW int 0 if false, 1 if true RENEW int 0 if false, 1 if true
""" """
Type = FundingOfferTypes()
def __init__(self, fid, symbol, mts_create, mts_updated, amount, amount_orig, f_type, def __init__(self, fid, symbol, mts_create, mts_updated, amount, amount_orig, f_type,
flags, status, rate, period, notify, hidden, renew): flags, status, rate, period, notify, hidden, renew):
# pylint: disable=invalid-name # pylint: disable=invalid-name

View File

@@ -2,7 +2,8 @@
Module used to describe all of the different notification data types Module used to describe all of the different notification data types
""" """
from . import Order from .order import Order
from .funding_offer import FundingOffer
class NotificationModal: class NotificationModal:
""" """
@@ -95,6 +96,10 @@ class Notification:
basic.notify_info = Order.from_raw_order(basic.notify_info) basic.notify_info = Order.from_raw_order(basic.notify_info)
elif basic.notify_type == NotificationTypes.ORDER_UPDATED_REQ: elif basic.notify_type == NotificationTypes.ORDER_UPDATED_REQ:
basic.notify_info = Order.from_raw_order(basic.notify_info) basic.notify_info = Order.from_raw_order(basic.notify_info)
elif basic.notify_type == NotificationTypes.FUNDING_OFFER_NEW:
basic.notify_info = FundingOffer.from_raw_offer(basic.notify_info)
elif basic.notify_type == NotificationTypes.FUNDING_OFFER_CANCEL:
basic.notify_info = FundingOffer.from_raw_offer(basic.notify_info)
return basic return basic
def __str__(self): def __str__(self):

View File

@@ -351,6 +351,53 @@ class BfxRest:
credits = await self.post(endpoint, params=params) credits = await self.post(endpoint, params=params)
return [FundingCredit.from_raw_credit(c) for c in credits] return [FundingCredit.from_raw_credit(c) for c in credits]
async def submit_funding_offer(self, symbol, amount, rate, period,
funding_type=FundingOffer.Type.LIMIT, hidden=False):
"""
Submits a new funding offer
@param symbol string: pair symbol i.e fUSD
@param amount float: funding size
@param rate float: percentage rate to charge per a day
@param period int: number of days for funding to remain active once accepted
"""
payload = {
"type": funding_type,
"symbol": symbol,
"amount": str(amount),
"rate": str(rate),
"period": period,
}
# calculate and add flags
flags = calculate_order_flags(hidden, None, None, None, None)
payload['flags'] = flags
endpoint = "auth/w/funding/offer/submit"
raw_notification = await self.post(endpoint, payload)
return Notification.from_raw_order(raw_notification)
async def submit_cancel_funding_offer(self, fundingId):
"""
Cancel a funding offer
@param fundingId int: the id of the funding offer
"""
endpoint = "auth/w/funding/offer/cancel"
raw_notification = await self.post(endpoint, { 'id': fundingId })
return Notification.from_raw_order(raw_notification)
# async def submit_close_funding(self, id, type):
# """
# `/v2/auth/w/funding/close` (params: `id`, `type` (credit|loan))
# """
# pass
# async def submit_auto_funding(self, ):
# """
# `/v2/auth/w/funding/auto` (params: `status` (1|0), `currency`, `amount`, `rate`, `period`)
# (`rate === 0` means `FRR`)
# """
# pass
################################################## ##################################################
# Orders # # Orders #
################################################## ##################################################
@@ -462,7 +509,6 @@ class BfxRest:
payload['flags'] = flags payload['flags'] = flags
endpoint = "auth/w/order/update" endpoint = "auth/w/order/update"
raw_notification = await self.post(endpoint, payload) raw_notification = await self.post(endpoint, payload)
print (raw_notification)
return Notification.from_raw_order(raw_notification) return Notification.from_raw_order(raw_notification)