Skip to content
This repository was archived by the owner on Sep 19, 2024. It is now read-only.

Commit

Permalink
Merge pull request #3 from oskarwojciski/search_by_symbol
Browse files Browse the repository at this point in the history
Search by symbol
  • Loading branch information
r--w authored Dec 27, 2018
2 parents b175452 + 3135f27 commit 588ab9a
Show file tree
Hide file tree
Showing 11 changed files with 354 additions and 58 deletions.
69 changes: 61 additions & 8 deletions Gopkg.lock

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

16 changes: 13 additions & 3 deletions cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,15 +191,25 @@ func commandVolume(argument string) (string, error) {
func getTickerByQuery(query string) (*coinpaprika.Ticker, error) {
paprikaClient := coinpaprika.NewClient(nil)

searchOpts := &coinpaprika.SearchOptions{Query: query, Categories: "currencies"}
searchOpts := &coinpaprika.SearchOptions{Query: query, Categories: "currencies", Modifier: "symbol_search"}
result, err := paprikaClient.Search.Search(searchOpts)
if err != nil {
return nil, errors.Wrap(err, "query:"+query)
}

log.Debugf("found %d results for query :%s", len(result.Currencies), query)
log.Debugf("found %d results for query by symbol :%s", len(result.Currencies), query)
if len(result.Currencies) <= 0 {
return nil, errors.Errorf("invalid coin name|ticker|symbol")
//search by name:
searchOpts = &coinpaprika.SearchOptions{Query: query, Categories: "currencies"}
result, err = paprikaClient.Search.Search(searchOpts)
if err != nil {
return nil, errors.Wrap(err, "query:"+query)
}
log.Debugf("found %d results for query by name :%s", len(result.Currencies), query)

if len(result.Currencies) <= 0 {
return nil, errors.Errorf("invalid coin name|ticker|symbol")
}
}
if result.Currencies[0].ID == nil {
return nil, errors.New("missing id for a coin")
Expand Down
6 changes: 6 additions & 0 deletions cmd/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ func (suite *RunTestSuite) TestCommandPrice() {

if !r.error {
suite.NoError(err)
} else {
suite.Error(err)
}

if r.contains != "" {
Expand Down Expand Up @@ -75,6 +77,8 @@ func (suite *RunTestSuite) TestCommandSupply() {
supplyInt, err := strconv.Atoi(supplyStrings[0])
suite.NoError(err)
suite.True(supplyInt > 100, "should be more than 100")
} else {
suite.Error(err)
}
}
}
Expand Down Expand Up @@ -107,6 +111,8 @@ func (suite *RunTestSuite) TestCommandVolume() {
volumeFloat, err := strconv.ParseFloat(volumeStrings[0], 64)
suite.NoError(err)
suite.True(volumeFloat > 100, "should be more than 100")
} else {
suite.Error(err)
}
}
}
Expand Down

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

Loading

0 comments on commit 588ab9a

Please sign in to comment.