mirror of
https://github.com/Ichinga-Samuel/aiomql.git
synced 2026-08-08 01:37:45 +00:00
v4
This commit is contained in:
@@ -27,9 +27,7 @@ async def make_buy_sell_orders():
|
||||
return {"buy": Order(**buy_req), "sell": Order(**sell_req)}
|
||||
|
||||
|
||||
def test_trade_mode(
|
||||
config, backtest_engine, history, positions, order_sell, order_buy, btc_usd
|
||||
):
|
||||
def test_trade_mode(config, backtest_engine, history, positions, order_sell, order_buy, btc_usd):
|
||||
assert config.mode == "backtest"
|
||||
assert isinstance(backtest_engine, BackTestEngine)
|
||||
assert isinstance(history.mt5, MetaBackTester)
|
||||
@@ -79,26 +77,16 @@ async def test_history(backtest_engine, history, order_sell, order_buy, position
|
||||
async def test_margin(backtest_engine, order_sell, order_buy):
|
||||
await backtest_engine.setup_account(balance=100)
|
||||
so_margin = await backtest_engine.order_calc_margin(
|
||||
action=order_sell.action,
|
||||
volume=order_sell.volume,
|
||||
symbol=order_sell.symbol,
|
||||
price=order_sell.price,
|
||||
action=order_sell.action, volume=order_sell.volume, symbol=order_sell.symbol, price=order_sell.price
|
||||
)
|
||||
bo_margin = await backtest_engine.order_calc_margin(
|
||||
action=order_buy.action,
|
||||
volume=order_buy.volume,
|
||||
symbol=order_buy.symbol,
|
||||
price=order_buy.price,
|
||||
action=order_buy.action, volume=order_buy.volume, symbol=order_buy.symbol, price=order_buy.price
|
||||
)
|
||||
total_margin = so_margin + bo_margin
|
||||
await backtest_engine.order_send(request=order_sell.request)
|
||||
await backtest_engine.order_send(request=order_buy.request)
|
||||
# noinspection PyTestUnpassedFixture
|
||||
assert (
|
||||
backtest_engine.positions.margin
|
||||
== total_margin
|
||||
== backtest_engine._account.margin
|
||||
)
|
||||
assert backtest_engine.positions.margin == total_margin == backtest_engine._account.margin
|
||||
backtest_engine.reset(clear_data=True)
|
||||
|
||||
|
||||
@@ -124,11 +112,7 @@ async def test_account(backtest_engine, positions):
|
||||
deal = backtest_engine.deals.history_deals_get(position=bo.order)
|
||||
bo_profit = deal[-1].profit
|
||||
assert len(all_pos) == 1
|
||||
assert (
|
||||
backtest_engine.positions.margin
|
||||
== backtest_engine._account.margin
|
||||
== backtest_engine.positions.margins[so.order]
|
||||
)
|
||||
assert backtest_engine.positions.margin == backtest_engine._account.margin == backtest_engine.positions.margins[so.order]
|
||||
profit = sum([pos.profit for pos in all_pos])
|
||||
n_balance = backtest_engine._account.balance
|
||||
n_equity = backtest_engine._account.equity
|
||||
@@ -155,9 +139,7 @@ async def test_wrapup(positions, buy_order, sell_order, backtest_engine, config)
|
||||
last_equity = backtest_engine._account.equity
|
||||
last_profit = backtest_engine._account.profit
|
||||
tdata = GetData.load_data(name=config.backtest_dir / f"{backtest_engine.name}.pkl")
|
||||
new_bte = BackTestEngine(
|
||||
data=tdata, restart=False, assign_to_config=False, preload=False
|
||||
)
|
||||
new_bte = BackTestEngine(data=tdata, restart=False, assign_to_config=False, preload=False)
|
||||
assert new_bte._account.balance == last_balance
|
||||
assert new_bte._account.equity == last_equity
|
||||
assert new_bte._account.profit == last_profit
|
||||
|
||||
Reference in New Issue
Block a user