Skip to content

Instantly share code, notes, and snippets.

@inlinechan
Last active July 24, 2019 08:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save inlinechan/9c8c77c58321e65804574b80a4d24b0e to your computer and use it in GitHub Desktop.
Save inlinechan/9c8c77c58321e65804574b80a4d24b0e to your computer and use it in GitHub Desktop.
# 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())
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())
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment