diff --git a/alphapointhttp.go b/alphapointhttp.go index fef2333f..a20334d1 100644 --- a/alphapointhttp.go +++ b/alphapointhttp.go @@ -203,6 +203,19 @@ func (a *Alphapoint) GetTicker(symbol string) (AlphapointTicker, error) { return response, nil } +func (a *Alphapoint) GetTickerPrice(currency string) TickerPrice { + var tickerPrice TickerPrice + ticker, err := a.GetTicker(currency) + if err != nil { + log.Println(err) + return TickerPrice{} + } + tickerPrice.Ask = ticker.Ask + tickerPrice.Bid = ticker.Bid + + return tickerPrice +} + func (a *Alphapoint) GetTrades(symbol string, startIndex, count int) (AlphapointTrades, error) { request := make(map[string]interface{}) request["ins"] = symbol diff --git a/anxhttp.go b/anxhttp.go index 8b130d16..9e90cac7 100644 --- a/anxhttp.go +++ b/anxhttp.go @@ -188,6 +188,15 @@ func (a *ANX) GetTicker(currency string) ANXTicker { return ticker } +func (a *ANX) GetTickerPrice(currency string) TickerPrice { + var tickerPrice TickerPrice + ticker := a.GetTicker(currency) + tickerPrice.Ask = ticker.Data.Buy.Value + tickerPrice.Bid = ticker.Data.Sell.Value + + return tickerPrice +} + func (a *ANX) GetAPIKey(username, password, otp, deviceID string) (string, string) { request := make(map[string]interface{}) request["nonce"] = strconv.FormatInt(time.Now().UnixNano(), 10)[0:13] diff --git a/anxroutes.go b/anxroutes.go deleted file mode 100644 index 18e089c7..00000000 --- a/anxroutes.go +++ /dev/null @@ -1,27 +0,0 @@ -package main - -import ( - "encoding/json" - "net/http" - "github.com/gorilla/mux" -) - -func getLatestAnxTicker(w http.ResponseWriter, r *http.Request) { - vars := mux.Vars(r) - currency := vars["currency"] - response := bot.exchange.anx.GetTicker(currency) - w.Header().Set("Content-Type", "application/json; charset=UTF-8") - w.WriteHeader(http.StatusOK) - if err := json.NewEncoder(w).Encode(response); err != nil { - panic(err) - } -} - -var anxRoutes = Routes{ - Route{ - "Index", - "GET", - "/exchanges/anx/latest/{currency}", - getLatestAnxTicker, - }, -} \ No newline at end of file diff --git a/bitfinexhttp.go b/bitfinexhttp.go index 3871f5c7..ef4b1ef1 100644 --- a/bitfinexhttp.go +++ b/bitfinexhttp.go @@ -284,6 +284,20 @@ func (b *Bitfinex) GetTicker(symbol string, values url.Values) (BitfinexTicker, return response, nil } + +func (b *Bitfinex) GetTickerPrice(currency string) TickerPrice { + var tickerPrice TickerPrice + ticker, err := b.GetTicker(currency, nil) + if err != nil { + log.Println(err) + return tickerPrice + } + tickerPrice.Ask = ticker.Ask + tickerPrice.Bid = ticker.Bid + + return tickerPrice +} + type BitfinexLendbookBidAsk struct { Rate float64 `json:"rate,string"` Amount float64 `json:"amount,string"` diff --git a/bitstamphttp.go b/bitstamphttp.go index c30dc513..7648a9fc 100644 --- a/bitstamphttp.go +++ b/bitstamphttp.go @@ -234,6 +234,19 @@ func (b *Bitstamp) GetTicker(hourly bool) (BitstampTicker, error) { return ticker, nil } +func (b *Bitstamp) GetTickerPrice(currency string) TickerPrice { + var tickerPrice TickerPrice + ticker, err := b.GetTicker(true) + if err != nil { + log.Println(err) + return tickerPrice + } + tickerPrice.Ask = ticker.Ask + tickerPrice.Bid = ticker.Bid + + return tickerPrice +} + func (b *Bitstamp) GetOrderbook() (BitstampOrderbook, error) { type response struct { Timestamp int64 `json:"timestamp,string"` diff --git a/brightonpeakhttp.go b/brightonpeakhttp.go index 2208f30a..872fc314 100644 --- a/brightonpeakhttp.go +++ b/brightonpeakhttp.go @@ -134,6 +134,19 @@ func (b *BrightonPeak) GetTicker(symbol string) (AlphapointTicker, error) { return b.API.GetTicker(symbol) } +func (b *BrightonPeak) GetTickerPrice(currency string) TickerPrice { + var tickerPrice TickerPrice + ticker, err := b.GetTicker(currency) + if err != nil { + log.Println(err) + return tickerPrice + } + tickerPrice.Ask = ticker.Ask + tickerPrice.Bid = ticker.Bid + + return tickerPrice +} + func (b *BrightonPeak) GetTrades(symbol string, startIndex, count int) (AlphapointTrades, error) { return b.API.GetTrades(symbol, startIndex, count) } diff --git a/btcchttp.go b/btcchttp.go index e8cfddf1..652fb8b0 100644 --- a/btcchttp.go +++ b/btcchttp.go @@ -272,6 +272,15 @@ func (b *BTCC) GetTicker(symbol string) BTCCTicker { return resp.Ticker } +func (b *BTCC) GetTickerPrice(currency string) TickerPrice { + var tickerPrice TickerPrice + ticker := b.GetTicker(currency) + tickerPrice.Ask = ticker.Sell + tickerPrice.Bid = ticker.Buy + + return tickerPrice +} + func (b *BTCC) GetTradesLast24h(symbol string) bool { req := fmt.Sprintf("%sdata/trades?market=%s", BTCC_API_URL, symbol) err := SendHTTPGetRequest(req, true, nil) diff --git a/btcehttp.go b/btcehttp.go index 0367d047..e9b65c17 100644 --- a/btcehttp.go +++ b/btcehttp.go @@ -185,6 +185,21 @@ func (b *BTCE) GetTicker(symbol string) (map[string]BTCeTicker, error) { return response.Data, nil } +/// This getticker is different, so I'll let someone else implement.... +/// Or I will, just later... +func (b *BTCE) GetTickerPrice(currency string) TickerPrice { + var tickerPrice TickerPrice + /*ticker, err:= b.GetTicker(currency) + if err != nil { + log.Println(err) + return tickerPrice + } + tickerPrice.Ask = ticker.Buy + tickerPrice.Bid = ticker.Sell + */ + return tickerPrice +} + func (b *BTCE) GetDepth(symbol string) { type Response struct { Data map[string]BTCEOrderbook diff --git a/btcmarkets.go b/btcmarkets.go index 5f82f9ab..5f50adfa 100644 --- a/btcmarkets.go +++ b/btcmarkets.go @@ -188,6 +188,19 @@ func (b *BTCMarkets) GetTicker(symbol string) (BTCMarketsTicker, error) { return ticker, nil } +func (b *BTCMarkets) GetTickerPrice(currency string) TickerPrice { + var tickerPrice TickerPrice + ticker, err := b.GetTicker(currency) + if err != nil { + log.Println(err) + return tickerPrice + } + tickerPrice.Ask = ticker.BestAsk + tickerPrice.Bid = ticker.BestBID + + return tickerPrice +} + func (b *BTCMarkets) GetOrderbook(symbol string) (BTCMarketsOrderbook, error) { orderbook := BTCMarketsOrderbook{} path := fmt.Sprintf("/market/%s/AUD/orderbook", symbol) diff --git a/coinbasehttp.go b/coinbasehttp.go index 7d98ee5b..d157fca6 100644 --- a/coinbasehttp.go +++ b/coinbasehttp.go @@ -359,6 +359,18 @@ func (c *Coinbase) GetTicker(symbol string) (CoinbaseTicker, error) { return ticker, nil } +func (c *Coinbase) GetTickerPrice(currency string) TickerPrice { + var tickerPrice TickerPrice + ticker, err := c.GetTicker(currency) + if err != nil { + log.Println(err) + return TickerPrice{} + } + tickerPrice.Ask = ticker.Price + + return tickerPrice +} + func (c *Coinbase) GetTrades(symbol string) ([]CoinbaseTrade, error) { trades := []CoinbaseTrade{} path := fmt.Sprintf("%s/%s/%s", COINBASE_API_URL+COINBASE_PRODUCTS, symbol, COINBASE_TRADES) diff --git a/geminihttp.go b/geminihttp.go index 8cdf1946..f5594e95 100644 --- a/geminihttp.go +++ b/geminihttp.go @@ -186,6 +186,13 @@ func (g *Gemini) Run() { } } +/// Once GetTicker is created, then add in GetTickerPrice code plz - Scott +func (g *Gemini) GetTickerPrice(currency string) TickerPrice { + var tickerPrice TickerPrice + + return tickerPrice +} + func (g *Gemini) GetSymbols() ([]string, error) { symbols := []string{} path := fmt.Sprintf("%s/v%s/%s", GEMINI_API_URL, GEMINI_API_VERSION, GEMINI_SYMBOLS) diff --git a/huobihttp.go b/huobihttp.go index e77625f0..acc3aecf 100644 --- a/huobihttp.go +++ b/huobihttp.go @@ -132,6 +132,15 @@ func (h *HUOBI) GetTicker(symbol string) HuobiTicker { return resp.Ticker } +func (h *HUOBI) GetTickerPrice(currency string) TickerPrice { + var tickerPrice TickerPrice + ticker := h.GetTicker(currency) + tickerPrice.Ask = ticker.Sell + tickerPrice.Bid = ticker.Buy + + return tickerPrice +} + func (h *HUOBI) GetOrderBook(symbol string) bool { path := fmt.Sprintf("http://market.huobi.com/staticmarket/depth_%s_json.js", symbol) err := SendHTTPGetRequest(path, true, nil) diff --git a/interfaces.go b/interfaces.go index 8fd4bfd2..ea2b2d0d 100644 --- a/interfaces.go +++ b/interfaces.go @@ -6,4 +6,6 @@ type IBotExchange interface { SetDefaults() GetName() string IsEnabled() bool + GetTickerPrice(currency string) TickerPrice } + diff --git a/itbithttp.go b/itbithttp.go index f7b4f300..c249c5cb 100644 --- a/itbithttp.go +++ b/itbithttp.go @@ -134,6 +134,16 @@ func (i *ItBit) GetTicker(currency string) ItBitTicker { return itbitTicker } +func (i *ItBit) GetTickerPrice(currency string) TickerPrice { + var tickerPrice TickerPrice + ticker := i.GetTicker(currency) + + tickerPrice.Ask = ticker.Ask + tickerPrice.Bid = ticker.Bid + + return tickerPrice +} + type ItbitOrderbookEntry struct { Quantitiy float64 `json:"quantity,string"` Price float64 `json:"price,string"` diff --git a/kraken.go b/kraken.go index e1e646cc..71a56106 100644 --- a/kraken.go +++ b/kraken.go @@ -229,6 +229,21 @@ func (k *Kraken) GetTicker(symbol string) error { return nil } +//This will return the TickerPrice struct when tickers are completed here.. +func (k *Kraken) GetTickerPrice(currency string) TickerPrice { + var tickerPrice TickerPrice + /* + ticker, err := i.GetTicker(currency) + if err != nil { + log.Println(err) + return tickerPrice + } + tickerPrice.Ask = ticker.Ask + tickerPrice.Bid = ticker.Bid + */ + return tickerPrice +} + func (k *Kraken) GetOHLC(symbol string) error { values := url.Values{} values.Set("pair", symbol) diff --git a/lakebtchttp.go b/lakebtchttp.go index 8b6417f2..a84d3133 100644 --- a/lakebtchttp.go +++ b/lakebtchttp.go @@ -148,6 +148,21 @@ func (l *LakeBTC) GetTicker() LakeBTCTickerResponse { return response } +func (l *LakeBTC) GetTickerPrice(currency string) TickerPrice { + var tickerPrice TickerPrice + ticker := l.GetTicker() + + if(currency == "USD") { + tickerPrice.Ask = ticker.USD.Ask + tickerPrice.Bid = ticker.USD.Bid + } else if(currency =="CNY") { + tickerPrice.Ask = ticker.CNY.Ask + tickerPrice.Bid = ticker.CNY.Bid + } + + return tickerPrice +} + func (l *LakeBTC) GetOrderBook(currency string) bool { req := LAKEBTC_ORDERBOOK if currency == "CNY" { diff --git a/localbitcoinshttp.go b/localbitcoinshttp.go index d6a8b977..c5ad4219 100644 --- a/localbitcoinshttp.go +++ b/localbitcoinshttp.go @@ -136,6 +136,18 @@ func (l *LocalBitcoins) GetTicker() (map[string]LocalBitcoinsTicker, error) { return result, nil } +func (l *LocalBitcoins) GetTickerPrice(currency string) TickerPrice { + var tickerPrice TickerPrice + ticker, err := l.GetTicker() + if err != nil { + log.Println(err) + return tickerPrice + } + tickerPrice.Ask = ticker[currency].Rates.Last + + return tickerPrice +} + type LocalBitcoinsTrade struct { TID int64 `json:"tid"` Date int64 `json:"date"` diff --git a/okcoinhttp.go b/okcoinhttp.go index 79a47834..1411ee2a 100644 --- a/okcoinhttp.go +++ b/okcoinhttp.go @@ -322,6 +322,19 @@ func (o *OKCoin) GetTicker(symbol string) (OKCoinTicker, error) { return resp.Ticker, nil } +func (o *OKCoin) GetTickerPrice(currency string) TickerPrice { + var tickerPrice TickerPrice + ticker, err := o.GetTicker(currency) + if err != nil { + log.Println(err) + return tickerPrice + } + tickerPrice.Ask = ticker.Sell + tickerPrice.Bid = ticker.Buy + + return tickerPrice +} + func (o *OKCoin) GetOrderBook(symbol string, size int64, merge bool) (OKCoinOrderbook, error) { resp := OKCoinOrderbook{} vals := url.Values{} diff --git a/poloniexhttp.go b/poloniexhttp.go index 1925c591..4e525c64 100644 --- a/poloniexhttp.go +++ b/poloniexhttp.go @@ -161,6 +161,19 @@ func (p *Poloniex) GetTicker() (map[string]PoloniexTicker, error) { return resp.Data, nil } +func (p *Poloniex) GetTickerPrice(currency string) TickerPrice { + var tickerPrice TickerPrice + ticker, err := p.GetTicker() + if err != nil { + log.Println(err) + return tickerPrice + } + tickerPrice.Ask = ticker[currency].Last + tickerPrice.Bid = ticker[currency].HighestBid + + return tickerPrice +} + func (p *Poloniex) GetVolume() (interface{}, error) { var resp interface{} path := fmt.Sprintf("%s/public?command=return24hVolume", POLONIEX_API_URL) diff --git a/restfulRouter.go b/restfulRouter.go index ea4edae0..063be8d8 100644 --- a/restfulRouter.go +++ b/restfulRouter.go @@ -8,7 +8,7 @@ import ( func NewRouter(exchanges []IBotExchange) *mux.Router { router := mux.NewRouter().StrictSlash(true) - allRoutes := append(routes,anxRoutes...) + allRoutes := append(routes,exchangeRoutes...) for _, route := range allRoutes { var handler http.Handler handler = route.HandlerFunc diff --git a/tickerRoutes.go b/tickerRoutes.go new file mode 100644 index 00000000..396bf7d1 --- /dev/null +++ b/tickerRoutes.go @@ -0,0 +1,36 @@ +package main + +import ( + "encoding/json" + "net/http" + "github.com/gorilla/mux" +) + +func jsonTickerResponse(w http.ResponseWriter, r *http.Request) { + vars := mux.Vars(r) + currency := vars["currency"] + exchangeName := vars["exchangeName"] + var response TickerPrice; + for i := 0; i < len(bot.exchanges); i++ { + if bot.exchanges[i] != nil { + if(bot.exchanges[i].IsEnabled() && bot.exchanges[i].GetName() == exchangeName) { + response = bot.exchanges[i].GetTickerPrice(currency) + } + } + } + + w.Header().Set("Content-Type", "application/json; charset=UTF-8") + w.WriteHeader(http.StatusOK) + if err := json.NewEncoder(w).Encode(response); err != nil { + panic(err) + } +} + +var exchangeRoutes = Routes{ + Route{ + "Index", + "GET", + "/exchanges/{exchangeName}/latest/{currency}", + jsonTickerResponse, + }, +} \ No newline at end of file