junmanbo / tutong

0 stars 0 forks source link

Feature/using getattr #10

Closed junmanbo closed 1 year ago

junmanbo commented 1 year ago

거래소 클래스를 필요한 대로 추가

EXCHANGE_CLASSES = {"UPBIT": Upbit, "KIS": KIS}

def get_client(exchange_nm: str, key: models.ExchangeKey | None): if not key: access_key = None secret_key = None account = None else: access_key = key.access_key secret_key = key.secret_key account = key.account

if exchange_nm in EXCHANGE_CLASSES:
    client_class = EXCHANGE_CLASSES[exchange_nm]
    client = client_class(access_key, secret_key, account)
    return client
else:
    return None
- 다음과 같이 module 을 import 해서 사용 가능
`client = trading.get_client(exchange_nm, key)`

- krw 일 경우 현재가 1 로 설정 (total balance 가져올 때 현재가도 추가)
```python
    def get_total_balance(self):
        total_balance = {}
        balances = self.get_balance()
        balances = balances.get("info")
        for balance in balances:
            currency = balance.get("currency")
            avg_price = int(float(balance.get("avg_buy_price")))
            amount = float(balance.get("balance"))
            price = self.get_price(symbol=currency)
            if currency == "KRW":
                avg_price = 1
                price = 1
            notional = amount * price
            if notional < 10:
                continue
            total_balance[currency] = {
                "amount": amount,
                "avg_price": avg_price,
                "notional": notional,
                "price": price,
            }

        return total_balance