Esempio n. 1
0
    def test_market_exchange(self, with_login):
        """添加测试用例,两个交易所对接同一个市场,手动在数据库中修改两者为深度共享"""
        manager = PlatformManager('tenant')
        m_api = MarketManagementApi()
        e_api = ExchangeManagementApi()
        api = manager.account_api
        verify_api = manager.verify_api
        account_api = AccountApi()
        v_api = VerificationApi()
        pm = ProjectManagementApi()
        vc = VentureContactsApi()
        user = register_with_login(
            'tenant', with_login,
            [vc, pm, api, v_api, verify_api, m_api, e_api, account_api])
        self.data['user1'] = user
        token0 = user['token']
        email = user.get('email')
        # 绑定电话
        faker = Faker('zh_CN')
        phone = faker.phone_number()
        verify = verify_info(manager, email, "bind_phone")
        manager.bind_phone(phone,
                           DEFAULT_VERIFY_CODE,
                           area_code="+86",
                           token=verify.token)
        id_number = get_random_id_number()
        individual_verify('tenant', id_number, token0)
        exchange_api = ExchangeManagementApi()
        e = Exchange(exchange_api, token0)
        exchange = e.get_exchange()
        e_api.exchange_post(exchange)
        rv = account_api.accounts_account_info_get()
        account_id = rv.account_info.account_id
        audit_api = AuditApi()
        admin_token = get_admin_token()
        set_login_status(audit_api, admin_token)
        rv = audit_api.tenant_audits_get(uid=account_id,
                                         exchange_name=exchange.name,
                                         type='audit')
        task = rv.items[0]
        task_id = task.id
        res = PostTenantAuditRequest(id=task_id,
                                     is_data_received=True,
                                     status='approved',
                                     failure_type=1)
        audit_api.tenant_audits_audit_post(res)
        # 复审
        res = PostTenantReAuditRequest(id=task_id,
                                       status='approved',
                                       failure_type=None)
        audit_api.tenant_audits_re_audit_post(res)
        rv = e_api.exchange_exchange_id_get()
        exchange_id = rv.id
        # 对接币种
        contacts_api = ContactsApi()
        user = self.data['user']
        email, password = user['email'], user['password']
        token = with_login('tenant', [contacts_api], email, password)
        project_id = self.data['project_id']
        req = {
            'exchangeId': exchange_id,
            'projectId': project_id,
            'sponsor': 'tenant'
        }

        rv = contacts_api.contacts_post(req)
        # 处理对接邀请
        rv = pm.projects_id_contacts_get(project_id, 'tenant')
        # 处理对接邀请
        contact_id = rv.items[0].contact_id
        vc.contacts_put({'contactId': contact_id, 'status': 'accepted'})
        #
        # rv = contacts_api.contacts_projects_exchange_id_get(exchange_id,
        #                                                     'pending')
        # contact_id = rv.items[0].id
        # contacts_api.contacts_put({'contactId': contact_id,
        #                            'status': 'accepted'})
        rv = contacts_api.contacts_check_get(project_id=project_id,
                                             exchange_id=exchange_id)
        assert rv.result
        rv = e_api.exchange_exchange_coin_get()
        res = PostOrderMarketRequest()
        s_coin = self.data['s_coin']
        b_coin = self.data['b_coin']
        res.seller_coin_id = s_coin.id
        res.buyer_coin_id = b_coin.id
        res.allotted_time = AllottedTime._6month
        res.fee_rate = TestMarket1.fee_rate
        rv = e_api.exchange_exchange_coin_get()
        # 配置交易对市场
        rv = e_api.exchange_order_market_post(res)
        order_id = rv.order_id
        usdt_id = b_coin.id
        # 充钱
        free_charge(token0, usdt_id, account_id)

        data = {
            "challenge": "048ebbe51f829995db76ac4b81546403",
            "seccode": "048ebbe51f829995db76ac4b81546403",
            "validate": "true",
            "account": "mailto:[email protected]",
            "code": "666666",
            "secondCode": "Ls1w1w",
            "type": "pay"
        }
        rv = v_api.accounts_verify_post(data)
        p = PutOrderMarketRequest(order_id=order_id, token=rv.token)
        e_api.exchange_order_market_put(p)
        # 获取交易对市场
        rv = m_api.markets_get()
        items = rv.items
        assert len(items) == 1
