mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-13 23:16:45 +00:00
Exchange: Poloniex fixes (#537)
* fix panic bug where item type was different intermittently * fix nonce bug where it requires an actual timestamp for each consecutive call * add in default case * Added in type conversion check and check dataset length to continue
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user