Last active
April 28, 2024 23:13
-
-
Save Ichinga-Samuel/d12f34d724e32398ce2865ed2a96f10c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import asyncio | |
from aiomql import Account, OrderType, TradeAction, Order, ForexSymbol | |
async def main(): | |
async with Account(): | |
# create a symbol | |
sym = ForexSymbol(name="BTCUSD") | |
# Confirm the symbol is available for this account and initialize with default values. | |
res = await sym.init() | |
# I want to place a market buy order, risk only 2 usd to gain 4 usd and using the minimum volume | |
amount = 2 | |
volume = sym.volume_min | |
# get the value of my risk in points | |
points = sym.compute_points(amount=amount, volume=volume) | |
# get the current price tick and calculate the stop loss and take profit | |
tick = await sym.info_tick() | |
points_value = points * sym.point | |
sl = tick.ask - points_value | |
tp = tick.ask + 2 * points_value | |
# create order | |
order = Order(symbol=sym.name, type=OrderType.BUY, volume=volume, action=TradeAction.DEAL, | |
price=tick.ask, sl=sl, tp=tp) | |
# check order. returns an OrderCheckResult object | |
chk = await order.check() | |
print(chk.comment) | |
# confirm that my profit is 4 usd | |
profit = await order.calc_profit() | |
print(profit) | |
# send order returns an OrderSendResult object | |
res = await order.send() | |
print(res.comment) | |
asyncio.run(main()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment