trd-utils 0.0.1__py3-none-any.whl → 0.0.3__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of trd-utils might be problematic. Click here for more details.

@@ -2,7 +2,15 @@ from typing import Any, Optional
2
2
  from ..types_helper import BaseModel
3
3
  from decimal import Decimal
4
4
 
5
- default_quantize = Decimal("1.00")
5
+ from .common_utils import (
6
+ dec_to_str,
7
+ dec_to_normalize,
8
+ )
9
+
10
+ ORDER_TYPES_MAP = {
11
+ 0: "LONG",
12
+ 1: "SHORT",
13
+ }
6
14
 
7
15
 
8
16
  class BxApiResponse(BaseModel):
@@ -383,12 +391,12 @@ class CopyTraderPositionInfo(BaseModel):
383
391
  def __str__(self):
384
392
  return (
385
393
  f"{self.coin_name} / {self.valuation_coin_name} {self.position_side} "
386
- + f"{self.leverage.quantize(default_quantize)}x "
387
- + f"vol: {self.volume.quantize(default_quantize)}; "
388
- + f"price: {self.avg_price.quantize(default_quantize)}; "
389
- + f"margin: {self.margin.quantize(default_quantize)}; "
390
- + f"pnl: {self.unrealized_pnl.quantize(default_quantize)}; "
391
- + f"ROI: {(self.position_earning_rate * 100).quantize(default_quantize)}%"
394
+ + f"{dec_to_str(self.leverage)}x "
395
+ + f"vol: {dec_to_str(self.volume)}; "
396
+ + f"price: {dec_to_normalize(self.avg_price)}; "
397
+ + f"margin: {dec_to_str(self.margin)}; "
398
+ + f"unrealized-PnL: {dec_to_str(self.unrealized_pnl)}; "
399
+ + f"ROI: {dec_to_str((self.position_earning_rate * 100))}%"
392
400
  )
393
401
 
394
402
  def __repr__(self):
@@ -570,7 +578,7 @@ class TotalAssetsInfo(BaseModel):
570
578
  sign: str = None
571
579
 
572
580
  def __str__(self):
573
- return f"{self.currency_amount.quantize(default_quantize)} {self.sign}"
581
+ return f"{dec_to_str(self.currency_amount)} {self.sign}"
574
582
 
575
583
  def __repr__(self):
576
584
  return self.__str__()
@@ -648,7 +656,17 @@ class ContractTakeProfitInfo(BaseModel):
648
656
  all_close: bool = None
649
657
 
650
658
  class ContractStopLossInfo(BaseModel):
651
- pass
659
+ id: int = None
660
+
661
+ # this is id of the contract that this take-profit info belongs to.
662
+ order_no: int = None
663
+ margin_coin_name: str = None
664
+ type: int = None
665
+ margin: Decimal = None
666
+ stop_rate: Decimal = None
667
+ stop_price: Decimal = None
668
+ close_style: int = None
669
+ all_close: bool = None
652
670
 
653
671
  class ProfitLossInfoContainer(BaseModel):
654
672
  loss_nums: int = None
@@ -702,6 +720,54 @@ class ContractOrderInfo(BaseModel):
702
720
  configs: Any = None # just dictionaries of take-profit and stop-loss configs.
703
721
  stop_offset_rate: Decimal = None
704
722
 
723
+ def is_long(self) -> bool:
724
+ return self.order_type == 0
725
+
726
+ def get_open_price(self) -> Decimal:
727
+ return self.display_price
728
+
729
+ def get_liquidation_price(self) -> Decimal:
730
+ return self.sys_force_price
731
+
732
+ def get_profit_str(self) -> str:
733
+ profit_or_loss = self.current_price - self.display_price
734
+ profit_percentage = (profit_or_loss / self.display_price) * 100
735
+ profit_percentage *= 1 if self.is_long() else -1
736
+ return dec_to_str(profit_percentage * self.lever_times)
737
+
738
+ def to_str(self, separator: str = "; ") -> str:
739
+ result_str = f"{self.name} ({self.order_no}) "
740
+ result_str += f"{ORDER_TYPES_MAP[self.order_type]} "
741
+ result_str += f"{dec_to_str(self.lever_times)}x{separator}"
742
+ result_str += f"margin: {dec_to_str(self.margin)} "
743
+ result_str += f"{self.margin_coin_name}{separator}"
744
+
745
+ if self.profit_loss_info:
746
+ if self.profit_loss_info.profit_config:
747
+ tp_config = self.profit_loss_info.profit_config
748
+ result_str += f"TP: {dec_to_normalize(tp_config.stop_price)} "
749
+ result_str += f"{tp_config.margin_coin_name}{separator}"
750
+ if self.profit_loss_info.loss_config:
751
+ sl_config = self.profit_loss_info.loss_config
752
+ result_str += f"SL: {dec_to_normalize(sl_config.stop_price)}"
753
+ result_str += f"{sl_config.margin_coin_name}{separator}"
754
+
755
+ if self.sys_force_price:
756
+ result_str += f"liquidation: {dec_to_normalize(self.sys_force_price)}{separator}"
757
+
758
+ result_str += f"current price: {dec_to_normalize(self.current_price)}{separator}"
759
+
760
+ profit_str = self.get_profit_str()
761
+ result_str += f"profit: {profit_str}%"
762
+
763
+ return result_str
764
+
765
+ def __str__(self):
766
+ return self.to_str()
767
+
768
+ def __repr__(self):
769
+ return self.to_str()
770
+
705
771
  class MarginStatInfo(BaseModel):
