def test_coin_market(self, with_login): manager = PlatformManager('tenant') m_api = MarketManagementApi() e_api = ExchangeManagementApi() api = manager.account_api verify_api = manager.verify_api account_api = AccountApi() user = register_with_login( 'tenant', with_login, [api, verify_api, m_api, e_api, account_api]) self.data['user'] = user token = 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, token) exchange_api = ExchangeManagementApi() e = Exchange(exchange_api, token) exchange = e.get_exchange() e_api.exchange_post(exchange) # 获取交易对市场列表 try: m_api.markets_get() except ApiException as e: # 交易所不存在 assert e.status == 400 else: assert False, '市场应当不存在' # 初审复审 rv = account_api.accounts_account_info_get() account_id = rv.account_info.account_id self.data['account_id'] = 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') audit_api.tenant_audits_audit_post(res) # 复审 res = PostTenantReAuditRequest(id=task_id, status='approved') audit_api.tenant_audits_re_audit_post(res) rv = e_api.exchange_exchange_id_get() exchange_id = rv.id self.data['exchange_id'] = exchange_id
def test_market_price(self, with_login): """4.新增市场——获取交易对市场列表——获取交易对市场单价""" user = self.data['user'] email, password = user['email'], user['password'] m_api = MarketManagementApi() with_login('tenant', [m_api], email, password) data = { 'buyer_coin_id': str(self.data['b_coin'].id), # todo 后续去掉str 'seller_coin_id': str(self.data['s_coin'].id) # todo 后续去掉str } res = m_api.markets_price_get(**data) assert res.price
def test_open_market(self, with_login): """8.新增市场——获取交易对市场列表——开启市场——获取交易对市场""" m_api = MarketManagementApi() user = self.data['user1'] email, password = user['email'], user['password'] token = with_login('tenant', [m_api], email, password) rv = m_api.markets_get() market_id = rv.items[0].id try: m_api.markets_id_open_put(id=market_id) except Exception as e: assert e.status == 400 else: assert False, '市场running状态,不应该申请open'
def test_deep_sharing(self, with_login): """3.新增市场——获取交易对市场列表——验证交易对市场是否是深度共享""" market_api = MarketApi() s_api = SystemManagementApi() m_api = MarketManagementApi() f_api = FavoriteManagementApi() user = self.data['user'] email, password = user['email'], user['password'] token = with_login('tenant', [f_api, s_api, m_api, market_api], email, password) data = { 'name': self.data['s_coin'].name, 'partition_id': self.data['b_coin'].id, 'page': 1 } rv = s_api.system_trading_pair_get(**data) item = rv.items[0] is_deep_sharing = item.is_deep_sharing buyer_coin_id = self.data['b_coin'].id seller_coin_id = self.data['s_coin'].id buyer_coin_id = str(buyer_coin_id) # todo 后续去掉 seller_coin_id = str(seller_coin_id) # todo 后续去掉 rsp = m_api.markets_deep_sharing_verify_get(buyer_coin_id, seller_coin_id) assert is_deep_sharing == rsp.bit # 合并测试用例 """3.新增交易所与市场——获取交易所市场列表——收藏——收藏列表(市场)""" # 模糊查询市场列表 exchange_id = TestMarket1.data['exchange_id'] rv = market_api.markets_suggestion_get('', exchange_id) item = rv.items[0] market_id = item.id req = PostFavoriterMarketRequest() req.favorite_id = market_id req.exchange_id = exchange_id req.type = 'market' f_api.favorites_market_post(req) # 收藏列表 rv = f_api.favorites_get(exchange_id=exchange_id, type='market') item = rv.items[0] assert item.favorite_id == market_id """7.收藏市场成功——收藏列表(市场)——取消收藏""" favorite_record_id = item.id f_api.favorites_delete(favorite_record_id) rv = f_api.favorites_is_favorite_get(favorite_id=market_id, exchange_id=exchange_id, type='market') assert not rv.status
def test_market_detail(self, with_login): """5.新增市场——获取交易对市场列表——获取交易币种——获取交易对市场单价——获取市场详情""" # 获取交易对市场 m_api = MarketManagementApi() user = self.data['user'] email, password = user['email'], user['password'] with_login('tenant', [m_api], email, password) rv = m_api.markets_get() market_id = rv.items[0].id market_detail = m_api.markets_id_get(market_id) assert market_detail.id == market_id # total_rate = float(TestMarket1.fee_rate) + float(self.service_rate) # assert market_detail.total_rate == 0.00011 # todo 暂时不测这个 # assert market_detail.fee_rate == Decimal(TestMarket1.fee_rate) # todo 暂时不测这个 # assert market_detail.service_rate == float(TestMarket1.service_rate) assert market_detail.buyer_coin_id == str( self.data['b_coin'].id) # todo 后续去掉str assert market_detail.seller_coin_id == str( self.data['s_coin'].id) # todo 后续去掉str
def test_recharge_market(self, with_login): """9.新增市场——获取交易对市场列表——交易市场续费——获取交易对市场""" v_api = VerificationApi() m_api = MarketManagementApi() e_api = ExchangeManagementApi() user = self.data['user'] email, password = user['email'], user['password'] with_login('tenant', [m_api, e_api, e_api, v_api], email, password) rv = m_api.markets_get() market_id = rv.items[0].id # m_api.markets_id_open_put(id=market_id) rv = m_api.markets_get() items = rv.items assert len(items) == 1 item = items[0] disabled_at = item.disabled_at data = PostOrderMarketRenewRequest(market_id=market_id, allotted_time=AllottedTime._6month) res = e_api.exchange_order_market_renew_post(data) order_id = res.order_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) # 支付订单 res = PutOrderMarketRequest(order_id=order_id, token=rv.token) e_api.exchange_order_market_renew_put(res) # 获取市场列表 rv = m_api.markets_get() items = rv.items assert len(items) == 1 item = items[0] disabled_at_1 = item.disabled_at allot = relativedelta(disabled_at_1, disabled_at).months assert allot == AllottedTime._6month
def test_update_market(self, with_login): """6.新增市场——获取交易对市场列表——修改市场信息——获取交易对市场""" # 获取交易对市场 m_api = MarketManagementApi() user = self.data['user'] email, password = user['email'], user['password'] token = with_login('tenant', [m_api], email, password) rv = m_api.markets_get() market_id = rv.items[0].id market_detail = m_api.markets_id_get(market_id) new_fee_rate = str(market_detail.fee_rate + 0.001) # 后续去掉str m_api.markets_id_put(id=market_id, fee_rate=new_fee_rate) market_detail_1 = m_api.markets_id_get(market_id) assert market_detail_1.fee_rate == float(new_fee_rate) # 后续去掉float
def test_open_market(self, with_login): """8.新增市场——获取交易对市场列表——开启市场——获取交易对市场""" m_api = MarketManagementApi() user = self.data['user'] email, password = user['email'], user['password'] token = with_login('tenant', [m_api], email, password) rv = m_api.markets_get() market_id = rv.items[0].id m_api.markets_id_open_put(id=market_id) res = m_api.markets_get() item = res.items[0] assert item.status == 'running'
def test_close_market(self, with_login): """7.新增市场——获取交易对市场列表——关闭市场——获取交易对市场""" a_api = AccountApi() audit_api = AuditApi() v_api = VerificationApi() m_api = MarketManagementApi() e_api = ExchangeManagementApi() user = self.data['user'] email, password = user['email'], user['password'] token = with_login('tenant', [a_api, m_api, v_api, e_api], email, password) rv = m_api.markets_get() market_id = rv.items[0].id res = PostMarketCloseRequest(id=market_id, closing_reason='a' * 11) data = { "challenge": "048ebbe51f829995db76ac4b81546403", "seccode": "048ebbe51f829995db76ac4b81546403", "validate": "true", "account": "mailto:[email protected]", "code": "666666", "secondCode": "Ls1w1w", "type": "close_market" } rv = v_api.accounts_verify_post(data) res.token = rv.token rv = m_api.markets_close_post(res) res = m_api.markets_get() item = res.items[0] assert item.status == 'in_review' # 合并测试用例 """11.前台申请关闭交易市场——关闭交易所市场审核列表——关闭交易所市场审核详情初审 ——提交关闭交易所审核初审——关闭交易所市场审核列表""" # 审核列表 rv = e_api.exchange_exchange_id_get() exchange_id = rv.id admin_token = get_admin_token() set_login_status(audit_api, admin_token) rv = audit_api.shutdown_market_audits_get(page=1, exchange_id=exchange_id) item = rv.items[0] status = item.status assert status == 'audit' ticket_number = item.ticket_number rv = audit_api.shutdown_market_audits_id_tasks_audit_get(ticket_number) account_info = a_api.accounts_account_info_get() account_id = account_info.account_info.account_id assert rv.uid == account_id assert rv.exchange_id == exchange_id s = self.data['s_coin'].name b = self.data['b_coin'].name assert rv.trading_pair == f'{s}/{b}' # 初审 data = PostShutdownMarketAuditRequest(id=ticket_number, status='approved') audit_api.shutdown_market_audits_audit_post(data) res = m_api.markets_get() item = res.items[0] assert item.status == 'in_review' # 获取初审详情 rv = audit_api.shutdown_market_audits_id_audit_get(ticket_number) assert rv.audit_status == 'approved' rv = audit_api.shutdown_market_audits_get(exchange_id=exchange_id) item = rv.items[0] assert item.status == 're_audit' # 合并测试用例 """12.申请关闭交易所市场初审通过——关闭交易所市场审核列表 ——提交关闭交易所审核复审——关闭交易所市场审核列表""" rv = audit_api.shutdown_market_audits_id_tasks_re_audit_get( id=ticket_number) assert rv.audit_status == 'approved' # 复审 data = PostShutdownMarketReAuditRequest(id=ticket_number, status='approved') audit_api.shutdown_market_audits_re_audit_post(data) # 复审详情 rv = audit_api.shutdown_market_audits_id_re_audit_get(ticket_number) assert rv.audit_status == 'approved' assert rv.re_status == 'approved' rv = audit_api.shutdown_market_audits_get(exchange_id=exchange_id) item = rv.items[0] assert item.status == 'approved' res = m_api.markets_get() item = res.items[0] assert item.status == 'wait_close'
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
def test_add_market2(self, with_login): user = self.data['user'] email, password = user['email'], user['password'] m_api = MarketManagementApi() e_api = ExchangeManagementApi() s_api = SponsorApi() venture_api = VentureApi() va_api = VentureAccountApi() project_api = ProjectApi() contacts_api = ContactsApi() tam_api = TenantAssetManagementApi() v_api = VerificationApi() ma_api = MainExchangeApi() vc = VentureContactsApi() pm = ProjectManagementApi() tenant_ca = TenantContactsApi() token = with_login('tenant', [ pm, vc, ma_api, v_api, contacts_api, project_api, m_api, e_api, va_api, s_api, venture_api, tam_api, tenant_ca ], email, password) # 交易币种 rv = e_api.exchange_exchange_coin_get() seller_coin = rv.seller_coin buyer_coin = rv.buyer_coin b_coin = buyer_coin[0] if seller_coin: s_coin = seller_coin[0] else: sponsor = get_sponsors() # 登录保健方 account, password = sponsor['account'], sponsor['password'] sponsor_api = SponsorApi() sponsor_token = get_sponsor_token(account, password, email='test') set_login_status(sponsor_api, sponsor_token) project = get_project(token) # req = ApplicationRequest(**project) rv = venture_api.applications_post(body=project) application_id = rv.id # 查看申请列表 rv = venture_api.applications_get(page=1, order='desc') assert len(rv.items) == 2 item = rv.items[0] assert item.project_name == project['projectName'] assert item.fullname == project['fullName'] assert item.short_name == project['shortName'] rv = venture_api.applications_num_get(status='under_review') assert int(rv.result) == 0 rv = venture_api.applications_num_get(status='passed') assert int(rv.result) == 0 rv = venture_api.applications_num_get(status='undone') assert int(rv.result) == 1 # 设置保健机构 venture_api.applications_id_set_sponsor_put( application_id, {'sponsorId': sponsor['id']}) rv = venture_api.applications_num_get(status='undone') assert int(rv.result) == 0 rv = venture_api.applications_num_get(status='under_review') assert int(rv.result) == 1 rv = venture_api.applications_num_get(status='passed') assert int(rv.result) == 0 project_name = project['projectName'] sponsor_project_api = SponsorsProjectApi() set_login_status(sponsor_project_api, sponsor_token) rv = sponsor_project_api.projects_get(page=1, project_name=project_name) assert len(rv.items) >= 1 rv = sponsor_project_api.projects_id_get(id=application_id) assert rv sponsor_project_api.projects_sponsor_put({ 'id': application_id, 'status': 1, 'remark': 'test' }) rv = venture_api.applications_num_get(status='undone') assert int(rv.result) == 0 rv = venture_api.applications_num_get(status='under_review') assert int(rv.result) == 0 rv = venture_api.applications_num_get(status='passed') assert int(rv.result) == 1 rv = venture_api.applications_num_get(status='turn_down') assert int(rv.result) == 1 # 保鉴成功列表 rv = sponsor_project_api.sponsor_record_success_get( page=1, coin_name=project['shortName']) # 项目列表 rv = venture_api.projects_get(page=1) project_id = rv.items[0].project_id self.data['project_id'] = project_id # 设置接入方式 setting = PutProjectRequestSetting(access_method='accept', open=True) req = PutProjectRequest() req.setting = setting venture_api.projects_id_put(project_id, 'setting', req) # 获取项目详情 rv = venture_api.projects_id_get(project_id) exchange_id = TestMarket1.data['exchange_id'] rv = project_api.projects_get(coin_name=project['shortName']) assert len(rv.items) == 0 # 初始化项目 s_api = SystemManagementApi() staff_project_api = StaffProjectApi() asset_management_api = AssetManagementApi() admin_token = get_admin_token() set_login_status(staff_project_api, admin_token) set_login_status(asset_management_api, admin_token) set_login_status(s_api, admin_token) coin_name = project['shortName'] rv = asset_management_api.asset_mgmt_coins_get(coin_name=coin_name) coin_id = rv.items[0].coin_id coin_config_id = rv.items[0].id # 修改币种配置 res = PutSystemCoinsInitRequest() res.usdt_price = '1251' res.rc_times = 8 res.wc_times = 8 res.withdraw_rate = 0.1 res.min_withdraw = 100 res.min_withdraw_fee = 0.1 res.max_withdraw = 1000 res.min_recharge = 10 res.address_tag_switch = True res.day_withdraw_total = 125564 res.address_type = 'OX' res.address_url = 'http://unknown.com' res.txid_url = 'http://unknown.com' # asset_management_api.asset_mgmt_coins_id_put(coin_id, res) asset_management_api.asset_mgmt_coins_id_init_put( coin_config_id, res) rv = project_api.projects_get(coin_name=project['shortName']) assert len(rv.items) == 1 setting = PutProjectRequestSetting(access_method='refuse', open=True) req = PutProjectRequest() req.setting = setting venture_api.projects_id_put(project_id, 'setting', req) # refuse rv = project_api.projects_get(coin_name=project['shortName']) assert len(rv.items) == 0 setting = PutProjectRequestSetting(access_method='verification', open=True) req = PutProjectRequest() req.setting = setting venture_api.projects_id_put(project_id, 'setting', req) rv = project_api.projects_get(coin_name=project['shortName']) assert len(rv.items) == 1 rv = s_api.system_trading_pair_get(name=project['shortName'], partition_id=b_coin.id) # 对接币种 req = { 'exchangeId': exchange_id, 'projectId': project_id, 'sponsor': 'tenant' } contacts_api.contacts_post(req) rv = pm.projects_id_exchanges_get(project_id) rv = pm.projects_id_contacts_get(project_id, 'tenant') assert rv.items[0].exchange_id == exchange_id rv1 = contacts_api.contacts_check_get(project_id=project_id, exchange_id=exchange_id) assert rv1.result r1 = contacts_api.contacts_project_id_status_get(project_id) assert r1.status == 'pending' # 处理对接邀请 contact_id = rv.items[0].contact_id r = tenant_ca.contacts_projects_exchange_id_get( exchange_id, 'pending') assert not r.items vc.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 = contacts_api.contacts_project_id_status_get(project_id) assert rv.status == 'accepted' rv = e_api.exchange_exchange_coin_get() seller_coin = rv.seller_coin s_coin = seller_coin[0] # 主平台获取买卖方币种列表 rv = ma_api.exchanges_exchange_coin_exchange_id_get(exchange_id) assert rv.seller_coin[0].name == project['shortName'] self.data['s_coin'] = s_coin self.data['b_coin'] = b_coin res = PostOrderMarketRequest() 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 now = datetime.now() disabled_at = now + relativedelta(months=AllottedTime._6month) 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 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)
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()
import random import pytest from swagger_client.main.api.entrust_api import EntrustApi # noqa: E501 from swagger_client.main.models.post_entrusts_request import PostEntrustsRequest from swagger_client.tenant.api.market_management_api import MarketManagementApi from swagger_client.tenant.api.exchange_entrust_api import ExchangeEntrustApi from .data import (FIELDS, EntrustTypeMarket, get_random_price_and_volume, market_test_data_set1, market_test_data_set2, market_test_data_set3) api = EntrustApi() tenant_market_api = MarketManagementApi() tenant_exchange_api = ExchangeEntrustApi() class TestMarketEntrust: @pytest.mark.parametrize(FIELDS, market_test_data_set1) def test_one_buy_one_sell(self, market_id, price, entrust_type, trade_type, volume, trigger_price, auto_cancel_at, volume_flag, special_login): payload = PostEntrustsRequest() payload.price = 1000_00 payload.entrust_type = 'market' payload.trade_type = 'sell' # payload.trigger_price = trigger_price payload.volume = 1000_00 # payload.auto_cancel_at = auto_cancel_at # login special_info = special_login( [api, tenant_market_api, tenant_exchange_api])
def test_coin_market(self, with_login): manager = PlatformManager('tenant') m_api = MarketManagementApi() e_api = ExchangeManagementApi() api = manager.account_api verify_api = manager.verify_api account_api = AccountApi() contacts_api = ContactsApi() vc = VentureContactsApi() venture_pm = ProjectManagementApi() tenant_ca = TenantContactsApi() user = register_with_login('tenant', with_login, [ api, verify_api, m_api, e_api, account_api, contacts_api, vc, venture_pm, tenant_ca ]) self.data['user2'] = user token = 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, token) exchange_api = ExchangeManagementApi() e = Exchange(exchange_api, token) exchange = e.get_exchange() e_api.exchange_post(exchange) # 获取交易对市场列表 try: m_api.markets_get() except ApiException as e: # 交易所不存在 assert e.status == 400 else: assert False, '市场应当不存在' # 初审复审 rv = account_api.accounts_account_info_get() account_id = rv.account_info.account_id self.data['account_id'] = 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') audit_api.tenant_audits_audit_post(res) # 复审 res = PostTenantReAuditRequest(id=task_id, status='approved') audit_api.tenant_audits_re_audit_post(res) rv = e_api.exchange_exchange_id_get() exchange_id = rv.id self.data['exchange_id'] = exchange_id rv = e_api.exchange_exchange_coin_get() seller_coin = rv.seller_coin buyer_coin = rv.buyer_coin b_coin = buyer_coin[0] if seller_coin: s_coin = seller_coin[0] else: # 对接币种 # 租户主动发起对接 project_id1 = self.data['project_id1'] project_id2 = self.data['project_id2'] req = { 'exchangeId': exchange_id, 'projectId': project_id1, 'sponsor': 'tenant' } contacts_api.contacts_post(req) # 项目方主动发起对接 req = { 'exchangeId': exchange_id, 'projectId': project_id2, 'sponsor': 'venture' } vc.contacts_post(req) rv1 = venture_pm.projects_id_contacts_get(project_id1, 'tenant') rv2 = tenant_ca.contacts_projects_exchange_id_get( exchange_id, 'pending') # 处理对接邀请 contact_id1 = rv1.items[0].contact_id contact_id2 = rv2.items[0].id vc.contacts_put({'contactId': contact_id1, 'status': 'accepted'}) rv = contacts_api.contacts_check_get(project_id=project_id1, exchange_id=exchange_id) # pprint(rv) contacts_api.contacts_put({ 'contactId': contact_id2, 'status': 'accepted' }) rv = vc.contacts_check_get(project_id2, exchange_id) rv = contacts_api.contacts_check_get(project_id1, exchange_id) assert rv.result rv = contacts_api.contacts_project_id_status_get(project_id1) assert rv.status == 'accepted' rv = contacts_api.contacts_project_id_status_get(project_id2) assert rv.status == 'accepted'
def test_register(self, with_login): manager = PlatformManager('tenant') m_api = MarketManagementApi() e_api = ExchangeManagementApi() api = manager.account_api verify_api = manager.verify_api account_api = AccountApi() venture_api = VentureApi() va_api = VentureAccountApi() contacts_api = ContactsApi() vc = VentureContactsApi() pm = ProjectManagementApi() user = register_with_login('tenant', with_login, [ api, verify_api, m_api, e_api, account_api, venture_api, va_api, contacts_api, pm, vc ]) token = user['token'] email = user.get('email') self.data['token1'] = token # 绑定电话 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, token) # 授权 res = PostPlatFormRegisterRequest() va_api.create_platform(body=res) # 申请项目 project1 = get_project(token) rv = venture_api.applications_post(body=project1) application_id_1 = rv.id sponsor = get_sponsors() # 登录保健方 account, password = sponsor['account'], sponsor['password'] sponsor_token = get_sponsor_token(account, password, email='test') project2 = get_project(token) # req = ApplicationRequest(**project) rv = venture_api.applications_post(body=project2) application_id_2 = rv.id rv = venture_api.projects_get(page=1) assert len(rv.items) == 0 rv = venture_api.applications_get(page=1) assert len(rv.items) == 2 # 设置保健机构 venture_api.applications_id_set_sponsor_put( application_id_1, {'sponsorId': sponsor['id']}) venture_api.applications_id_set_sponsor_put( application_id_2, {'sponsorId': sponsor['id']}) sponsor_project_api = SponsorsProjectApi() set_login_status(sponsor_project_api, sponsor_token) sponsor_project_api.projects_sponsor_put({ 'id': application_id_1, 'status': 1, 'remark': 'test' }) sponsor_project_api.projects_sponsor_put({ 'id': application_id_2, 'status': 1, 'remark': 'test' }) rv = venture_api.projects_get(page=1) project_id1 = rv.items[1].project_id project_id2 = rv.items[0].project_id self.data['project_id1'] = project_id1 self.data['project_id2'] = project_id2 # 设置接入方式 setting = PutProjectRequestSetting(access_method='verification', open=True) req = PutProjectRequest() req.setting = setting venture_api.projects_id_put(project_id1, 'setting', req) venture_api.projects_id_put(project_id2, 'setting', req) # 获取项目详情 # 初始化项目 s_api = SystemManagementApi() staff_project_api = StaffProjectApi() asset_management_api = AssetManagementApi() admin_token = get_admin_token() set_login_status(staff_project_api, admin_token) set_login_status(asset_management_api, admin_token) set_login_status(s_api, admin_token) coin_name1 = project1['shortName'] rv = asset_management_api.asset_mgmt_coins_get(coin_name=coin_name1) coin_config_id1 = rv.items[0].id coin_name2 = project2['shortName'] rv = asset_management_api.asset_mgmt_coins_get(coin_name=coin_name2) coin_config_id2 = rv.items[0].id # 修改币种配置 res = PutSystemCoinsInitRequest() res.usdt_price = '1251' res.rc_times = 8 res.wc_times = 8 res.withdraw_rate = 0.1 res.min_withdraw = 100 res.min_withdraw_fee = 0.1 res.max_withdraw = 1000 res.min_recharge = 10 res.address_tag_switch = True res.day_withdraw_total = 125564 res.address_type = 'OX' res.address_url = 'http://unknown.com' res.txid_url = 'http://unknown.com' asset_management_api.asset_mgmt_coins_id_init_put(coin_config_id1, res) asset_management_api.asset_mgmt_coins_id_init_put(coin_config_id2, res)
def test_add_market(self, with_login): user = self.data['user'] email, password = user['email'], user['password'] m_api = MarketManagementApi() e_api = ExchangeManagementApi() s_api = SponsorApi() venture_api = VentureApi() va_api = VentureAccountApi() project_api = ProjectApi() contacts_api = ContactsApi() tam_api = TenantAssetManagementApi() v_api = VerificationApi() ma_api = MainExchangeApi() vc = VentureContactsApi() pm = ProjectManagementApi() token = with_login('tenant', [ pm, vc, ma_api, v_api, contacts_api, project_api, m_api, e_api, va_api, s_api, venture_api, tam_api ], email, password) # 授权 res = PostPlatFormRegisterRequest() va_api.create_platform(body=res) # 交易币种 rv = e_api.exchange_exchange_coin_get() seller_coin = rv.seller_coin buyer_coin = rv.buyer_coin b_coin = buyer_coin[0] if seller_coin: s_coin = seller_coin[0] else: sponsor = get_sponsors() # 登录保健方 account, password = sponsor['account'], sponsor['password'] sponsor_api = SponsorApi() sponsor_token = get_sponsor_token(account, password, email='test') set_login_status(sponsor_api, sponsor_token) project = get_project(token) # req = ApplicationRequest(**project) rv = venture_api.applications_post(body=project) application_id = rv.id # 查看申请详情 rv = venture_api.applications_id_get(application_id) assert rv.status == 'undone' # 查看申请裂表 rv = venture_api.applications_get(page=1) assert len(rv.items) == 1 item = rv.items[0] assert item.project_name == project['projectName'] assert item.fullname == project['fullName'] assert item.short_name == project['shortName'] rv = venture_api.applications_num_get(status='under_review') assert int(rv.result) == 0 rv = venture_api.applications_num_get(status='passed') assert int(rv.result) == 0 rv = venture_api.applications_num_get(status='undone') assert int(rv.result) == 1 # 设置保健机构 venture_api.applications_id_set_sponsor_put( application_id, {'sponsorId': sponsor['id']}) rv = venture_api.applications_num_get(status='undone') assert int(rv.result) == 0 rv = venture_api.applications_num_get(status='under_review') assert int(rv.result) == 1 rv = venture_api.applications_num_get(status='passed') assert int(rv.result) == 0 rv = venture_api.applications_id_get(application_id) assert rv.status == 'under_review' project_name = project['projectName'] sponsor_project_api = SponsorsProjectApi() set_login_status(sponsor_project_api, sponsor_token) rv = sponsor_project_api.projects_get(page=1, project_name=project_name) assert len(rv.items) >= 1 rv = sponsor_project_api.projects_id_get(id=application_id) assert rv # 保健通过 sponsor_project_api.projects_sponsor_put({ 'id': application_id, 'status': 1, 'remark': 'test' }) rv = venture_api.applications_num_get(status='undone') assert int(rv.result) == 0 rv = venture_api.applications_num_get(status='under_review') assert int(rv.result) == 0 rv = venture_api.applications_num_get(status='passed') assert int(rv.result) == 1 rv = venture_api.applications_id_get(application_id) assert rv.status == 'passed' # 保鉴成功列表 rv = sponsor_project_api.sponsor_record_success_get( page=1, coin_name=project['shortName']) assert len(rv.items) == 1 assert rv.items[0].full_name == project['fullName'] # 项目列表 rv = venture_api.projects_get(page=1) project_id = rv.items[0].project_id self.data['project_id'] = project_id # 设置接入方式 setting = PutProjectRequestSetting(access_method='verification', open=True) req = PutProjectRequest() req.setting = setting venture_api.projects_id_put(project_id, 'setting', req) # 获取项目详情 rv = venture_api.projects_id_get(project_id) exchange_id = TestMarket1.data['exchange_id'] # 初始化项目 s_api = SystemManagementApi() staff_project_api = StaffProjectApi() asset_management_api = AssetManagementApi() admin_token = get_admin_token() set_login_status(staff_project_api, admin_token) set_login_status(asset_management_api, admin_token) set_login_status(s_api, admin_token) coin_name = project['shortName'] rv = asset_management_api.asset_mgmt_coins_get(coin_name=coin_name) coin_id = rv.items[0].coin_id coin_config_id = rv.items[0].id # 修改币种配置 res = PutSystemCoinsInitRequest() res.usdt_price = '1251' res.rc_times = 8 res.wc_times = 8 res.withdraw_rate = 0.1 res.min_withdraw = 100 res.min_withdraw_fee = 0.1 res.max_withdraw = 1000 res.min_recharge = 10 res.address_tag_switch = True res.day_withdraw_total = 125564 res.address_type = 'OX' res.address_url = 'http://unknown.com' res.txid_url = 'http://unknown.com' # asset_management_api.asset_mgmt_coins_id_put(coin_id, res) asset_management_api.asset_mgmt_coins_id_init_put( coin_config_id, res) rv = s_api.system_trading_pair_get(name=project['shortName'], partition_id=b_coin.id) # 对接币种 req = { 'exchangeId': exchange_id, 'projectId': project_id, 'sponsor': 'tenant' } contacts_api.contacts_post(req) rv = contacts_api.contacts_check_get(project_id, exchange_id) 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_check_get(project_id=project_id, exchange_id=exchange_id) assert rv.result rv = e_api.exchange_exchange_coin_get() seller_coin = rv.seller_coin s_coin = seller_coin[0] # 主平台获取买卖方币种列表 rv = ma_api.exchanges_exchange_coin_exchange_id_get(exchange_id) assert rv.seller_coin[0].name == project['shortName'] self.data['s_coin'] = s_coin self.data['b_coin'] = b_coin res = PostOrderMarketRequest() 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 now = datetime.now() create_at = now.strftime("%Y-%m") disabled_at = now + relativedelta(months=AllottedTime._6month) disabled_at = disabled_at.strftime("%Y-%m") 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(token, usdt_id, self.data['account_id']) rv = tam_api.asset_mgmt_assets_get() # 临时接口充币 rv = tam_api.asset_mgmt_balance_coin_id_get(usdt_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 item = items[0] sell_coin_name = s_coin.name buy_coin_name = b_coin.name # total_rate = TestMarket1.fee_rate + float(TestMarket1.service_rate) # assert item.total_rate == 0.00011 # todo暂时不测这个 # assert item.fee_rate == TestMarket1.fee_rate # todo暂时不测这个 assert item.status == 'running' assert item.trading_pair == f'{sell_coin_name}/{buy_coin_name}' assert item.created_at.strftime('%Y-%m') == create_at assert item.disabled_at.strftime('%Y-%m') == disabled_at # 获取交易所总数据 rv = ma_api.exchanges_total_data_get() assert float(rv.exchange_amount) >= 1 # 批量修改交易币对单价 s_api.system_trading_pair_update_list_put(1111, True, True) rv = s_api.system_trading_pair_get(partition_id=b_coin.id) for each in rv.items: assert float(each.price) == 1111
def test_add_market1(self, with_login): user = self.data['user'] email, password = user['email'], user['password'] m_api = MarketManagementApi() e_api = ExchangeManagementApi() s_api = SponsorApi() venture_api = VentureApi() va_api = VentureAccountApi() project_api = ProjectApi() contacts_api = ContactsApi() tam_api = TenantAssetManagementApi() v_api = VerificationApi() ma_api = MainExchangeApi() vc = VentureContactsApi() pm = ProjectManagementApi() token = with_login('tenant', [ pm, vc, ma_api, v_api, contacts_api, project_api, m_api, e_api, va_api, s_api, venture_api, tam_api ], email, password) # 授权 res = PostPlatFormRegisterRequest() va_api.create_platform(body=res) # 交易币种 rv = e_api.exchange_exchange_coin_get() seller_coin = rv.seller_coin buyer_coin = rv.buyer_coin b_coin = buyer_coin[0] if seller_coin: s_coin = seller_coin[0] else: sponsor = get_sponsors() # 登录保健方 account, password = sponsor['account'], sponsor['password'] sponsor_api = SponsorApi() sponsor_token = get_sponsor_token(account, password, email='test') set_login_status(sponsor_api, sponsor_token) project = get_project(token) # req = ApplicationRequest(**project) rv = venture_api.applications_post(body=project) application_id = rv.id # 查看申请列表 rv = venture_api.applications_get(page=1) assert len(rv.items) == 1 item = rv.items[0] assert item.project_name == project['projectName'] assert item.fullname == project['fullName'] assert item.short_name == project['shortName'] rv = venture_api.applications_num_get(status='under_review') assert int(rv.result) == 0 rv = venture_api.applications_num_get(status='passed') assert int(rv.result) == 0 rv = venture_api.applications_num_get(status='undone') assert int(rv.result) == 1 # 设置保健机构 venture_api.applications_id_set_sponsor_put( application_id, {'sponsorId': sponsor['id']}) rv = venture_api.applications_num_get(status='undone') assert int(rv.result) == 0 rv = venture_api.applications_num_get(status='under_review') assert int(rv.result) == 1 rv = venture_api.applications_num_get(status='passed') assert int(rv.result) == 0 project_name = project['projectName'] sponsor_project_api = SponsorsProjectApi() set_login_status(sponsor_project_api, sponsor_token) rv = sponsor_project_api.projects_get(page=1, project_name=project_name) assert len(rv.items) >= 1 rv = sponsor_project_api.projects_id_get(id=application_id) assert rv # 保健不通过 sponsor_project_api.projects_sponsor_put({ 'id': application_id, 'status': 0, 'remark': 'test' }) rv = venture_api.applications_num_get(status='undone') assert int(rv.result) == 0 rv = venture_api.applications_num_get(status='under_review') assert int(rv.result) == 0 rv = venture_api.applications_num_get(status='passed') assert int(rv.result) == 0 rv = venture_api.applications_num_get(status='turn_down') assert int(rv.result) == 1 # 保鉴成功列表 rv = sponsor_project_api.sponsor_record_success_get( page=1, coin_name=project['shortName']) assert not rv.items # 项目列表 rv = venture_api.projects_get(page=1) assert len(rv.items) == 0