trd-utils 0.0.1__tar.gz → 0.0.2__tar.gz
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.
- {trd_utils-0.0.1 → trd_utils-0.0.2}/PKG-INFO +1 -1
- {trd_utils-0.0.1 → trd_utils-0.0.2}/pyproject.toml +1 -1
- {trd_utils-0.0.1 → trd_utils-0.0.2}/trd_utils/bx_ultra/bx_types.py +75 -9
- {trd_utils-0.0.1 → trd_utils-0.0.2}/trd_utils/bx_ultra/common_utils.py +8 -0
- {trd_utils-0.0.1 → trd_utils-0.0.2}/LICENSE +0 -0
- {trd_utils-0.0.1 → trd_utils-0.0.2}/README.md +0 -0
- {trd_utils-0.0.1 → trd_utils-0.0.2}/trd_utils/__init__.py +0 -0
- {trd_utils-0.0.1 → trd_utils-0.0.2}/trd_utils/bx_ultra/__init__.py +0 -0
- {trd_utils-0.0.1 → trd_utils-0.0.2}/trd_utils/bx_ultra/bx_ultra_client.py +0 -0
- {trd_utils-0.0.1 → trd_utils-0.0.2}/trd_utils/cipher/__init__.py +0 -0
- {trd_utils-0.0.1 → trd_utils-0.0.2}/trd_utils/html_utils/__init__.py +0 -0
- {trd_utils-0.0.1 → trd_utils-0.0.2}/trd_utils/html_utils/html_formats.py +0 -0
- {trd_utils-0.0.1 → trd_utils-0.0.2}/trd_utils/tradingview/__init__.py +0 -0
- {trd_utils-0.0.1 → trd_utils-0.0.2}/trd_utils/tradingview/tradingview_client.py +0 -0
- {trd_utils-0.0.1 → trd_utils-0.0.2}/trd_utils/tradingview/tradingview_types.py +0 -0
- {trd_utils-0.0.1 → trd_utils-0.0.2}/trd_utils/types_helper/__init__.py +0 -0
- {trd_utils-0.0.1 → trd_utils-0.0.2}/trd_utils/types_helper/base_model.py +0 -0
|
@@ -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
|
-
|
|
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
|
|
387
|
-
+ f"vol: {self.volume
|
|
388
|
-
+ f"price: {self.avg_price
|
|
389
|
-
+ f"margin: {self.margin
|
|
390
|
-
+ f"
|
|
391
|
-
+ f"ROI: {(self.position_earning_rate * 100)
|
|
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
|
|
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
|
-
|
|
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,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|