Last active
July 24, 2019 08:17
-
-
Save inlinechan/9c8c77c58321e65804574b80a4d24b0e 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
# Python | |
import asyncio | |
import ccxt.async_support as ccxt | |
from datetime import datetime, timedelta | |
async def print_bitfinex_ethbtc_ticker(): | |
bitfinex = ccxt.bitfinex() | |
# print(await bitfinex.fetch_ticker('ETH/BTC')) | |
timestamp = datetime.timestamp(datetime.now() - timedelta(days=50)) | |
ohlcs = await bitfinex.fetch_ohlcv('BTC/USD', since=timestamp * 1000, | |
timeframe='1d') | |
o = ohlcs[-1] | |
dt_object = datetime.fromtimestamp(o[0]/1000) | |
print(dt_object, o[1:]) | |
await bitfinex.close() | |
# asyncio.get_event_loop().run_until_complete(print_bitfinex_ethbtc_ticker()) | |
asyncio.run(print_poloniex_ethbtc_ticker()) |
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, timedelta | |
from pytz import timezone, utc | |
# def next_15min(dt): | |
# extra_minutes = dt.timetuple()[4] % 15 | |
# dt_next = dt + timedelta(minutes=15 - extra_minutes) | |
# return dt_next.replace(second=0, microsecond=0) | |
def next_minutes(dt, minutes=15): | |
extra_minutes = dt.timetuple()[4] % minutes | |
dt_next = dt + timedelta(minutes=minutes - extra_minutes) | |
return dt_next.replace(second=0, microsecond=0) | |
async def main(): | |
while True: | |
now = utc.localize(datetime.utcnow()) | |
kst = timezone('Asia/Seoul') | |
# fmt = '%Y-%m-%d %H:%M:%S %Z%z' | |
# next_dt = next_15min(now) | |
next_dt = next_minutes(now, minutes=15) | |
remain = (next_dt - now).total_seconds() | |
# print(f"{now} - {next_dt} - {next_dt.astimezone(kst)}") | |
print(f"waiting for {remain} seconds until {next_dt.astimezone(kst)}") | |
await asyncio.sleep(remain) | |
if __name__ == '__main__': | |
asyncio.run(main()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment