Skip to content

Commit

Permalink
Fixed linter issues, fixed test deployment for auth request, added da…
Browse files Browse the repository at this point in the history
…ta types for error returns for Liqui Exchange.
  • Loading branch information
shazbert committed Feb 26, 2018
1 parent bfdb6ba commit 5dc8ddf
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 67 deletions.
28 changes: 18 additions & 10 deletions exchanges/liqui/liqui.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ func (l *Liqui) Setup(exch config.ExchangeConfig) {

// GetFee returns a fee for a specific currency
func (l *Liqui) GetFee(currency string) (float64, error) {
log.Println(l.Info.Pairs)
val, ok := l.Info.Pairs[common.StringToLower(currency)]
if !ok {
return 0, errors.New("currency does not exist")
Expand Down Expand Up @@ -124,10 +123,12 @@ func (l *Liqui) GetInfo() (Info, error) {
// currencyPair - example "eth_btc"
func (l *Liqui) GetTicker(currencyPair string) (map[string]Ticker, error) {
type Response struct {
Data map[string]Ticker
Data map[string]Ticker
Success int `json:"success"`
Error string `json:"error"`
}

response := Response{}
response := Response{Data: make(map[string]Ticker)}
req := fmt.Sprintf("%s/%s/%s/%s", liquiAPIPublicURL, liquiAPIPublicVersion, liquiTicker, currencyPair)

return response.Data,
Expand All @@ -139,10 +140,12 @@ func (l *Liqui) GetTicker(currencyPair string) (map[string]Ticker, error) {
// displayed (150 by default). Is set to less than 2000.
func (l *Liqui) GetDepth(currencyPair string) (Orderbook, error) {
type Response struct {
Data map[string]Orderbook
Data map[string]Orderbook
Success int `json:"success"`
Error string `json:"error"`
}

response := Response{}
response := Response{Data: make(map[string]Orderbook)}
req := fmt.Sprintf("%s/%s/%s/%s", liquiAPIPublicURL, liquiAPIPublicVersion, liquiDepth, currencyPair)

return response.Data[currencyPair],
Expand All @@ -154,10 +157,12 @@ func (l *Liqui) GetDepth(currencyPair string) (Orderbook, error) {
// displayed (150 by default). The maximum allowable value is 2000.
func (l *Liqui) GetTrades(currencyPair string) ([]Trades, error) {
type Response struct {
Data map[string][]Trades
Data map[string][]Trades
Success int `json:"success"`
Error string `json:"error"`
}

response := Response{}
response := Response{Data: make(map[string][]Trades)}
req := fmt.Sprintf("%s/%s/%s/%s", liquiAPIPublicURL, liquiAPIPublicVersion, liquiTrades, currencyPair)

return response.Data[currencyPair],
Expand Down Expand Up @@ -190,19 +195,21 @@ func (l *Liqui) Trade(pair, orderType string, amount, price float64) (float64, e

// GetActiveOrders returns the list of your active orders.
func (l *Liqui) GetActiveOrders(pair string) (map[string]ActiveOrders, error) {
result := make(map[string]ActiveOrders)

req := url.Values{}
req.Add("pair", pair)

var result map[string]ActiveOrders
return result, l.SendAuthenticatedHTTPRequest(liquiActiveOrders, req, &result)
}

// GetOrderInfo returns the information on particular order.
func (l *Liqui) GetOrderInfo(OrderID int64) (map[string]OrderInfo, error) {
result := make(map[string]OrderInfo)

req := url.Values{}
req.Add("order_id", strconv.FormatInt(OrderID, 10))

var result map[string]OrderInfo
return result, l.SendAuthenticatedHTTPRequest(liquiOrderInfo, req, &result)
}

Expand All @@ -223,11 +230,12 @@ func (l *Liqui) CancelOrder(OrderID int64) (bool, error) {

// GetTradeHistory returns trade history
func (l *Liqui) GetTradeHistory(vals url.Values, pair string) (map[string]TradeHistory, error) {
result := make(map[string]TradeHistory)

if pair != "" {
vals.Add("pair", pair)
}

var result map[string]TradeHistory
return result, l.SendAuthenticatedHTTPRequest(liquiTradeHistory, vals, &result)
}

Expand Down
92 changes: 45 additions & 47 deletions exchanges/liqui/liqui_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package liqui

import (
"log"
"net/url"
"testing"

Expand Down Expand Up @@ -34,92 +35,89 @@ func TestSetup(t *testing.T) {
}

func TestGetFee(t *testing.T) {
t.Parallel()
_, err := l.GetFee("usd")
if err == nil {
t.Error("Test Failed - liqui GetFee() error", err)
}
}

func TestGetAvailablePairs(t *testing.T) {
t.Parallel()
v := l.GetAvailablePairs(false)
if len(v) != 0 {
t.Error("Test Failed - liqui GetFee() error")
}
}

func TestGetInfo(t *testing.T) {
t.Parallel()
_, err := l.GetInfo()
if err != nil {
t.Error("Test Failed - liqui GetInfo() error", err)
}
}

func TestGetTicker(t *testing.T) {
t.Parallel()
_, err := l.GetTicker("eth_btc")
if err != nil {
t.Error("Test Failed - liqui GetTicker() error", err)
}
}

func TestGetDepth(t *testing.T) {
_, err := l.GetDepth("eth_btc")
t.Parallel()
v, err := l.GetDepth("eth_btc")
if err != nil {
t.Error("Test Failed - liqui GetDepth() error", err)
}
log.Println(v)
}

func TestGetTrades(t *testing.T) {
t.Parallel()
_, err := l.GetTrades("eth_btc")
if err != nil {
t.Error("Test Failed - liqui GetTrades() error", err)
}
}

func TestGetAccountInfo(t *testing.T) {
_, err := l.GetAccountInfo()
if err == nil {
t.Error("Test Failed - liqui GetAccountInfo() error", err)
}
}

func TestTrade(t *testing.T) {
_, err := l.Trade("", "", 0, 1)
if err == nil {
t.Error("Test Failed - liqui Trade() error", err)
}
}

func TestGetActiveOrders(t *testing.T) {
_, err := l.GetActiveOrders("eth_btc")
if err == nil {
t.Error("Test Failed - liqui GetActiveOrders() error", err)
}
}

func TestGetOrderInfo(t *testing.T) {
_, err := l.GetOrderInfo(1337)
if err == nil {
t.Error("Test Failed - liqui GetOrderInfo() error", err)
}
}

func TestCancelOrder(t *testing.T) {
_, err := l.CancelOrder(1337)
if err == nil {
t.Error("Test Failed - liqui CancelOrder() error", err)
}
}

func TestGetTradeHistory(t *testing.T) {
_, err := l.GetTradeHistory(url.Values{}, "")
if err == nil {
t.Error("Test Failed - liqui GetTradeHistory() error", err)
}
}

func TestWithdrawCoins(t *testing.T) {
_, err := l.WithdrawCoins("btc", 1337, "someaddr")
if err == nil {
t.Error("Test Failed - liqui WithdrawCoins() error", err)
func TestAuthRequests(t *testing.T) {
if l.APIKey != "" && l.APISecret != "" {
_, err := l.GetAccountInfo()
if err == nil {
t.Error("Test Failed - liqui GetAccountInfo() error", err)
}

_, err = l.Trade("", "", 0, 1)
if err == nil {
t.Error("Test Failed - liqui Trade() error", err)
}

_, err = l.GetActiveOrders("eth_btc")
if err == nil {
t.Error("Test Failed - liqui GetActiveOrders() error", err)
}

_, err = l.GetOrderInfo(1337)
if err == nil {
t.Error("Test Failed - liqui GetOrderInfo() error", err)
}

_, err = l.CancelOrder(1337)
if err == nil {
t.Error("Test Failed - liqui CancelOrder() error", err)
}

_, err = l.GetTradeHistory(url.Values{}, "")
if err == nil {
t.Error("Test Failed - liqui GetTradeHistory() error", err)
}

_, err = l.WithdrawCoins("btc", 1337, "someaddr")
if err == nil {
t.Error("Test Failed - liqui WithdrawCoins() error", err)
}
}
}
34 changes: 25 additions & 9 deletions exchanges/liqui/liqui_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ package liqui
type Info struct {
ServerTime int64 `json:"server_time"`
Pairs map[string]PairData `json:"pairs"`
Success int `json:"success"`
Error string `json:"error"`
}

// PairData is a sub-type for Info
Expand All @@ -18,15 +20,15 @@ type PairData struct {

// Ticker contains ticker information
type Ticker struct {
High float64
Low float64
Avg float64
Vol float64
Vol_cur float64
Last float64
Buy float64
Sell float64
Updated int64
High float64
Low float64
Avg float64
Vol float64
VolumeCurrency float64
Last float64
Buy float64
Sell float64
Updated int64
}

// Orderbook references both ask and bid sides
Expand Down Expand Up @@ -55,6 +57,8 @@ type AccountInfo struct {
ServerTime float64 `json:"server_time"`
TransactionCount int `json:"transaction_count"`
OpenOrders int `json:"open_orders"`
Success int `json:"success"`
Error string `json:"error"`
}

// ActiveOrders holds active order information
Expand All @@ -65,6 +69,8 @@ type ActiveOrders struct {
Rate float64 `json:"rate"`
TimestampCreated float64 `json:"time_created"`
Status int `json:"status"`
Success int `json:"success"`
Error string `json:"error"`
}

// OrderInfo holds specific order information
Expand All @@ -76,12 +82,16 @@ type OrderInfo struct {
Rate float64 `json:"rate"`
TimestampCreated float64 `json:"time_created"`
Status int `json:"status"`
Success int `json:"success"`
Error string `json:"error"`
}

// CancelOrder holds cancelled order information
type CancelOrder struct {
OrderID float64 `json:"order_id"`
Funds map[string]float64 `json:"funds"`
Success int `json:"success"`
Error string `json:"error"`
}

// Trade holds trading information
Expand All @@ -90,6 +100,8 @@ type Trade struct {
Remains float64 `json:"remains"`
OrderID float64 `json:"order_id"`
Funds map[string]float64 `json:"funds"`
Success int `json:"success"`
Error string `json:"error"`
}

// TradeHistory contains trade history data
Expand All @@ -101,6 +113,8 @@ type TradeHistory struct {
OrderID float64 `json:"order_id"`
MyOrder int `json:"is_your_order"`
Timestamp float64 `json:"timestamp"`
Success int `json:"success"`
Error string `json:"error"`
}

// Response is a generalized return type
Expand All @@ -115,4 +129,6 @@ type WithdrawCoins struct {
TID int64 `json:"tId"`
AmountSent float64 `json:"amountSent"`
Funds map[string]float64 `json:"funds"`
Success int `json:"success"`
Error string `json:"error"`
}
2 changes: 1 addition & 1 deletion exchanges/liqui/liqui_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (l *Liqui) UpdateTicker(p pair.CurrencyPair, assetType string) (ticker.Pric
tp.Bid = result[currency].Buy
tp.Last = result[currency].Last
tp.Low = result[currency].Low
tp.Volume = result[currency].Vol_cur
tp.Volume = result[currency].VolumeCurrency
ticker.ProcessTicker(l.Name, x, tp, assetType)
}

Expand Down

0 comments on commit 5dc8ddf

Please sign in to comment.