diff --git a/bfxapi/rest/BfxRestInterface.py b/bfxapi/rest/BfxRestInterface.py index 88a08f5..eac75ca 100644 --- a/bfxapi/rest/BfxRestInterface.py +++ b/bfxapi/rest/BfxRestInterface.py @@ -496,3 +496,6 @@ class _RestAuthenticatedEndpoints(_Requests): def get_base_margin_info(self) -> BaseMarginInfo: return serializers.BaseMarginInfo.parse(*(self._POST(f"auth/r/info/margin/base")[1])) + + def claim_position(self, id: int, amount: Optional[Union[Decimal, float, str]] = None) -> Notification[Claim]: + return serializers._Notification[Claim](serializer=serializers.Claim).parse(*self._POST("auth/w/position/claim", data={ "id": id, "amount": amount })) \ No newline at end of file diff --git a/bfxapi/rest/serializers.py b/bfxapi/rest/serializers.py index 044eb51..ec09995 100644 --- a/bfxapi/rest/serializers.py +++ b/bfxapi/rest/serializers.py @@ -235,7 +235,6 @@ TradingMarketAveragePrice = generate_labeler_serializer("TradingMarketAveragePri "AMOUNT" ]) - FundingMarketAveragePrice = generate_labeler_serializer("FundingMarketAveragePrice", klass=types.FundingMarketAveragePrice, labels=[ "RATE_AVG", "AMOUNT" @@ -299,8 +298,8 @@ Position = generate_labeler_serializer("Position", klass=types.Position, labels= "STATUS", "AMOUNT", "BASE_PRICE", - "FUNDING", - "FUNDING_TYPE", + "MARGIN_FUNDING", + "MARGIN_FUNDING_TYPE", "PL", "PL_PERC", "PRICE_LIQ", @@ -489,4 +488,27 @@ BaseMarginInfo = generate_labeler_serializer("BaseMarginInfo", klass=types.BaseM "MARGIN_MIN" ]) +Claim = generate_labeler_serializer("Claim", klass=types.Claim, labels=[ + "SYMBOL", + "POSITION_STATUS", + "AMOUNT", + "BASE_PRICE", + "MARGIN_FUNDING", + "MARGIN_FUNDING_TYPE", + "_PLACEHOLDER", + "_PLACEHOLDER", + "_PLACEHOLDER", + "_PLACEHOLDER", + "_PLACEHOLDER", + "POSITION_ID", + "MTS_CREATE", + "MTS_UPDATE", + "_PLACEHOLDER", + "POS_TYPE", + "_PLACEHOLDER", + "COLLATERAL", + "MIN_COLLATERAL", + "META" +]) + #endregion \ No newline at end of file diff --git a/bfxapi/rest/types.py b/bfxapi/rest/types.py index f9dc96d..720874e 100644 --- a/bfxapi/rest/types.py +++ b/bfxapi/rest/types.py @@ -388,4 +388,20 @@ class BaseMarginInfo(_Type): MARGIN_NET: float MARGIN_MIN: float +@dataclass +class Claim(_Type): + SYMBOL: str + POSITION_STATUS: str + AMOUNT: float + BASE_PRICE: float + MARGIN_FUNDING: float + MARGIN_FUNDING_TYPE: int + POSITION_ID: int + MTS_CREATE: int + MTS_UPDATE: int + POS_TYPE: int + COLLATERAL: str + MIN_COLLATERAL: str + META: JSON + #endregion \ No newline at end of file diff --git a/examples/rest/claim_position.py b/examples/rest/claim_position.py new file mode 100644 index 0000000..de409a3 --- /dev/null +++ b/examples/rest/claim_position.py @@ -0,0 +1,19 @@ +# python -c "from examples.rest.claim_position import *" + +import os + +from bfxapi.client import Client, Constants + +bfx = Client( + REST_HOST=Constants.REST_HOST, + API_KEY=os.getenv("BFX_API_KEY"), + API_SECRET=os.getenv("BFX_API_SECRET") +) + +open_margin_positions = bfx.rest.auth.get_positions() + +# claim all positions +for position in open_margin_positions: + print(f"Position {position}") + claim = bfx.rest.auth.claim_position(position.POSITION_ID, amount=0.000001) + print(f"Claim {claim.NOTIFY_INFO}") \ No newline at end of file diff --git a/examples/rest/create_funding_offer.py b/examples/rest/create_funding_offer.py index 2be1e5a..e41e3b3 100644 --- a/examples/rest/create_funding_offer.py +++ b/examples/rest/create_funding_offer.py @@ -1,3 +1,5 @@ +# python -c "from examples.rest.create_funding_offer import *" + import os from bfxapi.client import Client, Constants diff --git a/examples/rest/create_order.py b/examples/rest/create_order.py index 71a99ca..c4286d2 100644 --- a/examples/rest/create_order.py +++ b/examples/rest/create_order.py @@ -1,3 +1,5 @@ +# python -c "from examples.rest.create_order import *" + import os from bfxapi.client import Client, Constants