mirror of
https://github.com/aljazceru/bitfinex-api-py.git
synced 2025-12-19 14:54:21 +01:00
models/position: fix cconstruction of position from raw array
This commit is contained in:
committed by
Jacob Plaster
parent
b78f567d01
commit
2221ca3e4c
@@ -38,7 +38,7 @@ class OrderSide:
|
|||||||
|
|
||||||
class OrderClosedModel:
|
class OrderClosedModel:
|
||||||
"""
|
"""
|
||||||
Enum used index the different values in a raw order array
|
Enum used to index the different values in a raw order array
|
||||||
"""
|
"""
|
||||||
ID = 0
|
ID = 0
|
||||||
GID = 1
|
GID = 1
|
||||||
|
|||||||
@@ -1,25 +1,55 @@
|
|||||||
"""
|
"""
|
||||||
Module used to describe all of the different data types
|
Module used to describe all of the different data types
|
||||||
"""
|
"""
|
||||||
|
class PositionModel:
|
||||||
|
"""
|
||||||
|
Enum used to index the different values in a raw order array
|
||||||
|
"""
|
||||||
|
SYMBOL = 0
|
||||||
|
STATUS = 1
|
||||||
|
AMOUNT = 2
|
||||||
|
BASE_PRICE = 3
|
||||||
|
MARGIN_FUNDING = 4
|
||||||
|
MARGIN_FUNDING_TYPE = 5
|
||||||
|
PL = 6
|
||||||
|
PL_PERC = 7
|
||||||
|
PRICE_LIQ = 8
|
||||||
|
LEVERAGE = 9
|
||||||
|
# _PLACEHOLDER,
|
||||||
|
POSITION_ID = 11
|
||||||
|
MTS_CREATE = 12
|
||||||
|
MTS_UPDATE = 13
|
||||||
|
# _PLACEHOLDER
|
||||||
|
TYPE = 15
|
||||||
|
# _PLACEHOLDER,
|
||||||
|
COLLATERAL = 17
|
||||||
|
COLLATERAL_MIN = 18
|
||||||
|
META = 19
|
||||||
|
|
||||||
class Position:
|
class Position:
|
||||||
"""
|
"""
|
||||||
SYMBOL string Pair (tBTCUSD, ...).
|
SYMBOL string Pair (tBTCUSD, …).
|
||||||
STATUS string Status (ACTIVE, CLOSED).
|
STATUS string Status (ACTIVE, CLOSED).
|
||||||
AMOUNT float Size of the position. Positive values means a long position,
|
±AMOUNT float Size of the position. A positive value indicates a long position; a negative value indicates a short position.
|
||||||
negative values means a short position.
|
BASE_PRICE float Base price of the position. (Average traded price of the previous orders of the position)
|
||||||
BASE_PRICE float The price at which you entered your position.
|
|
||||||
MARGIN_FUNDING float The amount of funding being used for this position.
|
MARGIN_FUNDING float The amount of funding being used for this position.
|
||||||
MARGIN_FUNDING_TYPE int 0 for daily, 1 for term.
|
MARGIN_FUNDING_TYPE int 0 for daily, 1 for term.
|
||||||
PL float Profit & Loss
|
PL float Profit & Loss
|
||||||
PL_PERC float Profit & Loss Percentage
|
PL_PERC float Profit & Loss Percentage
|
||||||
PRICE_LIQ float Liquidation price
|
PRICE_LIQ float Liquidation price
|
||||||
LEVERAGE float Beta value
|
LEVERAGE float Leverage used for the position
|
||||||
|
POSITION_ID int64 Position ID
|
||||||
|
MTS_CREATE int Millisecond timestamp of creation
|
||||||
|
MTS_UPDATE int Millisecond timestamp of update
|
||||||
|
TYPE int Identifies the type of position, 0 = Margin position, 1 = Derivatives position
|
||||||
|
COLLATERAL float The amount of collateral applied to the open position
|
||||||
|
COLLATERAL_MIN float The minimum amount of collateral required for the position
|
||||||
|
META json string Additional meta information about the position
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, symbol, status, amount, b_price, m_funding, m_funding_type,
|
def __init__(self, symbol, status, amount, b_price, m_funding, m_funding_type,
|
||||||
profit_loss, profit_loss_perc, l_price, lev):
|
profit_loss, profit_loss_perc, l_price, lev, id, mts_create, mts_update,
|
||||||
|
p_type, collateral, collateral_min, meta):
|
||||||
self.symbol = symbol
|
self.symbol = symbol
|
||||||
self.status = status
|
self.status = status
|
||||||
self.amount = amount
|
self.amount = amount
|
||||||
@@ -30,6 +60,13 @@ class Position:
|
|||||||
self.profit_loss_percentage = profit_loss_perc
|
self.profit_loss_percentage = profit_loss_perc
|
||||||
self.liquidation_price = l_price
|
self.liquidation_price = l_price
|
||||||
self.leverage = lev
|
self.leverage = lev
|
||||||
|
self.id = id
|
||||||
|
self.mts_create = mts_create
|
||||||
|
self.mts_update = mts_update
|
||||||
|
self.type = p_type
|
||||||
|
self.collateral = collateral
|
||||||
|
self.collateral_min = collateral_min
|
||||||
|
self.meta = meta
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def from_raw_rest_position(raw_position):
|
def from_raw_rest_position(raw_position):
|
||||||
@@ -38,7 +75,26 @@ class Position:
|
|||||||
|
|
||||||
@return Position
|
@return Position
|
||||||
"""
|
"""
|
||||||
return Position(*raw_position)
|
sym = raw_position[PositionModel.SYMBOL]
|
||||||
|
status = raw_position[PositionModel.STATUS]
|
||||||
|
amnt = raw_position[PositionModel.AMOUNT]
|
||||||
|
b_price = raw_position[PositionModel.BASE_PRICE]
|
||||||
|
m_fund = raw_position[PositionModel.MARGIN_FUNDING]
|
||||||
|
m_fund_t = raw_position[PositionModel.MARGIN_FUNDING_TYPE]
|
||||||
|
pl = raw_position[PositionModel.PL]
|
||||||
|
pl_prc = raw_position[PositionModel.PL_PERC]
|
||||||
|
l_price = raw_position[PositionModel.PRICE_LIQ]
|
||||||
|
lev = raw_position[PositionModel.LEVERAGE]
|
||||||
|
pid = raw_position[PositionModel.POSITION_ID]
|
||||||
|
mtsc = raw_position[PositionModel.MTS_CREATE]
|
||||||
|
mtsu = raw_position[PositionModel.MTS_UPDATE]
|
||||||
|
ptype = raw_position[PositionModel.TYPE]
|
||||||
|
coll = raw_position[PositionModel.COLLATERAL]
|
||||||
|
coll_min = raw_position[PositionModel.COLLATERAL_MIN]
|
||||||
|
meta = raw_position[PositionModel.META]
|
||||||
|
|
||||||
|
return Position(sym, status, amnt, b_price, m_fund, m_fund_t, pl, pl_prc, l_price,
|
||||||
|
lev, pid, mtsc, mtsu, ptype, coll, coll_min, meta)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
''' Allow us to print the Trade object in a pretty format '''
|
''' Allow us to print the Trade object in a pretty format '''
|
||||||
|
|||||||
Reference in New Issue
Block a user