Thoughts of a software developer

18.02.2018 17:42 | Modified 18.02. 17:44
Your own little stock portfolio

Since last autumn, Google portfolio has had a warning like this: I’ve been meaning to make an own stock portfolios software since that warning first came. It’s not ready, but you can signup, login and add stocks to the portfolio. The address is portfolio.jelinden.fi if you’d like to try it out.

I first tried Yahoo as a data provider, but they made changes to their API:s so I had to find something else. Luckily, I found IEX. IEX is a stock exchange of their own. They have a free API for anyone to use.

How was the portfolio made

Frontend

For frontend, the use of React was a no brainer. Well, Go templates would have been a viable option, but I like to keep learning too. React has had a few versions since I’ve build something from the ground up. React 16.2 is the latest version when I’m writing this, and it’s in use. No Redux yet, although there would be some real use cases for it. I may have to take it in to use too.

Backend

Golang, my favourite language at the moment.

Database

Database used is ql, an embedded sql database. Stock data really needs a relational database. Of course one could do it with a key/value store or on document store, but I think you couldn’t get anything for it.

Session store

Session store is an embedded boltdb. Using BoltDB into this kind of storing is really simple and fast.

Initiate bolt bucket:

func InitBolt() {
    var err error
    boltDB, err = bolt.Open("/tmp/sessions.db", 0600, &bolt.Options{Timeout: 1 * time.Second})
    if err != nil {
        log.Println(err.Error())
    }
    boltDB.Update(func(tx *bolt.Tx) error {
        _, err := tx.CreateBucketIfNotExists([]byte(bucketName))
        if err != nil {
            return fmt.Errorf("create bucket: %s", err)
        }
        return nil
    })
}

Put session into bucket:

func PutSession(key string, value string) {
    boltDB.Update(func(tx *bolt.Tx) error {
        b := tx.Bucket([]byte(bucketName))
        return b.Put([]byte(key), []byte(value))
    })
}

What’s missing?

At least these three things are on the todo list:

  • Get price history and show a graph for portfolio development
  • Show dividend history and growth (graph maybe?)
  • Add the possibility to edit transactions

Links