diff --git a/bfxapi/models/funding_offer.py b/bfxapi/models/funding_offer.py index 16743a7..d848b63 100644 --- a/bfxapi/models/funding_offer.py +++ b/bfxapi/models/funding_offer.py @@ -2,6 +2,12 @@ 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: """ @@ -41,6 +47,8 @@ class FundingOffer: RENEW int 0 if false, 1 if true """ + Type = FundingOfferTypes() + def __init__(self, fid, symbol, mts_create, mts_updated, amount, amount_orig, f_type, flags, status, rate, period, notify, hidden, renew): # pylint: disable=invalid-name diff --git a/bfxapi/models/notification.py b/bfxapi/models/notification.py index 9d65ad2..91bd6dd 100644 --- a/bfxapi/models/notification.py +++ b/bfxapi/models/notification.py @@ -2,7 +2,8 @@ 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: """ @@ -95,6 +96,10 @@ class Notification: basic.notify_info = Order.from_raw_order(basic.notify_info) elif basic.notify_type == NotificationTypes.ORDER_UPDATED_REQ: 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 def __str__(self): diff --git a/bfxapi/rest/bfx_rest.py b/bfxapi/rest/bfx_rest.py index 7278e27..9d66fea 100644 --- a/bfxapi/rest/bfx_rest.py +++ b/bfxapi/rest/bfx_rest.py @@ -351,6 +351,53 @@ class BfxRest: credits = await self.post(endpoint, params=params) 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 # ################################################## @@ -462,7 +509,6 @@ class BfxRest: payload['flags'] = flags endpoint = "auth/w/order/update" raw_notification = await self.post(endpoint, payload) - print (raw_notification) return Notification.from_raw_order(raw_notification)