Esempio n. 2
0
    def test_exchange_project(self):
        """2.新增项目——对接交易所——获取交易所卖买方币种列表
            ——单一币种在单一交易所币对的行情统计"""
        exchange = new_exchange()
        exchange_api = ExchangeManagementApi()
        user_data = TestProject.data['user']
        token = user_data['token']
        exchange_api.api_client.set_default_header("Authentication-Token",
                                                   token)
        account_api = AccountApi()
        account_api.api_client.set_default_header("Authentication-Token",
                                                  token)
        account_info = account_api.accounts_account_info_get()
        account_id = account_info.accountInfo.accountId
        TestProject.data['account_id'] = account_id
        exchange_api.exchange_post(exchange)
        manager = PlatformManager('tenant')
        token = manager.login(sponsor_account, sponsor_pwd)
        audit_api = AuditApi()
        audit_api.api_client.set_default_header("Authentication-Token", token)
        # 初审
        rv = audit_api.tenant_audits_get()
        audit_list = rv.items
        _id = None
        for each in audit_list:
            if each.uid == account_id:
                _id = each.id  # 工单id
        assert not _id
        res = PostTenantAuditRequest(id=_id,
                                     is_data_received=True,
                                     status='approved',
                                     failure_type=1)
        audit_api.tenant_audits_audit_post(res)
        # 复审
        PostTenantReAuditRequest(id=_id, status='approved', failure_type=None)
        exchange_id = exchange_api.exchange_exchange_id_get()
        # 对接项目方
        contacts_api = ContactsApi()
        contacts_api.api_client.set_default_header("Authentication-Token",
                                                   token)
        req = {
            'exchangeId': exchange_id,
            'projectId': TestProject.data['project_id'],
            'sponsor': 'tenant'
        }
        contacts_api.contacts_post(req)
        # 获取交易所买卖方币种
        m_api = MarketManagementApi()
        m_api.api_client.set_default_header("Authentication-Token", token)
        trading_coins = m_api.markets_trading_coins_get()
        seller_coin = trading_coins.seller_coin
        s_coin = seller_coin[0]
        buyer_coin = trading_coins.buyer_coin
        b_coin = buyer_coin[0]
        assert s_coin == TestProject.data['project']['short_name']

        # 新建市场
        res = PostOrderMarketRequest()
        res.seller_coin_id = s_coin.id
        res.buyer_coin_id = b_coin.id
        TestProject.data['s_coin'] = s_coin
        TestProject.data['b_coin'] = b_coin
        res.allotted_time = AllottedTime._6month
        res.fee_rate = TestProject.fee_rate
        # 配置交易对市场
        rv = exchange_api.exchange_order_market_post(res)
        order_id = rv.order_id
        token = get_verify_token()
        p = PutOrderMarketRequest(order_id=order_id, token=token)
        exchange_api.exchange_order_market_put(p)

        # 单一币种在单一交易所币对的行情统计
        dashboard_api = DashboardApi()
        dashboard_api.api_client.set_default_header("Authentication-Token",
                                                    token)
        dashboard_api.dashboard_quotation_historical_data_post()
        dashboard_api.dashboard_quotations_summary_get(page_no=1,
                                                       page_size=10,
                                                       seller_coin=seller_coin)
        # 3.新增项目——对接交易所——获取交易所卖买方币种列表——单一币种在各交易所的行情概要
        dashboard_api.dashboard_daily_statistics_get()