Real Time Stock Simulator
Table of Contents
Description
The `Real Time Stock Simulator` is a tool to help test and develop another tool I am working on. I wanted something that would reliably create fake stock market data to test the other (nameless) tool I am working on. For now, my needs are fairly basic. I need it to create a ‘log’ for every interval (1 minute, 5 minutes, 15 minutes) for possibly hundreds of fake stocks and log the quotes to a database. I also need it to create backlogs of data; for example, if you want to generate data for two months prior it will generate the data for the specified intervals. In addition to backlogging data on command, as I will not have this tool running on a server 24/7 when I am doing local testing I need it to fill any gaps in data. If I start the application and don’t use it for a month I need it to detect the missing data in the database and generate all the missing data until the current datetime. Those are my needs at the moment, they may change later.
I am creating this as a library as I am not sure if I will ultimately use it via a web interface, or continue to use it as a CLI/TUI application.
I will only be testing with postgreSQL, unless my needs change in the future.
Due to the resource heavy nature of creating quotes for possibly hundreds of stock symbols for an arbitrary period of time (possibly with a frequency of 1 minute), I have chosen to use Rust for this project - and because I like using it :). I will eventually make this application concurrent, to reduce the time needed to create those backlogs. I’ll cross that bridge when I get there.
I will accept PRs if they are in line with what I want the application to do. Feel free to reach out if you have any ideas, or if something is not idiomatic (Rust is a relatively new language for me!).
Maintainers
- @afsharalex (Author)
Prerequisites
This depends on Postgres. This can be changed by changing the `features` line for the Diesel dependency, however be sure to ensure all SQL is compatible with your target database. I have only testing with postgreSQL - use at your own risk.
Features
- Create Stock Symbols.
- Generate past data for Stocks.
- Populate data at interval specified with data for all stocks created.
- Fill in any gaps if/when configuration is changed.
- On startup, ensure no gaps exist in stock data.
- Concurrently generate data.
Configuration
To get started, install the diesel-cli, create the database, and run the migrations. Copy the `env.example` as `.env` and set the `DATABASE_URL`.
Getting Started
You can install diesel’s cli with `cargo install diesel_cli`. After it is installed you can run `diesel setup` to create the database, then `diesel migration run` to run the migrations. I am including some utility programs to create, display, and delete data. Obviously you can simply use psql or pgadmin - use whichever you prefer. At the very least this will provide some documentation for how the data should be created/manipulated. These utility apps can be run as follow `cargo run –bin <app_name>`, for example: `cargo run –bin create_quote` will run the create_quote.rs program. They are located in the `src/bin` directory.
Troubleshooting
(empty)
To Do [4/11]
- [X] Add dependency for database
- [X] Add dependency for env files
- [X] Read env file
- [X] Connect to database
- [-] Quote
- [X] Migration files
- [X] Models
- [X] Create Quote program
- [X] Show Quotes program
- [X] Delete Quote program
- [ ] Batch Create program
- [ ] Stock
- [ ] Migration files
- [ ] Models
- [ ] Create Stock program
- [ ] Show Stocks program
- [ ] Delete Stock program
- [ ] Parse config file
- [ ] Validate config file
- [ ] Detect gaps in data
- [ ] Detect difference in config and existing data (prompt user to generate first!)
- [ ] Concurrently generate data
License
MIT License
Copyright (c) 2020 Alex Afshar
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.