(Engine) Variety of engine updates (#390)

* drop common uuid v4 func and imported package as needed

* removed common functions regarding json marshal and unmarshal and used the json package directly. WRT unmarshal it was calling reflect and converted to string which is also checked in the JSON package so it was doing a double up, this will be a tiny gain as it was directly used in the requester package for all our outbound requests.

* add in string

* explicitly throw away return error value

* atleast return the error that websocket initialise returns

* return error when not connected

* fix comment

* Adds comments

* move package declarations

* drop append whenever we call supported

* remove unused import

* Change incorrect spelling

* fix tests

* fix go import issue
This commit is contained in:
Ryan O'Hara-Reid
2019-12-03 10:06:08 +11:00
committed by Adrian Gallagher
parent c27b8657e2
commit 0c5d75b22c
70 changed files with 393 additions and 462 deletions

View File

@@ -1,6 +1,7 @@
package gemini
import (
"encoding/json"
"errors"
"fmt"
"net/http"
@@ -371,7 +372,7 @@ func (g *Gemini) SendAuthenticatedHTTPRequest(method, path string, params map[st
req[key] = value
}
PayloadJSON, err := common.JSONEncode(req)
PayloadJSON, err := json.Marshal(req)
if err != nil {
return errors.New("sendAuthenticatedHTTPRequest: Unable to JSON request")
}

View File

@@ -3,6 +3,7 @@
package gemini
import (
"encoding/json"
"errors"
"fmt"
"net/http"
@@ -11,7 +12,6 @@ import (
"time"
"github.com/gorilla/websocket"
"github.com/thrasher-corp/gocryptotrader/common"
"github.com/thrasher-corp/gocryptotrader/common/crypto"
"github.com/thrasher-corp/gocryptotrader/currency"
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
@@ -99,7 +99,7 @@ func (g *Gemini) WsSecureSubscribe(dialer *websocket.Dialer, url string) error {
Request: fmt.Sprintf("/v1/%v", url),
Nonce: time.Now().UnixNano(),
}
PayloadJSON, err := common.JSONEncode(payload)
PayloadJSON, err := json.Marshal(payload)
if err != nil {
return fmt.Errorf("%v sendAuthenticatedHTTPRequest: Unable to JSON request", g.Name)
}
@@ -166,7 +166,7 @@ func (g *Gemini) WsHandleData() {
continue
}
var result map[string]interface{}
err := common.JSONDecode(resp.Raw, &result)
err := json.Unmarshal(resp.Raw, &result)
if err != nil {
g.Websocket.DataHandler <- fmt.Errorf("%v Error: %v, Raw: %v", g.Name, err, string(resp.Raw))
continue
@@ -174,7 +174,7 @@ func (g *Gemini) WsHandleData() {
switch result["type"] {
case "subscription_ack":
var result WsSubscriptionAcknowledgementResponse
err := common.JSONDecode(resp.Raw, &result)
err := json.Unmarshal(resp.Raw, &result)
if err != nil {
g.Websocket.DataHandler <- err
continue
@@ -182,7 +182,7 @@ func (g *Gemini) WsHandleData() {
g.Websocket.DataHandler <- result
case "initial":
var result WsSubscriptionAcknowledgementResponse
err := common.JSONDecode(resp.Raw, &result)
err := json.Unmarshal(resp.Raw, &result)
if err != nil {
g.Websocket.DataHandler <- err
continue
@@ -190,7 +190,7 @@ func (g *Gemini) WsHandleData() {
g.Websocket.DataHandler <- result
case "accepted":
var result WsActiveOrdersResponse
err := common.JSONDecode(resp.Raw, &result)
err := json.Unmarshal(resp.Raw, &result)
if err != nil {
g.Websocket.DataHandler <- err
continue
@@ -198,7 +198,7 @@ func (g *Gemini) WsHandleData() {
g.Websocket.DataHandler <- result
case "booked":
var result WsOrderBookedResponse
err := common.JSONDecode(resp.Raw, &result)
err := json.Unmarshal(resp.Raw, &result)
if err != nil {
g.Websocket.DataHandler <- err
continue
@@ -206,7 +206,7 @@ func (g *Gemini) WsHandleData() {
g.Websocket.DataHandler <- result
case "fill":
var result WsOrderFilledResponse
err := common.JSONDecode(resp.Raw, &result)
err := json.Unmarshal(resp.Raw, &result)
if err != nil {
g.Websocket.DataHandler <- err
continue
@@ -214,7 +214,7 @@ func (g *Gemini) WsHandleData() {
g.Websocket.DataHandler <- result
case "cancelled":
var result WsOrderCancelledResponse
err := common.JSONDecode(resp.Raw, &result)
err := json.Unmarshal(resp.Raw, &result)
if err != nil {
g.Websocket.DataHandler <- err
continue
@@ -222,7 +222,7 @@ func (g *Gemini) WsHandleData() {
g.Websocket.DataHandler <- result
case "closed":
var result WsOrderClosedResponse
err := common.JSONDecode(resp.Raw, &result)
err := json.Unmarshal(resp.Raw, &result)
if err != nil {
g.Websocket.DataHandler <- err
continue
@@ -230,7 +230,7 @@ func (g *Gemini) WsHandleData() {
g.Websocket.DataHandler <- result
case "heartbeat":
var result WsHeartbeatResponse
err := common.JSONDecode(resp.Raw, &result)
err := json.Unmarshal(resp.Raw, &result)
if err != nil {
g.Websocket.DataHandler <- err
continue
@@ -243,7 +243,7 @@ func (g *Gemini) WsHandleData() {
continue
}
var marketUpdate WsMarketUpdateResponse
err := common.JSONDecode(resp.Raw, &marketUpdate)
err := json.Unmarshal(resp.Raw, &marketUpdate)
if err != nil {
g.Websocket.DataHandler <- err
continue