From a86462b338da3d686185b8e4116f8401f6ff208e Mon Sep 17 00:00:00 2001 From: Ryan O'Hara-Reid Date: Mon, 18 Sep 2017 15:58:24 +1000 Subject: [PATCH] Fixed merge issues, fixed race condition in gemini package. --- common/common.go | 6 ----- exchanges/gemini/gemini.go | 6 +++++ exchanges/wex/wex.go | 8 +++---- portfolio/portfolio.go | 47 +------------------------------------- 4 files changed, 11 insertions(+), 56 deletions(-) diff --git a/common/common.go b/common/common.go index 1d4da4ce..2717e727 100644 --- a/common/common.go +++ b/common/common.go @@ -306,13 +306,7 @@ func SendHTTPGetRequest(url string, jsonDecode, isVerbose bool, result interface } if res.StatusCode != 200 { -<<<<<<< dae90a2eaa109648bdb85f8298d805e00ad4e974 - log.Printf("HTTP status code: %d\n", res.StatusCode) - log.Printf("URL: %s\n", url) - return errors.New("status code was not 200") -======= return fmt.Errorf("common.SendHTTPGetRequest() error: HTTP status code %d", res.StatusCode) ->>>>>>> In the common package added JSONDecode error check. Added verbosity in SendHTTPGetRequest. Updated Nonce package function. Fixed issues in ItBit package and expanded test coverage. } contents, err := ioutil.ReadAll(res.Body) diff --git a/exchanges/gemini/gemini.go b/exchanges/gemini/gemini.go index e83585f5..9ff8c6b9 100644 --- a/exchanges/gemini/gemini.go +++ b/exchanges/gemini/gemini.go @@ -7,6 +7,7 @@ import ( "net/url" "strconv" "strings" + "sync" "time" "github.com/thrasher-/gocryptotrader/common" @@ -71,10 +72,13 @@ var ( // needed append the sandbox function as well. type Gemini struct { exchange.Base + M sync.Mutex } // AddSession adds a new session to the gemini base func (g *Gemini) AddSession(sessionID int, apiKey, apiSecret, role string, needsHeartbeat bool) error { + g.M.Lock() + defer g.M.Unlock() if sessionAPIKey == nil { IsSession = true sessionAPIKey = make(map[int]string) @@ -139,6 +143,8 @@ func (g *Gemini) Setup(exch config.ExchangeConfig) { // Session is a session manager for differing APIKeys and roles, use this for all function // calls in this package func (g *Gemini) Session(sessionID int) *Gemini { + g.M.Lock() + defer g.M.Unlock() g.APIUrl = geminiAPIURL _, ok := sessionAPIKey[sessionID] if !ok { diff --git a/exchanges/wex/wex.go b/exchanges/wex/wex.go index 3ac246c1..ee5ba2fe 100644 --- a/exchanges/wex/wex.go +++ b/exchanges/wex/wex.go @@ -94,7 +94,7 @@ func (w *WEX) GetFee() float64 { func (w *WEX) GetInfo() (Info, error) { req := fmt.Sprintf("%s/%s/%s/", wexAPIPublicURL, wexAPIPublicVersion, wexInfo) resp := Info{} - err := common.SendHTTPGetRequest(req, true, &resp) + err := common.SendHTTPGetRequest(req, true, w.Verbose, &resp) if err != nil { return resp, err @@ -111,7 +111,7 @@ func (w *WEX) GetTicker(symbol string) (map[string]Ticker, error) { response := Response{} req := fmt.Sprintf("%s/%s/%s/%s", wexAPIPublicURL, wexAPIPublicVersion, wexTicker, symbol) - err := common.SendHTTPGetRequest(req, true, &response.Data) + err := common.SendHTTPGetRequest(req, true, w.Verbose, &response.Data) if err != nil { return nil, err @@ -128,7 +128,7 @@ func (w *WEX) GetDepth(symbol string) (Orderbook, error) { response := Response{} req := fmt.Sprintf("%s/%s/%s/%s", wexAPIPublicURL, wexAPIPublicVersion, wexDepth, symbol) - err := common.SendHTTPGetRequest(req, true, &response.Data) + err := common.SendHTTPGetRequest(req, true, w.Verbose, &response.Data) if err != nil { return Orderbook{}, err } @@ -146,7 +146,7 @@ func (w *WEX) GetTrades(symbol string) ([]Trades, error) { response := Response{} req := fmt.Sprintf("%s/%s/%s/%s", wexAPIPublicURL, wexAPIPublicVersion, wexTrades, symbol) - err := common.SendHTTPGetRequest(req, true, &response.Data) + err := common.SendHTTPGetRequest(req, true, w.Verbose, &response.Data) if err != nil { return nil, err } diff --git a/portfolio/portfolio.go b/portfolio/portfolio.go index 9a8d7632..ff486a79 100644 --- a/portfolio/portfolio.go +++ b/portfolio/portfolio.go @@ -90,62 +90,17 @@ func GetEthereumBalance(address []string) (EtherchainBalanceResponse, error) { return result, nil } -<<<<<<< dae90a2eaa109648bdb85f8298d805e00ad4e974 // GetCryptoIDAddress queries CryptoID for an address balance for a // specified cryptocurrency func GetCryptoIDAddress(address string, coinType string) (float64, error) { ok, err := common.IsValidCryptoAddress(address, coinType) if !ok || err != nil { return 0, errors.New("invalid address") -======= -// GetBlockrBalanceSingle queries Blockr for an address balance for either a -// LTC or a BTC single address -func GetBlockrBalanceSingle(address string, coinType string) (BlockrAddressBalanceSingle, error) { - valid, _ := common.IsValidCryptoAddress(address, coinType) - if !valid { - return BlockrAddressBalanceSingle{}, fmt.Errorf( - "Not a %s address", common.StringToUpper(coinType), - ) } - url := fmt.Sprintf( - "https://%s.%s/v%s/%s/%s", common.StringToLower(coinType), blockrAPIURL, - blockrAPIVersion, blockrAddressBalance, address, - ) - result := BlockrAddressBalanceSingle{} - err := common.SendHTTPGetRequest(url, true, false, &result) - if err != nil { - return result, err - } - if result.Status != "success" { - return result, errors.New(result.Message) ->>>>>>> In the common package added JSONDecode error check. Added verbosity in SendHTTPGetRequest. Updated Nonce package function. Fixed issues in ItBit package and expanded test coverage. - } - -<<<<<<< dae90a2eaa109648bdb85f8298d805e00ad4e974 var result interface{} url := fmt.Sprintf("%s/%s/api.dws?q=getbalance&a=%s", cryptoIDAPIURL, common.StringToLower(coinType), address) - err = common.SendHTTPGetRequest(url, true, &result) -======= -// GetBlockrAddressMulti queries Blockr for an address balance for either a LTC -// or a BTC multiple addresses -func GetBlockrAddressMulti(addresses []string, coinType string) (BlockrAddressBalanceMulti, error) { - for _, add := range addresses { - valid, _ := common.IsValidCryptoAddress(add, coinType) - if !valid { - return BlockrAddressBalanceMulti{}, fmt.Errorf( - "Not a %s address", common.StringToUpper(coinType), - ) - } - } - addressesStr := common.JoinStrings(addresses, ",") - url := fmt.Sprintf( - "https://%s.%s/v%s/%s/%s", common.StringToLower(coinType), blockrAPIURL, - blockrAPIVersion, blockrAddressBalance, addressesStr, - ) - result := BlockrAddressBalanceMulti{} - err := common.SendHTTPGetRequest(url, true, false, &result) ->>>>>>> In the common package added JSONDecode error check. Added verbosity in SendHTTPGetRequest. Updated Nonce package function. Fixed issues in ItBit package and expanded test coverage. + err = common.SendHTTPGetRequest(url, true, false, &result) if err != nil { return 0, err }