Split up common.go, file path fixes and much more

This commit is contained in:
Adrian Gallagher
2019-06-04 17:04:18 +10:00
parent 8c62316e82
commit e965e54e09
74 changed files with 524 additions and 617 deletions

View File

@@ -13,6 +13,7 @@ import (
"github.com/gorilla/websocket"
"github.com/thrasher-/gocryptotrader/common"
"github.com/thrasher-/gocryptotrader/common/convert"
"github.com/thrasher-/gocryptotrader/common/crypto"
"github.com/thrasher-/gocryptotrader/currency"
exchange "github.com/thrasher-/gocryptotrader/exchanges"
@@ -66,7 +67,7 @@ func (z *ZB) SpotNewOrder(arg SpotNewOrderRequestParams) (int64, error) {
return 0, err
}
if result.Code != 1000 {
return 0, fmt.Errorf("unsucessful new order, message: %s code: %d", result.Message, result.Code)
return 0, fmt.Errorf("unsuccessful new order, message: %s code: %d", result.Message, result.Code)
}
newOrderID, err := strconv.ParseInt(result.ID, 10, 64)
if err != nil {
@@ -252,7 +253,7 @@ func (z *ZB) GetSpotKline(arg KlinesRequestParams) (KLineResponse, error) {
return res, errors.New("zb rawKlines unmarshal failed")
}
for _, k := range rawKlineDatas {
ot, err := common.TimeFromUnixTimestampFloat(k[0])
ot, err := convert.TimeFromUnixTimestampFloat(k[0])
if err != nil {
return res, errors.New("zb cannot parse Kline.OpenTime")
}

View File

@@ -5,6 +5,7 @@ import (
"fmt"
"net/http"
"net/url"
"strings"
"time"
"github.com/gorilla/websocket"
@@ -89,7 +90,7 @@ func (z *ZB) WsHandleData() {
continue
}
switch {
case common.StringContains(result.Channel, "markets"):
case strings.Contains(result.Channel, "markets"):
if !result.Success {
z.Websocket.DataHandler <- fmt.Errorf("zb_websocket.go error - unsuccessful market response %s", wsErrCodes[result.Code])
continue
@@ -102,8 +103,8 @@ func (z *ZB) WsHandleData() {
continue
}
case common.StringContains(result.Channel, "ticker"):
cPair := common.SplitStrings(result.Channel, "_")
case strings.Contains(result.Channel, "ticker"):
cPair := strings.Split(result.Channel, "_")
var ticker WsTicker
@@ -123,7 +124,7 @@ func (z *ZB) WsHandleData() {
LowPrice: ticker.Data.Low,
}
case common.StringContains(result.Channel, "depth"):
case strings.Contains(result.Channel, "depth"):
var depth WsDepth
err := common.JSONDecode(resp.Raw, &depth)
if err != nil {
@@ -149,7 +150,7 @@ func (z *ZB) WsHandleData() {
})
}
channelInfo := common.SplitStrings(result.Channel, "_")
channelInfo := strings.Split(result.Channel, "_")
cPair := currency.NewPairFromString(channelInfo[0])
var newOrderBook orderbook.Base
@@ -172,7 +173,7 @@ func (z *ZB) WsHandleData() {
Exchange: z.GetName(),
}
case common.StringContains(result.Channel, "trades"):
case strings.Contains(result.Channel, "trades"):
var trades WsTrades
err := common.JSONDecode(resp.Raw, &trades)
if err != nil {
@@ -183,7 +184,7 @@ func (z *ZB) WsHandleData() {
// Most up to date trade
t := trades.Data[len(trades.Data)-1]
channelInfo := common.SplitStrings(result.Channel, "_")
channelInfo := strings.Split(result.Channel, "_")
cPair := currency.NewPairFromString(channelInfo[0])
z.Websocket.DataHandler <- exchange.TradeData{

View File

@@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"strconv"
"strings"
"sync"
"time"
@@ -179,7 +180,7 @@ func (z *ZB) UpdateTicker(p currency.Pair, assetType assets.AssetType) (ticker.P
}
for _, x := range z.GetEnabledPairs(assetType) {
currencySplit := common.SplitStrings(z.FormatExchangeCurrency(x, assetType).String(), "_")
currencySplit := strings.Split(z.FormatExchangeCurrency(x, assetType).String(), "_")
currency := currencySplit[0] + currencySplit[1]
var tp ticker.Price
tp.Pair = x
@@ -312,7 +313,7 @@ func (z *ZB) SubmitOrder(p currency.Pair, side exchange.OrderSide, _ exchange.Or
var params = SpotNewOrderRequestParams{
Amount: amount,
Price: price,
Symbol: common.StringToLower(p.String()),
Symbol: strings.ToLower(p.String()),
Type: oT,
}
response, err := z.SpotNewOrder(params)