{ "cells": [ { "cell_type": "code", "execution_count": 15, "id": "c9606e56", "metadata": {}, "outputs": [], "source": [ "import math\n", "from datetime import datetime, timezone" ] }, { "cell_type": "code", "execution_count": 1, "id": "2b5d7d21", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'type': 'SNAPSHOT',\n", " 'data': {'t': 'SNAPSHOT',\n", " 'm': 'ETH-USD',\n", " 'b': [{'q': '362.381', 'p': '2318.1'}],\n", " 'a': [{'q': '70.572', 'p': '2318.2'}],\n", " 'd': '1'},\n", " 'ts': 1776822518279,\n", " 'seq': 14}" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "{\"type\":\"SNAPSHOT\",\"data\":{\"t\":\"SNAPSHOT\",\"m\":\"ETH-USD\",\"b\":[{\"q\":\"362.381\",\"p\":\"2318.1\"}],\"a\":[{\"q\":\"70.572\",\"p\":\"2318.2\"}],\"d\":\"1\"},\"ts\":1776822518279,\"seq\":14}" ] }, { "cell_type": "code", "execution_count": 2, "id": "19f51572", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'data': {'m': 'ETH-USD', 'f': '-0.000001', 'T': 1776823319595},\n", " 'ts': 1776823319595,\n", " 'seq': 2}" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "{'data': {'m': 'ETH-USD', 'f': '-0.000001', 'T': 1776823319595}, 'ts': 1776823319595, 'seq': 2}" ] }, { "cell_type": "code", "execution_count": 41, "id": "68006231", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Timestamp('2026-04-22 03:00:00')" ] }, "execution_count": 41, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import pandas as pd\n", "\n", "pd.to_datetime(1776826800000, unit='ms')" ] }, { "cell_type": "code", "execution_count": 12, "id": "5561153b", "metadata": {}, "outputs": [], "source": [ "def time_round_down(dt, interval_mins=5) -> int: # returns timestamp in seconds\n", " interval_secs = interval_mins * 60\n", " seconds = dt.timestamp()\n", " rounded_seconds = math.floor(seconds / interval_secs) * interval_secs\n", " \n", " return rounded_seconds" ] }, { "cell_type": "code", "execution_count": 40, "id": "bd83b59f", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "1776826800000" ] }, "execution_count": 40, "metadata": {}, "output_type": "execute_result" } ], "source": [ "(time_round_down(dt=datetime.now(timezone.utc), interval_mins=60)+(60*60))*1000" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "id": "665377af", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "id": "af5c751b", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "py_313", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.13.12" } }, "nbformat": 4, "nbformat_minor": 5 }