mirror of
https://github.com/Ichinga-Samuel/aiomql.git
synced 2026-08-23 00:38:07 +00:00
v3.21
This commit is contained in:
@@ -1,40 +0,0 @@
|
||||
from datetime import time
|
||||
import logging
|
||||
|
||||
from aiomql import Bot, ForexSymbol, FingerTrap, Session, Sessions, RAM, SimpleTrader, TimeFrame
|
||||
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
|
||||
|
||||
def build_bot():
|
||||
bot = Bot()
|
||||
|
||||
# create sessions for the strategies
|
||||
london = Session(name='London', start=8, end=time(hour=15, minute=30), on_end='close_all')
|
||||
new_york = Session(name='New York', start=13, end=time(hour=20, minute=30))
|
||||
tokyo = Session(name='Tokyo', start=23, end=time(hour=6, minute=30))
|
||||
|
||||
# configure the parameters and the trader for a strategy
|
||||
params = {'trend_candles_count': 500, 'fast_period': 8, 'slow_period': 34, 'entry_timeframe': TimeFrame.M5}
|
||||
gbpusd = ForexSymbol(name='GBPUSD')
|
||||
st1 = FingerTrap(symbol=gbpusd, params=params,
|
||||
trader=SimpleTrader(symbol=gbpusd, ram=RAM(risk=0.05, risk_to_reward=2)),
|
||||
sessions=Sessions(london, new_york))
|
||||
|
||||
# use the default for the other strategies
|
||||
st2 = FingerTrap(symbol=ForexSymbol(name='AUDUSD'), sessions=Sessions(tokyo, new_york))
|
||||
st3 = FingerTrap(symbol=ForexSymbol(name='USDCAD'), sessions=Sessions(new_york))
|
||||
st4 = FingerTrap(symbol=ForexSymbol(name='USDJPY'), sessions=Sessions(tokyo))
|
||||
st5 = FingerTrap(symbol=ForexSymbol(name='EURGBP'), sessions=Sessions(london))
|
||||
|
||||
# sessions are not required
|
||||
st6 = FingerTrap(symbol=ForexSymbol(name='EURUSD'))
|
||||
|
||||
# add strategies to the bot
|
||||
bot.add_strategies([st1, st2, st3, st4, st5, st6])
|
||||
|
||||
bot.execute()
|
||||
|
||||
|
||||
# run the bot
|
||||
build_bot()
|
||||
@@ -1,52 +0,0 @@
|
||||
import asyncio
|
||||
from aiomql import Symbol, TimeFrame, Account, Candle, Candles
|
||||
|
||||
|
||||
async def main():
|
||||
"""Example of using the Candle and Candles classes.
|
||||
The candle class is a single price bar. Holding the OHLCV data for a single price bar.
|
||||
The Candles class is a container of Candle objects. It is an Iterable of Candle objects.
|
||||
It can be sliced and indexed. It can also be accessed with keywords.
|
||||
It is a wrapper around a pandas DataFrame. Which is what it uses to store the data.
|
||||
"""
|
||||
async with Account():
|
||||
sym = Symbol(name="EURUSD")
|
||||
|
||||
# Get EURUSD price bars for the past 48 hours
|
||||
candles: Candles = await sym.copy_rates_from_pos(timeframe=TimeFrame.H1, count=48, start_position=0)
|
||||
|
||||
# get size of candles
|
||||
print(len(candles)) # 48
|
||||
|
||||
# get the latest candle by accessing the last one.
|
||||
last: Candle = candles[-1] # A Candle object
|
||||
print(type(last))
|
||||
print(last.Index)
|
||||
|
||||
# slicing returns a Candles object
|
||||
half = candles[24:]
|
||||
print(type(half))
|
||||
print(len(half))
|
||||
|
||||
close = candles['close'] # close price of all the candles as a pandas series
|
||||
print(type(close))
|
||||
print(close)
|
||||
|
||||
# compute ema using pandas ta
|
||||
candles.ta.ema(length=34, append=True, fillna=0)
|
||||
# rename the column to ema
|
||||
candles.rename(EMA_34='ema')
|
||||
|
||||
# use talib to compute crossover. This returns a series object that is not part of the candles object.
|
||||
closeXema = candles.ta_lib.cross(candles.close, candles.ema)
|
||||
|
||||
# add to the candles
|
||||
candles['closeXema'] = closeXema
|
||||
print(candles)
|
||||
|
||||
# iterate over the first 5 candles
|
||||
for candle in candles[:5]:
|
||||
print(candle.open, candle.Index)
|
||||
|
||||
|
||||
asyncio.run(main())
|
||||
@@ -1,37 +0,0 @@
|
||||
import asyncio
|
||||
|
||||
from aiomql import Account, OrderType, TradeAction, Order, ForexSymbol
|
||||
|
||||
|
||||
async def main():
|
||||
async with Account():
|
||||
|
||||
# create a symbol
|
||||
sym = ForexSymbol(name="EURUSD-T")
|
||||
|
||||
# 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 2usd, and target 10 pips in this trade.
|
||||
# The ForexSymbol object has a compute_volume method that can be used to compute the volume
|
||||
# given a target pips and amount.
|
||||
volume = await sym.compute_volume(amount=2, points=100)
|
||||
|
||||
# a risk to reward ratio of 1:2
|
||||
# get the price tick of the symbol
|
||||
tick = await sym.info_tick()
|
||||
sl = tick.ask - (10 * sym.pip)
|
||||
tp = tick.ask + (20 * sym.pip)
|
||||
# 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)
|
||||
|
||||
# send order returns an OrderSendResult object
|
||||
res = await order.send()
|
||||
print(res)
|
||||
|
||||
|
||||
asyncio.run(main())
|
||||
@@ -1,63 +0,0 @@
|
||||
import logging
|
||||
|
||||
import asyncio
|
||||
from datetime import datetime
|
||||
from aiomql import ForexSymbol, Account, Positions, History, SimpleTrader as Trader, OrderType, RAM
|
||||
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
|
||||
|
||||
async def main():
|
||||
# Account details are in the aiomql.json file
|
||||
async with Account():
|
||||
|
||||
# get start time
|
||||
start = datetime.now()
|
||||
|
||||
# create two symbols and initialize them
|
||||
sym1 = ForexSymbol(name="EURUSD-T")
|
||||
sym2 = ForexSymbol(name="GBPUSD-T")
|
||||
await sym1.init()
|
||||
await sym2.init()
|
||||
|
||||
# Risk Assets Management instance
|
||||
# fix the amount to be risked at 2 USD. USD is the account currency.
|
||||
ram = RAM(amount=2, points=100)
|
||||
|
||||
# Create two traders instance
|
||||
trd = Trader(symbol=sym1, ram=ram)
|
||||
trd2 = Trader(symbol=sym2, ram=ram)
|
||||
|
||||
# Place Trades
|
||||
await trd.place_trade(order_type=OrderType.SELL)
|
||||
await trd2.place_trade(order_type=OrderType.BUY)
|
||||
|
||||
# Create a Positions object
|
||||
pos = Positions(group='*USD*')
|
||||
|
||||
# get the number of open positions
|
||||
total = await pos.positions_total()
|
||||
print(f'{total} Open positions') # 2
|
||||
|
||||
# close all open positions
|
||||
await pos.close_all()
|
||||
end = datetime.now()
|
||||
|
||||
# get the number of open positions
|
||||
total = await pos.positions_total()
|
||||
print(f'{total} Open positions')
|
||||
|
||||
# get historical trades
|
||||
start = datetime(day=start.day-1, month=start.month, year=start.year, hour=start.hour, minute=0, second=0)
|
||||
his = History(date_from=start.timestamp(), date_to=end.timestamp())
|
||||
|
||||
# get the number of order
|
||||
orders = await his.orders_total()
|
||||
print(f'{orders} orders')
|
||||
|
||||
# get the number of deals
|
||||
# total_deals = await his.deals_total()
|
||||
# print(f'{total_deals} Deals')
|
||||
|
||||
|
||||
asyncio.run(main())
|
||||
@@ -1,7 +0,0 @@
|
||||
actual_profit,ask,bid,closed,date,deal,ecc,entry_ema,etf,expected_profit,fast_ema,name,order,price,slow_ema,symbol,tcc,time,ttf,volume,win
|
||||
0,9213.42,9213.19,False,2024-02-11,1950149753,3360,5,M5,1.97,8,FingerTrap,5052174005,9213.42,20,Volatility 10 (1s) Index,672,22:15:53.721625,H1,0.56,False
|
||||
0,9209.47,9209.24,False,2024-02-11,1950153282,3360,5,M5,1.46,8,FingerTrap,5052177651,9209.47,20,Volatility 10 (1s) Index,672,22:27:18.718854,H1,0.77,False
|
||||
0,250524.34,250470.34,False,2024-02-11,1950153281,3360,5,M5,1.16,8,FingerTrap,5052177650,250524.34,20,Volatility 75 Index,672,22:27:18.424899,H1,0.001,False
|
||||
0,2013.326,2013.201,False,2024-02-11,1950156825,3360,5,M5,1.45,8,FingerTrap,5052181298,2013.201,20,Volatility 25 Index,672,22:38:15.979751,H1,0.86,False
|
||||
0,8620.27,8618.53,False,2024-02-11,1950156826,3360,5,M5,1.46,8,FingerTrap,5052181299,8618.53,20,Volatility 75 (1s) Index,672,22:38:16.244947,H1,0.109,False
|
||||
0,2018.152,2018.027,False,2024-02-12,1950193973,3360,5,M5,1.44,8,FingerTrap,5052218853,2018.152,20,Volatility 25 Index,672,01:00:00.730605,H1,1.48,False
|
||||
|
@@ -1,40 +0,0 @@
|
||||
import asyncio
|
||||
from datetime import datetime
|
||||
from aiomql import ForexSymbol, TimeFrame, Account, Config
|
||||
|
||||
|
||||
config = Config()
|
||||
|
||||
|
||||
async def main():
|
||||
async with Account():
|
||||
sym = ForexSymbol(name="EURUSD-T")
|
||||
res = await sym.init()
|
||||
if not res:
|
||||
print('Symbol not available')
|
||||
return
|
||||
|
||||
# get the last 1000 rates.
|
||||
# data is returned as a Candles object
|
||||
candles = await sym.copy_rates_from_pos(timeframe=TimeFrame.H1, count=1000, start_position=0)
|
||||
print(len(candles)) # 1000
|
||||
|
||||
# get candles of the last 24 hours
|
||||
today = datetime.now()
|
||||
yesterday = today.replace(day=today.day - 1)
|
||||
rates = await sym.copy_rates_range(timeframe=TimeFrame.H1, date_from=yesterday, date_to=today)
|
||||
print(len(rates)) # 24
|
||||
|
||||
# get price ticks for the last 24 hours
|
||||
# data is returned as a Ticks object
|
||||
ticks = await sym.copy_ticks_range(date_from=yesterday, date_to=today)
|
||||
print(len(ticks)) # ??
|
||||
|
||||
# get the current price tick
|
||||
tick = await sym.info_tick()
|
||||
# ask and bid price
|
||||
ask, bid = tick.ask, tick.bid
|
||||
print(ask, bid)
|
||||
|
||||
|
||||
asyncio.run(main())
|
||||
Reference in New Issue
Block a user