Skip to content

Instantly share code, notes, and snippets.

import asyncio
from aiomql import Account
async def main():
# since our login details are defined in aiomql.json
# we can just call Account() without any arguments
async with Account() as acc:
print(acc.balance)
import logging
from aiomql import ForexSymbol, Bot, Sessions, FingerTrap
logging.basicConfig(level=logging.WARNING)
def run_bot():
bot = Bot()
symbols = ['EURUSD', 'GBPUSD', 'USDJPY', 'USDCHF', 'USDCAD', 'AUDUSD', 'NZDUSD', 'EURGBP', 'EURJPY', 'GBPJPY']
strategies = [FingerTrap(symbol=ForexSymbol(name=symbol)) for symbol in symbols]
from aiomql import Config, Account
config = Config()
print(config.path, config.login, config.password)
# load the config from a file different file.
# remember to pass reload=True to reload the config file
Config(filename='config.json', reload=True)
import re
def validate_email(email_address):
email_address = email_address.split()
# email address can start with any alphanumeric character.
# username part i.e the part before the @ symbol cannot be more than 64 characters
# domain part i.e the part after the @ symbol cannot be more than 251 characters
# domain part can end with any of the following top level domain name (.com, .org, .net)
pattern = re.compile(r"(?P<username>^[a-z0-9][\w.]{,63})@(?P<domain>[\w]{1,247}(.com|.net|.org)$)", flags=re.IGNORECASE|re.ASCII)
if not pattern.match(email_address):
import asyncio
from logging import getLogger
from aiomql import Trader, ForexSymbol, RAM, OrderType, Account
logger = getLogger(__name__)
class SimpleTrader(Trader):
import asyncio
from datetime import datetime
from aiomql import Symbol, TimeFrame, Account
async def main():
# Assume account details are in the config file
async with Account():
sym = Symbol(name="BTCUSD")
res = await sym.init()
import asyncio
from datetime import datetime
from pytz import timezone
from aiomql import ForexSymbol, Account, Positions, History, Order, OrderType, RAM, TradeAction
async def main():
async with Account():
# get start time using local timezone
import asyncio
from aiomql import Account, OrderType, TradeAction, Order, ForexSymbol
async def main():
async with Account():
# create a symbol
sym = ForexSymbol(name="BTCUSD")
import asyncio
from aiomql import Symbol, TimeFrame, Account
async def main():
async with Account():
# create a symbol
sym = Symbol(name="EURUSD")
# initialize the symbol
res = await sym.init()
from fastapi import FastAPI, File, UploadFile, Depends
from filestore import LocalStorage, Result
app = FastAPI()
# local storage instance for single file upload
loc = LocalStorage(name='book', required=True)
# local storage instance for multiple file upload with a maximum of 2 files from a single field
loc2 = LocalStorage(name='book', required=True, count=2)