From 6e06d18b1836ee8961abf2270939bc287a95aaf6 Mon Sep 17 00:00:00 2001 From: Adrian Gallagher Date: Fri, 26 Feb 2021 10:20:02 +1100 Subject: [PATCH] Bugfix: Fix LocalBitcoins orderbook path issue (#636) * Fix LBTC path issue * Add t.Parallel() * Adjust bittrex withdrawal fee --- exchanges/localbitcoins/localbitcoins.go | 58 +- exchanges/localbitcoins/localbitcoins_test.go | 15 + .../localbitcoins/localbitcoins.json | 1275 +++++++++++++++++ 3 files changed, 1320 insertions(+), 28 deletions(-) diff --git a/exchanges/localbitcoins/localbitcoins.go b/exchanges/localbitcoins/localbitcoins.go index a407de47021..6a509b84940 100644 --- a/exchanges/localbitcoins/localbitcoins.go +++ b/exchanges/localbitcoins/localbitcoins.go @@ -67,6 +67,8 @@ const ( localbitcoinsAPIBitcoincharts = "/bitcoincharts/" localbitcoinsAPICashBuy = "/buy-bitcoins-with-cash/" localbitcoinsAPIOnlineBuy = "/buy-bitcoins-online/" + localbitcoinsAPIOrderbook = "/orderbook.json" + localbitcoinsAPITrades = "/trades.json" // Trade Types tradeTypeLocalSell = "LOCAL_SELL" @@ -672,7 +674,8 @@ func (l *LocalBitcoins) GetTradableCurrencies() ([]string, error) { // GetTrades returns all closed trades in online buy and online sell categories, // updated every 15 minutes. func (l *LocalBitcoins) GetTrades(currency string, values url.Values) ([]Trade, error) { - path := common.EncodeURLValues(fmt.Sprintf("%s%s/trades.json", localbitcoinsAPIBitcoincharts, currency), values) + endpoint := localbitcoinsAPIBitcoincharts + currency + localbitcoinsAPITrades + path := common.EncodeURLValues(endpoint, values) var result []Trade return result, l.SendHTTPRequest(exchange.RestSpot, path, &result, request.Unset) } @@ -683,49 +686,42 @@ func (l *LocalBitcoins) GetTrades(currency string, values url.Values) ([]Trade, // entered by the ad author. func (l *LocalBitcoins) GetOrderbook(currency string) (Orderbook, error) { type response struct { - Bids [][]string `json:"bids"` - Asks [][]string `json:"asks"` + Bids [][2]string `json:"bids"` + Asks [][2]string `json:"asks"` } - path := fmt.Sprintf("%s/%s/orderbook.json", localbitcoinsAPIBitcoincharts, currency+"/orderbook.json") + path := localbitcoinsAPIBitcoincharts + currency + localbitcoinsAPIOrderbook resp := response{} - err := l.SendHTTPRequest(exchange.RestSpot, path, &resp, orderBookLimiter) - - if err != nil { - return Orderbook{}, err + var ob Orderbook + if err := l.SendHTTPRequest(exchange.RestSpot, path, &resp, orderBookLimiter); err != nil { + return ob, err } - orderbook := Orderbook{} - - for _, x := range resp.Bids { - price, err := strconv.ParseFloat(x[0], 64) + for x := range resp.Bids { + price, err := strconv.ParseFloat(resp.Bids[x][0], 64) if err != nil { - log.Error(log.ExchangeSys, err) - continue + return ob, err } - amount, err := strconv.ParseFloat(x[1], 64) + amount, err := strconv.ParseFloat(resp.Bids[x][1], 64) if err != nil { - log.Error(log.ExchangeSys, err) - continue + return ob, err } - orderbook.Bids = append(orderbook.Bids, Price{price, amount}) + ob.Bids = append(ob.Bids, Price{price, amount}) } - for _, x := range resp.Asks { - price, err := strconv.ParseFloat(x[0], 64) + for x := range resp.Asks { + price, err := strconv.ParseFloat(resp.Asks[x][0], 64) if err != nil { - log.Error(log.ExchangeSys, err) - continue + return ob, err } - amount, err := strconv.ParseFloat(x[1], 64) + amount, err := strconv.ParseFloat(resp.Asks[x][1], 64) if err != nil { - log.Error(log.ExchangeSys, err) - continue + return ob, err } - orderbook.Asks = append(orderbook.Asks, Price{price, amount}) + ob.Asks = append(ob.Asks, Price{price, amount}) } - return orderbook, nil + return ob, nil } // SendHTTPRequest sends an unauthenticated HTTP request @@ -768,7 +764,13 @@ func (l *LocalBitcoins) SendAuthenticatedHTTPRequest(ep exchange.URL, method, pa headers["Content-Type"] = "application/x-www-form-urlencoded" if l.Verbose { - log.Debugf(log.ExchangeSys, "Sending POST request to `%s`, path: `%s`, params: `%s`.", endpoint, path, encoded) + log.Debugf(log.ExchangeSys, "%s Sending `%s` request to `%s`, path: `%s`, params: `%s`.", + l.Name, + method, + endpoint, + path, + encoded, + ) } if method == http.MethodGet && len(encoded) > 0 { diff --git a/exchanges/localbitcoins/localbitcoins_test.go b/exchanges/localbitcoins/localbitcoins_test.go index 0e5697f04c6..8acdc7335ef 100644 --- a/exchanges/localbitcoins/localbitcoins_test.go +++ b/exchanges/localbitcoins/localbitcoins_test.go @@ -96,12 +96,27 @@ func setFeeBuilder() *exchange.FeeBuilder { } func TestGetTrades(t *testing.T) { + t.Parallel() _, err := l.GetTrades("LTC", nil) if err != nil { t.Error(err) } } +func TestGetOrderbook(t *testing.T) { + t.Parallel() + ob, err := l.GetOrderbook("AUD") + if err != nil { + t.Fatal(err) + } + if mockTests { + if ob.Bids[0].Price != 88781.42 && ob.Bids[0].Amount != 10000.00 || + ob.Asks[0].Price != 14400.00 && ob.Asks[0].Amount != 0.77 { + t.Error("incorrect orderbook values") + } + } +} + // TestGetFeeByTypeOfflineTradeFee logic test func TestGetFeeByTypeOfflineTradeFee(t *testing.T) { t.Parallel() diff --git a/testdata/http_mock/localbitcoins/localbitcoins.json b/testdata/http_mock/localbitcoins/localbitcoins.json index 4c893e81399..2aa0fe00bbe 100644 --- a/testdata/http_mock/localbitcoins/localbitcoins.json +++ b/testdata/http_mock/localbitcoins/localbitcoins.json @@ -3396,6 +3396,1281 @@ } ] }, + "/bitcoincharts/AUD/orderbook.json": { + "GET": [ + { + "data": { + "asks": [ + [ + "14400.00", + "0.77" + ], + [ + "15900.00", + "0.85" + ], + [ + "45200.00", + "385.00" + ], + [ + "61896.90", + "9800.00" + ], + [ + "63147.35", + "4402.63" + ], + [ + "63147.35", + "11.38" + ], + [ + "63772.57", + "7.82" + ], + [ + "63772.57", + "7.82" + ], + [ + "63835.09", + "7.17" + ], + [ + "64022.65", + "22.35" + ], + [ + "64085.18", + "100.00" + ], + [ + "64085.18", + "1018.37" + ], + [ + "64116.44", + "200.00" + ], + [ + "64210.22", + "1.23" + ], + [ + "64397.79", + "3.50" + ], + [ + "64397.79", + "138.55" + ], + [ + "64397.79", + "138.55" + ], + [ + "64397.79", + "0.77" + ], + [ + "64397.79", + "1287.95" + ], + [ + "64397.79", + "6879.09" + ], + [ + "64397.79", + "0.37" + ], + [ + "64772.92", + "3889.05" + ], + [ + "64897.96", + "500.00" + ], + [ + "65011.26", + "47154.43" + ], + [ + "65016.76", + "47158.42" + ], + [ + "65022.96", + "47162.92" + ], + [ + "65023.01", + "500.00" + ], + [ + "65023.01", + "600.00" + ], + [ + "65023.01", + "1033.28" + ], + [ + "65023.01", + "1033.28" + ], + [ + "65023.01", + "20000.00" + ], + [ + "65178.97", + "2000.00" + ], + [ + "65178.97", + "10000.00" + ], + [ + "65178.97", + "30000.00" + ], + [ + "65273.10", + "100.00" + ], + [ + "65648.23", + "50.00" + ], + [ + "65648.23", + "500.00" + ], + [ + "65648.23", + "500.00" + ], + [ + "65648.23", + "656.48" + ], + [ + "65648.23", + "3216.97" + ], + [ + "65648.26", + "3500.00" + ], + [ + "65808.72", + "30000.00" + ], + [ + "65808.72", + "2000.00" + ], + [ + "65808.72", + "9999.00" + ], + [ + "65808.72", + "10000.00" + ], + [ + "65898.35", + "2999.00" + ], + [ + "65960.84", + "1319.21" + ], + [ + "65960.84", + "1000.00" + ], + [ + "65960.84", + "9000.00" + ], + [ + "66200.00", + "7944.00" + ], + [ + "66273.45", + "500.00" + ], + [ + "66273.45", + "11.38" + ], + [ + "66273.45", + "650.00" + ], + [ + "66523.57", + "1999.00" + ], + [ + "66586.06", + "2000.00" + ], + [ + "66586.06", + "18.95" + ], + [ + "66598.57", + "1000.00" + ], + [ + "66733.00", + "2000.00" + ], + [ + "66733.50", + "5000.00" + ], + [ + "66898.00", + "3000.00" + ], + [ + "66898.00", + "3000.00" + ], + [ + "66898.00", + "3344.90" + ], + [ + "66898.00", + "3000.00" + ], + [ + "66898.67", + "500.00" + ], + [ + "66898.67", + "13379.73" + ], + [ + "66898.67", + "100.00" + ], + [ + "67148.79", + "999.00" + ], + [ + "67523.89", + "20.00" + ], + [ + "67523.89", + "500.00" + ], + [ + "67980.86", + "9469.23" + ], + [ + "67980.86", + "9469.23" + ], + [ + "67980.86", + "9469.23" + ], + [ + "67980.86", + "9469.23" + ], + [ + "67980.86", + "9469.23" + ], + [ + "68074.09", + "500.00" + ], + [ + "68080.34", + "500.00" + ], + [ + "68149.00", + "3000.00" + ], + [ + "68149.00", + "3407.45" + ], + [ + "68149.12", + "1111.00" + ], + [ + "68149.12", + "5000.00" + ], + [ + "68604.53", + "500.00" + ], + [ + "68604.53", + "1000.00" + ], + [ + "68604.53", + "500.00" + ], + [ + "68774.34", + "49883.90" + ], + [ + "68774.34", + "687.74" + ], + [ + "68774.34", + "7000.00" + ], + [ + "68774.34", + "14.05" + ], + [ + "68774.34", + "1179.41" + ], + [ + "68774.34", + "5000.00" + ], + [ + "68774.34", + "0.69" + ], + [ + "68774.34", + "144.47" + ], + [ + "68774.34", + "250.00" + ], + [ + "69399.56", + "1.04" + ], + [ + "69399.56", + "0.69" + ], + [ + "70024.78", + "4789.48" + ], + [ + "70024.78", + "3000.00" + ], + [ + "70024.78", + "15000.00" + ], + [ + "70024.78", + "200.00" + ], + [ + "70024.78", + "100.00" + ], + [ + "70024.78", + "2.74" + ], + [ + "70650.00", + "300.00" + ], + [ + "70962.61", + "5000.00" + ], + [ + "71275.22", + "1500.00" + ], + [ + "71722.92", + "1000.00" + ], + [ + "71887.94", + "237.00" + ], + [ + "71900.44", + "1003.59" + ], + [ + "71900.44", + "4.67" + ], + [ + "72213.05", + "4500.00" + ], + [ + "72463.14", + "500.00" + ], + [ + "72525.66", + "1500.00" + ], + [ + "73025.84", + "33.15" + ], + [ + "73150.88", + "731.50" + ], + [ + "73150.88", + "0.73" + ], + [ + "73776.11", + "91.55" + ], + [ + "73776.11", + "1036.85" + ], + [ + "73776.11", + "317.55" + ], + [ + "73776.11", + "0.02" + ], + [ + "73776.11", + "1036.85" + ], + [ + "73776.11", + "317.55" + ], + [ + "74401.33", + "9.23" + ], + [ + "74401.33", + "0.48" + ], + [ + "74401.33", + "1300.00" + ], + [ + "74523.23", + "1000.00" + ], + [ + "74713.94", + "4.39" + ], + [ + "74828.83", + "350.00" + ], + [ + "75026.55", + "1000.00" + ], + [ + "75026.55", + "150.00" + ], + [ + "75026.55", + "1500.00" + ], + [ + "75026.55", + "50.00" + ], + [ + "75026.55", + "2000.00" + ], + [ + "75026.55", + "104.55" + ], + [ + "75026.55", + "156.69" + ], + [ + "75026.55", + "1500.00" + ], + [ + "75651.77", + "173.12" + ], + [ + "75651.77", + "133.00" + ], + [ + "75651.77", + "136.94" + ], + [ + "75651.77", + "0.64" + ], + [ + "75651.77", + "591.34" + ], + [ + "76270.74", + "34.62" + ], + [ + "76276.99", + "130.00" + ], + [ + "76276.99", + "459.42" + ], + [ + "76276.99", + "336.54" + ], + [ + "76339.51", + "119.78" + ], + [ + "76902.21", + "932.74" + ], + [ + "76902.21", + "50.00" + ], + [ + "76902.21", + "13.00" + ], + [ + "76902.21", + "254.59" + ], + [ + "76902.21", + "346.96" + ], + [ + "76902.21", + "1.77" + ], + [ + "76902.21", + "15.00" + ], + [ + "76902.21", + "1.32" + ], + [ + "77329.78", + "129.00" + ], + [ + "77527.43", + "0.02" + ], + [ + "77527.43", + "150.00" + ], + [ + "78152.65", + "0.23" + ], + [ + "78152.65", + "8.35" + ], + [ + "78152.65", + "17000.00" + ], + [ + "78152.65", + "1000.00" + ], + [ + "78152.65", + "1000.00" + ], + [ + "78152.65", + "892.37" + ], + [ + "78152.65", + "4.39" + ], + [ + "78152.65", + "500.00" + ], + [ + "78152.65", + "1284.86" + ], + [ + "78152.65", + "600.00" + ], + [ + "78152.65", + "843.34" + ], + [ + "78152.65", + "150.00" + ], + [ + "78152.65", + "3.75" + ], + [ + "78152.65", + "8.40" + ], + [ + "78152.65", + "85.47" + ], + [ + "78152.65", + "15.96" + ], + [ + "78152.65", + "11.34" + ], + [ + "78152.65", + "2000.00" + ], + [ + "78152.65", + "1284.86" + ], + [ + "78152.65", + "110.41" + ], + [ + "78152.65", + "781.52" + ], + [ + "78777.88", + "787.77" + ], + [ + "79278.05", + "502.15" + ], + [ + "79380.00", + "9.27" + ], + [ + "79403.10", + "0.08" + ], + [ + "79500.00", + "10218.59" + ], + [ + "79716.07", + "299.00" + ], + [ + "79716.07", + "299.00" + ], + [ + "79719.30", + "299.00" + ], + [ + "80028.32", + "5.89" + ], + [ + "80653.54", + "0.17" + ], + [ + "80653.54", + "4.81" + ], + [ + "81278.76", + "1614.21" + ], + [ + "81278.76", + "5763.89" + ], + [ + "81278.76", + "324.64" + ], + [ + "81278.76", + "1287.00" + ], + [ + "81278.76", + "100.00" + ], + [ + "81278.76", + "20000.00" + ], + [ + "81278.76", + "477.53" + ], + [ + "84404.87", + "367.67" + ], + [ + "84404.87", + "5985.58" + ], + [ + "84404.87", + "1500.00" + ], + [ + "85655.31", + "5000.00" + ], + [ + "86280.53", + "3152.48" + ], + [ + "86280.53", + "0.01" + ], + [ + "89000.00", + "2500.00" + ], + [ + "93783.19", + "18756.63" + ], + [ + "93783.19", + "500.00" + ], + [ + "93783.19", + "300.00" + ], + [ + "93783.19", + "700.00" + ], + [ + "93783.19", + "347.76" + ], + [ + "98159.73", + "1500.00" + ], + [ + "99000.00", + "500.00" + ], + [ + "99410.18", + "1500.00" + ], + [ + "100035.40", + "1400.00" + ], + [ + "100035.40", + "1500.00" + ], + [ + "100660.62", + "2000.00" + ], + [ + "101285.84", + "1500.00" + ], + [ + "101285.84", + "1500.00" + ], + [ + "101285.84", + "1300.00" + ], + [ + "101911.06", + "1500.00" + ], + [ + "103161.50", + "1500.00" + ], + [ + "103161.50", + "1500.00" + ], + [ + "103786.73", + "1500.00" + ], + [ + "106287.61", + "394.12" + ], + [ + "106287.61", + "3500.00" + ], + [ + "112539.82", + "500.00" + ], + [ + "162557.52", + "500.00" + ], + [ + "162557.52", + "500.00" + ] + ], + "bids": [ + [ + "88781.42", + "10000.00" + ], + [ + "87530.97", + "2000.00" + ], + [ + "87530.97", + "2000.00" + ], + [ + "87530.97", + "1747.00" + ], + [ + "84404.87", + "1895.00" + ], + [ + "84404.87", + "2000.00" + ], + [ + "81278.76", + "2500.00" + ], + [ + "81278.76", + "314738.82" + ], + [ + "81278.76", + "2000.00" + ], + [ + "80028.32", + "10000.00" + ], + [ + "78152.65", + "37565.71" + ], + [ + "78152.65", + "2000.00" + ], + [ + "75026.55", + "3000.00" + ], + [ + "75026.55", + "254434.18" + ], + [ + "75026.55", + "249512.03" + ], + [ + "75026.55", + "292377.58" + ], + [ + "75026.55", + "22635.11" + ], + [ + "68774.34", + "309390.83" + ], + [ + "65648.23", + "100000.00" + ], + [ + "64710.40", + "6000.00" + ], + [ + "64397.79", + "6000.00" + ], + [ + "63147.35", + "1200.00" + ], + [ + "63000.00", + "55000.00" + ], + [ + "62522.12", + "30555.89" + ], + [ + "62522.12", + "20000.00" + ], + [ + "62522.12", + "58.04" + ], + [ + "62522.12", + "10000.00" + ], + [ + "62310.00", + "51000.00" + ], + [ + "62119.89", + "1000.00" + ], + [ + "61896.90", + "28329.96" + ], + [ + "61646.81", + "9000.00" + ], + [ + "61584.29", + "5000.00" + ], + [ + "61584.29", + "8000.00" + ], + [ + "61584.29", + "2000.00" + ], + [ + "61500.00", + "295.00" + ], + [ + "61466.52", + "800.00" + ], + [ + "61428.01", + "30000.00" + ], + [ + "61428.01", + "30000.00" + ], + [ + "61396.73", + "10000.00" + ], + [ + "61271.68", + "1500.00" + ], + [ + "61271.68", + "2000.00" + ], + [ + "61271.68", + "10000.00" + ], + [ + "61271.68", + "50000.00" + ], + [ + "61271.68", + "50000.00" + ], + [ + "61114.60", + "30000.00" + ], + [ + "61084.12", + "1000.00" + ], + [ + "60959.07", + "178.36" + ], + [ + "60896.55", + "1400.00" + ], + [ + "60646.46", + "10000.00" + ], + [ + "60646.46", + "55000.00" + ], + [ + "60646.46", + "1500.00" + ], + [ + "60333.85", + "2000.00" + ], + [ + "60021.24", + "4000.00" + ], + [ + "60021.24", + "2000.00" + ], + [ + "60021.24", + "60000.00" + ], + [ + "60021.24", + "2000.00" + ], + [ + "60021.24", + "10000.00" + ], + [ + "60021.24", + "10000.00" + ], + [ + "60021.24", + "3000.00" + ], + [ + "60021.24", + "20000.00" + ], + [ + "59396.02", + "2000.00" + ], + [ + "59396.02", + "10000.00" + ], + [ + "59396.02", + "13497.00" + ], + [ + "59396.02", + "100000.00" + ], + [ + "59396.02", + "9500.00" + ], + [ + "59396.02", + "21000.00" + ], + [ + "59396.02", + "500.00" + ], + [ + "59396.02", + "25000.00" + ], + [ + "58833.32", + "125000.00" + ], + [ + "58770.80", + "5000.00" + ], + [ + "58770.80", + "300.00" + ], + [ + "57378.34", + "10000.00" + ], + [ + "57378.34", + "10000.00" + ], + [ + "57378.34", + "10000.00" + ], + [ + "57378.34", + "5000.00" + ], + [ + "57145.22", + "5000.00" + ], + [ + "56957.65", + "9000.00" + ], + [ + "56764.00", + "3000.00" + ], + [ + "56269.91", + "12000.00" + ], + [ + "56269.91", + "5000.00" + ], + [ + "56269.91", + "8000.00" + ], + [ + "56269.91", + "5000.00" + ], + [ + "56143.45", + "1000.00" + ], + [ + "56132.00", + "5000.00" + ], + [ + "56131.00", + "6000.00" + ], + [ + "53637.00", + "500.00" + ], + [ + "53143.81", + "200.00" + ], + [ + "53143.81", + "800.00" + ], + [ + "53143.81", + "1600.00" + ], + [ + "50017.70", + "19630.00" + ], + [ + "50017.70", + "10000.00" + ], + [ + "20000.00", + "250.00" + ] + ] + }, + "queryString": "", + "bodyParams": "", + "headers": {} + } + ] + }, "/bitcoincharts/LTC/trades.json": { "GET": [ {