Skip to content

Commit

Permalink
Merge pull request #30 from necryin/new_currencies
Browse files Browse the repository at this point in the history
new currrencies + auth errors
  • Loading branch information
necryin authored Apr 13, 2020
2 parents d8afabb + 2882bee commit 3cc3cf4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
6 changes: 6 additions & 0 deletions rest_domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ const (
RUB Currency = "RUB"
USD Currency = "USD"
EUR Currency = "EUR"
TRY Currency = "TRY"
JPY Currency = "JPY"
CNY Currency = "CNY"
CHF Currency = "CHF"
GBP Currency = "GBP"
HKD Currency = "HKD"
)

type OperationType string
Expand Down
13 changes: 13 additions & 0 deletions streaming_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@ func (c *StreamingClient) UnsubscribeInstrumentInfo(figi, requestID string) erro
return nil
}

var ErrForbidden = errors.New("invalid token")
var ErrUnauthorized = errors.New("token not provided")

func (c *StreamingClient) connect() (*websocket.Conn, error) {
dialer := websocket.Dialer{
Proxy: http.ProxyFromEnvironment,
Expand All @@ -177,6 +180,16 @@ func (c *StreamingClient) connect() (*websocket.Conn, error) {

conn, resp, err := dialer.Dial(c.apiURL, http.Header{"Authorization": {"Bearer " + c.token}})
if err != nil {
if resp != nil {
if resp.StatusCode == http.StatusForbidden {
return nil, ErrForbidden
}
if resp.StatusCode == http.StatusUnauthorized {
return nil, ErrUnauthorized
}

return nil, errors.Wrapf(err, "can't connect to %s %s", c.apiURL, resp.Status)
}
return nil, errors.Wrapf(err, "can't connect to %s", c.apiURL)
}
defer resp.Body.Close()
Expand Down

0 comments on commit 3cc3cf4

Please sign in to comment.