def create_order(self) -> SellOutputDto:
        fund_name = self._input_dto.fund_name
        uid = self._input_dto.uid
        sell_repo = SellRepo(uid)

        user_qty, sell_order_snapshots = eventLoop.run_until_complete(
            self.get_sell_order_info(sell_repo, fund_name))
        unfinished_order = sell_repo.find_unfinished_order(
            sell_order_snapshots)
        order_id = ApplySellDomainService(uid).get_order_id(
            unfinished_order, user_qty)
        network_commission = sell_repo.find_network_commission(
            self._input_dto.asset, self._input_dto.network)

        withdrawal_input = WithdrawDto(uid=uid,
                                       order_id=order_id,
                                       address=self._input_dto.address,
                                       asset=self._input_dto.asset,
                                       network=self._input_dto.network,
                                       network_commission=network_commission,
                                       datetime=koreaDatetime,
                                       updated_datetime=koreaDatetime)

        order_input = OrderDto(uid=uid,
                               order_id=order_id,
                               fund_name=fund_name,
                               side=sideSellFiled,
                               base_qty=str(user_qty),
                               datetime=koreaDatetime,
                               updated_datetime=koreaDatetime)

        order_result = eventLoop.run_until_complete(
            self.build_order_result(sell_repo, order_input, withdrawal_input))
        return order_result
예제 #2
0
 def sign_in(self) -> SignInOutputDto:
     uid = self._input_dto.uid
     simple_pw = eventLoop.run_until_complete(
         UserRepo(uid).find_simple_pw())
     token = SignInDomainService(uid).get_token(self._input_dto.simple_pw,
                                                simple_pw)
     return SignInOutputDto(token)
예제 #3
0
    def user_history(self):
        uid = self._input_dto.uid
        user_repo = UserRepo(uid)
        history_domain = UserHistoryDomainService()

        deposit_datas, withdrawal_datas, exchange_datas = eventLoop.run_until_complete(
            self.get_user_history_datas(user_repo))
        deposits_list, withdrawals_list, exchanges_list = \
            eventLoop.run_until_complete(self.get_order_list(history_domain, deposit_datas, withdrawal_datas, exchange_datas))

        extend_all_list = deposits_list + withdrawals_list + exchanges_list
        history_list = sorted(extend_all_list,
                              key=lambda extend_all_list:
                              (extend_all_list[datetimeFiled]),
                              reverse=True)
        return history_list
예제 #4
0
    def send_mail(self) -> EmailOutputDto:
        otp, hash_otp, email_msg = eventLoop.run_until_complete(\
            EmailDomainService(ArgonEntity('private')).create_template(self._input_dto.user_email))
        otp_params = EmailDto(hash_otp)

        EmailRepo(self._input_dto.uid).save_otp(asdict(otp_params))
        mail().send(email_msg)

        return EmailOutputDto(otp, hash_otp)
예제 #5
0
 async def get_asset_output_dto(self, sell_repo, asset_domain,
                                latest_completes_order_time,
                                current_price) -> AssetOutputDto:
     current_buy_list = asset_domain.get_current_buy_order(
         latest_completes_order_time)
     total_base_qty = eventLoop.run_until_complete(
         asset_domain.get_total_base_qty(current_buy_list))
     total_asset = eventLoop.run_until_complete(
         asset_domain.get_total_asset(current_price, current_buy_list))
     yield_return, total_return = eventLoop.run_until_complete(
         asset_domain.get_yield_asset(total_asset, total_base_qty))
     btc_fee, usdt_fee = eventLoop.run_until_complete(
         self.get_all_network_commistion(sell_repo))
     return AssetOutputDto(total_base_qty=total_base_qty,
                           total_return=total_return,
                           yield_return=yield_return,
                           total_asset=total_asset,
                           btc_withdrawal_fee=btc_fee,
                           usdt_withdrawal_fee=usdt_fee)
