mirror of
https://github.com/aljazceru/bitfinex-api-py.git
synced 2025-12-19 06:44:22 +01:00
derivatives
This commit is contained in:
@@ -519,3 +519,9 @@ class _RestAuthenticatedEndpoints(_Requests):
|
||||
|
||||
def get_positions_audit(self, ids: Optional[List[int]] = None, start: Optional[str] = None, end: Optional[str] = None, limit: Optional[int] = None) -> List[PositionAudit]:
|
||||
return [ serializers.PositionAudit.parse(*sub_data) for sub_data in self._POST("auth/r/positions/audit", data={ "ids": ids, "start": start, "end": end, "limit": limit }) ]
|
||||
|
||||
def set_derivative_position_collateral(self, symbol: str, collateral: Union[Decimal, float, str]) -> DerivativePositionCollateral:
|
||||
return serializers.DerivativePositionCollateral.parse(*(self._POST("auth/w/deriv/collateral/set", data={ "symbol": symbol, "collateral": collateral })[0]))
|
||||
|
||||
def get_derivative_position_collateral_limits(self, symbol: str) -> DerivativePositionCollateralLimits:
|
||||
return serializers.DerivativePositionCollateralLimits.parse(*self._POST("auth/calc/deriv/collateral/limits", data={ "symbol": symbol }))
|
||||
|
||||
@@ -594,4 +594,13 @@ PositionAudit = generate_labeler_serializer("PositionAudit", klass=types.Positio
|
||||
"META"
|
||||
])
|
||||
|
||||
DerivativePositionCollateral = generate_labeler_serializer("DerivativePositionCollateral", klass=types.DerivativePositionCollateral, labels=[
|
||||
"STATUS"
|
||||
])
|
||||
|
||||
DerivativePositionCollateralLimits = generate_labeler_serializer("DerivativePositionCollateralLimits", klass=types.DerivativePositionCollateralLimits, labels=[
|
||||
"MIN_COLLATERAL",
|
||||
"MAX_COLLATERAL"
|
||||
])
|
||||
|
||||
#endregion
|
||||
@@ -465,4 +465,13 @@ class PositionAudit(_Type):
|
||||
COLLATERAL_MIN: float
|
||||
META: JSON
|
||||
|
||||
@dataclass
|
||||
class DerivativePositionCollateral(_Type):
|
||||
STATUS: int
|
||||
|
||||
@dataclass
|
||||
class DerivativePositionCollateralLimits(_Type):
|
||||
MIN_COLLATERAL: float
|
||||
MAX_COLLATERAL: float
|
||||
|
||||
#endregion
|
||||
31
examples/rest/derivatives.py
Normal file
31
examples/rest/derivatives.py
Normal file
@@ -0,0 +1,31 @@
|
||||
# python -c "import examples.rest.derivatives"
|
||||
|
||||
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")
|
||||
)
|
||||
|
||||
# Create a new order
|
||||
submitted_order = bfx.rest.auth.submit_order(
|
||||
symbol="tBTCF0:USTF0",
|
||||
amount="0.015",
|
||||
price="16700",
|
||||
lev=10,
|
||||
type="LIMIT"
|
||||
)
|
||||
|
||||
print("Submit Order Notification:", submitted_order)
|
||||
|
||||
# Get position collateral limits
|
||||
limits = bfx.rest.auth.get_derivative_position_collateral_limits(symbol="tBTCF0:USTF0")
|
||||
print(f"Limits {limits}")
|
||||
|
||||
# Update position collateral
|
||||
response = bfx.rest.auth.set_derivative_position_collateral(symbol="tBTCF0:USTF0", collateral=50)
|
||||
print(response.STATUS)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# python -c "import examples.rest.get_positions_snapshot"
|
||||
# python -c "import examples.rest.get_positions"
|
||||
|
||||
import os
|
||||
import time
|
||||
|
||||
Reference in New Issue
Block a user