Skip to content

Commit

Permalink
Merge pull request #98 from alpacahq/feature/poly-nats-servers
Browse files Browse the repository at this point in the history
configurable nats servers (polygon plugin)
  • Loading branch information
rocketbitz authored Jun 26, 2018
2 parents 0d121d7 + 81524f4 commit 5c13467
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
2 changes: 2 additions & 0 deletions contrib/polygon/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Name | Type | Default | Description
--- | --- | --- | ---
api_key | string | none | Your polygon api key
base_url | string | none | The URL to use in the HTTP client
nats_servers | string | Comma separated list of nats servers to connect to
symbols | slice of strings | none | The symbols to retrieve chart bars for

### Example
Expand All @@ -25,6 +26,7 @@ bgworkers:
config:
api_key: your_api_key
base_url: https://api.polygon.io
nats_servers: nats://nats1.polygon.io:30401, nats://nats2.polygon.io:30402, nats://nats3.polygon.io:30403
symbols:
- AAPL
- SPY
Expand Down
8 changes: 6 additions & 2 deletions contrib/polygon/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type GetAggregatesResponse struct {

var (
baseURL = "https://api.polygon.io"
servers = "nats://nats1.polygon.io:30401, nats://nats2.polygon.io:30402, nats://nats3.polygon.io:30403"
apiKey string
NY, _ = time.LoadLocation("America/New_York")
)
Expand All @@ -45,6 +46,10 @@ func SetBaseURL(url string) {
baseURL = url
}

func SetNatsServers(serverList string) {
servers = serverList
}

func GetAggregates(symbol string, from time.Time) (*GetAggregatesResponse, error) {
resp := GetAggregatesResponse{}

Expand Down Expand Up @@ -124,9 +129,8 @@ type StreamAggregate struct {
E int64 `json:"-"`
}

// Stream from the polygon nats server
func Stream(handler func(m *nats.Msg), symbols []string) (err error) {
servers := "nats://nats1.polygon.io:30401, nats://nats2.polygon.io:30402, nats://nats3.polygon.io:30403"

nc, _ := nats.Connect(
servers,
nats.Token(apiKey))
Expand Down
3 changes: 3 additions & 0 deletions contrib/polygon/polygon.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ type FetcherConfig struct {
// polygon API base URL in case it is being proxied
// (defaults to https://api.polygon.io/)
BaseURL string `json:"base_url"`
// list of nats servers to connect to
// (defaults to "nats://nats1.polygon.io:30401, nats://nats2.polygon.io:30402, nats://nats3.polygon.io:30403")
NatsServers string `json:"nats_servers"`
// list of symbols that are important
Symbols []string `json:"symbols"`
// time string when to start first time, in "YYYY-MM-DD HH:MM" format
Expand Down

0 comments on commit 5c13467

Please sign in to comment.