Git Product home page Git Product logo

fake_stock_alerts's Introduction

fake_stock_alerts

Have you ever wanted fake stock alerts? Well now you can have some. Follow randomly generated Buy/Sell stock alerts for a randomly generated user who has imaginary friends one randomly generated execution at a time!

Build the binary

docker run --rm -v $PWD:/usr/local/go/src/github.com/amoskyler/fake_stock_alerts -w /usr/local/go/src/github.com/amoskyler/fake_stock_alerts golang:1.7.1 go get; go build -v

Run tests (with coverage)

docker run --rm -v $PWD:/usr/local/go/src/github.com/amoskyler/fake_stock_alerts -w /usr/local/go/src/github.com/amoskyler/fake_stock_alerts golang:1.7.1 go get; go test ./... -race -v

Intro & Design

I implemented this little application in go as an intro into the language. Prior to this I've written a bit of go packet code but in this project I explored and got introduced to and familiarized with a lot of basic go principles.

General

  1. The method alert.GenerateAlerts(*User) Alerts returns a custom list of alerts for the user provided user. It returns a slice of Alert in the type Alerts Alerts.ToString() string outputs a list in the format "'<date>,<BUY|SELL>,<ticker>','<date>,<BUY|SELL>,<ticker>'"
  2. Unit tests have been implemented for the transaction counter logic (here) as well as the Alert collection sorting logic (here). Additional Tests: here
  3. Good future testing
    • Test struct/type constructor functions
    • Test TickerMap state updates in the transactioncounter when new transactions are added
    • Test alert property validity on generation
  4. Alerts implements the sortable interface (Len, Less, Swap) which returns the alerts by highest volume moved with O(n*log(n)) complexity
    • This means alerts with net high SELLs will appear above a ticker with low BUYs
    • This can almost certainly be optimized as we can most likely generate the user's Alerts as we consume their friend's list of transactions (which is O(n), in our case)
    • See alert.go

There are four primary components which make the fake stock alerter a reality.

transaction.Transaction

A simple data structure which defines a single transaction (ticker, type, date).

  • generate with transaction.GenerateRandomTransaction

transactioncounter.Counter

The transaction counter is essentially a transaction collection. Counter provides helpers for adding/calculating the TickerMap (which stores all tickers associated to their net transaction flow) When transactions are added to the Counter the updated TickerMap is calculated via a simple foreach loop, incr/decrementing a hash, keyed by the ticker string as it consumes a list of transactions. The hash is calcualted in O(n) time as each transaction is consumed

The Counter also filters/errors out invalid transaction structures and applies date range validation in order to filter out of interest transactions. Counter internally tracks both filtered and un-filtered transaction lists

alert.Alert

Alert implements the sortable interface so it can be used with the native go package, "sort". It implements it's sort a little differently than most high/low algorithms - it calculates position using the highest absolute values

user.User

A user has a friends list, as well as a series of transactions

Basic Usage

user := user.GenerateRandomUser(1, 20, 20)

alerts := alert.GenerateAlerts(user)
fmt.Println(alerts.ToString())

/* Outputs ~:
[
Alerts for user 0
5 Alerts

	"2,BUY,TWTR",
	"1,SELL,TWLO",
	"1,BUY,AAPL",
	"1,SELL,FB",
	"1,SELL,TSLA"
]
*/

fake_stock_alerts's People

Contributors

amoskyler avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.