{ "info": { "author": "Alpaca", "author_email": "oss@alpaca.markets", "bugtrack_url": null, "classifiers": [], "description": "# pymarketstore\nPython driver for MarketStore\n\nBuild Status: ![build status](https://circleci.com/gh/alpacahq/pymarketstore/tree/master.png?971fa5b1079e8af0568db6caf772132c54f04dc2)\n\nPymarketstore can query and write financial timeseries data from [MarketStore](https://github.com/alpacahq/marketstore)\n\nTested with 2.7, 3.3+\n\n## How to install\n\n```\n$ pip install pymarketstore\n```\n\n## Examples\n\n```\nIn [1]: import pymarketstore as pymkts\n\n## query data\n\nIn [2]: param = pymkts.Params('BTC', '1Min', 'OHLCV', limit=10)\n\nIn [3]: cli = pymkts.Client()\n\nIn [4]: reply = cli.query(param)\n\nIn [5]: reply.first().df()\nOut[5]:\n Open High Low Close Volume\nEpoch\n2018-01-17 17:19:00+00:00 10400.00 10400.25 10315.00 10337.25 7.772154\n2018-01-17 17:20:00+00:00 10328.22 10359.00 10328.22 10337.00 14.206040\n2018-01-17 17:21:00+00:00 10337.01 10337.01 10180.01 10192.15 7.906481\n2018-01-17 17:22:00+00:00 10199.99 10200.00 10129.88 10160.08 28.119562\n2018-01-17 17:23:00+00:00 10140.01 10161.00 10115.00 10115.01 11.283704\n2018-01-17 17:24:00+00:00 10115.00 10194.99 10102.35 10194.99 10.617131\n2018-01-17 17:25:00+00:00 10194.99 10240.00 10194.98 10220.00 8.586766\n2018-01-17 17:26:00+00:00 10210.02 10210.02 10101.00 10138.00 6.616969\n2018-01-17 17:27:00+00:00 10137.99 10138.00 10108.76 10124.94 9.962978\n2018-01-17 17:28:00+00:00 10124.95 10142.39 10124.94 10142.39 2.262249\n\n## write data\n\nIn [7]: import numpy as np\n\nIn [8]: import pandas as pd\n\nIn [9]: data = np.array([(pd.Timestamp('2017-01-01 00:00').value / 10**9, 10.0)], dtype=[('Epoch', 'i8'), ('Ask', 'f4')])\n\nIn [10]: cli.write(data, 'TEST/1Min/Tick')\nOut[10]: {'responses': None}\n\nIn [11]: cli.query(pymkts.Params('TEST', '1Min', 'Tick')).first().df()\nOut[11]:\n Ask\nEpoch\n2017-01-01 00:00:00+00:00 10.0\n\n```\n\n## Client\n\n`pymkts.Client(endpoint='http://localhost:5993/rpc')`\n\nConstruct a client object with endpoint.\n\n## Query\n\n`pymkts.Client#query(symbols, timeframe, attrgroup, start=None, end=None, limit=None, limit_from_start=False)`\n\nYou can build parameters using `pymkts.Params`.\n\n- symbols: string for a single symbol or a list of symbol string for multi-symbol query\n- timeframe: timeframe string\n- attrgroup: attribute group string. symbols, timeframe and attrgroup compose a bucket key to query in the server\n- start: unix epoch second (int), datetime object or timestamp string. The result will include only data timestamped equal to or after this time.\n- end: unix epoch second (int), datetime object or timestamp string. The result will include only data timestamped equal to or before this time.\n- limit: the number of records to be returned, counting from either start or end boundary.\n- limit_from_start: boolean to indicate `limit` is from the start boundary. Defaults to False.\n\nPass one or multiple instances of `Params` to `Client.query()`. It will return `QueryReply` object which holds internal numpy array data returned from the server.\n\n## Write\n\n`pymkts.Client#write(data, tbk)`\n\nYou can write a numpy array to the server via `Client.write()` method. The data parameter must be numpy's [recarray type](https://docs.scipy.org/doc/numpy-dev/reference/generated/numpy.recarray.html) with\na column named `Epoch` in int64 type at the first column. `tbk` is the bucket key of the data records.\n\n## List Symbols\n\n`pymkts.Client#list_symbols()`\n\nThe list of all symbols stored in the server are returned.\n\n## Server version\n\n`pymkts.Client#server_version()`\n\nReturns a string of Marketstore-Version header from a server response.\n\n## Streaming\n\nIf the server supports WebSocket streaming, you can connect to it using\n`pymkts.StreamConn` class. For convenience, you can call `pymkts.Client#stream()` to obtain the instance with the same server\ninformation as REST client.\n\nOnce you have this instance, you will set up some event handles by\neither `register()` method or `@on()` decorator. These methods accept\nregular expressions to filter which stream to act on.\n\nTo actually connect and start receiving the messages from the server,\nyou will call `run()` with the stream names. By default, it subscribes\nto all by `*/*/*`.\n\n`pymkts.Client#stream()`\n\nReturn a `StreamConn` which is a websocket connection to the server.\n\n`pymkts.StreamConn#(endpoint)`\n\nCreate a connection instance to the `endpoint` server. The endpoint\nstring is a full URL with \"ws\" or \"wss\" scheme with the port and path.\n\n`pymkts.StreamConn#register(stream_path, func)`\n`@pymkts.StreamConn#on(stream_path)`\n\nAdd a new message handler to the connection. The function will be called\nwith `handler(StreamConn, {\"key\": \"...\", \"data\": {...,}})` if the key\n(time bucket key) matches with the `stream_path` regular expression.\nThe `on` method is a decorator version of `register`.\n\n`pymkts.StreamConn#run([stream1, stream2, ...])`\n\nStart communication with the server and go into an indefinite loop. It\ndoes not return until unhandled exception is raised, in which case the\nconnection is closed so you need to implement retry. Also, since this is\na blocking method, you may need to run it in a background thread.\n\n\nAn example code is as follows.\n\n```\nimport pymarketstore as pymkts\n\nconn = pymkts.StreamConn('ws://localhost:5993/ws')\n\n@conn.on(r'^BTC/')\ndef on_btc(conn, msg):\n print('received btc', msg['data'])\n\nconn.run(['BTC/*/*']) # runs until exception\n\n-> received btc {'Open': 4370.0, 'High': 4372.93, 'Low': 4370.0, 'Close': 4371.74, 'Volume': 3.3880948699999993, 'Epoch': 1507299600}\n```\n\n", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/xmurobi/pymarketstore", "keywords": "database,pandas,financial,timeseries", "license": "", "maintainer": "", "maintainer_email": "", "name": "pymarketstore2", "package_url": "https://pypi.org/project/pymarketstore2/", "platform": "", "project_url": "https://pypi.org/project/pymarketstore2/", "project_urls": { "Homepage": "https://github.com/xmurobi/pymarketstore" }, "release_url": "https://pypi.org/project/pymarketstore2/0.17/", "requires_dist": [ "msgpack-python", "numpy", "requests", "pandas", "six", "urllib3", "pytest", "websocket-client" ], "requires_python": "", "summary": "Marketstore python driver", "version": "0.17" }, "last_serial": 4785006, "releases": { "0.17": [ { "comment_text": "", "digests": { "md5": "b4c108858a5f86d72db8f0f136820295", "sha256": "a091f610b2bcfd816119159a22adc7d56be5bb5c85b99b743d90585b80dd4bd6" }, "downloads": -1, "filename": "pymarketstore2-0.17-py3-none-any.whl", "has_sig": false, "md5_digest": "b4c108858a5f86d72db8f0f136820295", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 12542, "upload_time": "2019-02-06T05:01:33", "url": "https://files.pythonhosted.org/packages/3d/d5/cc81da9b89286742e1abc69f5253d6915f52c8d7365a9ed0e975322eb7ee/pymarketstore2-0.17-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "7a7997efed2071ff4173c1d657e78859", "sha256": "26d780824f2902c44ce9714be359b42959b312023b3b2020441fd7d1a3261f89" }, "downloads": -1, "filename": "pymarketstore2-0.17.tar.gz", "has_sig": false, "md5_digest": "7a7997efed2071ff4173c1d657e78859", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 14600, "upload_time": "2019-02-06T05:01:35", "url": "https://files.pythonhosted.org/packages/b6/d0/f6df5dc54a2d582d1aecac0c6b59ec48e1f26a6e288ae1cafddc0d9c253f/pymarketstore2-0.17.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "b4c108858a5f86d72db8f0f136820295", "sha256": "a091f610b2bcfd816119159a22adc7d56be5bb5c85b99b743d90585b80dd4bd6" }, "downloads": -1, "filename": "pymarketstore2-0.17-py3-none-any.whl", "has_sig": false, "md5_digest": "b4c108858a5f86d72db8f0f136820295", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 12542, "upload_time": "2019-02-06T05:01:33", "url": "https://files.pythonhosted.org/packages/3d/d5/cc81da9b89286742e1abc69f5253d6915f52c8d7365a9ed0e975322eb7ee/pymarketstore2-0.17-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "7a7997efed2071ff4173c1d657e78859", "sha256": "26d780824f2902c44ce9714be359b42959b312023b3b2020441fd7d1a3261f89" }, "downloads": -1, "filename": "pymarketstore2-0.17.tar.gz", "has_sig": false, "md5_digest": "7a7997efed2071ff4173c1d657e78859", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 14600, "upload_time": "2019-02-06T05:01:35", "url": "https://files.pythonhosted.org/packages/b6/d0/f6df5dc54a2d582d1aecac0c6b59ec48e1f26a6e288ae1cafddc0d9c253f/pymarketstore2-0.17.tar.gz" } ] }