예제 #6
0
    def check_otp(self) -> CheckOTPOutputDto:
        req_otp = self._input_dto.req_otp
        uid = self._input_dto.uid
        email_repo = EmailRepo(uid)
        argon_entity = ArgonEntity('private')

        crypto_otp, false_count, user_status = eventLoop.run_until_complete(
            self.get_user_otp_info(email_repo))

        email_input = CheckEmailInputDto(req_otp, crypto_otp, user_status,
                                         false_count, uid, email_repo)
        checked_otp = EmailDomainService(argon_entity).check_otp(email_input)
        return CheckOTPOutputDto(checked_otp)
    def create_withdrawal_receipt(self) -> WithdrawalOutputDto:
        uid = self._input_dto.uid
        withdrawal_domain = WithdrawalDomainService(uid)
        withdrawal_repo = WithdrawalRepo(uid)
        newest_withdrawal = self.get_newset_withdrawal(withdrawal_repo,
                                                       withdrawal_domain, uid)
        base_qty = self.get_newest_order(
            withdrawal_repo, withdrawal_domain, uid,
            newest_withdrawal[orderIDFiled])[baseQtyFiled]

        fund_price, avg_entry_price = eventLoop.run_until_complete(
            self.get_withdrawal_price(withdrawal_repo, uid,
                                      self._input_dto.fund_name))

        wd_status = newest_withdrawal[userStatusFiled]
        wd_asset = newest_withdrawal[assetFiled]
        wd_network = newest_withdrawal[networkFiled]
        wd_address = newest_withdrawal[addressFiled]
        wd_fee = newest_withdrawal.get(networkCommissionFiled, 0)

        remaining_secounds = eventLoop.run_until_complete(
            withdrawal_domain.get_remaining_secound(wd_status))
        amt_high, amt_low = self.amt_range(withdrawal_domain, uid, base_qty,
                                           fund_price, wd_asset)
        investment_principal, investment_profit = self.get_investment_info(
            uid, base_qty, fund_price, avg_entry_price)
        return WithdrawalOutputDto(uid=uid,
                                   status=wd_status,
                                   asset=wd_asset,
                                   network=wd_network,
                                   withdrawal_address=wd_address,
                                   remaining_secounds=remaining_secounds,
                                   expected_amt_high=amt_high,
                                   expected_amt_low=amt_low,
                                   investment_principal=investment_principal,
                                   inbestment_profit=investment_profit,
                                   withdrawal_fee=wd_fee)
예제 #8
0
    def user_asset(self):
        uid = self._input_dto.uid
        user_repo = UserRepo(uid)
        sell_repo = SellRepo(uid)
        asset_domain = UserAssetDomainService(uid, user_repo)

        current_price, latest_completes_order_time = self.get_user_asset_data(
            user_repo, asset_domain)
        output_dto = eventLoop.run_until_complete(
            self.get_asset_output_dto(
                sell_repo=sell_repo,
                asset_domain=asset_domain,
                latest_completes_order_time=latest_completes_order_time,
                current_price=current_price))
        return output_dto
예제 #9
0
    def create_user(self) -> SignUpOutputDto:
        uid = self._input_dto.uid
        email_noti = self._input_dto.email_notice
        push_noti = self._input_dto.push_notice
        noti_token = self._input_dto.notice_token
        user_repo = UserRepo(uid)
        nick_name = user_repo.find_user_display_name(
            self._input_dto.user_email)
        profile_url = user_repo.find_user_profile_url(
            self._input_dto.user_email)
        sign_up_domain_service = SignUpDomainService(UserRepo)
        available_account_list = user_repo.find_available_sub_account_list()

        available_account = eventLoop.run_until_complete(
            self.get_available_acount(
                sign_up_domain_service=sign_up_domain_service,
                uid=uid,
                available_account_list=available_account_list))

        user_private, user_public, notice_params = sign_up_domain_service.allocated_to_user(
            uid=uid,
            available_account=available_account,
            user_email=self._input_dto.user_email,
            simple_pw=self._input_dto.simple_pw,
            nick_name=nick_name,
            profile_url=profile_url,
            email_notice=email_noti,
            push_notice=push_noti,
            notice_token=noti_token)

        user_repo.save_user_initial_set(available_account=available_account,
                                        uid=uid,
                                        private_user_params=user_private,
                                        public_user_params=user_public,
                                        notice_params=notice_params)

        created_datetime = user_public[createTimeFiled]
        deposit_addresses = user_public[depositAddressFiled]
        user_email = user_public[userEmailFiled]
        status = user_public[userStatusFiled]
        return SignUpOutputDto(created_datetime=created_datetime,
                               deposit_addresses=deposit_addresses,
                               email=user_email,
                               status=status,
                               uid=uid)
예제 #10
0
 def get_password(self):
     uid = self._input_dto.uid
     simple_pw = eventLoop.run_until_complete(
         UserRepo(uid).find_simple_pw())
     return PasswordOutPutDto(simple_pw)
예제 #11
0
def server_time():
    result = eventLoop.run_until_complete(get_server_time())
    return success_response(result, 200)
예제 #12
0
def health_check():
    binance_url = '8.8.8.8'
    result = eventLoop.run_until_complete(get_health(binance_url))
    return success_response(result, 200)
 def get_newest_order(self, withdrawal_repo, withdrawal_domain, uid,
                      order_id):
     order_list = withdrawal_repo.find_order_list(order_id)
     newest_order = eventLoop.run_until_complete(
         withdrawal_domain.get_newest(order_list))
     return newest_order
 def get_newset_withdrawal(self, withdrawal_repo, withdrawal_domain, uid):
     withdrawal_list = withdrawal_repo.find_withdrawal_list()
     newest_withdrawal = eventLoop.run_until_complete(
         withdrawal_domain.get_newest(withdrawal_list))
     return newest_withdrawal