Skip to content

Commit

Permalink
* Documentation: Update documentation
Browse files Browse the repository at this point in the history
* Documentation: Add Streaming API description and usage example
  • Loading branch information
edward-yakop committed Jan 1, 2021
1 parent 444b1a9 commit 52839ca
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
26 changes: 23 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@

### 1.1 Building

To build, you need to install go (https://golang.org/) and glide (https://github.com/Masterminds/glide)
To build, you need to install go (https://golang.org/)

To build:

```
glide install
go build
```

Expand Down Expand Up @@ -201,3 +199,25 @@ type FXTHeader struct {
}
```

## 4 Streaming API

Stream tick data given the start and end time boundary.

``` Golang
location, _ := time.LoadLocation("America/New_York")
start := time.Date(2017, time.January, 10, 22, 0, 0, 0, location)
end := start.Add(4 * 24 * time.Hour)

// Create new stream that each tick will only be called withing start and end boundary
stream := stream.New("GBPJPY", start, end, createEmptyDir(t))

// Stream ticks with the requested parameter
stream.EachTick(func(time time.Time, tick *tickdata.TickData, err error) bool {
// time: Tick data time in new_york time zone
// tick: The tick data containg symbol, time (UTC), ask, bid, volume's ask and volume's bid
// err: Error occurs either during download or decoding dukas tick data file

return true // Sets to true to continue to next tick, false to stop
})
```

2 changes: 1 addition & 1 deletion api/tickdata/stream/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func downloadEnd(end time.Time) time.Time {
var isLogSetup = false

// time are in UTC
func NewStream(symbol string, start time.Time, end time.Time, downloadFolderPath string) *Stream {
func New(symbol string, start time.Time, end time.Time, downloadFolderPath string) *Stream {
if !isLogSetup {
isLogSetup = true
clog.NewConsole(0, clog.ConsoleConfig{
Expand Down
4 changes: 2 additions & 2 deletions api/tickdata/stream/stream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
func TestStream_EachTick_AlwaysContinue(t *testing.T) {
start := time.Date(2017, time.January, 10, 22, 0, 0, 0, time.UTC)
end := start.Add(1 * time.Hour)
stream := NewStream("GBPJPY", start, end, createEmptyDir(t))
stream := New("GBPJPY", start, end, createEmptyDir(t))
isRun := false

stream.EachTick(func(time time.Time, tick *tickdata.TickData, err error) bool {
Expand Down Expand Up @@ -56,7 +56,7 @@ func TestStream_EachTick_OnlyContinueTwice(t *testing.T) {

start := time.Date(2017, time.January, 10, 22, 0, 0, 0, location)
end := start.Add(4 * 24 * time.Hour)
stream := NewStream("GBPJPY", start, end, createEmptyDir(t))
stream := New("GBPJPY", start, end, createEmptyDir(t))

isRun := false
tickCount := 0
Expand Down

0 comments on commit 52839ca

Please sign in to comment.