mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-13 23:16:45 +00:00
Use common EncodeURLValues function where possible
This commit is contained in:
@@ -255,13 +255,8 @@ func (b *Bitfinex) Run() {
|
||||
}
|
||||
|
||||
func (b *Bitfinex) GetTicker(symbol string, values url.Values) (BitfinexTicker, error) {
|
||||
path := BITFINEX_API_URL + BITFINEX_TICKER + symbol
|
||||
path := EncodeURLValues(BITFINEX_API_URL+BITFINEX_TICKER+symbol, values)
|
||||
response := BitfinexTicker{}
|
||||
|
||||
if len(values) > 0 {
|
||||
path += "?" + values.Encode()
|
||||
}
|
||||
|
||||
err := SendHTTPGetRequest(path, true, &response)
|
||||
if err != nil {
|
||||
return response, err
|
||||
@@ -292,13 +287,8 @@ func (b *Bitfinex) GetStats(symbol string) (BitfinexStats, error) {
|
||||
}
|
||||
|
||||
func (b *Bitfinex) GetLendbook(symbol string, values url.Values) (BitfinexLendbook, error) {
|
||||
path := BITFINEX_API_URL + BITFINEX_LENDBOOK + symbol
|
||||
path := EncodeURLValues(BITFINEX_API_URL+BITFINEX_LENDBOOK+symbol, values)
|
||||
response := BitfinexLendbook{}
|
||||
|
||||
if len(values) > 0 {
|
||||
path += "?" + values.Encode()
|
||||
}
|
||||
|
||||
err := SendHTTPGetRequest(path, true, &response)
|
||||
if err != nil {
|
||||
return response, err
|
||||
@@ -307,13 +297,8 @@ func (b *Bitfinex) GetLendbook(symbol string, values url.Values) (BitfinexLendbo
|
||||
}
|
||||
|
||||
func (b *Bitfinex) GetOrderbook(symbol string, values url.Values) (BitfinexOrderbook, error) {
|
||||
path := BITFINEX_API_URL + BITFINEX_ORDERBOOK + symbol
|
||||
path := EncodeURLValues(BITFINEX_API_URL+BITFINEX_ORDERBOOK+symbol, values)
|
||||
response := BitfinexOrderbook{}
|
||||
|
||||
if len(values) > 0 {
|
||||
path += "?" + values.Encode()
|
||||
}
|
||||
|
||||
err := SendHTTPGetRequest(path, true, &response)
|
||||
if err != nil {
|
||||
return response, err
|
||||
@@ -322,13 +307,8 @@ func (b *Bitfinex) GetOrderbook(symbol string, values url.Values) (BitfinexOrder
|
||||
}
|
||||
|
||||
func (b *Bitfinex) GetTrades(symbol string, values url.Values) ([]BitfinexTradeStructure, error) {
|
||||
path := BITFINEX_API_URL + BITFINEX_TRADES + symbol
|
||||
path := EncodeURLValues(BITFINEX_API_URL+BITFINEX_TRADES+symbol, values)
|
||||
response := []BitfinexTradeStructure{}
|
||||
|
||||
if len(values) > 0 {
|
||||
path += "?" + values.Encode()
|
||||
}
|
||||
|
||||
err := SendHTTPGetRequest(path, true, &response)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -344,13 +324,8 @@ type BitfinexLends struct {
|
||||
}
|
||||
|
||||
func (b *Bitfinex) GetLends(symbol string, values url.Values) ([]BitfinexLends, error) {
|
||||
path := BITFINEX_API_URL + BITFINEX_LENDS + symbol
|
||||
path := EncodeURLValues(BITFINEX_API_URL+BITFINEX_LENDS+symbol, values)
|
||||
response := []BitfinexLends{}
|
||||
|
||||
if len(values) > 0 {
|
||||
path += "?" + values.Encode()
|
||||
}
|
||||
|
||||
err := SendHTTPGetRequest(path, true, &response)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -262,17 +262,9 @@ func (b *Bitstamp) GetOrderbook() (BitstampOrderbook, error) {
|
||||
}
|
||||
|
||||
func (b *Bitstamp) GetTransactions(values url.Values) ([]BitstampTransactions, error) {
|
||||
path := EncodeURLValues(BITSTAMP_API_URL+BITSTAMP_API_TRANSACTIONS, values)
|
||||
transactions := []BitstampTransactions{}
|
||||
path := BITSTAMP_API_URL + BITSTAMP_API_TRANSACTIONS
|
||||
|
||||
if len(values) > 0 {
|
||||
path += "?" + values.Encode()
|
||||
}
|
||||
|
||||
log.Println(path)
|
||||
|
||||
err := SendHTTPGetRequest(path, true, &transactions)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -274,11 +274,7 @@ func (b *BTCC) GetTradeHistory(symbol string, limit, sinceTid int64, time time.T
|
||||
v.Set("sincetype", strconv.FormatInt(time.Unix(), 10))
|
||||
}
|
||||
|
||||
values := v.Encode()
|
||||
if len(values) > 0 {
|
||||
req += "?" + values
|
||||
}
|
||||
|
||||
req = EncodeURLValues(req, v)
|
||||
err := SendHTTPGetRequest(req, true, nil)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
|
||||
@@ -366,13 +366,7 @@ func (c *Coinbase) GetHistoricRates(symbol string, start, end, granularity int64
|
||||
values.Set("granularity", strconv.FormatInt(granularity, 10))
|
||||
}
|
||||
|
||||
path := fmt.Sprintf("%s/%s/%s", COINBASE_API_URL+COINBASE_PRODUCTS, symbol, COINBASE_HISTORY)
|
||||
encoded := values.Encode()
|
||||
|
||||
if len(encoded) > 0 {
|
||||
path += encoded
|
||||
}
|
||||
|
||||
path := EncodeURLValues(fmt.Sprintf("%s/%s/%s", COINBASE_API_URL+COINBASE_PRODUCTS, symbol, COINBASE_HISTORY), values)
|
||||
err := SendHTTPGetRequest(path, true, &history)
|
||||
|
||||
if err != nil {
|
||||
@@ -521,12 +515,7 @@ type CoinbaseOrdersResponse struct {
|
||||
}
|
||||
|
||||
func (c *Coinbase) GetOrders(params url.Values) ([]CoinbaseOrdersResponse, error) {
|
||||
path := COINBASE_API_URL + COINBASE_ORDERS
|
||||
|
||||
if len(params) > 0 {
|
||||
path += "?" + params.Encode()
|
||||
}
|
||||
|
||||
path := EncodeURLValues(COINBASE_API_URL+COINBASE_ORDERS, params)
|
||||
resp := []CoinbaseOrdersResponse{}
|
||||
err := c.SendAuthenticatedHTTPRequest("GET", path, nil, &resp)
|
||||
if err != nil {
|
||||
@@ -574,18 +563,12 @@ type CoinbaseFillResponse struct {
|
||||
}
|
||||
|
||||
func (c *Coinbase) GetFills(params url.Values) ([]CoinbaseFillResponse, error) {
|
||||
path := COINBASE_API_URL + COINBASE_FILLS
|
||||
|
||||
if len(params) > 0 {
|
||||
path += "?" + params.Encode()
|
||||
}
|
||||
|
||||
path := EncodeURLValues(COINBASE_API_URL+COINBASE_FILLS, params)
|
||||
resp := []CoinbaseFillResponse{}
|
||||
err := c.SendAuthenticatedHTTPRequest("GET", path, nil, &resp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -177,13 +177,8 @@ func (g *Gemini) GetSymbols() ([]string, error) {
|
||||
}
|
||||
|
||||
func (g *Gemini) GetOrderbook(currency string, params url.Values) (GeminiOrderbook, error) {
|
||||
path := EncodeURLValues(fmt.Sprintf("%s/v%s/%s/%s", GEMINI_API_URL, GEMINI_API_VERSION, GEMINI_ORDERBOOK, currency), params)
|
||||
orderbook := GeminiOrderbook{}
|
||||
path := fmt.Sprintf("%s/v%s/%s/%s", GEMINI_API_URL, GEMINI_API_VERSION, GEMINI_ORDERBOOK, currency)
|
||||
|
||||
if params.Encode() != "" {
|
||||
path += "?" + params.Encode()
|
||||
}
|
||||
|
||||
err := SendHTTPGetRequest(path, true, &orderbook)
|
||||
if err != nil {
|
||||
return GeminiOrderbook{}, err
|
||||
@@ -193,13 +188,8 @@ func (g *Gemini) GetOrderbook(currency string, params url.Values) (GeminiOrderbo
|
||||
}
|
||||
|
||||
func (g *Gemini) GetTrades(currency string, params url.Values) ([]GeminiTrade, error) {
|
||||
path := EncodeURLValues(fmt.Sprintf("%s/v%s/%s/%s", GEMINI_API_URL, GEMINI_API_VERSION, GEMINI_TRADES, currency), params)
|
||||
trades := []GeminiTrade{}
|
||||
path := fmt.Sprintf("%s/v%s/%s/%s", GEMINI_API_URL, GEMINI_API_VERSION, GEMINI_TRADES, currency)
|
||||
|
||||
if params.Encode() != "" {
|
||||
path += "?" + params.Encode()
|
||||
}
|
||||
|
||||
err := SendHTTPGetRequest(path, true, &trades)
|
||||
if err != nil {
|
||||
return []GeminiTrade{}, err
|
||||
|
||||
14
itbithttp.go
14
itbithttp.go
@@ -190,12 +190,7 @@ func (i *ItBit) GetWalletBalance(walletID, currency string) {
|
||||
}
|
||||
|
||||
func (i *ItBit) GetWalletTrades(walletID string, params url.Values) {
|
||||
path := "/wallets/" + walletID + "/trades"
|
||||
|
||||
if len(params) > 0 {
|
||||
path += "?" + params.Encode()
|
||||
}
|
||||
|
||||
path := EncodeURLValues("/wallets/"+walletID+"/trades", params)
|
||||
err := i.SendAuthenticatedHTTPRequest("GET", path, nil)
|
||||
|
||||
if err != nil {
|
||||
@@ -204,12 +199,7 @@ func (i *ItBit) GetWalletTrades(walletID string, params url.Values) {
|
||||
}
|
||||
|
||||
func (i *ItBit) GetWalletOrders(walletID string, params url.Values) {
|
||||
path := "/wallets/" + walletID + "/orders"
|
||||
|
||||
if len(params) > 0 {
|
||||
path += "?" + params.Encode()
|
||||
}
|
||||
|
||||
path := EncodeURLValues("/wallets/"+walletID+"/orders", params)
|
||||
err := i.SendAuthenticatedHTTPRequest("GET", path, nil)
|
||||
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user