[Mod] use decimal.Decimal to ensure round_to precision, close #2002
This commit is contained in:
parent
c02b37bde2
commit
2448ef072d
@ -5,6 +5,7 @@ General utility functions.
|
||||
import json
|
||||
from pathlib import Path
|
||||
from typing import Callable
|
||||
from decimal import Decimal
|
||||
|
||||
import numpy as np
|
||||
import talib
|
||||
@ -109,11 +110,13 @@ def save_json(filename: str, data: dict):
|
||||
)
|
||||
|
||||
|
||||
def round_to(value: float, target: float):
|
||||
def round_to(value: float, target: float) -> float:
|
||||
"""
|
||||
Round price to price tick value.
|
||||
"""
|
||||
rounded = int(round(value / target)) * target
|
||||
value = Decimal(str(value))
|
||||
target = Decimal(str(target))
|
||||
rounded = float(int(round(value / target)) * target)
|
||||
return rounded
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user