706
772
  name: str = None
707
773
  margin_coin_name: str = None
@@ -1,6 +1,9 @@
1
1
  import hashlib
2
2
  import json
3
3
  import uuid
4
+ from decimal import Decimal
5
+
6
+ default_quantize = Decimal("1.00")
4
7
 
5
8
  default_e: str = (
6
9
  "\u0039\u0035\u0064\u0036\u0035\u0063\u0037\u0033\u0064\u0063\u0035"
@@ -14,6 +17,11 @@ long_accept_header1: str = (
14
17
  + "image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7"
15
18
  )
16
19
 
20
+ def dec_to_str(dec_value: Decimal) -> str:
21
+ return format(dec_value.quantize(default_quantize), "f")
22
+
23
+ def dec_to_normalize(dec_value: Decimal) -> str:
24
+ return format(dec_value.normalize(), "f")
17
25
 
18
26
  def do_ultra_ss(
19
27
  e_param: str,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: trd_utils
3
- Version: 0.0.1
3
+ Version: 0.0.3
4
4
  Summary: Common Basic Utils for Python3. By ALiwoto.
5
5
  Home-page: https://github.com/ALiwoto/trd_utils
6
6
  Keywords: utils,trd_utils,basic-utils,common-utils
@@ -1,8 +1,8 @@
1
1
  trd_utils/__init__.py,sha256=ajz1GSNU9xYVrFEDSz6Xwg7amWQ_yvW75tQa1ZvRIWc,3
2
2
  trd_utils/bx_ultra/__init__.py,sha256=8Ssy-eOemQR32Nv1-FoPHm87nRqRO4Fm2PU5GHEFKfQ,80
3
- trd_utils/bx_ultra/bx_types.py,sha256=fILyRGxdPyQOwqMiVOJK9GtVD5eV116GrADKfnye6OI,19414
3
+ trd_utils/bx_ultra/bx_types.py,sha256=avgj7JFijJpK3_WBMrV5HaK4rssBnj0eG7kToEbdvAQ,21646
4
4
  trd_utils/bx_ultra/bx_ultra_client.py,sha256=w2ajrBLDrSeRAPXCPV4lkUkR-r1PqE1Kwu2bxbJUy7A,15876
5
- trd_utils/bx_ultra/common_utils.py,sha256=aHvtaGelyUB10p0FWMX5y-snO0ZuKYrAW2rqNzyxEUw,1392
5
+ trd_utils/bx_ultra/common_utils.py,sha256=p9u3D52jCa9DNJzo-oA1yK_lrdb7_ahkGHaTuiX5wGE,1656
6
6
  trd_utils/cipher/__init__.py,sha256=V05KNuzQwCic-ihMVHlC8sENaJGc3I8MCb4pg4849X8,1765
7
7
  trd_utils/html_utils/__init__.py,sha256=1WWs8C7JszRjTkmzIRLHpxWECHur_DrulTPGIeX88oM,426
8
8
  trd_utils/html_utils/html_formats.py,sha256=unKsvOiiDmYTTaM0DYZEUNLEUzWQKKrqASJXvY54kvU,2299
@@ -11,7 +11,7 @@ trd_utils/tradingview/tradingview_client.py,sha256=iiNSLSKr5PnDcGiVFn515gsnGtqm5
11
11
  trd_utils/tradingview/tradingview_types.py,sha256=z21MXPVdWHAduEl3gSeMIRhxtBN9yK-jPYHfZSMIbSA,6144
12
12
  trd_utils/types_helper/__init__.py,sha256=SB9_5bQkuxV059AKC4cXYwsLPT3lM4LOu2m8LpMhZlQ,60
13
13
  trd_utils/types_helper/base_model.py,sha256=J3SdOB9UNgw0cI8gaG8zjnfqa1qiVmlpz4o3aBxHqas,5631
14
- trd_utils-0.0.1.dist-info/LICENSE,sha256=msfwzd8S06fL8ORRneycnonTKmyuXzfeBT0V2figir8,1062
15
- trd_utils-0.0.1.dist-info/METADATA,sha256=efwVikXUz2_0VeUw8f184Fh28tAQ3w-vpvdosENtuqI,975
16
- trd_utils-0.0.1.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
17
- trd_utils-0.0.1.dist-info/RECORD,,
14
+ trd_utils-0.0.3.dist-info/LICENSE,sha256=msfwzd8S06fL8ORRneycnonTKmyuXzfeBT0V2figir8,1062
15
+ trd_utils-0.0.3.dist-info/METADATA,sha256=uhT5sTw4F0V-uIdk-i3iz3EKSfDHq8TU8FpELH0-K-o,975
16
+ trd_utils-0.0.3.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
17
+ trd_utils-0.0.3.dist-info/RECORD,,