feat: add fmt_coin2
This commit is contained in:
@@ -11,7 +11,7 @@ from freqtrade.util.datetime_helpers import (
|
|||||||
format_ms_time,
|
format_ms_time,
|
||||||
shorten_date,
|
shorten_date,
|
||||||
)
|
)
|
||||||
from freqtrade.util.formatters import decimals_per_coin, fmt_coin, round_value
|
from freqtrade.util.formatters import decimals_per_coin, fmt_coin, fmt_coin2, round_value
|
||||||
from freqtrade.util.ft_precise import FtPrecise
|
from freqtrade.util.ft_precise import FtPrecise
|
||||||
from freqtrade.util.measure_time import MeasureTime
|
from freqtrade.util.measure_time import MeasureTime
|
||||||
from freqtrade.util.periodic_cache import PeriodicCache
|
from freqtrade.util.periodic_cache import PeriodicCache
|
||||||
@@ -38,6 +38,7 @@ __all__ = [
|
|||||||
"decimals_per_coin",
|
"decimals_per_coin",
|
||||||
"round_value",
|
"round_value",
|
||||||
"fmt_coin",
|
"fmt_coin",
|
||||||
|
"fmt_coin2",
|
||||||
"MeasureTime",
|
"MeasureTime",
|
||||||
"print_rich_table",
|
"print_rich_table",
|
||||||
"print_df_rich_table",
|
"print_df_rich_table",
|
||||||
|
|||||||
@@ -47,3 +47,22 @@ def fmt_coin(value: float, coin: str, show_coin_name=True, keep_trailing_zeros=F
|
|||||||
val = f"{val} {coin}"
|
val = f"{val} {coin}"
|
||||||
|
|
||||||
return val
|
return val
|
||||||
|
|
||||||
|
|
||||||
|
def fmt_coin2(
|
||||||
|
value: float, coin: str, decimals: int = 8, *, show_coin_name=True, keep_trailing_zeros=False
|
||||||
|
) -> str:
|
||||||
|
"""
|
||||||
|
Format price value for this coin. Should be preferred for rate formatting
|
||||||
|
:param value: Value to be printed
|
||||||
|
:param coin: Which coin are we printing the price / value for
|
||||||
|
:param decimals: Number of decimals to round to
|
||||||
|
:param show_coin_name: Return string in format: "222.22 USDT" or "222.22"
|
||||||
|
:param keep_trailing_zeros: Keep trailing zeros "222.200" vs. "222.2"
|
||||||
|
:return: Formatted / rounded value (with or without coin name)
|
||||||
|
"""
|
||||||
|
val = round_value(value, decimals, keep_trailing_zeros)
|
||||||
|
if show_coin_name:
|
||||||
|
val = f"{val} {coin}"
|
||||||
|
|
||||||
|
return val
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
from freqtrade.util import decimals_per_coin, fmt_coin, round_value
|
from freqtrade.util import decimals_per_coin, fmt_coin, round_value
|
||||||
|
from freqtrade.util.formatters import fmt_coin2
|
||||||
|
|
||||||
|
|
||||||
def test_decimals_per_coin():
|
def test_decimals_per_coin():
|
||||||
@@ -25,6 +26,16 @@ def test_fmt_coin():
|
|||||||
assert fmt_coin(222.2, "USDT", False, True) == "222.200"
|
assert fmt_coin(222.2, "USDT", False, True) == "222.200"
|
||||||
|
|
||||||
|
|
||||||
|
def test_fmt_coin2():
|
||||||
|
assert fmt_coin2(222.222222, "USDT") == "222.222222 USDT"
|
||||||
|
assert fmt_coin2(222.2, "XRP", 3, keep_trailing_zeros=True) == "222.200 XRP"
|
||||||
|
assert fmt_coin2(222.2, "USDT") == "222.2 USDT"
|
||||||
|
assert fmt_coin2(222.12745, "EUR") == "222.12745 EUR"
|
||||||
|
assert fmt_coin2(0.1274512123, "BTC") == "0.12745121 BTC"
|
||||||
|
assert fmt_coin2(0.1274512123, "ETH") == "0.12745121 ETH"
|
||||||
|
assert fmt_coin2(0.00001245, "PEPE") == "0.00001245 PEPE"
|
||||||
|
|
||||||
|
|
||||||
def test_round_value():
|
def test_round_value():
|
||||||
assert round_value(222.222222, 3) == "222.222"
|
assert round_value(222.222222, 3) == "222.222"
|
||||||
assert round_value(222.2, 3) == "222.2"
|
assert round_value(222.2, 3) == "222.2"
|
||||||
|
|||||||
Reference in New Issue
Block a user