diff --git a/exchanges/poloniex/poloniex.go b/exchanges/poloniex/poloniex.go index 618f31cd..9163eacb 100644 --- a/exchanges/poloniex/poloniex.go +++ b/exchanges/poloniex/poloniex.go @@ -785,7 +785,7 @@ func (p *Poloniex) SendAuthenticatedHTTPRequest(method, endpoint string, values headers := make(map[string]string) headers["Content-Type"] = "application/x-www-form-urlencoded" headers["Key"] = p.API.Credentials.Key - values.Set("nonce", p.Requester.GetNonce(true).String()) + values.Set("nonce", strconv.FormatInt(time.Now().UnixNano(), 10)) values.Set("command", endpoint) hmac := crypto.GetHMAC(crypto.HashSHA512, @@ -803,7 +803,6 @@ func (p *Poloniex) SendAuthenticatedHTTPRequest(method, endpoint string, values Body: bytes.NewBufferString(values.Encode()), Result: result, AuthRequest: true, - NonceEnabled: true, Verbose: p.Verbose, HTTPDebugging: p.HTTPDebugging, HTTPRecording: p.HTTPRecording, diff --git a/exchanges/poloniex/poloniex_websocket.go b/exchanges/poloniex/poloniex_websocket.go index d02a2f5e..0d1c2b04 100644 --- a/exchanges/poloniex/poloniex_websocket.go +++ b/exchanges/poloniex/poloniex_websocket.go @@ -314,11 +314,28 @@ func (p *Poloniex) wsHandleData(respRaw []byte) error { currencyPair := currencyIDMap[channelID] var trade WsTrade trade.Symbol = currencyIDMap[channelID] - dataL3 := dataL2.([]interface{}) - trade.TradeID, err = strconv.ParseInt(dataL3[1].(string), 10, 64) - if err != nil { - return err + dataL3, ok := dataL2.([]interface{}) + if !ok { + return errors.New("websocket trade update error: type conversion failure") } + + if len(dataL3) != 6 { + return errors.New("websocket trade update error: incorrect data returned") + } + + // tradeID type intermittently changes + switch t := dataL3[1].(type) { + case string: + trade.TradeID, err = strconv.ParseInt(t, 10, 64) + if err != nil { + return err + } + case float64: + trade.TradeID = int64(t) + default: + return fmt.Errorf("unhandled type for websocket trade update: %v", t) + } + side := order.Buy if dataL3[2].(float64) != 1 { side = order.Sell