2022-04-14 07:36:29 +00:00
|
|
|
from __future__ import annotations
|
|
|
|
|
2022-04-13 06:00:28 +00:00
|
|
|
from dataclasses import dataclass
|
2022-05-13 08:30:19 +00:00
|
|
|
from decimal import Decimal
|
2022-04-13 06:00:28 +00:00
|
|
|
|
2022-04-14 07:36:29 +00:00
|
|
|
import bbgo_pb2
|
|
|
|
|
2022-05-13 08:30:19 +00:00
|
|
|
from ..utils import parse_number
|
|
|
|
|
2022-04-13 06:00:28 +00:00
|
|
|
|
|
|
|
@dataclass
|
|
|
|
class Balance:
|
|
|
|
exchange: str
|
|
|
|
currency: str
|
2022-05-13 08:30:19 +00:00
|
|
|
available: Decimal
|
|
|
|
locked: Decimal
|
2022-04-14 07:36:29 +00:00
|
|
|
borrowed: str
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def from_pb(cls, obj: bbgo_pb2.Balance) -> Balance:
|
|
|
|
return cls(
|
|
|
|
exchange=obj.exchange,
|
|
|
|
currency=obj.currency,
|
2022-05-13 08:30:19 +00:00
|
|
|
available=parse_number(obj.available),
|
|
|
|
locked=parse_number(obj.locked),
|
2022-04-14 07:36:29 +00:00
|
|
|
borrowed=obj.borrowed,
|
|
|
|
)
|
|
|
|
|
2022-05-13 08:30:19 +00:00
|
|
|
def total(self) -> Decimal:
|
2022-04-14 07:36:29 +00:00
|
|
|
return self.available + self.locked
|