mirror of
https://github.com/Ichinga-Samuel/aiomql.git
synced 2026-08-20 07:18:08 +00:00
v4.0.1
This commit is contained in:
@@ -53,7 +53,7 @@ async def config(request):
|
||||
data = json.load(fh)
|
||||
json.dump(data, fh1, indent=2)
|
||||
json.dump(data, fh2, indent=2)
|
||||
config = Config(root="tests/live", filename="test.json")
|
||||
config = Config(root="tests/live", config_file="tests/live/test.json")
|
||||
yield config
|
||||
await cleanup()
|
||||
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
bid,volume,actual_profit,order,closed,price,ask,deal,win
|
||||
0.0,0.0,0,0,False,0.0,0.0,0,False
|
||||
0.0,0.0,0,0,False,0.0,0.0,0,False
|
||||
|
@@ -0,0 +1,24 @@
|
||||
[
|
||||
{
|
||||
"deal": 0,
|
||||
"order": 0,
|
||||
"volume": 0.0,
|
||||
"price": 0.0,
|
||||
"bid": 0.0,
|
||||
"ask": 0.0,
|
||||
"actual_profit": 0,
|
||||
"closed": false,
|
||||
"win": false
|
||||
},
|
||||
{
|
||||
"deal": 0,
|
||||
"order": 0,
|
||||
"volume": 0.0,
|
||||
"price": 0.0,
|
||||
"bid": 0.0,
|
||||
"ask": 0.0,
|
||||
"actual_profit": 0,
|
||||
"closed": false,
|
||||
"win": false
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1,3 @@
|
||||
bid,name,volume,actual_profit,order,closed,ema,price,ask,deal,rsi,win
|
||||
0.0,test_trades,0.0,0,0,False,20,0.0,0.0,0,14,False
|
||||
0.0,test_trades,0.0,0,0,False,20,0.0,0.0,0,14,False
|
||||
|
@@ -0,0 +1,30 @@
|
||||
[
|
||||
{
|
||||
"name": "test_trades",
|
||||
"ema": 20,
|
||||
"rsi": 14,
|
||||
"deal": 0,
|
||||
"order": 0,
|
||||
"volume": 0.0,
|
||||
"price": 0.0,
|
||||
"bid": 0.0,
|
||||
"ask": 0.0,
|
||||
"actual_profit": 0,
|
||||
"closed": false,
|
||||
"win": false
|
||||
},
|
||||
{
|
||||
"name": "test_trades",
|
||||
"ema": 20,
|
||||
"rsi": 14,
|
||||
"deal": 0,
|
||||
"order": 0,
|
||||
"volume": 0.0,
|
||||
"price": 0.0,
|
||||
"bid": 0.0,
|
||||
"ask": 0.0,
|
||||
"actual_profit": 0,
|
||||
"closed": false,
|
||||
"win": false
|
||||
}
|
||||
]
|
||||
@@ -25,5 +25,5 @@ class TestConfig:
|
||||
assert "server" in account_info
|
||||
|
||||
def test_load_config(self, config):
|
||||
config.load_config(file="tests/live/configs/test2.json")
|
||||
config.load_config(config_file="tests/live/configs/test2.json")
|
||||
assert config.filename == "test2.json"
|
||||
|
||||
@@ -5,7 +5,8 @@ from aiomql.lib.ram import RAM
|
||||
from aiomql.contrib.traders import SimpleTrader
|
||||
from aiomql.contrib.symbols import ForexSymbol
|
||||
from aiomql.core.constants import OrderType
|
||||
|
||||
from aiomql.lib.account import Account
|
||||
from aiomql._utils import round_down
|
||||
|
||||
class TestTrader:
|
||||
@classmethod
|
||||
@@ -13,11 +14,13 @@ class TestTrader:
|
||||
ram = RAM(fixed_amount=10)
|
||||
cls.trader = SimpleTrader(symbol=ForexSymbol(name="BTCUSD"), ram=ram)
|
||||
cls.simple_trader2 = SimpleTrader(symbol=ForexSymbol(name="EURJPY"), ram=ram)
|
||||
cls.account = Account()
|
||||
|
||||
@pytest.fixture(scope="class", autouse=True)
|
||||
async def initialize(self):
|
||||
await self.trader.symbol.initialize()
|
||||
await self.simple_trader2.symbol.initialize()
|
||||
await self.account.refresh()
|
||||
|
||||
async def test_create_order_no_stops(self):
|
||||
await self.trader.create_order_no_stops(order_type=OrderType.BUY)
|
||||
@@ -35,8 +38,8 @@ class TestTrader:
|
||||
profit = floor(await self.trader.order.calc_profit())
|
||||
loss = -floor(abs(await self.trader.order.calc_loss()))
|
||||
assert profit == -loss * self.trader.ram.risk_to_reward
|
||||
assert profit == self.trader.ram.fixed_amount * self.trader.ram.risk_to_reward
|
||||
assert loss == -self.trader.ram.fixed_amount
|
||||
assert abs(profit - self.trader.ram.fixed_amount * self.trader.ram.risk_to_reward) <= 2.5
|
||||
assert abs(abs(loss) - abs(-self.trader.ram.fixed_amount)) <= 2
|
||||
assert res is not None
|
||||
assert res.retcode == 10009
|
||||
|
||||
@@ -47,8 +50,8 @@ class TestTrader:
|
||||
profit = floor(await self.trader.order.calc_profit())
|
||||
loss = -floor(abs(await self.trader.order.calc_loss()))
|
||||
assert profit == -loss * self.trader.ram.risk_to_reward
|
||||
assert profit == self.trader.ram.fixed_amount * self.trader.ram.risk_to_reward
|
||||
assert loss == -self.trader.ram.fixed_amount
|
||||
assert abs(profit - self.trader.ram.fixed_amount * self.trader.ram.risk_to_reward) <= 2.5
|
||||
assert abs(abs(loss) - abs(-self.trader.ram.fixed_amount)) <= 2
|
||||
assert res is not None
|
||||
assert res.retcode == 10009
|
||||
|
||||
@@ -60,10 +63,10 @@ class TestTrader:
|
||||
tp = tick.ask + tp
|
||||
await self.trader.create_order_with_stops(order_type=OrderType.BUY, sl=sl, tp=tp)
|
||||
res = await self.trader.order.send()
|
||||
profit = floor(await self.trader.order.calc_profit())
|
||||
loss = -floor(abs(await self.trader.order.calc_loss()))
|
||||
assert profit == -loss * self.trader.ram.risk_to_reward
|
||||
assert profit == self.trader.ram.fixed_amount * self.trader.ram.risk_to_reward
|
||||
assert loss == -self.trader.ram.fixed_amount
|
||||
assert res is not None
|
||||
assert res.retcode == 10009
|
||||
profit = round(await self.trader.order.calc_profit(), self.account.currency_digits)
|
||||
loss = -round(abs(await self.trader.order.calc_loss()), self.account.currency_digits)
|
||||
assert profit == -loss * self.trader.ram.risk_to_reward
|
||||
assert abs(profit - (self.trader.ram.fixed_amount * self.trader.ram.risk_to_reward)) <= 2.5
|
||||
assert abs(abs(loss) - self.trader.ram.fixed_amount) <= 2.5
|
||||
|
||||
Reference in New Issue
Block a user