mirror of
https://github.com/Ichinga-Samuel/aiomql.git
synced 2026-08-14 04:18:05 +00:00
add docs
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
import asyncio
|
||||
from aiomql import Symbol, TimeFrame, Account
|
||||
|
||||
|
||||
async def main():
|
||||
async with Account():
|
||||
# create a symbol
|
||||
sym = Symbol(name="AUDUSD")
|
||||
|
||||
# Get EURUSD price bars for the past 48 hours
|
||||
candles = await sym.copy_rates_from_pos(timeframe=TimeFrame.H1, count=48, start_position=0)
|
||||
print(len(candles)) # 48
|
||||
|
||||
# get the latest candle by accessing the last one.
|
||||
last = candles[-1] # A Candle object
|
||||
print(type(last))
|
||||
print(last.time)
|
||||
|
||||
# get the last five hours
|
||||
last_five = candles[-5:] # A Candles object.
|
||||
print(type(last_five))
|
||||
print(last_five)
|
||||
|
||||
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())
|
||||
@@ -0,0 +1,37 @@
|
||||
import asyncio
|
||||
|
||||
from aiomql import Account, OrderType, TradeAction, Order, ForexSymbol
|
||||
|
||||
|
||||
async def main():
|
||||
async with Account():
|
||||
|
||||
# create a symbol
|
||||
sym = ForexSymbol(name="EURUSD")
|
||||
|
||||
# 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, pips=10)
|
||||
|
||||
# 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())
|
||||
@@ -0,0 +1,59 @@
|
||||
import asyncio
|
||||
from datetime import datetime
|
||||
from aiomql import ForexSymbol, Account, Positions, History, Trader, OrderType, RAM
|
||||
|
||||
|
||||
async def main():
|
||||
# Account details are in the aiomql.json file
|
||||
async with Account():
|
||||
|
||||
# get start time using local timezone
|
||||
tz = datetime.now().astimezone().tzinfo
|
||||
start = datetime.now(tz=tz)
|
||||
|
||||
# create two symbols and initialize them
|
||||
sym1 = ForexSymbol(name="EURUSD")
|
||||
sym2 = ForexSymbol(name="GBPUSD")
|
||||
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)
|
||||
|
||||
# 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(tz=tz)
|
||||
|
||||
# get the number of open positions
|
||||
total = await pos.positions_total()
|
||||
print(f'{total} Open positions') # 0
|
||||
|
||||
# get historical trades
|
||||
his = History(date_from=start, date_to=end)
|
||||
|
||||
# get the number of deals
|
||||
total_deals = await his.deals_total()
|
||||
print(f'{total_deals} Deals')
|
||||
|
||||
# get the number of order
|
||||
orders = await his.orders_total()
|
||||
print(f'{orders} orders')
|
||||
|
||||
|
||||
asyncio.run(main())
|
||||
@@ -0,0 +1,37 @@
|
||||
import asyncio
|
||||
from datetime import datetime
|
||||
from aiomql import ForexSymbol, Symbol, TimeFrame, Account
|
||||
|
||||
async def main():
|
||||
async with Account():
|
||||
sym = ForexSymbol(name="EURUSD")
|
||||
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())
|
||||
@@ -0,0 +1,17 @@
|
||||
from aiomql import ForexSymbol, Order, Trader, Account
|
||||
import asyncio
|
||||
|
||||
|
||||
async def main():
|
||||
async with Account():
|
||||
les = ForexSymbol(name='Volatility 50 (1s) Index')
|
||||
# t = ForexSymbol(name='EURUSD')
|
||||
await les.init()
|
||||
# await t.init()
|
||||
await les.info_tick()
|
||||
# await t.info_tick()
|
||||
vol = await les.compute_volume(amount=50, pips=10)
|
||||
print(les.tick.ask, les.tick.bid, les.volume_min, vol, les.point, les.digits, les.volume_max)
|
||||
print(les.tick.ask + les.point*100)
|
||||
|
||||
asyncio.run(main())
|
||||
Reference in New Issue
Block a user