Last active
April 28, 2024 21:58
-
-
Save Ichinga-Samuel/177addd1c0f21010a89638d7bb1332df 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 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() | |
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()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment