Ejemplo n.º 1
0
 def buy_limit_order(self, coin: Coin, price, amount) -> bool:
     order_log = self.upbit.buy_limit_order(f"KRW-{coin.name}", price, amount)
     uuid = order_log.get('uuid')
     coin.buy_uuid = uuid
     if not uuid:
         self.logger.warning(order_log)
         return False
     coin.status = Status.TRY_BUY
     return True
Ejemplo n.º 2
0
 def buy(self, coin: Coin, price_amount) -> bool:
     order_log = self.upbit.buy_market_order(f"KRW-{coin.name}", price_amount)
     uuid = order_log.get('uuid')
     coin.buy_uuid = uuid
     if not uuid:
         self.logger.warning(order_log)
         return False
     while uuid and self.upbit.get_order(uuid).get('state') == 'wait':
         time.sleep(1)
     self.logger.debug(f"{coin.name} buy {order_log=}")
     coin.status = Status.BOUGHT
     coin.dca_buy_cnt += 1
     coin.bought_amount += price_amount
     coin.avg_buy_price = float(self.get_balance_info(coin.name).get('avg_buy_price'))
     coin.buy_volume_cnt = float(self.get_balance_info(coin.name).get('balance'))
     self.hold_krw = float(self.get_balance_info()['balance'])
     return True