Prevent rounding errors in value calculation

Mark Veidemanis 1 year ago
parent 3f8fb66656
commit cb88cf33c2
Signed by: m
GPG Key ID: 5ACFCEED46C0904F

@ -1,3 +1,5 @@
from decimal import Decimal as D
from pydantic import BaseModel
@ -62,9 +64,9 @@ def parse_units(x):
def parse_value(x):
if float(x["long"]["units"]) > 0:
return float(x["long"]["units"]) * float(x["long"]["averagePrice"])
return D(x["long"]["units"]) * D(x["long"]["averagePrice"])
elif float(x["short"]["units"]) > 0:
return float(x["short"]["units"]) * float(x["short"]["averagePrice"])
return D(x["short"]["units"]) * D(x["short"]["averagePrice"])
else:
return 0

Loading…
Cancel
Save