Buckets:
AnonymousSpottedToad/candidate_bucket / codebase /python /noimank_easyths /test /integration /automation_test.py
| """自动化测试 - 同步操作模式 | |
| 需要运行中的同花顺客户端,使用 pytest -m integration 运行。 | |
| Author: noimank | |
| Email: noimank@163.com | |
| """ | |
| import pytest | |
| from easyths.core.tonghuashun_automator import TonghuashunAutomator | |
| from easyths.operations.account_query import AccountQueryOperation | |
| from easyths.operations.account_switch import AccountSwitchOperation | |
| from easyths.operations.buy import BuyOperation | |
| from easyths.operations.condition_buy import ConditionBuyOperation | |
| from easyths.operations.condition_order_cancel import ConditionOrderCancelOperation | |
| from easyths.operations.condition_order_query import ConditionOrderQueryOperation | |
| from easyths.operations.condition_sell import ConditionSellOperation | |
| from easyths.operations.funds_query import FundsQueryOperation | |
| from easyths.operations.historical_commission_query import ( | |
| HistoricalCommissionQueryOperation, | |
| ) | |
| from easyths.operations.holding_query import HoldingQueryOperation | |
| from easyths.operations.market_buy import MarketBuyOperation | |
| from easyths.operations.market_sell import MarketSellOperation | |
| from easyths.operations.order_cancel import OrderCancelOperation | |
| from easyths.operations.order_query import OrderQueryOperation | |
| from easyths.operations.reverse_repo_buy import ReverseRepoBuyOperation | |
| from easyths.operations.reverse_repo_query import ReverseRepoQueryOperation | |
| from easyths.operations.sell import SellOperation | |
| from easyths.operations.stop_loss_profit import StopLossProfitOperation | |
| pytestmark = pytest.mark.integration | |
| def test_buy_op(): | |
| """测试买入操作 - 同步模式""" | |
| # 创建自动化器 | |
| automator = TonghuashunAutomator() | |
| # 连接 | |
| automator.connect() | |
| try: | |
| # 创建买入操作 | |
| buy_op = BuyOperation(automator) | |
| # 执行买入(同步) | |
| params = {"stock_code": "000001", "price": 110.55, "quantity": 100} | |
| result = buy_op.run(params) | |
| print(f"买入结果: {result.success}, data: {result.data}") | |
| finally: | |
| # 断开连接 | |
| automator.disconnect() | |
| def test_automator_basic(): | |
| """测试自动化器基本功能""" | |
| automator = TonghuashunAutomator() | |
| try: | |
| # 连接 | |
| connected = automator.connect() | |
| print(f"连接结果: {connected}") | |
| assert connected, "连接失败" | |
| # 检查连接状态 | |
| is_connected = automator.is_connected() | |
| print(f"已连接: {is_connected}") | |
| assert is_connected, "未连接" | |
| # 获取主窗口 | |
| main_window = automator.main_window | |
| print(f"主窗口: {main_window is not None}") | |
| assert main_window is not None, "主窗口为空" | |
| # 断开连接 | |
| automator.disconnect() | |
| print("测试通过!") | |
| finally: | |
| pass | |
| def test_sell_op(): | |
| # 创建自动化器 | |
| automator = TonghuashunAutomator() | |
| # 连接 | |
| automator.connect() | |
| try: | |
| # 创建操作 | |
| op = SellOperation(automator) | |
| # 执行操作(同步) | |
| params = {"stock_code": "000001", "price": 11.55, "quantity": 1000} | |
| result = op.run(params) | |
| print(f"操作结果: {result.success}, data: {result.data}") | |
| finally: | |
| # 断开连接 | |
| automator.disconnect() | |
| def test_funds_query_op(): | |
| # 创建自动化器 | |
| automator = TonghuashunAutomator() | |
| # 连接 | |
| automator.connect() | |
| try: | |
| # 创建操作 | |
| op = FundsQueryOperation(automator) | |
| # 执行操作(同步) | |
| params = {} | |
| result = op.run(params) | |
| print(f"操作结果: {result.success}, data: {result.data}") | |
| finally: | |
| # 断开连接 | |
| automator.disconnect() | |
| def test_order_cancel_op(): | |
| # 创建自动化器 | |
| automator = TonghuashunAutomator() | |
| # 连接 | |
| automator.connect() | |
| try: | |
| # 创建操作 | |
| op = OrderCancelOperation(automator) | |
| # 执行操作(同步) | |
| params = {"stock_code": "000001", "cancel_type": "all"} | |
| result = op.run(params) | |
| print(f"操作结果: {result.success}, data: {result.data}") | |
| finally: | |
| # 断开连接 | |
| automator.disconnect() | |
| def test_holding_query_op(): | |
| # 创建自动化器 | |
| automator = TonghuashunAutomator() | |
| # 连接 | |
| automator.connect() | |
| try: | |
| # 创建操作 | |
| op = HoldingQueryOperation(automator) | |
| # 执行操作(同步) | |
| params = {} | |
| result = op.run(params) | |
| print(f"操作结果: {result}") | |
| finally: | |
| # 断开连接 | |
| automator.disconnect() | |
| def test_order_query_op(): | |
| # 创建自动化器 | |
| automator = TonghuashunAutomator() | |
| # 连接 | |
| automator.connect() | |
| try: | |
| # 创建操作 | |
| op = OrderQueryOperation(automator) | |
| # 执行操作(同步) | |
| params = {"stock_code": "000001"} | |
| result = op.run(params) | |
| print(f"操作结果: {result.success}, data: {result.data}") | |
| finally: | |
| # 断开连接 | |
| automator.disconnect() | |
| def test_historical_commission_query_op(): | |
| # 创建自动化器 | |
| automator = TonghuashunAutomator() | |
| # 连接 | |
| automator.connect() | |
| try: | |
| # 创建操作 | |
| op = HistoricalCommissionQueryOperation(automator) | |
| # 执行操作(同步) | |
| params = { | |
| # "stock_code": "000001" | |
| } | |
| result = op.run(params) | |
| print(f"操作结果: {result.success}, data: {result.data}") | |
| finally: | |
| # 断开连接 | |
| automator.disconnect() | |
| def test_reverse_repo_buy_op(): | |
| # 创建自动化器 | |
| automator = TonghuashunAutomator() | |
| # 连接 | |
| automator.connect() | |
| try: | |
| # 创建操作 | |
| op = ReverseRepoBuyOperation(automator) | |
| # 执行操作(同步) | |
| params = { | |
| # 交易市场 ["上海", "深圳"], | |
| "market": "上海", | |
| # 回购期限 ["1天期", "2天期", "3天期", "4天期", "7天期"] | |
| "time_range": "1天期", | |
| "amount": 100000, | |
| } | |
| result = op.run(params) | |
| print( | |
| f"操作结果: {result.success}, data: {result.data}, message={result.message}" | |
| ) | |
| finally: | |
| # 断开连接 | |
| automator.disconnect() | |
| def test_reverse_repo_query_op(): | |
| # 创建自动化器 | |
| automator = TonghuashunAutomator() | |
| # 连接 | |
| automator.connect() | |
| try: | |
| # 创建操作 | |
| op = ReverseRepoQueryOperation(automator) | |
| # 执行操作(同步) | |
| params = { | |
| # 交易市场 ["上海", "深圳"], | |
| "market": "上海", | |
| # 回购期限 ["1天期", "2天期", "3天期", "4天期", "7天期"] | |
| "time_range": "1天期", | |
| "amount": 100000, | |
| } | |
| result = op.run(params) | |
| print(f"操作结果: {result.success}, data: {result.data}") | |
| finally: | |
| # 断开连接 | |
| automator.disconnect() | |
| def test_condition_buy_op(): | |
| # 创建自动化器 | |
| automator = TonghuashunAutomator() | |
| # 连接 | |
| automator.connect() | |
| try: | |
| # 创建操作 | |
| op = ConditionBuyOperation(automator) | |
| # 执行操作(同步) | |
| params = {"stock_code": "000001", "target_price": 12.1, "quantity": 100} | |
| result = op.run(params) | |
| print(f"操作结果: {result.success}, data: {result.data}") | |
| finally: | |
| # 断开连接 | |
| automator.disconnect() | |
| def test_condition_sell_op(): | |
| # 创建自动化器 | |
| automator = TonghuashunAutomator() | |
| # 连接 | |
| automator.connect() | |
| try: | |
| # 创建操作 | |
| op = ConditionSellOperation(automator) | |
| # 执行操作(同步) | |
| params = {"stock_code": "000001", "target_price": 12.1, "quantity": 100} | |
| result = op.run(params) | |
| print(f"操作结果: {result.success}, data: {result.data}") | |
| finally: | |
| # 断开连接 | |
| automator.disconnect() | |
| def test_stop_loss_profit_op(): | |
| # 创建自动化器 | |
| automator = TonghuashunAutomator() | |
| # 连接 | |
| automator.connect() | |
| try: | |
| # 创建操作 | |
| op = StopLossProfitOperation(automator) | |
| # 执行操作(同步) | |
| params = { | |
| "stock_code": "000001", | |
| "stop_loss_percent": 3.1, | |
| "stop_profit_percent": 5.6, | |
| "quantity": 100, | |
| "expire_days": 1, | |
| } | |
| result = op.run(params) | |
| print(f"操作结果: {result.success}, data: {result.data}") | |
| finally: | |
| # 断开连接 | |
| automator.disconnect() | |
| def test_condition_order_query_op(): | |
| # 创建自动化器 | |
| automator = TonghuashunAutomator() | |
| # 连接 | |
| automator.connect() | |
| try: | |
| # 创建操作 | |
| op = ConditionOrderQueryOperation(automator) | |
| # 执行操作(同步) | |
| params = {} | |
| result = op.run(params) | |
| print(f"操作结果: {result.success}, data: {result.data}") | |
| finally: | |
| # 断开连接 | |
| automator.disconnect() | |
| def test_condition_order_cancel_op(): | |
| # 创建自动化器 | |
| automator = TonghuashunAutomator() | |
| # 连接 | |
| automator.connect() | |
| try: | |
| # 创建操作 | |
| op = ConditionOrderCancelOperation(automator) | |
| # 执行操作(同步) | |
| params = { | |
| # "stock_code": "000001", | |
| # "order_type": "买入" | |
| } | |
| result = op.run(params) | |
| print(f"操作结果: {result.success}, data: {result.data}") | |
| finally: | |
| # 断开连接 | |
| automator.disconnect() | |
| def test_market_buy_op(): | |
| # 创建自动化器 | |
| automator = TonghuashunAutomator() | |
| # 连接 | |
| automator.connect() | |
| try: | |
| # 创建操作 | |
| op = MarketBuyOperation(automator) | |
| # 执行操作(同步) | |
| params = {"stock_code": "000001", "quantity": 100, "execution_strategy": 7} | |
| result = op.run(params) | |
| print( | |
| f"操作结果: {result.success}, data: {result.data}, message: {result.message}" | |
| ) | |
| finally: | |
| # 断开连接 | |
| automator.disconnect() | |
| def test_market_sell_op(): | |
| # 创建自动化器 | |
| automator = TonghuashunAutomator() | |
| # 连接 | |
| automator.connect() | |
| try: | |
| # 创建操作 | |
| op = MarketSellOperation(automator) | |
| # 执行操作(同步) | |
| params = {"stock_code": "000001", "quantity": 100, "execution_strategy": 2} | |
| result = op.run(params) | |
| print( | |
| f"操作结果: {result.success}, data: {result.data}, message: {result.message}" | |
| ) | |
| finally: | |
| # 断开连接 | |
| automator.disconnect() | |
| def test_account_query(): | |
| # 创建自动化器 | |
| automator = TonghuashunAutomator() | |
| # 连接 | |
| automator.connect() | |
| try: | |
| # 创建操作 | |
| op = AccountQueryOperation(automator) | |
| # 执行操作(同步) | |
| params = {} | |
| result = op.run(params) | |
| print(f"操作结果: {result}") | |
| finally: | |
| # 断开连接 | |
| automator.disconnect() | |
| def test_account_switch(): | |
| # 创建自动化器 | |
| automator = TonghuashunAutomator() | |
| # 连接 | |
| automator.connect() | |
| try: | |
| # 先完成账户信息初始化 | |
| AccountQueryOperation(automator).run({}) | |
| # 创建操作 | |
| op = AccountSwitchOperation(automator) | |
| # 执行操作(同步) | |
| params = {"account_name": "模拟炒股"} | |
| result = op.run(params) | |
| print(f"操作结果: {result}") | |
| finally: | |
| # 断开连接 | |
| automator.disconnect() | |
Xet Storage Details
- Size:
- 11.6 kB
- Xet hash:
- 39c2037aeff8fbc60fab7d40807c9b8488276148100309fed537570eadd18c9d
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.