Update BTC Markets ticker/orderbook/trades code to support additional pairs

This commit is contained in:
Adrian Gallagher
2018-02-09 14:35:07 +11:00
parent c0958534de
commit 0d9d1a8da5
3 changed files with 15 additions and 9 deletions

View File

@@ -244,7 +244,7 @@
"AuthenticatedAPISupport": false,
"APIKey": "Key",
"APISecret": "Secret",
"AvailablePairs": "LTCAUD,BTCAUD",
"AvailablePairs": "LTCAUD,BTCAUD,ETHAUD,ETCAUD,XRPAUD,BCHAUD,LTCBTC,ETHBTC,ETCBTC,XRPBTC,BCHBTC",
"EnabledPairs": "LTCAUD,BTCAUD",
"BaseCurrencies": "AUD",
"AssetTypes": "SPOT",

View File

@@ -92,9 +92,10 @@ func (b *BTCMarkets) GetFee() float64 {
// GetTicker returns a ticker
// symbol - example "btc" or "ltc"
func (b *BTCMarkets) GetTicker(symbol string) (Ticker, error) {
func (b *BTCMarkets) GetTicker(firstPair, secondPair string) (Ticker, error) {
ticker := Ticker{}
path := fmt.Sprintf("/market/%s/AUD/tick", common.StringToUpper(symbol))
path := fmt.Sprintf("/market/%s/%s/tick", common.StringToUpper(firstPair),
common.StringToUpper(secondPair))
return ticker,
common.SendHTTPGetRequest(btcMarketsAPIURL+path, true, b.Verbose, &ticker)
@@ -102,9 +103,10 @@ func (b *BTCMarkets) GetTicker(symbol string) (Ticker, error) {
// GetOrderbook returns current orderbook
// symbol - example "btc" or "ltc"
func (b *BTCMarkets) GetOrderbook(symbol string) (Orderbook, error) {
func (b *BTCMarkets) GetOrderbook(firstPair, secondPair string) (Orderbook, error) {
orderbook := Orderbook{}
path := fmt.Sprintf("/market/%s/AUD/orderbook", common.StringToUpper(symbol))
path := fmt.Sprintf("/market/%s/%s/orderbook", common.StringToUpper(firstPair),
common.StringToUpper(secondPair))
return orderbook,
common.SendHTTPGetRequest(btcMarketsAPIURL+path, true, b.Verbose, &orderbook)
@@ -113,9 +115,11 @@ func (b *BTCMarkets) GetOrderbook(symbol string) (Orderbook, error) {
// GetTrades returns executed trades on the exchange
// symbol - example "btc" or "ltc"
// values - optional paramater "since" example values.Set(since, "59868345231")
func (b *BTCMarkets) GetTrades(symbol string, values url.Values) ([]Trade, error) {
func (b *BTCMarkets) GetTrades(firstPair, secondPair string, values url.Values) ([]Trade, error) {
trades := []Trade{}
path := common.EncodeURLValues(fmt.Sprintf("%s/market/%s/AUD/trades", btcMarketsAPIURL, symbol), values)
path := common.EncodeURLValues(fmt.Sprintf("%s/market/%s/%s/trades",
btcMarketsAPIURL, common.StringToUpper(firstPair),
common.StringToUpper(secondPair)), values)
return trades, common.SendHTTPGetRequest(path, true, b.Verbose, &trades)
}

View File

@@ -53,7 +53,8 @@ func (b *BTCMarkets) Run() {
// UpdateTicker updates and returns the ticker for a currency pair
func (b *BTCMarkets) UpdateTicker(p pair.CurrencyPair, assetType string) (ticker.Price, error) {
var tickerPrice ticker.Price
tick, err := b.GetTicker(p.GetFirstCurrency().String())
tick, err := b.GetTicker(p.GetFirstCurrency().String(),
p.GetSecondCurrency().String())
if err != nil {
return tickerPrice, err
}
@@ -86,7 +87,8 @@ func (b *BTCMarkets) GetOrderbookEx(p pair.CurrencyPair, assetType string) (orde
// UpdateOrderbook updates and returns the orderbook for a currency pair
func (b *BTCMarkets) UpdateOrderbook(p pair.CurrencyPair, assetType string) (orderbook.Base, error) {
var orderBook orderbook.Base
orderbookNew, err := b.GetOrderbook(p.GetFirstCurrency().String())
orderbookNew, err := b.GetOrderbook(p.GetFirstCurrency().String(),
p.GetSecondCurrency().String())
if err != nil {
return orderBook, err
}