Skip to content

Commit

Permalink
Adds write command.
Browse files Browse the repository at this point in the history
  • Loading branch information
ackleymi committed Aug 30, 2018
1 parent e2402de commit 0043550
Show file tree
Hide file tree
Showing 9 changed files with 448 additions and 274 deletions.
9 changes: 5 additions & 4 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@
# :zap: qtrn :zap:
The official cli tool for making financial markets analysis as fast as you are.

Pronounced "quote-tron" as a throwback to those awesome financial terminals of the 80's. This project is intended as a living example of the capabilities of the [finance-go] library.

## Commands
The current available commands are:
* `quote` - prints tables of quotes to the current shell
* `options` - prints tables of options contract quotes to the current shell
* `write` - writes tables of quotes/history to csv files

## Installation
In order to use this awesome tool, you'll need to get it on your machine!
Expand All @@ -25,7 +29,7 @@ brew install qtrn
2. Determine the appropriate distribution for your operating system (mac | windows | linux)
3. Download and untar the distribution. Shortcut for macs:
```
curl -sL https://github.com/piquette/qtrn/releases/download/v0.0.3/qtrn_0.0.3_darwin_amd64.tar.gz | tar zx
curl -sL https://github.com/piquette/qtrn/releases/download/v0.0.5/qtrn_0.0.5_darwin_amd64.tar.gz | tar zx
```
4. Move the binary into your local `$PATH`.
5. Run `qtrn help`.
Expand Down Expand Up @@ -78,3 +82,4 @@ goreleaser --rm-dist

[goreleaser]: https://github.com/goreleaser/goreleaser
[releases]: https://github.com/piquette/qtrn/releases
[finance-go]: https://github.com/piquette/finance-go
3 changes: 2 additions & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
finance "github.com/piquette/finance-go"
"github.com/piquette/qtrn/cmd/options"
quote "github.com/piquette/qtrn/cmd/quote"
"github.com/piquette/qtrn/cmd/write"

"github.com/piquette/qtrn/version"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -57,7 +58,7 @@ func Execute() error {
}

// cmdQtrn.AddCommand(chartCmd)
// cmdQtrn.AddCommand(writeCmd)
c.AddCommand(write.Cmd)
c.AddCommand(quote.Cmd)
c.AddCommand(options.Cmd)
c.PersistentFlags().BoolVarP(&insecureF, "insecure", "x", false, "set `--insecure` or `-x` to skip tls verification during requests")
Expand Down
41 changes: 41 additions & 0 deletions cmd/write/csv.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package write

import (
"encoding/csv"
"fmt"
"os"
"time"
)

// write writes data to a csv.
func write(header []string, prefix string, cmd string, data [][]string) error {
t := time.Now()
now := fmt.Sprintf("%d-%02d-%02d_%02d:%02d:%02d",
t.Year(), t.Month(), t.Day(),
t.Hour(), t.Minute(), t.Second())
fileTitle := fmt.Sprintf("%v_%v_%v.csv", prefix, cmd, now)
file, err := os.Create(fileTitle)
if err != nil {
return err
}
defer file.Close()

writer := csv.NewWriter(file)
defer writer.Flush()

if !removeHeaderF {
err = writer.Write(header)
if err != nil {
return err
}
}

for _, value := range data {
err = writer.Write(value)
if err != nil {
return err
}
}
fmt.Println(fileTitle)
return nil
}
Loading

0 comments on commit 0043550

Please sign in to comment.