From 780aae0fb186068f76da92e987c64bb6ac43128f Mon Sep 17 00:00:00 2001 From: Giulio De Pasquale Date: Wed, 16 Dec 2020 11:28:48 +0000 Subject: [PATCH] extracted pos_to_json --- bfxbot/utils.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/bfxbot/utils.py b/bfxbot/utils.py index e0b3285..a25cb9b 100644 --- a/bfxbot/utils.py +++ b/bfxbot/utils.py @@ -1,6 +1,20 @@ +from bfxbot.models import PositionWrapper + TAKER_FEE = 0.2 MAKER_FEE = 0.1 def net_pl_percentage(perc: float, reference_fee_perc: float): return perc - reference_fee_perc + + +def pos_to_json(pw: PositionWrapper): + return { + "id": pw.position.id, + "amount": pw.position.amount, + "base_price": pw.position.base_price, + "state": str(pw.state()), + "symbol": pw.position.symbol, + "profit_loss": pw.net_profit_loss(), + "profit_loss_percentage": pw.net_profit_loss_percentage() + }