Skip to content

Instantly share code, notes, and snippets.

@keesvanbochove
Last active May 15, 2021 13:01
Show Gist options
  • Save keesvanbochove/7aabdca34194a1a199209e60a781142e to your computer and use it in GitHub Desktop.
Save keesvanbochove/7aabdca34194a1a199209e60a781142e to your computer and use it in GitHub Desktop.
Pull Kraken closing market crypto prices on a specific date
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "!pip install ccxt",
"execution_count": 2,
"outputs": [
{
"output_type": "stream",
"text": "Collecting ccxt\n\u001b[?25l Downloading https://files.pythonhosted.org/packages/26/6a/e374b0cab2c2af2ad87442e8e967be54f4aa565d40047a49bdbe38af2c6a/ccxt-1.18.134-py2.py3-none-any.whl (1.2MB)\n\u001b[K 100% |████████████████████████████████| 1.2MB 1.2MB/s ta 0:00:01\n\u001b[?25hCollecting aiodns==1.1.1; python_version >= \"3.5.2\" (from ccxt)\n Downloading https://files.pythonhosted.org/packages/bd/f5/b69cb930fd5ab0569396659afe3f3c0d37d4098e5d0ba6afdf6fd9388cb0/aiodns-1.1.1-py2.py3-none-any.whl\nRequirement already satisfied: certifi>=2018.1.18 in /home/nbuser/anaconda3_501/lib/python3.6/site-packages (from ccxt) (2018.10.15)\nCollecting yarl==1.1.0; python_version >= \"3.5.2\" (from ccxt)\n\u001b[?25l Downloading https://files.pythonhosted.org/packages/9a/fe/1fc0d9e277f1ff0d29ac44742f769c55f12cc7e66a89ab340f5321937179/yarl-1.1.0-cp36-cp36m-manylinux1_x86_64.whl (255kB)\n\u001b[K 100% |████████████████████████████████| 256kB 1.9MB/s ta 0:00:01\n\u001b[?25hCollecting aiohttp>=3.0.1; python_version >= \"3.5.2\" (from ccxt)\n\u001b[?25l Downloading https://files.pythonhosted.org/packages/0d/5c/f87987f4dc8b2cfcf37c83a814ea4b2aff4d285cbffc0ab08b2b4fa3f584/aiohttp-3.5.4-cp36-cp36m-manylinux1_x86_64.whl (1.2MB)\n\u001b[K 100% |████████████████████████████████| 1.2MB 1.2MB/s ta 0:00:01\n\u001b[?25hRequirement already satisfied: requests>=2.18.4 in /home/nbuser/anaconda3_501/lib/python3.6/site-packages (from ccxt) (2.21.0)\nRequirement already satisfied: setuptools>=38.5.1 in /home/nbuser/anaconda3_501/lib/python3.6/site-packages (from ccxt) (40.6.3)\nCollecting pycares>=1.0.0 (from aiodns==1.1.1; python_version >= \"3.5.2\"->ccxt)\n\u001b[?25l Downloading https://files.pythonhosted.org/packages/f3/3d/e5fbd1c958ccd001320a42dd0deb0475017e1b0af92c5dbbb0d0d3bd8b8b/pycares-2.4.0-cp36-cp36m-manylinux1_x86_64.whl (198kB)\n\u001b[K 100% |████████████████████████████████| 204kB 1.6MB/s ta 0:00:01\n\u001b[?25hCollecting multidict>=4.0 (from yarl==1.1.0; python_version >= \"3.5.2\"->ccxt)\n\u001b[?25l Downloading https://files.pythonhosted.org/packages/71/cc/ceb5b8c76e7a23212b9e0353053cc35a9d86c763d852a76d9b941fe81fbc/multidict-4.5.2-cp36-cp36m-manylinux1_x86_64.whl (309kB)\n\u001b[K 100% |████████████████████████████████| 317kB 2.1MB/s ta 0:00:01\n\u001b[?25hRequirement already satisfied: idna>=2.0 in /home/nbuser/anaconda3_501/lib/python3.6/site-packages (from yarl==1.1.0; python_version >= \"3.5.2\"->ccxt) (2.7)\nRequirement already satisfied: chardet<4.0,>=2.0 in /home/nbuser/anaconda3_501/lib/python3.6/site-packages (from aiohttp>=3.0.1; python_version >= \"3.5.2\"->ccxt) (3.0.4)\nCollecting idna-ssl>=1.0; python_version < \"3.7\" (from aiohttp>=3.0.1; python_version >= \"3.5.2\"->ccxt)\n Downloading https://files.pythonhosted.org/packages/46/03/07c4894aae38b0de52b52586b24bf189bb83e4ddabfe2e2c8f2419eec6f4/idna-ssl-1.1.0.tar.gz\nRequirement already satisfied: attrs>=17.3.0 in /home/nbuser/anaconda3_501/lib/python3.6/site-packages (from aiohttp>=3.0.1; python_version >= \"3.5.2\"->ccxt) (18.2.0)\nRequirement already satisfied: typing-extensions>=3.6.5; python_version < \"3.7\" in /home/nbuser/anaconda3_501/lib/python3.6/site-packages (from aiohttp>=3.0.1; python_version >= \"3.5.2\"->ccxt) (3.6.6)\nCollecting async-timeout<4.0,>=3.0 (from aiohttp>=3.0.1; python_version >= \"3.5.2\"->ccxt)\n Downloading https://files.pythonhosted.org/packages/e1/1e/5a4441be21b0726c4464f3f23c8b19628372f606755a9d2e46c187e65ec4/async_timeout-3.0.1-py3-none-any.whl\nRequirement already satisfied: urllib3<1.25,>=1.21.1 in /home/nbuser/anaconda3_501/lib/python3.6/site-packages (from requests>=2.18.4->ccxt) (1.23)\nBuilding wheels for collected packages: idna-ssl\n Running setup.py bdist_wheel for idna-ssl ... \u001b[?25ldone\n\u001b[?25h Stored in directory: /home/nbuser/.cache/pip/wheels/d3/00/b3/32d613e19e08a739751dd6bf998cfed277728f8b2127ad4eb7\nSuccessfully built idna-ssl\nInstalling collected packages: pycares, aiodns, multidict, yarl, idna-ssl, async-timeout, aiohttp, ccxt\nSuccessfully installed aiodns-1.1.1 aiohttp-3.5.4 async-timeout-3.0.1 ccxt-1.18.134 idna-ssl-1.1.0 multidict-4.5.2 pycares-2.4.0 yarl-1.1.0\n",
"name": "stdout"
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "import ccxt\nimport datetime",
"execution_count": 26,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "exchange = ccxt.kraken()\nexchange.enableRateLimit = True\nexchange.loadMarkets()",
"execution_count": 24,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "date = datetime.datetime(2018,12,31)\nprint(\"Closing prices in EUR on {:%d, %b %Y}\".format(date))\nfor market in exchange.markets:\n if market.endswith(\"EUR\"):\n for candle in exchange.fetch_ohlcv (market, '1d'):\n if (datetime.datetime.utcfromtimestamp(candle[0]/1000) == date):\n print(market,candle[4])",
"execution_count": 48,
"outputs": [
{
"output_type": "stream",
"text": "Closing prices in EUR on 31, Dec 2018\nADA/EUR 0.035465\nBCH/EUR 130.4\nBSV/EUR 73.6\nDASH/EUR 67.81\nEOS/EUR 2.2049\nGNO/EUR 9.17\nQTUM/EUR 1.87\nETC/EUR 4.361\nETH/EUR 114.96\nLTC/EUR 26.19\nREP/EUR 6.649\nXTZ/EUR 0.3912\nBTC/EUR 3235.9\nXLM/EUR 0.09632\nXMR/EUR 39.93\nXRP/EUR 0.30516\nZEC/EUR 48.5\n",
"name": "stdout"
}
]
}
],
"metadata": {
"kernelspec": {
"name": "python36",
"display_name": "Python 3.6",
"language": "python"
},
"language_info": {
"mimetype": "text/x-python",
"nbconvert_exporter": "python",
"name": "python",
"pygments_lexer": "ipython3",
"version": "3.6.6",
"file_extension": ".py",
"codemirror_mode": {
"version": 3,
"name": "ipython"
}
}
},
"nbformat": 4,
"nbformat_minor": 1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment