Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add symbol search #30

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/.idea
35 changes: 33 additions & 2 deletions av.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package av

import (
"encoding/json"
"io/ioutil"
"net/http"
"net/url"
"time"
Expand All @@ -21,10 +23,13 @@ const (
queryMarket = "market"
queryEndpoint = "function"
queryInterval = "interval"
queryKeywords = "keywords"

valueCompact = "compact"
valueJson = "csv"
valueCsv = "csv"
valueJson = "json"
valueDigitcalCurrencyEndpoint = "DIGITAL_CURRENCY_INTRADAY"
valueSymbolSearchEndpoint = "SYMBOL_SEARCH"

pathQuery = "query"

Expand Down Expand Up @@ -94,7 +99,7 @@ func (c *Client) buildRequestPath(params map[string]string) *url.URL {
// base parameters
query := endpoint.Query()
query.Set(queryApiKey, c.apiKey)
query.Set(queryDataType, valueJson)
query.Set(queryDataType, valueCsv)
query.Set(queryOutputSize, valueCompact)

// additional parameters
Expand Down Expand Up @@ -153,3 +158,29 @@ func (c *Client) DigitalCurrency(digital, physical string) ([]*DigitalCurrencySe
defer response.Body.Close()
return parseDigitalCurrencySeriesData(response.Body)
}

func (c *Client) SymbolSearch(keywords string) (*SymbolMatches, error) {
endpoint := c.buildRequestPath(map[string]string{
queryEndpoint: valueSymbolSearchEndpoint,
queryDataType: valueJson,
queryKeywords: keywords,
})

response, err := c.conn.Request(endpoint)

if err != nil {
return nil, err
}

defer response.Body.Close()
body, err := ioutil.ReadAll(response.Body)

if err != nil {
return nil, err
}

var matches *SymbolMatches
json.Unmarshal(body, &matches)

return matches, nil
}
17 changes: 17 additions & 0 deletions symbol_matches.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package av

type SymbolMatches struct {
BestMatches []*SymbolMatch `json:"bestMatches"`
}

type SymbolMatch struct {
Symbol string `json:"1. symbol"`
Name string `json:"2. name"`
Type string `json:"3. type"`
Region string `json:"4. region"`
MarketOpen string `json:"5. marketOpen"`
MarketClose string `json:"6. marketClose"`
Timezone string `json:"7. timezone"`
Currency string `json:"8. currency"`
MatchScore float64 `json:"9. matchScore,string"`
}