Skip to content

Commit

Permalink
add GetPairPrice method
Browse files Browse the repository at this point in the history
  • Loading branch information
Sagleft committed Jul 6, 2022
1 parent 1bccd89 commit 3b205b5
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
6 changes: 6 additions & 0 deletions structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,3 +265,9 @@ type OperationsHistoryDataContainer struct {
}

type mapTable map[string]interface{}

type PairPriceData struct {
PairSymbol string
BestAskPrice float64
BestBidPrice float64
}
30 changes: 30 additions & 0 deletions trade.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,3 +148,33 @@ func (c *Client) GetMarketCurrenciesList(pairSymbol string) (*CurrenciesListData
}
return &response.Result, nil
}

func (c *Client) GetPairPrice(pairCode string) (PairPriceData, error) {
result := PairPriceData{}
pairs, err := c.GetPairs()
if err != nil {
return result, err
}

for i := 0; i < len(pairs); i++ {
pairData := pairs[i]
if pairData.Pair.PairCode == pairCode {
bookData, err := c.GetOrderBook(pairData.Pair.PairCode)
if err != nil {
return result, err
}

if len(bookData.Buy) > 0 {
result.BestAskPrice = bookData.Buy[0].Price
}
if len(bookData.Sell) > 0 {
result.BestBidPrice = bookData.Sell[0].Price
}
return result, nil
} else {
continue
}
}

return result, errors.New("pair " + pairCode + " not found")
}

0 comments on commit 3b205b5

Please sign in to comment.