{"_id":"stock","_rev":"10-348f792895365dc972a1afbf95b1b523","name":"stock","description":"A fast and efficient Node.js storage engine for stock market tick data and couple of modules for trading software development.","dist-tags":{"latest":"0.0.9"},"versions":{"0.0.8":{"name":"stock","description":"A fast and efficient Node.js storage engine for stock market tick data and couple of modules for trading software development.","version":"0.0.8","author":{"name":"Egor Egorov","email":"me@egorfine.com"},"homepage":"http://egorfine.github.com/node-stock","bugs":{"url":"http://github.com/egorFiNE/node-stock/issues"},"repository":{"type":"git","url":"git://github.com/egorfine/node-stock.git"},"dependencies":{"compress-buffer":">= 0.5.1","date-utils":">= 1.2.5","optimist":">= 0.2.8"},"devDependencies":{"nodeunit":">= 0.6.0"},"_npmUser":{"name":"egorfine","email":"me@egorfine.com"},"_id":"stock@0.0.8","engines":{"node":"*"},"_engineSupported":true,"_npmVersion":"1.1.0-alpha-2","_nodeVersion":"v0.6.3","_defaultsLoaded":true,"dist":{"shasum":"6c837dcf65334c7851e9121ad2e7853a6c07b85c","tarball":"https://registry.npmjs.org/stock/-/stock-0.0.8.tgz","integrity":"sha512-o3cDLxJVBlAMC43Kqp7gUdOAxKGHI3tJDi8TAEkx2fuNpF2trtualkFWNTT9LOIhj3duQpBh6UlRb+0d4FYvcA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIEBmHMEqcmu0i9JZf/dyRKOAsPmgsWU+TP2aKIyTElHqAiEA5pg35ZsgYi+f1snYZ2JoTSuRn15OgIYf3lVBAiZb9AI="}]},"maintainers":[{"name":"egorfine","email":"me@egorfine.com"}],"directories":{},"deprecated":"hasn't been updated for years. Only kept to read ancient tick data archives"},"0.0.9":{"name":"stock","description":"A fast and efficient Node.js storage engine for stock market tick data and couple of modules for trading software development.","version":"0.0.9","author":{"name":"Egor Egorov","email":"me@egorfine.com"},"homepage":"http://egorfine.github.com/node-stock","bugs":{"url":"http://github.com/egorFiNE/node-stock/issues"},"repository":{"type":"git","url":"http://github.com/egorfine/node-stock.git"},"dependencies":{"compress-buffer":">= 0.5.1","date-utils":">= 1.2.5","optimist":">= 0.2.8"},"devDependencies":{"nodeunit":">= 0.6.0"},"readme":"# node-stock\n\nAn extremely fast and efficient **[Node.js](http://nodejs.org)** storage engine for raw stock market tick data as well as a couple of handy modules for trading software development.  \n\n**node-stock** is used by my proprietary blackbox trading company for all our robots. The code has been in production for more than a year now, so it is considered mature.\n\nThe code is well coverted by unit tests.\n\n# Modules\n\n## TickStorage, Symbols, Symbol\n\nThe main thing: a tick storage engine.\n\n## …and others\n\n* **ExtraNumber** - incredibly small yet vital module for internal price representation in **node-stock**.\n* **ExtraDate** - date and time calculations specifically helpful for algorithmic trading on NYSE,  NASDAQ and CME;\n* **WorkingDays** - NYSE and NASDAQ working days calculator;\n* **TimePeriod** - defines a list of human-readable day time periods and a few calculations with it; \n* **ExtraLog** - console.log and formatter functions tailored to **node-stock** internal formats of price and date/time;\n* **CandlesCalculator** - Fast OLHC calculator over raw tick data;\n\n# Coding agreements\n\n## Price format\n\nAll prices in **node-stock** and derived software are stored in integer in 1/100 of a cent. I.e. $23,45 becomes 234500. To convert a conventional price to this format, use `parseInt(price*10000)`. To show a human-readable version, use <code>Number.humanReadablePrice()</code> in **ExtraNumber**: \n\n```javascript\nrequire('stock/ExtraNumber');\n\nvar price = 23.56;\nprice = parseInt(price*10000);\n\nconsole.log(\"Price = %s\", price.humanReadablePrice());\n\n// or: \n\nrequire('stock/ExtraLog');\n\nExtraLog.log(\"Price = %p\", price);\n```\n\n## Other agreements\n\n**Daystamp**. A daystamp is a date in form of YYYYMMDD. It can be Number or String, so your code must handle both cases. See <code>ExtraDate</code>, it contains all you need for daystamp calculations. \n\n**Day minute**. It's the number of a minute since 00:00 in the current day. I.e. 9:30 am becomes 570 (9*60+30=570). BTW, 24hr time is used thorough the project and so should you. \n\n**dbPath**. Path to the tickers database, a folder. See below for database structure description.\n\n**Time zones management**. You absolutely should run your software in the time zone of the stock exchange you are trading with. There are two ways of doing that: \n\n**1.** Set <code>TZ</code> environment variable: \n\n\tTZ=America/New_York node something.js \n\n**2.** Set <code>process.env.TZ</code> right at the start of your script before making anything else, especially before calling any Date methods: \n\n```javascript\nprocess.env.TZ='America/New_York';\nconsole.log(\"Hello at %s\", new Date());\n\n// or: \n\nrequire('stock/ExtraDate');\nrequire('stock/ExtraLog');\nprocess.env.TZ='America/New_York';\nExtraLog.log(\"Hello at %D\", Date.unixtime());\n```\n\n# Requirements\n\n* **Node.js** &gt;= 0.6.0; s\n* **node-date-utils** https://github.com/JerrySievert/node-date-utils or <code>npm install date-utils</code>;\n* **node-compress-buffer** https://github.com/egorFiNE/node-compress-buffer or <code>npm install compress-buffer</code>;\n* **optimist** https://github.com/substack/node-optimist.git or <code>npm install optimist</code>; \n* **nodeunit** for unit testing; \n\n**Note:** nodeunit must be launched in New York time zone: \n\n\tTZ=America/New_York nodeunit test/\n\n# Installation\n\n<code>npm install stock</code>.\n\n# FAQ\n\n## Q: Why such a complex file format for ticks files? \n\nA: It's not. If you actually start developing your own ticks database you will inevitably end up with a similar format. For a funny reference: this format is about forty times smaller and way faster than text files.\n\n## Q: Can you sell me raw ticks database for XXX or ZZZ?\n\nA: Unfortunately, no. My license doesn't allow reselling of tick data. However, if you need some tick data **strictly** for R&D - please get in touch with me by email, we can work something out. \n\n**However,** I have made one particular NYSE ticker publicly available so that you can play around with data. Should be enough for basic testing and development. It's anonymized, but the data is correct and intact; please don't try to figure out which company it is. You can find nyse.zip in Downloads area at Github. \n\n## Q: Augmentation of built-in classes?! You moron!\n\n**node-stock** adds methods to <code>Date</code> (see **ExtraDate**) and <code>Number</code> (see **ExtraNumber**).\n\nThis practice is wrong. Please do not inherit it in your project. There are only *extremely* rare cases when it's okay to do so, and I consider these two modules an example of those. \n\n## Q: How do I run unit tests?\n\n<code>nodeunit test/</code>\n\n# Database structure\n\nDatabase path (<code>dbPath</code>) is a folder which contains tickers folders: \n\n\t/mnt/storage/tickers/\n\t/mnt/storage/tickers/AAPL/\n\t/mnt/storage/tickers/ORCL/\n\t/mnt/storage/tickers/YHOO/\n\t…\n\nEach ticker folder contains TickStorage files, each named with a daystamp of that day: \n\n\t/mnt/storage/tickers/YHOO/20110103.ticks\n\t/mnt/storage/tickers/YHOO/20110104.ticks\n\t…\n\nEach file is in TickStorage format. \n\nYou don't need to traverse this folder structure manually: there are two handy modules that will do that for you: <code>Symbols</code> and <code>Symbol</code>. They abstract the actual file storage from you. \n\nHere's a handy sinopsis: \n\n```javascript\nSymbols = require('stock/Symbols');\nSymbol = require('stock/Symbol');\nTickStorage = require('stock/TickStorage');\nrequire('stock/ExtraDate');\nrequire('stock/ExtraNumber');\n\nvar dbPath = '/Users/egor/tickers';\n\n// initialise the class that works with tickers database (a folder of tickers folders) \nvar symbols  = new Symbols(dbPath);\n\n// now actually load the list of tickers (folders) available at that path\nif (!symbols.load()) {\n\tconsole.log(\"Cannot load tickers database!\");\n\treturn;\n}\n\n\n// now let's iterate over all tickers available\nvar symbol;\nwhile ((symbol=symbols.next())) {\n\t// mind that here \"symbol\" is a instantiated \"Symbol\" class\n\n\t// actually load list of days (files) at for that ticker (folder)\n\tif (!symbol.load()) {\n\t\tconsole.log(\"Cannot load days for %s\", symbol.symbol);\n\t\treturn;\n\t}\n\n\n\t// prepare tick storage for the first day of that ticker\n\tvar tickStorage = new TickStorage(dbPath, symbol.symbol, symbol.firstDay());\n\n\t// actually load the raw tick data for this symbol at that day\n\tif (!tickStorage.load()) {\n\t\tconsole.log(\"Cannot load ticks for %s/%s\", symbol.symbol, symbol.firstDay());\n\t\treturn;\n\t}\n\n\t// iterate over market ticks and calculate total volume\n\tvar tick, totalVolume=0;\n\twhile ((tick=tickStorage.nextTick())) {\n\t\tif (tick.isMarket) {\n\t\t\ttotalVolume+=tick.volume;\n\t\t}\n\t}\n\n\tconsole.log(\"%s total volume = %d\", symbol.symbol, totalVolume);\n}\n```\n\n\n# License \n\n**node-stock** is triple-licensed. \n\nIf you are using **node-stock** in-house and do not redistribute the software, you can use it under LGPL v2.1. Essentially this means \"do whatever you want as long as it's in-house\". Feel free to provide commercial services or make zillions of money with this software. Just drop me an email so I can share your joy.\n\nIf you are redistributing **node-stock**, please consider it GPLv2 licensed. \n\nIf neither option is good for you, I can sell you a commercial license, which also includes my personal support. Contact me by email. \n\n# Contacts\n\n**node-stock** is created by Egor Egorov, me@egorfine.com. I welcome your comments and suggestions, please feel free to drop me an email. \n","_id":"stock@0.0.9","dist":{"shasum":"5095510132efbaa1bba2a128d90c0c9c13f2cb2b","tarball":"https://registry.npmjs.org/stock/-/stock-0.0.9.tgz","integrity":"sha512-avkzEfM+8ywHNGKy/LpepTEFDq9Z1aXhgNMJiAJzALyNpLawMJwTywMJ1ZNxLlw7vmh3GPc7rZPkncVLHAG/Hw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCJ/keorKIZ9zvVCc83TtZKGuxTLGOpucji47UbpLmo5QIhAN36m2vJxpSu2TLAYq2rL6a19L7QV3aYFPWBGoduqDpf"}]},"maintainers":[{"name":"egorfine","email":"me@egorfine.com"}],"directories":{},"deprecated":"hasn't been updated for years. Only kept to read ancient tick data archives"}},"readme":"# node-stock\n\nAn extremely fast and efficient **[Node.js](http://nodejs.org)** storage engine for raw stock market tick data as well as a couple of handy modules for trading software development.  \n\n**node-stock** is used by my proprietary blackbox trading company for all our robots. The code has been in production for more than a year now, so it is considered mature.\n\nThe code is well unit-tested.\n\n# Modules\n\n## TickStorage, Symbols, Symbol\n\nThe main thing: a tick storage engine.\n\n## …and others\n\n* **ExtraNumber** - incredibly small yet vital module for internal price representation in **node-stock**.\n* **ExtraDate** - date and time calculations specifically helpful for algorithmic trading on NYSE,  NASDAQ and CME;\n* **WorkingDays** - NYSE and NASDAQ working days calculator;\n* **TimePeriod** - defines a list of human-readable day time periods and a few calculations with it; \n* **ExtraLog** - console.log and formatter functions tailored to **node-stock** internal formats of price and date/time;\n* **CandlesCalculator** - Fast OLHC calculator over raw tick data;\n\n# Coding agreements\n\n## Price format\n\nAll prices in **node-stock** and derived software are stored in integer in 1/100 of a cent. I.e. $23,45 becomes 234500. To convert a conventional price to this format, use <code>parseInt(price*10000)</code>. To show a human-readable version, use <code>Number.humanReadablePrice()</code> in **ExtraNumber**: \n\n```javascript\nrequire('stock/ExtraNumber');\n\nvar price = 23.56;\nprice = parseInt(price*10000);\n\nconsole.log(\"Price = %s\", price.humanReadablePrice());\n\n// or: \n\nrequire('stock/ExtraLog');\n\nExtraLog.log(\"Price = %p\", price);\n```\n\n## Other agreements\n\n**Daystamp**. A daystamp is a date in form of YYYYMMDD. It can be Number or String, so your code must handle both cases. See <code>ExtraDate</code>, it contains all you need for daystamp calculations. \n\n**Day minute**. It's the number of a minute since 00:00 in the current day. I.e. 9:30 am becomes 570 (9*60+30=570). BTW, 24hr time is used thorough the project and so should you. \n\n**dbPath**. Path to the tickers database, a folder. See below for database structure description.\n\n**Time zones management**. You absolutely should run your software in the time zone of the stock exchange you are trading with. There are two ways of doing that: \n\n**1.** Set <code>TZ</code> environment variable: \n\n\tTZ=America/New_York node something.js \n\n**2.** Set <code>process.env.TZ</code> right at the start of your script before making anything else, especially before calling any Date methods: \n\n```javascript\nprocess.env.TZ='America/New_York';\nconsole.log(\"Hello at %s\", new Date());\n\n// or: \n\nrequire('stock/ExtraDate');\nrequire('stock/ExtraLog');\nprocess.env.TZ='America/New_York';\nExtraLog.log(\"Hello at %D\", Date.unixtime());\n```\n\n# Requirements\n\n* **Node.js** &gt;= 0.6.0; s\n* **node-date-utils** https://github.com/JerrySievert/node-date-utils or <code>npm install date-utils</code>;\n* **node-compress-buffer** https://github.com/egorFiNE/node-compress-buffer or <code>npm install compress-buffer</code>;\n* **optimist** https://github.com/substack/node-optimist.git or <code>npm install optimist</code>; \n* **nodeunit** for unit testing; \n\n**Note:** nodeunit must be launched in New York time zone: \n\n\tTZ=America/New_York nodeunit test/\n\n# Installation\n\n<code>npm install stock</code>.\n\n# FAQ\n\n## Q: Why such a complex file format for ticks files? \n\nA: It's not. If you actually start developing your own ticks database you will inevitably end up with a similar format. For a funny reference: this format is about forty times smaller and way faster than text files.\n\n## Q: Can you sell me raw ticks database for XXX or ZZZ?\n\nA: Unfortunately, no. My license doesn't allow reselling of tick data. However if you need some tick data **strictly** for R&D - please get in touch with me by email, we can work something out. \n\n**However,** I have made one particular NYSE ticker and one NASDAQ ticker publicly available so that you can play around with data. Should be enough for basic testing and development. They are anonymized but the data is correct and intact; please don't try to figure out which company it is. You can find nyse.zip and nasdaq.zip at Downloads area at Github. \n\n## Q: Augmentation of built-in classes?! You moron!\n\n**node-stock** adds methods to <code>Date</code> (see **ExtraDate**) and <code>Number</code> (see **ExtraNumber**).\n\nThis practice is wrong. Please do not inherit it in your project. There are only *extremely* rare cases when it's okay to do so and I consider these two modules an example of those. \n\n## Q: How do I run unit tests?\n\n<code>nodeunit test/</code>\n\n# Database structure\n\nDatabase path (<code>dbPath</code>) is a folder which contains tickers folders: \n\n\t/mnt/storage/tickers/\n\t/mnt/storage/tickers/AAPL/\n\t/mnt/storage/tickers/ORCL/\n\t/mnt/storage/tickers/YHOO/\n\t…\n\nEach ticker folder contains TickStorage files, each named with a daystamp of that day: \n\n\t/mnt/storage/tickers/YHOO/20110103.ticks\n\t/mnt/storage/tickers/YHOO/20110104.ticks\n\t…\n\nEach file is in TickStorage format. \n\nYou don't need to traverse this folder structure manually: there are two handy modules that will do that for you: <code>Symbols</code> and <code>Symbol</code>. They abstract the actual file storage from you. \n\nHere's a handy sinopsis: \n\n```javascript\nSymbols = require('stock/Symbols');\nSymbol = require('stock/Symbol');\nTickStorage = require('stock/TickStorage');\nrequire('stock/ExtraDate');\nrequire('stock/ExtraNumber');\n\nvar dbPath = '/Users/egor/tickers';\n\n// initialise the class that works with tickers database (a folder of tickers folders) \nvar symbols  = new Symbols(dbPath);\n\n// now actually load the list of tickers (folders) available at that path\nif (!symbols.load()) {\n\tconsole.log(\"Cannot load tickers database!\");\n\treturn;\n}\n\n\n// now let's iterate over all tickers available\nvar symbol;\nwhile ((symbol=symbols.next())) {\n\t// mind that here \"symbol\" is a instantiated \"Symbol\" class\n\n\t// actually load list of days (files) at for that ticker (folder)\n\tif (!symbol.load()) {\n\t\tconsole.log(\"Cannot load days for %s\", symbol.symbol);\n\t\treturn;\n\t}\n\n\n\t// prepare tick storage for the first day of that ticker\n\tvar tickStorage = new TickStorage(dbPath, symbol.symbol, symbol.firstDay());\n\n\t// actually load the raw tick data for this symbol at that day\n\tif (!tickStorage.load()) {\n\t\tconsole.log(\"Cannot load ticks for %s/%s\", symbol.symbol, symbol.firstDay());\n\t\treturn;\n\t}\n\n\t// iterate over market ticks and calculate total volume\n\tvar tick, totalVolume=0;\n\twhile ((tick=tickStorage.nextTick())) {\n\t\tif (tick.isMarket) {\n\t\t\ttotalVolume+=tick.volume;\n\t\t}\n\t}\n\n\tconsole.log(\"%s total volume = %d\", symbol.symbol, totalVolume);\n}\n```\n\n\n# License \n\n**node-stock** is triple-licensed. \n\nIf you are using **node-stock** in-house and do not redistribute the software, you can use it under LGPL v2.1. Essentially this means \"do whatever you want as long as it's in-house\". Feel free to provide commercial services or make zillions of money with this software. Just drop me an email so I can share your joy.\n\nIf you are redistributing **node-stock**, please consider it GPLv2 licensed. \n\nIf neither option is good for you, I can sell you a commercial license, which also includes my personal support. Contact me by email. \n\n# Contacts\n\n**node-stock** is created by Egor Egorov, me@egorfine.com. I welcome your comments and suggestions, please feel free to drop me an email. \n","maintainers":[{"name":"egorfine","email":"me@egorfine.com"}],"time":{"modified":"2022-06-27T00:27:57.654Z","created":"2011-11-29T22:02:38.294Z","0.0.8":"2011-11-29T22:02:40.193Z","0.0.9":"2012-09-08T20:37:52.978Z"},"author":{"name":"Egor Egorov","email":"me@egorfine.com"},"repository":{"type":"git","url":"http://github.com/egorfine/node-stock.git"},"users":{}}