derivatives

This commit is contained in:
itsdeka
2023-01-26 16:44:32 +01:00
committed by Davide Casale
parent ca91588067
commit 48433fbb01
5 changed files with 56 additions and 1 deletions

View File

@@ -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 }))

View File

@@ -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

View File

@@ -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

View 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)

View File

@@ -1,4 +1,4 @@
# python -c "import examples.rest.get_positions_snapshot"
# python -c "import examples.rest.get_positions"
import os
import time