Link up OKEX and fix config test

This commit is contained in:
Adrian Gallagher
2018-01-29 20:52:00 +11:00
parent f6b38897db
commit 784e9e48f5
5 changed files with 139 additions and 4 deletions

View File

@@ -34,7 +34,9 @@ Join our slack to discuss all things related to GoCryptoTrader! [GoCryptoTrader
| LakeBTC | Yes | No | NA |
| Liqui | Yes | No | NA |
| LocalBitcoins | Yes | NA | NA |
| OKCoin (both) | Yes | Yes | No |
| OKCoin China | Yes | Yes | No |
| OKCoin International | Yes | Yes | No |
| OKEX | Yes | No | No |
| Poloniex | Yes | Yes | NA |
| WEX | Yes | NA | NA |

View File

@@ -89,7 +89,7 @@ func TestGetEnabledExchanges(t *testing.T) {
}
exchanges := cfg.GetEnabledExchanges()
if len(exchanges) != 19 {
if len(exchanges) != 20 {
t.Error(
"Test failed. TestGetEnabledExchanges. Enabled exchanges value mismatch",
)
@@ -141,7 +141,7 @@ func TestGetDisabledExchanges(t *testing.T) {
}
func TestCountEnabledExchanges(t *testing.T) {
defaultEnabledExchanges := 19
defaultEnabledExchanges := 20
GetConfigEnabledExchanges := GetConfig()
err := GetConfigEnabledExchanges.LoadConfig(ConfigTestFile)
if err != nil {

View File

@@ -22,6 +22,7 @@ import (
"github.com/thrasher-/gocryptotrader/exchanges/liqui"
"github.com/thrasher-/gocryptotrader/exchanges/localbitcoins"
"github.com/thrasher-/gocryptotrader/exchanges/okcoin"
"github.com/thrasher-/gocryptotrader/exchanges/okex"
"github.com/thrasher-/gocryptotrader/exchanges/poloniex"
"github.com/thrasher-/gocryptotrader/exchanges/wex"
)
@@ -158,6 +159,8 @@ func LoadExchange(name string) error {
exch = new(okcoin.OKCoin)
case "okcoin international":
exch = new(okcoin.OKCoin)
case "okex":
exch = new(okex.OKEX)
case "poloniex":
exch = new(poloniex.Poloniex)
case "wex":

View File

@@ -614,7 +614,7 @@ func (o *OKEX) GetSpotTicker(symbol string) (SpotPrice, error) {
}
//GetSpotMarketDepth returns Market Depth
func (o *OKEX) GetSpotMarketDepth(symbol, size string) (interface{}, error) {
func (o *OKEX) GetSpotMarketDepth(symbol, size string) (ActualSpotDepth, error) {
resp := SpotDepth{}
fullDepth := ActualSpotDepth{}

View File

@@ -0,0 +1,130 @@
package okex
import (
"errors"
"log"
"github.com/thrasher-/gocryptotrader/common"
"github.com/thrasher-/gocryptotrader/currency/pair"
"github.com/thrasher-/gocryptotrader/exchanges"
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
)
// Start starts the OKEX go routine
func (o *OKEX) Start() {
go o.Run()
}
// Run implements the OKEX wrapper
func (o *OKEX) Run() {
if o.Verbose {
log.Printf("%s Websocket: %s. (url: %s).\n", o.GetName(), common.IsEnabled(o.Websocket), o.WebsocketURL)
log.Printf("%s polling delay: %ds.\n", o.GetName(), o.RESTPollingDelay)
log.Printf("%s %d currencies enabled: %s.\n", o.GetName(), len(o.EnabledPairs), o.EnabledPairs)
}
}
// UpdateTicker updates and returns the ticker for a currency pair
func (o *OKEX) UpdateTicker(p pair.CurrencyPair, assetType string) (ticker.Price, error) {
currency := exchange.FormatExchangeCurrency(o.Name, p).String()
var tickerPrice ticker.Price
if assetType != ticker.Spot {
tick, err := o.GetContractPrice(currency, assetType)
if err != nil {
return tickerPrice, err
}
tickerPrice.Pair = p
tickerPrice.Ask = tick.Ticker.Sell
tickerPrice.Bid = tick.Ticker.Buy
tickerPrice.Low = tick.Ticker.Low
tickerPrice.Last = tick.Ticker.Last
tickerPrice.Volume = tick.Ticker.Vol
tickerPrice.High = tick.Ticker.High
ticker.ProcessTicker(o.GetName(), p, tickerPrice, assetType)
} else {
tick, err := o.GetSpotTicker(currency)
if err != nil {
return tickerPrice, err
}
tickerPrice.Pair = p
tickerPrice.Ask = tick.Ticker.Sell
tickerPrice.Bid = tick.Ticker.Buy
tickerPrice.Low = tick.Ticker.Low
tickerPrice.Last = tick.Ticker.Last
tickerPrice.Volume = tick.Ticker.Vol
tickerPrice.High = tick.Ticker.High
ticker.ProcessTicker(o.GetName(), p, tickerPrice, ticker.Spot)
}
return ticker.GetTicker(o.Name, p, assetType)
}
// GetTickerPrice returns the ticker for a currency pair
func (o *OKEX) GetTickerPrice(p pair.CurrencyPair, assetType string) (ticker.Price, error) {
tickerNew, err := ticker.GetTicker(o.GetName(), p, assetType)
if err != nil {
return o.UpdateTicker(p, assetType)
}
return tickerNew, nil
}
// GetOrderbookEx returns orderbook base on the currency pair
func (o *OKEX) GetOrderbookEx(currency pair.CurrencyPair, assetType string) (orderbook.Base, error) {
ob, err := orderbook.GetOrderbook(o.GetName(), currency, assetType)
if err != nil {
return o.UpdateOrderbook(currency, assetType)
}
return ob, nil
}
// UpdateOrderbook updates and returns the orderbook for a currency pair
func (o *OKEX) UpdateOrderbook(p pair.CurrencyPair, assetType string) (orderbook.Base, error) {
var orderBook orderbook.Base
currency := exchange.FormatExchangeCurrency(o.Name, p).String()
if assetType != ticker.Spot {
orderbookNew, err := o.GetContractMarketDepth(currency, assetType)
if err != nil {
return orderBook, err
}
for x := range orderbookNew.Bids {
data := orderbookNew.Bids[x]
orderBook.Bids = append(orderBook.Bids, orderbook.Item{Amount: data.Volume, Price: data.Price})
}
for x := range orderbookNew.Asks {
data := orderbookNew.Asks[x]
orderBook.Asks = append(orderBook.Asks, orderbook.Item{Amount: data.Volume, Price: data.Price})
}
} else {
orderbookNew, err := o.GetSpotMarketDepth(currency, "200")
if err != nil {
return orderBook, err
}
for x := range orderbookNew.Bids {
data := orderbookNew.Bids[x]
orderBook.Bids = append(orderBook.Bids, orderbook.Item{Amount: data.Volume, Price: data.Price})
}
for x := range orderbookNew.Asks {
data := orderbookNew.Asks[x]
orderBook.Asks = append(orderBook.Asks, orderbook.Item{Amount: data.Volume, Price: data.Price})
}
}
orderbook.ProcessOrderbook(o.GetName(), p, orderBook, assetType)
return orderbook.GetOrderbook(o.Name, p, assetType)
}
// GetExchangeAccountInfo retrieves balances for all enabled currencies for the
// OKEX exchange
func (o *OKEX) GetExchangeAccountInfo() (exchange.AccountInfo, error) {
var response exchange.AccountInfo
return response, errors.New("not implemented")
}