diff --git a/exchanges/okcoin/okcoin.go b/exchanges/okcoin/okcoin.go index a366640b..5e22f5b2 100644 --- a/exchanges/okcoin/okcoin.go +++ b/exchanges/okcoin/okcoin.go @@ -16,61 +16,62 @@ import ( ) const ( - OKCOIN_API_URL = "https://www.okcoin.com/api/v1/" - OKCOIN_API_URL_CHINA = "https://www.okcoin.cn/api/v1/" - OKCOIN_API_VERSION = "1" - OKCOIN_WEBSOCKET_URL = "wss://real.okcoin.com:10440/websocket/okcoinapi" - OKCOIN_WEBSOCKET_URL_CHINA = "wss://real.okcoin.cn:10440/websocket/okcoinapi" - OKCOIN_TICKER = "ticker.do" - OKCOIN_DEPTH = "depth.do" - OKCOIN_TRADES = "trades.do" - OKCOIN_KLINE = "kline.do" - OKCOIN_USERINFO = "userinfo.do" - OKCOIN_TRADE = "trade.do" - OKCOIN_TRADE_HISTORY = "trade_history.do" - OKCOIN_TRADE_BATCH = "batch_trade.do" - OKCOIN_ORDER_CANCEL = "cancel_order.do" - OKCOIN_ORDER_INFO = "order_info.do" - OKCOIN_ORDERS_INFO = "orders_info.do" - OKCOIN_ORDER_HISTORY = "order_history.do" - OKCOIN_WITHDRAW = "withdraw.do" - OKCOIN_WITHDRAW_CANCEL = "cancel_withdraw.do" - OKCOIN_WITHDRAW_INFO = "withdraw_info.do" - OKCOIN_ORDER_FEE = "order_fee.do" - OKCOIN_LEND_DEPTH = "lend_depth.do" - OKCOIN_BORROWS_INFO = "borrows_info.do" - OKCOIN_BORROW_MONEY = "borrow_money.do" - OKCOIN_BORROW_CANCEL = "cancel_borrow.do" - OKCOIN_BORROW_ORDER_INFO = "borrow_order_info.do" - OKCOIN_REPAYMENT = "repayment.do" - OKCOIN_UNREPAYMENTS_INFO = "unrepayments_info.do" - OKCOIN_ACCOUNT_RECORDS = "account_records.do" - OKCOIN_FUTURES_TICKER = "future_ticker.do" - OKCOIN_FUTURES_DEPTH = "future_depth.do" - OKCOIN_FUTURES_TRADES = "future_trades.do" - OKCOIN_FUTURES_INDEX = "future_index.do" - OKCOIN_EXCHANGE_RATE = "exchange_rate.do" - OKCOIN_FUTURES_ESTIMATED_PRICE = "future_estimated_price.do" - OKCOIN_FUTURES_KLINE = "future_kline.do" - OKCOIN_FUTURES_HOLD_AMOUNT = "future_hold_amount.do" - OKCOIN_FUTURES_USERINFO = "future_userinfo.do" - OKCOIN_FUTURES_POSITION = "future_position.do" - OKCOIN_FUTURES_TRADE = "future_trade.do" - OKCOIN_FUTURES_TRADE_HISTORY = "future_trades_history.do" - OKCOIN_FUTURES_TRADE_BATCH = "future_batch_trade.do" - OKCOIN_FUTURES_CANCEL = "future_cancel.do" - OKCOIN_FUTURES_ORDER_INFO = "future_order_info.do" - OKCOIN_FUTURES_ORDERS_INFO = "future_orders_info.do" - OKCOIN_FUTURES_USERINFO_4FIX = "future_userinfo_4fix.do" - OKCOIN_FUTURES_POSITION_4FIX = "future_position_4fix.do" - OKCOIN_FUTURES_EXPLOSIVE = "future_explosive.do" - OKCOIN_FUTURES_DEVOLVE = "future_devolve.do" + okcoinAPIURL = "https://www.okcoin.com/api/v1/" + okcoinAPIURLChina = "https://www.okcoin.cn/api/v1/" + okcoinAPIVersion = "1" + okcoinWebsocketURL = "wss://real.okcoin.com:10440/websocket/okcoinapi" + okcoinWebsocketURLChina = "wss://real.okcoin.cn:10440/websocket/okcoinapi" + okcoinTicker = "ticker.do" + okcoinDepth = "depth.do" + okcoinTrades = "trades.do" + okcoinKline = "kline.do" + okcoinUserInfo = "userinfo.do" + okcoinTrade = "trade.do" + okcoinTradeHistory = "trade_history.do" + okcoinTradeBatch = "batch_trade.do" + okcoinOrderCancel = "cancel_order.do" + okcoinOrderInfo = "order_info.do" + okcoinOrdersInfo = "orders_info.do" + okcoinOrderHistory = "order_history.do" + okcoinWithdraw = "withdraw.do" + okcoinWithdrawCancel = "cancel_withdraw.do" + okcoinWithdrawInfo = "withdraw_info.do" + okcoinOrderFee = "order_fee.do" + okcoinLendDepth = "lend_depth.do" + okcoinBorrowsInfo = "borrows_info.do" + okcoinBorrowMoney = "borrow_money.do" + okcoinBorrowCancel = "cancel_borrow.do" + okcoinBorrowOrderInfo = "borrow_order_info.do" + okcoinRepayment = "repayment.do" + okcoinUnrepaymentsInfo = "unrepayments_info.do" + okcoinAccountRecords = "account_records.do" + okcoinFuturesTicker = "future_ticker.do" + okcoinFuturesDepth = "future_depth.do" + okcoinFuturesTrades = "future_trades.do" + okcoinFuturesIndex = "future_index.do" + okcoinExchangeRate = "exchange_rate.do" + okcoinFuturesEstimatedPrice = "future_estimated_price.do" + okcoinFuturesKline = "future_kline.do" + okcoinFuturesHoldAmount = "future_hold_amount.do" + okcoinFuturesUserInfo = "future_userinfo.do" + okcoinFuturesPosition = "future_position.do" + okcoinFuturesTrade = "future_trade.do" + okcoinFuturesTradeHistory = "future_trades_history.do" + okcoinFuturesTradeBatch = "future_batch_trade.do" + okcoinFuturesCancel = "future_cancel.do" + okcoinFuturesOrderInfo = "future_order_info.do" + okcoinFuturesOrdersInfo = "future_orders_info.do" + okcoinFuturesUserInfo4Fix = "future_userinfo_4fix.do" + okcoinFuturesposition4Fix = "future_position_4fix.do" + okcoinFuturesExplosive = "future_explosive.do" + okcoinFuturesDevolve = "future_devolve.do" ) var ( okcoinDefaultsSet = false ) +// OKCoin is the overarching type across this package type OKCoin struct { exchange.Base RESTErrors map[string]string @@ -79,6 +80,7 @@ type OKCoin struct { WebsocketConn *websocket.Conn } +// setCurrencyPairFormats sets currency pair formatting for this package func (o *OKCoin) setCurrencyPairFormats() { o.RequestCurrencyPairFormat.Delimiter = "_" o.RequestCurrencyPairFormat.Uppercase = false @@ -86,6 +88,7 @@ func (o *OKCoin) setCurrencyPairFormats() { o.ConfigCurrencyPairFormat.Uppercase = true } +// SetDefaults sets current default values for this package func (o *OKCoin) SetDefaults() { o.SetErrorDefaults() o.SetWebsocketErrorDefaults() @@ -98,19 +101,20 @@ func (o *OKCoin) SetDefaults() { if okcoinDefaultsSet { o.AssetTypes = append(o.AssetTypes, o.FuturesValues...) - o.APIUrl = OKCOIN_API_URL + o.APIUrl = okcoinAPIURL o.Name = "OKCOIN International" - o.WebsocketURL = OKCOIN_WEBSOCKET_URL + o.WebsocketURL = okcoinWebsocketURL o.setCurrencyPairFormats() } else { - o.APIUrl = OKCOIN_API_URL_CHINA + o.APIUrl = okcoinAPIURLChina o.Name = "OKCOIN China" - o.WebsocketURL = OKCOIN_WEBSOCKET_URL_CHINA + o.WebsocketURL = okcoinWebsocketURLChina okcoinDefaultsSet = true o.setCurrencyPairFormats() } } +// Setup sets exchange configuration parameters func (o *OKCoin) Setup(exch config.ExchangeConfig) { if !exch.Enabled { o.SetEnabled(false) @@ -135,32 +139,34 @@ func (o *OKCoin) Setup(exch config.ExchangeConfig) { } } +// GetFee returns current fees for the exchange func (o *OKCoin) GetFee(maker bool) float64 { - if o.APIUrl == OKCOIN_API_URL { + if o.APIUrl == okcoinAPIURL { if maker { return o.MakerFee - } else { - return o.TakerFee } + return o.TakerFee } // Chinese exchange does not have any trading fees return 0 } -func (o *OKCoin) GetTicker(symbol string) (OKCoinTicker, error) { - resp := OKCoinTickerResponse{} +// GetTicker returns the current ticker +func (o *OKCoin) GetTicker(symbol string) (Ticker, error) { + resp := TickerResponse{} vals := url.Values{} vals.Set("symbol", symbol) - path := common.EncodeURLValues(o.APIUrl+OKCOIN_TICKER, vals) + path := common.EncodeURLValues(o.APIUrl+okcoinTicker, vals) err := common.SendHTTPGetRequest(path, true, o.Verbose, &resp) if err != nil { - return OKCoinTicker{}, err + return Ticker{}, err } return resp.Ticker, nil } -func (o *OKCoin) GetOrderBook(symbol string, size int64, merge bool) (OKCoinOrderbook, error) { - resp := OKCoinOrderbook{} +// GetOrderBook returns the current order book by size +func (o *OKCoin) GetOrderBook(symbol string, size int64, merge bool) (Orderbook, error) { + resp := Orderbook{} vals := url.Values{} vals.Set("symbol", symbol) if size != 0 { @@ -170,7 +176,7 @@ func (o *OKCoin) GetOrderBook(symbol string, size int64, merge bool) (OKCoinOrde vals.Set("merge", "1") } - path := common.EncodeURLValues(o.APIUrl+OKCOIN_DEPTH, vals) + path := common.EncodeURLValues(o.APIUrl+okcoinDepth, vals) err := common.SendHTTPGetRequest(path, true, o.Verbose, &resp) if err != nil { return resp, err @@ -178,15 +184,16 @@ func (o *OKCoin) GetOrderBook(symbol string, size int64, merge bool) (OKCoinOrde return resp, nil } -func (o *OKCoin) GetTrades(symbol string, since int64) ([]OKCoinTrades, error) { - result := []OKCoinTrades{} +// GetTrades returns historic trades since a timestamp +func (o *OKCoin) GetTrades(symbol string, since int64) ([]Trades, error) { + result := []Trades{} vals := url.Values{} vals.Set("symbol", symbol) if since != 0 { vals.Set("since", strconv.FormatInt(since, 10)) } - path := common.EncodeURLValues(o.APIUrl+OKCOIN_TRADES, vals) + path := common.EncodeURLValues(o.APIUrl+okcoinTrades, vals) err := common.SendHTTPGetRequest(path, true, o.Verbose, &result) if err != nil { return nil, err @@ -194,6 +201,7 @@ func (o *OKCoin) GetTrades(symbol string, since int64) ([]OKCoinTrades, error) { return result, nil } +// GetKline returns kline data func (o *OKCoin) GetKline(symbol, klineType string, size, since int64) ([]interface{}, error) { resp := []interface{}{} vals := url.Values{} @@ -208,7 +216,7 @@ func (o *OKCoin) GetKline(symbol, klineType string, size, since int64) ([]interf vals.Set("since", strconv.FormatInt(since, 10)) } - path := common.EncodeURLValues(o.APIUrl+OKCOIN_KLINE, vals) + path := common.EncodeURLValues(o.APIUrl+okcoinKline, vals) err := common.SendHTTPGetRequest(path, true, o.Verbose, &resp) if err != nil { return nil, err @@ -217,21 +225,23 @@ func (o *OKCoin) GetKline(symbol, klineType string, size, since int64) ([]interf return resp, nil } -func (o *OKCoin) GetFuturesTicker(symbol, contractType string) (OKCoinFuturesTicker, error) { - resp := OKCoinFuturesTickerResponse{} +// GetFuturesTicker returns a current ticker for the futures market +func (o *OKCoin) GetFuturesTicker(symbol, contractType string) (FuturesTicker, error) { + resp := FuturesTickerResponse{} vals := url.Values{} vals.Set("symbol", symbol) vals.Set("contract_type", contractType) - path := common.EncodeURLValues(o.APIUrl+OKCOIN_FUTURES_TICKER, vals) + path := common.EncodeURLValues(o.APIUrl+okcoinFuturesTicker, vals) err := common.SendHTTPGetRequest(path, true, o.Verbose, &resp) if err != nil { - return OKCoinFuturesTicker{}, err + return FuturesTicker{}, err } return resp.Ticker, nil } -func (o *OKCoin) GetFuturesDepth(symbol, contractType string, size int64, merge bool) (OKCoinOrderbook, error) { - result := OKCoinOrderbook{} +// GetFuturesDepth returns current depth for the futures market +func (o *OKCoin) GetFuturesDepth(symbol, contractType string, size int64, merge bool) (Orderbook, error) { + result := Orderbook{} vals := url.Values{} vals.Set("symbol", symbol) vals.Set("contract_type", contractType) @@ -243,7 +253,7 @@ func (o *OKCoin) GetFuturesDepth(symbol, contractType string, size int64, merge vals.Set("merge", "1") } - path := common.EncodeURLValues(o.APIUrl+OKCOIN_FUTURES_DEPTH, vals) + path := common.EncodeURLValues(o.APIUrl+okcoinFuturesDepth, vals) err := common.SendHTTPGetRequest(path, true, o.Verbose, &result) if err != nil { return result, err @@ -251,13 +261,14 @@ func (o *OKCoin) GetFuturesDepth(symbol, contractType string, size int64, merge return result, nil } -func (o *OKCoin) GetFuturesTrades(symbol, contractType string) ([]OKCoinFuturesTrades, error) { - result := []OKCoinFuturesTrades{} +// GetFuturesTrades returns historic trades for the futures market +func (o *OKCoin) GetFuturesTrades(symbol, contractType string) ([]FuturesTrades, error) { + result := []FuturesTrades{} vals := url.Values{} vals.Set("symbol", symbol) vals.Set("contract_type", contractType) - path := common.EncodeURLValues(o.APIUrl+OKCOIN_FUTURES_TRADES, vals) + path := common.EncodeURLValues(o.APIUrl+okcoinFuturesTrades, vals) err := common.SendHTTPGetRequest(path, true, o.Verbose, &result) if err != nil { return nil, err @@ -265,6 +276,7 @@ func (o *OKCoin) GetFuturesTrades(symbol, contractType string) ([]OKCoinFuturesT return result, nil } +// GetFuturesIndex returns an index for the futures market func (o *OKCoin) GetFuturesIndex(symbol string) (float64, error) { type Response struct { Index float64 `json:"future_index"` @@ -274,7 +286,7 @@ func (o *OKCoin) GetFuturesIndex(symbol string) (float64, error) { vals := url.Values{} vals.Set("symbol", symbol) - path := common.EncodeURLValues(o.APIUrl+OKCOIN_FUTURES_INDEX, vals) + path := common.EncodeURLValues(o.APIUrl+okcoinFuturesIndex, vals) err := common.SendHTTPGetRequest(path, true, o.Verbose, &result) if err != nil { return 0, err @@ -282,19 +294,22 @@ func (o *OKCoin) GetFuturesIndex(symbol string) (float64, error) { return result.Index, nil } +// GetFuturesExchangeRate returns the exchange rate for the futures market func (o *OKCoin) GetFuturesExchangeRate() (float64, error) { type Response struct { Rate float64 `json:"rate"` } result := Response{} - err := common.SendHTTPGetRequest(o.APIUrl+OKCOIN_EXCHANGE_RATE, true, o.Verbose, &result) + err := common.SendHTTPGetRequest(o.APIUrl+okcoinExchangeRate, true, o.Verbose, &result) if err != nil { return result.Rate, err } return result.Rate, nil } +// GetFuturesEstimatedPrice returns a current estimated futures price for a +// currency func (o *OKCoin) GetFuturesEstimatedPrice(symbol string) (float64, error) { type Response struct { Price float64 `json:"forecast_price"` @@ -303,7 +318,7 @@ func (o *OKCoin) GetFuturesEstimatedPrice(symbol string) (float64, error) { result := Response{} vals := url.Values{} vals.Set("symbol", symbol) - path := common.EncodeURLValues(o.APIUrl+OKCOIN_FUTURES_ESTIMATED_PRICE, vals) + path := common.EncodeURLValues(o.APIUrl+okcoinFuturesEstimatedPrice, vals) err := common.SendHTTPGetRequest(path, true, o.Verbose, &result) if err != nil { return result.Price, err @@ -311,6 +326,8 @@ func (o *OKCoin) GetFuturesEstimatedPrice(symbol string) (float64, error) { return result.Price, nil } +// GetFuturesKline returns kline data for a specific currency on the futures +// market func (o *OKCoin) GetFuturesKline(symbol, klineType, contractType string, size, since int64) ([]interface{}, error) { resp := []interface{}{} vals := url.Values{} @@ -325,7 +342,7 @@ func (o *OKCoin) GetFuturesKline(symbol, klineType, contractType string, size, s vals.Set("since", strconv.FormatInt(since, 10)) } - path := common.EncodeURLValues(o.APIUrl+OKCOIN_FUTURES_KLINE, vals) + path := common.EncodeURLValues(o.APIUrl+okcoinFuturesKline, vals) err := common.SendHTTPGetRequest(path, true, o.Verbose, &resp) if err != nil { @@ -334,13 +351,14 @@ func (o *OKCoin) GetFuturesKline(symbol, klineType, contractType string, size, s return resp, nil } -func (o *OKCoin) GetFuturesHoldAmount(symbol, contractType string) ([]OKCoinFuturesHoldAmount, error) { - resp := []OKCoinFuturesHoldAmount{} +// GetFuturesHoldAmount returns the hold amount for a futures trade +func (o *OKCoin) GetFuturesHoldAmount(symbol, contractType string) ([]FuturesHoldAmount, error) { + resp := []FuturesHoldAmount{} vals := url.Values{} vals.Set("symbol", symbol) vals.Set("contract_type", contractType) - path := common.EncodeURLValues(o.APIUrl+OKCOIN_FUTURES_HOLD_AMOUNT, vals) + path := common.EncodeURLValues(o.APIUrl+okcoinFuturesHoldAmount, vals) err := common.SendHTTPGetRequest(path, true, o.Verbose, &resp) if err != nil { @@ -349,9 +367,10 @@ func (o *OKCoin) GetFuturesHoldAmount(symbol, contractType string) ([]OKCoinFutu return resp, nil } -func (o *OKCoin) GetFuturesExplosive(symbol, contractType string, status, currentPage, pageLength int64) ([]OKCoinFuturesExplosive, error) { +// GetFuturesExplosive returns the explosive for a futures contract +func (o *OKCoin) GetFuturesExplosive(symbol, contractType string, status, currentPage, pageLength int64) ([]FuturesExplosive, error) { type Response struct { - Data []OKCoinFuturesExplosive `json:"data"` + Data []FuturesExplosive `json:"data"` } resp := Response{} vals := url.Values{} @@ -361,7 +380,7 @@ func (o *OKCoin) GetFuturesExplosive(symbol, contractType string, status, curren vals.Set("current_page", strconv.FormatInt(currentPage, 10)) vals.Set("page_length", strconv.FormatInt(pageLength, 10)) - path := common.EncodeURLValues(o.APIUrl+OKCOIN_FUTURES_EXPLOSIVE, vals) + path := common.EncodeURLValues(o.APIUrl+okcoinFuturesExplosive, vals) err := common.SendHTTPGetRequest(path, true, o.Verbose, &resp) if err != nil { @@ -371,9 +390,10 @@ func (o *OKCoin) GetFuturesExplosive(symbol, contractType string, status, curren return resp.Data, nil } -func (o *OKCoin) GetUserInfo() (OKCoinUserInfo, error) { - result := OKCoinUserInfo{} - err := o.SendAuthenticatedHTTPRequest(OKCOIN_USERINFO, url.Values{}, &result) +// GetUserInfo returns user information associated with the calling APIkeys +func (o *OKCoin) GetUserInfo() (UserInfo, error) { + result := UserInfo{} + err := o.SendAuthenticatedHTTPRequest(okcoinUserInfo, url.Values{}, &result) if err != nil { return result, err @@ -382,6 +402,7 @@ func (o *OKCoin) GetUserInfo() (OKCoinUserInfo, error) { return result, nil } +// Trade initiates a new trade func (o *OKCoin) Trade(amount, price float64, symbol, orderType string) (int64, error) { type Response struct { Result bool `json:"result"` @@ -395,26 +416,27 @@ func (o *OKCoin) Trade(amount, price float64, symbol, orderType string) (int64, result := Response{} - err := o.SendAuthenticatedHTTPRequest(OKCOIN_TRADE, v, &result) + err := o.SendAuthenticatedHTTPRequest(okcoinTrade, v, &result) if err != nil { return 0, err } if !result.Result { - return 0, errors.New("Unable to place order.") + return 0, errors.New("unable to place order") } return result.OrderID, nil } -func (o *OKCoin) GetTradeHistory(symbol string, TradeID int64) ([]OKCoinTrades, error) { - result := []OKCoinTrades{} +// GetTradeHistory returns client trade history +func (o *OKCoin) GetTradeHistory(symbol string, TradeID int64) ([]Trades, error) { + result := []Trades{} v := url.Values{} v.Set("symbol", symbol) v.Set("since", strconv.FormatInt(TradeID, 10)) - err := o.SendAuthenticatedHTTPRequest(OKCOIN_TRADE_HISTORY, v, &result) + err := o.SendAuthenticatedHTTPRequest(okcoinTradeHistory, v, &result) if err != nil { return nil, err @@ -423,14 +445,15 @@ func (o *OKCoin) GetTradeHistory(symbol string, TradeID int64) ([]OKCoinTrades, return result, nil } -func (o *OKCoin) BatchTrade(orderData string, symbol, orderType string) (OKCoinBatchTrade, error) { +// BatchTrade initiates a trade by batch order +func (o *OKCoin) BatchTrade(orderData string, symbol, orderType string) (BatchTrade, error) { v := url.Values{} v.Set("orders_data", orderData) v.Set("symbol", symbol) v.Set("type", orderType) - result := OKCoinBatchTrade{} + result := BatchTrade{} - err := o.SendAuthenticatedHTTPRequest(OKCOIN_TRADE_BATCH, v, &result) + err := o.SendAuthenticatedHTTPRequest(okcoinTradeBatch, v, &result) if err != nil { return result, err @@ -439,60 +462,56 @@ func (o *OKCoin) BatchTrade(orderData string, symbol, orderType string) (OKCoinB return result, nil } -func (o *OKCoin) CancelOrder(orderID []int64, symbol string) (OKCoinCancelOrderResponse, error) { +// CancelOrder cancels a specific order or list of orders by orderID +func (o *OKCoin) CancelOrder(orderID []int64, symbol string) (CancelOrderResponse, error) { v := url.Values{} orders := []string{} - orderStr := "" - result := OKCoinCancelOrderResponse{} + result := CancelOrderResponse{} + + orderStr := strconv.FormatInt(orderID[0], 10) if len(orderID) > 1 { for x := range orderID { orders = append(orders, strconv.FormatInt(orderID[x], 10)) } orderStr = common.JoinStrings(orders, ",") - } else { - orderStr = strconv.FormatInt(orderID[0], 10) } v.Set("order_id", orderStr) v.Set("symbol", symbol) - err := o.SendAuthenticatedHTTPRequest(OKCOIN_ORDER_CANCEL, v, &result) - - if err != nil { - return result, err - } - - return result, nil + return result, o.SendAuthenticatedHTTPRequest(okcoinOrderCancel, v, &result) } -func (o *OKCoin) GetOrderInfo(orderID int64, symbol string) ([]OKCoinOrderInfo, error) { +// GetOrderInfo returns order information by orderID +func (o *OKCoin) GetOrderInfo(orderID int64, symbol string) ([]OrderInfo, error) { type Response struct { - Result bool `json:"result"` - Orders []OKCoinOrderInfo `json:"orders"` + Result bool `json:"result"` + Orders []OrderInfo `json:"orders"` } v := url.Values{} v.Set("symbol", symbol) v.Set("order_id", strconv.FormatInt(orderID, 10)) result := Response{} - err := o.SendAuthenticatedHTTPRequest(OKCOIN_ORDER_INFO, v, &result) + err := o.SendAuthenticatedHTTPRequest(okcoinOrderInfo, v, &result) if err != nil { return nil, err } if result.Result != true { - return nil, errors.New("Unable to retrieve order info.") + return nil, errors.New("unable to retrieve order info") } return result.Orders, nil } -func (o *OKCoin) GetOrderInfoBatch(orderID []int64, symbol string) ([]OKCoinOrderInfo, error) { +// GetOrderInfoBatch returns order info on a batch of orders +func (o *OKCoin) GetOrderInfoBatch(orderID []int64, symbol string) ([]OrderInfo, error) { type Response struct { - Result bool `json:"result"` - Orders []OKCoinOrderInfo `json:"orders"` + Result bool `json:"result"` + Orders []OrderInfo `json:"orders"` } orders := []string{} @@ -505,28 +524,29 @@ func (o *OKCoin) GetOrderInfoBatch(orderID []int64, symbol string) ([]OKCoinOrde v.Set("order_id", common.JoinStrings(orders, ",")) result := Response{} - err := o.SendAuthenticatedHTTPRequest(OKCOIN_ORDER_INFO, v, &result) + err := o.SendAuthenticatedHTTPRequest(okcoinOrderInfo, v, &result) if err != nil { return nil, err } if result.Result != true { - return nil, errors.New("Unable to retrieve order info.") + return nil, errors.New("unable to retrieve order info") } return result.Orders, nil } -func (o *OKCoin) GetOrderHistory(pageLength, currentPage int64, status, symbol string) (OKCoinOrderHistory, error) { +// GetOrderHistory returns a history of orders +func (o *OKCoin) GetOrderHistory(pageLength, currentPage int64, status, symbol string) (OrderHistory, error) { v := url.Values{} v.Set("symbol", symbol) v.Set("status", status) v.Set("current_page", strconv.FormatInt(currentPage, 10)) v.Set("page_length", strconv.FormatInt(pageLength, 10)) - result := OKCoinOrderHistory{} + result := OrderHistory{} - err := o.SendAuthenticatedHTTPRequest(OKCOIN_ORDER_HISTORY, v, &result) + err := o.SendAuthenticatedHTTPRequest(okcoinOrderHistory, v, &result) if err != nil { return result, err @@ -535,6 +555,7 @@ func (o *OKCoin) GetOrderHistory(pageLength, currentPage int64, status, symbol s return result, nil } +// Withdrawal withdraws a cryptocurrency to a supplied address func (o *OKCoin) Withdrawal(symbol string, fee float64, tradePWD, address string, amount float64) (int, error) { v := url.Values{} v.Set("symbol", symbol) @@ -545,67 +566,70 @@ func (o *OKCoin) Withdrawal(symbol string, fee float64, tradePWD, address string v.Set("trade_pwd", tradePWD) v.Set("withdraw_address", address) v.Set("withdraw_amount", strconv.FormatFloat(amount, 'f', -1, 64)) - result := OKCoinWithdrawalResponse{} + result := WithdrawalResponse{} - err := o.SendAuthenticatedHTTPRequest(OKCOIN_WITHDRAW, v, &result) + err := o.SendAuthenticatedHTTPRequest(okcoinWithdraw, v, &result) if err != nil { return 0, err } if !result.Result { - return 0, errors.New("Unable to process withdrawal request.") + return 0, errors.New("unable to process withdrawal request") } return result.WithdrawID, nil } +// CancelWithdrawal cancels a withdrawal func (o *OKCoin) CancelWithdrawal(symbol string, withdrawalID int64) (int, error) { v := url.Values{} v.Set("symbol", symbol) v.Set("withdrawal_id", strconv.FormatInt(withdrawalID, 10)) - result := OKCoinWithdrawalResponse{} + result := WithdrawalResponse{} - err := o.SendAuthenticatedHTTPRequest(OKCOIN_WITHDRAW_CANCEL, v, &result) + err := o.SendAuthenticatedHTTPRequest(okcoinWithdrawCancel, v, &result) if err != nil { return 0, err } if !result.Result { - return 0, errors.New("Unable to process withdrawal cancel request.") + return 0, errors.New("unable to process withdrawal cancel request") } return result.WithdrawID, nil } -func (o *OKCoin) GetWithdrawalInfo(symbol string, withdrawalID int64) ([]OKCoinWithdrawInfo, error) { +// GetWithdrawalInfo returns withdrawal information +func (o *OKCoin) GetWithdrawalInfo(symbol string, withdrawalID int64) ([]WithdrawInfo, error) { type Response struct { Result bool - Withdraw []OKCoinWithdrawInfo `json:"withdraw"` + Withdraw []WithdrawInfo `json:"withdraw"` } v := url.Values{} v.Set("symbol", symbol) v.Set("withdrawal_id", strconv.FormatInt(withdrawalID, 10)) result := Response{} - err := o.SendAuthenticatedHTTPRequest(OKCOIN_WITHDRAW_INFO, v, &result) + err := o.SendAuthenticatedHTTPRequest(okcoinWithdrawInfo, v, &result) if err != nil { return nil, err } if !result.Result { - return nil, errors.New("Unable to process withdrawal cancel request.") + return nil, errors.New("unable to process withdrawal cancel request") } return result.Withdraw, nil } -func (o *OKCoin) GetOrderFeeInfo(symbol string, orderID int64) (OKCoinOrderFeeInfo, error) { +// GetOrderFeeInfo returns order fee information +func (o *OKCoin) GetOrderFeeInfo(symbol string, orderID int64) (OrderFeeInfo, error) { type Response struct { - Data OKCoinOrderFeeInfo `json:"data"` - Result bool `json:"result"` + Data OrderFeeInfo `json:"data"` + Result bool `json:"result"` } v := url.Values{} @@ -613,29 +637,30 @@ func (o *OKCoin) GetOrderFeeInfo(symbol string, orderID int64) (OKCoinOrderFeeIn v.Set("order_id", strconv.FormatInt(orderID, 10)) result := Response{} - err := o.SendAuthenticatedHTTPRequest(OKCOIN_ORDER_FEE, v, &result) + err := o.SendAuthenticatedHTTPRequest(okcoinOrderFee, v, &result) if err != nil { return result.Data, err } if !result.Result { - return result.Data, errors.New("Unable to get order fee info.") + return result.Data, errors.New("unable to get order fee info") } return result.Data, nil } -func (o *OKCoin) GetLendDepth(symbol string) ([]OKCoinLendDepth, error) { +// GetLendDepth returns the depth of lends +func (o *OKCoin) GetLendDepth(symbol string) ([]LendDepth, error) { type Response struct { - LendDepth []OKCoinLendDepth `json:"lend_depth"` + LendDepth []LendDepth `json:"lend_depth"` } v := url.Values{} v.Set("symbol", symbol) result := Response{} - err := o.SendAuthenticatedHTTPRequest(OKCOIN_LEND_DEPTH, v, &result) + err := o.SendAuthenticatedHTTPRequest(okcoinLendDepth, v, &result) if err != nil { return nil, err @@ -644,12 +669,13 @@ func (o *OKCoin) GetLendDepth(symbol string) ([]OKCoinLendDepth, error) { return result.LendDepth, nil } -func (o *OKCoin) GetBorrowInfo(symbol string) (OKCoinBorrowInfo, error) { +// GetBorrowInfo returns borrow information +func (o *OKCoin) GetBorrowInfo(symbol string) (BorrowInfo, error) { v := url.Values{} v.Set("symbol", symbol) - result := OKCoinBorrowInfo{} + result := BorrowInfo{} - err := o.SendAuthenticatedHTTPRequest(OKCOIN_BORROWS_INFO, v, &result) + err := o.SendAuthenticatedHTTPRequest(okcoinBorrowsInfo, v, &result) if err != nil { return result, nil @@ -658,113 +684,119 @@ func (o *OKCoin) GetBorrowInfo(symbol string) (OKCoinBorrowInfo, error) { return result, nil } +// Borrow initiates a borrow request func (o *OKCoin) Borrow(symbol, days string, amount, rate float64) (int, error) { v := url.Values{} v.Set("symbol", symbol) v.Set("days", days) v.Set("amount", strconv.FormatFloat(amount, 'f', -1, 64)) v.Set("rate", strconv.FormatFloat(rate, 'f', -1, 64)) - result := OKCoinBorrowResponse{} + result := BorrowResponse{} - err := o.SendAuthenticatedHTTPRequest(OKCOIN_BORROW_MONEY, v, &result) + err := o.SendAuthenticatedHTTPRequest(okcoinBorrowMoney, v, &result) if err != nil { return 0, err } if !result.Result { - return 0, errors.New("Unable to borrow.") + return 0, errors.New("unable to borrow") } return result.BorrowID, nil } +// CancelBorrow cancels a borrow request func (o *OKCoin) CancelBorrow(symbol string, borrowID int64) (bool, error) { v := url.Values{} v.Set("symbol", symbol) v.Set("borrow_id", strconv.FormatInt(borrowID, 10)) - result := OKCoinBorrowResponse{} + result := BorrowResponse{} - err := o.SendAuthenticatedHTTPRequest(OKCOIN_BORROW_CANCEL, v, &result) + err := o.SendAuthenticatedHTTPRequest(okcoinBorrowCancel, v, &result) if err != nil { return false, err } if !result.Result { - return false, errors.New("Unable to cancel borrow.") + return false, errors.New("unable to cancel borrow") } return true, nil } -func (o *OKCoin) GetBorrowOrderInfo(borrowID int64) (OKCoinBorrowInfo, error) { +// GetBorrowOrderInfo returns information about a borrow order +func (o *OKCoin) GetBorrowOrderInfo(borrowID int64) (BorrowInfo, error) { type Response struct { - Result bool `json:"result"` - BorrowOrder OKCoinBorrowInfo `json:"borrow_order"` + Result bool `json:"result"` + BorrowOrder BorrowInfo `json:"borrow_order"` } v := url.Values{} v.Set("borrow_id", strconv.FormatInt(borrowID, 10)) result := Response{} - err := o.SendAuthenticatedHTTPRequest(OKCOIN_BORROW_ORDER_INFO, v, &result) + err := o.SendAuthenticatedHTTPRequest(okcoinBorrowOrderInfo, v, &result) if err != nil { return result.BorrowOrder, err } if !result.Result { - return result.BorrowOrder, errors.New("Unable to get borrow info.") + return result.BorrowOrder, errors.New("unable to get borrow info") } return result.BorrowOrder, nil } +// GetRepaymentInfo returns information on a repayment func (o *OKCoin) GetRepaymentInfo(borrowID int64) (bool, error) { v := url.Values{} v.Set("borrow_id", strconv.FormatInt(borrowID, 10)) - result := OKCoinBorrowResponse{} + result := BorrowResponse{} - err := o.SendAuthenticatedHTTPRequest(OKCOIN_REPAYMENT, v, &result) + err := o.SendAuthenticatedHTTPRequest(okcoinRepayment, v, &result) if err != nil { return false, err } if !result.Result { - return false, errors.New("Unable to get repayment info.") + return false, errors.New("unable to get repayment info") } return true, nil } -func (o *OKCoin) GetUnrepaymentsInfo(symbol string, currentPage, pageLength int) ([]OKCoinBorrowOrder, error) { +// GetUnrepaymentsInfo returns information on an unrepayment +func (o *OKCoin) GetUnrepaymentsInfo(symbol string, currentPage, pageLength int) ([]BorrowOrder, error) { type Response struct { - Unrepayments []OKCoinBorrowOrder `json:"unrepayments"` - Result bool `json:"result"` + Unrepayments []BorrowOrder `json:"unrepayments"` + Result bool `json:"result"` } v := url.Values{} v.Set("symbol", symbol) v.Set("current_page", strconv.Itoa(currentPage)) v.Set("page_length", strconv.Itoa(pageLength)) result := Response{} - err := o.SendAuthenticatedHTTPRequest(OKCOIN_UNREPAYMENTS_INFO, v, &result) + err := o.SendAuthenticatedHTTPRequest(okcoinUnrepaymentsInfo, v, &result) if err != nil { return nil, err } if !result.Result { - return nil, errors.New("Unable to get unrepayments info.") + return nil, errors.New("unable to get unrepayments info") } return result.Unrepayments, nil } -func (o *OKCoin) GetAccountRecords(symbol string, recType, currentPage, pageLength int) ([]OKCoinAccountRecords, error) { +// GetAccountRecords returns account records +func (o *OKCoin) GetAccountRecords(symbol string, recType, currentPage, pageLength int) ([]AccountRecords, error) { type Response struct { - Records []OKCoinAccountRecords `json:"records"` - Symbol string `json:"symbol"` + Records []AccountRecords `json:"records"` + Symbol string `json:"symbol"` } v := url.Values{} v.Set("symbol", symbol) @@ -773,7 +805,7 @@ func (o *OKCoin) GetAccountRecords(symbol string, recType, currentPage, pageLeng v.Set("page_length", strconv.Itoa(pageLength)) result := Response{} - err := o.SendAuthenticatedHTTPRequest(OKCOIN_ACCOUNT_RECORDS, v, &result) + err := o.SendAuthenticatedHTTPRequest(okcoinAccountRecords, v, &result) if err != nil { return nil, err @@ -782,25 +814,28 @@ func (o *OKCoin) GetAccountRecords(symbol string, recType, currentPage, pageLeng return result.Records, nil } +// GetFuturesUserInfo returns information on a users futures func (o *OKCoin) GetFuturesUserInfo() { - err := o.SendAuthenticatedHTTPRequest(OKCOIN_FUTURES_USERINFO, url.Values{}, nil) + err := o.SendAuthenticatedHTTPRequest(okcoinFuturesUserInfo, url.Values{}, nil) if err != nil { log.Println(err) } } +// GetFuturesPosition returns position on a futures contract func (o *OKCoin) GetFuturesPosition(symbol, contractType string) { v := url.Values{} v.Set("symbol", symbol) v.Set("contract_type", contractType) - err := o.SendAuthenticatedHTTPRequest(OKCOIN_FUTURES_POSITION, v, nil) + err := o.SendAuthenticatedHTTPRequest(okcoinFuturesPosition, v, nil) if err != nil { log.Println(err) } } +// FuturesTrade initiates a new futures trade func (o *OKCoin) FuturesTrade(amount, price float64, matchPrice, leverage int64, symbol, contractType, orderType string) { v := url.Values{} v.Set("symbol", symbol) @@ -811,13 +846,14 @@ func (o *OKCoin) FuturesTrade(amount, price float64, matchPrice, leverage int64, v.Set("match_price", strconv.FormatInt(matchPrice, 10)) v.Set("lever_rate", strconv.FormatInt(leverage, 10)) - err := o.SendAuthenticatedHTTPRequest(OKCOIN_FUTURES_TRADE, v, nil) + err := o.SendAuthenticatedHTTPRequest(okcoinFuturesTrade, v, nil) if err != nil { log.Println(err) } } +// FuturesBatchTrade initiates a batch of futures contract trades func (o *OKCoin) FuturesBatchTrade(orderData, symbol, contractType string, leverage int64, orderType string) { v := url.Values{} //to-do batch trade support for orders_data) v.Set("symbol", symbol) @@ -825,26 +861,28 @@ func (o *OKCoin) FuturesBatchTrade(orderData, symbol, contractType string, lever v.Set("orders_data", orderData) v.Set("lever_rate", strconv.FormatInt(leverage, 10)) - err := o.SendAuthenticatedHTTPRequest(OKCOIN_FUTURES_TRADE_BATCH, v, nil) + err := o.SendAuthenticatedHTTPRequest(okcoinFuturesTradeBatch, v, nil) if err != nil { log.Println(err) } } +// CancelFuturesOrder cancels a futures contract order func (o *OKCoin) CancelFuturesOrder(orderID int64, symbol, contractType string) { v := url.Values{} v.Set("symbol", symbol) v.Set("contract_type", contractType) v.Set("order_id", strconv.FormatInt(orderID, 10)) - err := o.SendAuthenticatedHTTPRequest(OKCOIN_FUTURES_CANCEL, v, nil) + err := o.SendAuthenticatedHTTPRequest(okcoinFuturesCancel, v, nil) if err != nil { log.Println(err) } } +// GetFuturesOrderInfo returns information on a specfic futures contract order func (o *OKCoin) GetFuturesOrderInfo(orderID, status, currentPage, pageLength int64, symbol, contractType string) { v := url.Values{} v.Set("symbol", symbol) @@ -854,49 +892,53 @@ func (o *OKCoin) GetFuturesOrderInfo(orderID, status, currentPage, pageLength in v.Set("current_page", strconv.FormatInt(currentPage, 10)) v.Set("page_length", strconv.FormatInt(pageLength, 10)) - err := o.SendAuthenticatedHTTPRequest(OKCOIN_FUTURES_ORDER_INFO, v, nil) + err := o.SendAuthenticatedHTTPRequest(okcoinFuturesOrderInfo, v, nil) if err != nil { log.Println(err) } } +// GetFutureOrdersInfo returns information on a range of futures orders func (o *OKCoin) GetFutureOrdersInfo(orderID int64, contractType, symbol string) { v := url.Values{} v.Set("order_id", strconv.FormatInt(orderID, 10)) v.Set("contract_type", contractType) v.Set("symbol", symbol) - err := o.SendAuthenticatedHTTPRequest(OKCOIN_FUTURES_ORDERS_INFO, v, nil) + err := o.SendAuthenticatedHTTPRequest(okcoinFuturesOrdersInfo, v, nil) if err != nil { log.Println(err) } } +// GetFuturesUserInfo4Fix returns futures user info fix rate func (o *OKCoin) GetFuturesUserInfo4Fix() { v := url.Values{} - err := o.SendAuthenticatedHTTPRequest(OKCOIN_FUTURES_USERINFO_4FIX, v, nil) + err := o.SendAuthenticatedHTTPRequest(okcoinFuturesUserInfo4Fix, v, nil) if err != nil { log.Println(err) } } +// GetFuturesUserPosition4Fix returns futures user info on a fixed position func (o *OKCoin) GetFuturesUserPosition4Fix(symbol, contractType string) { v := url.Values{} v.Set("symbol", symbol) v.Set("contract_type", contractType) v.Set("type", strconv.FormatInt(1, 10)) - err := o.SendAuthenticatedHTTPRequest(OKCOIN_FUTURES_POSITION_4FIX, v, nil) + err := o.SendAuthenticatedHTTPRequest(okcoinFuturesUserInfo4Fix, v, nil) if err != nil { log.Println(err) } } +// SendAuthenticatedHTTPRequest sends an authenticated HTTP request func (o *OKCoin) SendAuthenticatedHTTPRequest(method string, v url.Values, result interface{}) (err error) { if !o.AuthenticatedAPISupport { return fmt.Errorf(exchange.WarningAuthenticatedRequestWithoutCredentialsSet, o.Name) @@ -935,6 +977,7 @@ func (o *OKCoin) SendAuthenticatedHTTPRequest(method string, v url.Values, resul return nil } +// SetErrorDefaults sets default error map func (o *OKCoin) SetErrorDefaults() { o.RESTErrors = map[string]string{ "10000": "Required field, can not be null", diff --git a/exchanges/okcoin/okcoin_types.go b/exchanges/okcoin/okcoin_types.go index b099e53b..d78e79f4 100644 --- a/exchanges/okcoin/okcoin_types.go +++ b/exchanges/okcoin/okcoin_types.go @@ -1,6 +1,7 @@ package okcoin -type OKCoinTicker struct { +// Ticker holds ticker data +type Ticker struct { Buy float64 `json:",string"` High float64 `json:",string"` Last float64 `json:",string"` @@ -9,32 +10,38 @@ type OKCoinTicker struct { Vol float64 `json:",string"` } -type OKCoinTickerResponse struct { +// TickerResponse is the response type for ticker +type TickerResponse struct { Date string - Ticker OKCoinTicker -} -type OKCoinFuturesTicker struct { - Last float64 - Buy float64 - Sell float64 - High float64 - Low float64 - Vol float64 - Contract_ID int64 - Unit_Amount float64 + Ticker Ticker } -type OKCoinOrderbook struct { +// FuturesTicker holds futures ticker data +type FuturesTicker struct { + Last float64 + Buy float64 + Sell float64 + High float64 + Low float64 + Vol float64 + ContractID int64 + UnitAmount float64 +} + +// Orderbook holds orderbook data +type Orderbook struct { Asks [][]float64 `json:"asks"` Bids [][]float64 `json:"bids"` } -type OKCoinFuturesTickerResponse struct { +// FuturesTickerResponse is a response type +type FuturesTickerResponse struct { Date string - Ticker OKCoinFuturesTicker + Ticker FuturesTicker } -type OKCoinBorrowInfo struct { +// BorrowInfo holds borrowing amount data +type BorrowInfo struct { BorrowBTC float64 `json:"borrow_btc"` BorrowLTC float64 `json:"borrow_ltc"` BorrowCNY float64 `json:"borrow_cny"` @@ -47,7 +54,8 @@ type OKCoinBorrowInfo struct { DailyInterestCNY float64 `json:"today_interest_cny"` } -type OKCoinBorrowOrder struct { +// BorrowOrder holds order data +type BorrowOrder struct { Amount float64 `json:"amount"` BorrowDate int64 `json:"borrow_date"` BorrowID int64 `json:"borrow_id"` @@ -58,7 +66,8 @@ type OKCoinBorrowOrder struct { Symbol string `json:"symbol"` } -type OKCoinRecord struct { +// Record hold record data +type Record struct { Address string `json:"addr"` Account int64 `json:"account,string"` Amount float64 `json:"amount"` @@ -69,12 +78,14 @@ type OKCoinRecord struct { Date float64 `json:"date"` } -type OKCoinAccountRecords struct { - Records []OKCoinRecord `json:"records"` - Symbol string `json:"symbol"` +// AccountRecords holds account record data +type AccountRecords struct { + Records []Record `json:"records"` + Symbol string `json:"symbol"` } -type OKCoinFuturesOrder struct { +// FuturesOrder holds information about a futures order +type FuturesOrder struct { Amount float64 `json:"amount"` ContractName string `json:"contract_name"` DateCreated float64 `json:"create_date"` @@ -90,19 +101,22 @@ type OKCoinFuturesOrder struct { UnitAmount int64 `json:"unit_amount"` } -type OKCoinFuturesHoldAmount struct { +// FuturesHoldAmount contains futures hold amount data +type FuturesHoldAmount struct { Amount float64 `json:"amount"` ContractName string `json:"contract_name"` } -type OKCoinFuturesExplosive struct { +// FuturesExplosive holds inforamtion about explosive futures +type FuturesExplosive struct { Amount float64 `json:"amount,string"` DateCreated string `json:"create_date"` Loss float64 `json:"loss,string"` Type int64 `json:"type"` } -type OKCoinTrades struct { +// Trades holds trade data +type Trades struct { Amount float64 `json:"amount,string"` Date int64 `json:"date"` DateMS int64 `json:"date_ms"` @@ -111,7 +125,8 @@ type OKCoinTrades struct { Type string `json:"type"` } -type OKCoinFuturesTrades struct { +// FuturesTrades holds trade data for the futures market +type FuturesTrades struct { Amount float64 `json:"amount"` Date int64 `json:"date"` DateMS int64 `json:"date_ms"` @@ -120,7 +135,8 @@ type OKCoinFuturesTrades struct { Type string `json:"type"` } -type OKCoinUserInfo struct { +// UserInfo holds user account details +type UserInfo struct { Info struct { Funds struct { Asset struct { @@ -154,7 +170,8 @@ type OKCoinUserInfo struct { Result bool `json:"result"` } -type OKCoinBatchTrade struct { +// BatchTrade holds data on a batch of trades +type BatchTrade struct { OrderInfo []struct { OrderID int64 `json:"order_id"` ErrorCode int64 `json:"error_code"` @@ -162,12 +179,14 @@ type OKCoinBatchTrade struct { Result bool `json:"result"` } -type OKCoinCancelOrderResponse struct { +// CancelOrderResponse is a response type for a cancelled order +type CancelOrderResponse struct { Success string Error string } -type OKCoinOrderInfo struct { +// OrderInfo holds data on an order +type OrderInfo struct { Amount float64 `json:"amount"` AvgPrice float64 `json:"avg_price"` Created int64 `json:"create_date"` @@ -180,20 +199,23 @@ type OKCoinOrderInfo struct { Type string `json:"type"` } -type OKCoinOrderHistory struct { - CurrentPage int `json:"current_page"` - Orders []OKCoinOrderInfo `json:"orders"` - PageLength int `json:"page_length"` - Result bool `json:"result"` - Total int `json:"total"` +// OrderHistory holds information on order history +type OrderHistory struct { + CurrentPage int `json:"current_page"` + Orders []OrderInfo `json:"orders"` + PageLength int `json:"page_length"` + Result bool `json:"result"` + Total int `json:"total"` } -type OKCoinWithdrawalResponse struct { +// WithdrawalResponse is a response type for withdrawal +type WithdrawalResponse struct { WithdrawID int `json:"withdraw_id"` Result bool `json:"result"` } -type OKCoinWithdrawInfo struct { +// WithdrawInfo holds data on a withdraw +type WithdrawInfo struct { Address string `json:"address"` Amount float64 `json:"amount"` Created int64 `json:"created_date"` @@ -202,30 +224,35 @@ type OKCoinWithdrawInfo struct { WithdrawID int64 `json:"withdraw_id"` } -type OKCoinOrderFeeInfo struct { +// OrderFeeInfo holds data on order fees +type OrderFeeInfo struct { Fee float64 `json:"fee,string"` OrderID int64 `json:"order_id"` Type string `json:"type"` } -type OKCoinLendDepth struct { +// LendDepth hold lend depths +type LendDepth struct { Amount float64 `json:"amount"` Days string `json:"days"` Num int64 `json:"num"` Rate float64 `json:"rate,string"` } -type OKCoinBorrowResponse struct { +// BorrowResponse is a response type for borrow +type BorrowResponse struct { Result bool `json:"result"` BorrowID int `json:"borrow_id"` } -type OKCoinWebsocketFutureIndex struct { +// WebsocketFutureIndex holds future index data for websocket +type WebsocketFutureIndex struct { FutureIndex float64 `json:"futureIndex"` Timestamp int64 `json:"timestamp,string"` } -type OKCoinWebsocketTicker struct { +// WebsocketTicker holds ticker data for websocket +type WebsocketTicker struct { Timestamp float64 Vol string Buy float64 @@ -235,7 +262,8 @@ type OKCoinWebsocketTicker struct { Sell float64 } -type OKCoinWebsocketFuturesTicker struct { +// WebsocketFuturesTicker holds futures ticker data for websocket +type WebsocketFuturesTicker struct { Buy float64 `json:"buy"` ContractID string `json:"contractId"` High float64 `json:"high"` @@ -247,13 +275,15 @@ type OKCoinWebsocketFuturesTicker struct { Volume float64 `json:"vol,string"` } -type OKCoinWebsocketOrderbook struct { +// WebsocketOrderbook holds orderbook data for websocket +type WebsocketOrderbook struct { Asks [][]float64 `json:"asks"` Bids [][]float64 `json:"bids"` Timestamp int64 `json:"timestamp,string"` } -type OKCoinWebsocketUserinfo struct { +// WebsocketUserinfo holds user info for websocket +type WebsocketUserinfo struct { Info struct { Funds struct { Asset struct { @@ -277,7 +307,8 @@ type OKCoinWebsocketUserinfo struct { Result bool `json:"result"` } -type OKCoinWebsocketFuturesContract struct { +// WebsocketFuturesContract holds futures contract information for websocket +type WebsocketFuturesContract struct { Available float64 `json:"available"` Balance float64 `json:"balance"` Bond float64 `json:"bond"` @@ -288,23 +319,25 @@ type OKCoinWebsocketFuturesContract struct { Loss float64 `json:"unprofit"` } -type OKCoinWebsocketFuturesUserInfo struct { +// WebsocketFuturesUserInfo holds futures user information for websocket +type WebsocketFuturesUserInfo struct { Info struct { BTC struct { - Balance float64 `json:"balance"` - Contracts []OKCoinWebsocketFuturesContract `json:"contracts"` - Rights float64 `json:"rights"` + Balance float64 `json:"balance"` + Contracts []WebsocketFuturesContract `json:"contracts"` + Rights float64 `json:"rights"` } `json:"btc"` LTC struct { - Balance float64 `json:"balance"` - Contracts []OKCoinWebsocketFuturesContract `json:"contracts"` - Rights float64 `json:"rights"` + Balance float64 `json:"balance"` + Contracts []WebsocketFuturesContract `json:"contracts"` + Rights float64 `json:"rights"` } `json:"ltc"` } `json:"info"` Result bool `json:"result"` } -type OKCoinWebsocketOrder struct { +// WebsocketOrder holds order data for websocket +type WebsocketOrder struct { Amount float64 `json:"amount"` AvgPrice float64 `json:"avg_price"` DateCreated float64 `json:"create_date"` @@ -317,7 +350,8 @@ type OKCoinWebsocketOrder struct { OrderType string `json:"type"` } -type OKCoinWebsocketFuturesOrder struct { +// WebsocketFuturesOrder holds futures order data for websocket +type WebsocketFuturesOrder struct { Amount float64 `json:"amount"` ContractName string `json:"contract_name"` DateCreated float64 `json:"createdDate"` @@ -333,7 +367,8 @@ type OKCoinWebsocketFuturesOrder struct { UnitAmount float64 `json:"unit_amount"` } -type OKCoinWebsocketRealtrades struct { +// WebsocketRealtrades holds real trade data for WebSocket +type WebsocketRealtrades struct { AveragePrice float64 `json:"averagePrice,string"` CompletedTradeAmount float64 `json:"completedTradeAmount,string"` DateCreated float64 `json:"createdDate"` @@ -350,7 +385,8 @@ type OKCoinWebsocketRealtrades struct { UnTrade float64 `json:"unTrade,string"` } -type OKCoinWebsocketFuturesRealtrades struct { +// WebsocketFuturesRealtrades holds futures real trade data for websocket +type WebsocketFuturesRealtrades struct { Amount float64 `json:"amount,string"` ContractID float64 `json:"contract_id,string"` ContractName string `json:"contract_name"` @@ -366,29 +402,34 @@ type OKCoinWebsocketFuturesRealtrades struct { LeverageAmount int `json:"lever_rate,string"` } -type OKCoinWebsocketEvent struct { +// WebsocketEvent holds websocket events +type WebsocketEvent struct { Event string `json:"event"` Channel string `json:"channel"` } -type OKCoinWebsocketResponse struct { +// WebsocketResponse holds websocket responses +type WebsocketResponse struct { Channel string `json:"channel"` Data interface{} `json:"data"` } -type OKCoinWebsocketEventAuth struct { +// WebsocketEventAuth holds websocket authenticated events +type WebsocketEventAuth struct { Event string `json:"event"` Channel string `json:"channel"` Parameters map[string]string `json:"parameters"` } -type OKCoinWebsocketEventAuthRemove struct { +// WebsocketEventAuthRemove holds websocket remove authenticated events +type WebsocketEventAuthRemove struct { Event string `json:"event"` Channel string `json:"channel"` Parameters map[string]string `json:"parameters"` } -type OKCoinWebsocketTradeOrderResponse struct { +// WebsocketTradeOrderResponse holds trade order responses for websocket +type WebsocketTradeOrderResponse struct { OrderID int64 `json:"order_id,string"` Result bool `json:"result,string"` } diff --git a/exchanges/okcoin/okcoin_websocket.go b/exchanges/okcoin/okcoin_websocket.go index 3a81a2f4..0d63b89d 100644 --- a/exchanges/okcoin/okcoin_websocket.go +++ b/exchanges/okcoin/okcoin_websocket.go @@ -15,23 +15,24 @@ import ( ) const ( - OKCOIN_WEBSOCKET_USD_REALTRADES = "ok_usd_realtrades" - OKCOIN_WEBSOCKET_CNY_REALTRADES = "ok_cny_realtrades" - OKCOIN_WEBSOCKET_SPOTUSD_TRADE = "ok_spotusd_trade" - OKCOIN_WEBSOCKET_SPOTCNY_TRADE = "ok_spotcny_trade" - OKCOIN_WEBSOCKET_SPOTUSD_CANCEL_ORDER = "ok_spotusd_cancel_order" - OKCOIN_WEBSOCKET_SPOTCNY_CANCEL_ORDER = "ok_spotcny_cancel_order" - OKCOIN_WEBSOCKET_SPOTUSD_USERINFO = "ok_spotusd_userinfo" - OKCOIN_WEBSOCKET_SPOTCNY_USERINFO = "ok_spotcny_userinfo" - OKCOIN_WEBSOCKET_SPOTUSD_ORDER_INFO = "ok_spotusd_order_info" - OKCOIN_WEBSOCKET_SPOTCNY_ORDER_INFO = "ok_spotcny_order_info" - OKCOIN_WEBSOCKET_FUTURES_TRADE = "ok_futuresusd_trade" - OKCOIN_WEBSOCKET_FUTURES_CANCEL_ORDER = "ok_futuresusd_cancel_order" - OKCOIN_WEBSOCKET_FUTURES_REALTRADES = "ok_usd_future_realtrades" - OKCOIN_WEBSOCKET_FUTURES_USERINFO = "ok_futureusd_userinfo" - OKCOIN_WEBSOCKET_FUTURES_ORDER_INFO = "ok_futureusd_order_info" + okcoinWebsocketUSDRealTrades = "ok_usd_realtrades" + okcoinWebsocketCNYRealTrades = "ok_cny_realtrades" + okcoinWebsocketSpotUSDTrade = "ok_spotusd_trade" + okcoinWebsocketSpotCNYTrade = "ok_spotcny_trade" + okcoinWebsocketSpotUSDCancelOrder = "ok_spotusd_cancel_order" + okcoinWebsocketSpotCNYCancelOrder = "ok_spotcny_cancel_order" + okcoinWebsocketSpotUSDUserInfo = "ok_spotusd_userinfo" + okcoinWebsocketSpotCNYUserInfo = "ok_spotcny_userinfo" + okcoinWebsocketSpotUSDOrderInfo = "ok_spotusd_order_info" + okcoinWebsocketSpotCNYOrderInfo = "ok_spotcny_order_info" + okcoinWebsocketFuturesTrade = "ok_futuresusd_trade" + okcoinWebsocketFuturesCancelOrder = "ok_futuresusd_cancel_order" + okcoinWebsocketFuturesRealTrades = "ok_usd_future_realtrades" + okcoinWebsocketFuturesUserInfo = "ok_futureusd_userinfo" + okcoinWebsocketFuturesOrderInfo = "ok_futureusd_order_info" ) +// PingHandler handles the keep alive func (o *OKCoin) PingHandler(message string) error { err := o.WebsocketConn.WriteControl(websocket.PingMessage, []byte("{'event':'ping'}"), time.Now().Add(time.Second)) @@ -42,8 +43,9 @@ func (o *OKCoin) PingHandler(message string) error { return nil } +// AddChannel adds a new channel on the websocket client func (o *OKCoin) AddChannel(channel string) { - event := OKCoinWebsocketEvent{"addChannel", channel} + event := WebsocketEvent{"addChannel", channel} json, err := common.JSONEncode(event) if err != nil { log.Println(err) @@ -61,8 +63,9 @@ func (o *OKCoin) AddChannel(channel string) { } } +// RemoveChannel removes a channel on the websocket client func (o *OKCoin) RemoveChannel(channel string) { - event := OKCoinWebsocketEvent{"removeChannel", channel} + event := WebsocketEvent{"removeChannel", channel} json, err := common.JSONEncode(event) if err != nil { log.Println(err) @@ -80,23 +83,23 @@ func (o *OKCoin) RemoveChannel(channel string) { } } +// WebsocketSpotTrade handles spot trade request on the websocket client func (o *OKCoin) WebsocketSpotTrade(symbol, orderType string, price, amount float64) { values := make(map[string]string) values["symbol"] = symbol values["type"] = orderType values["price"] = strconv.FormatFloat(price, 'f', -1, 64) values["amount"] = strconv.FormatFloat(amount, 'f', -1, 64) - channel := "" - if o.WebsocketURL == OKCOIN_WEBSOCKET_URL_CHINA { - channel = OKCOIN_WEBSOCKET_SPOTCNY_TRADE - } else { - channel = OKCOIN_WEBSOCKET_SPOTUSD_TRADE + channel := okcoinWebsocketSpotUSDTrade + if o.WebsocketURL == okcoinWebsocketURLChina { + channel = okcoinWebsocketSpotCNYTrade } o.AddChannelAuthenticated(channel, values) } +// WebsocketFuturesTrade handles a futures trade on the websocket client func (o *OKCoin) WebsocketFuturesTrade(symbol, contractType string, price, amount float64, orderType, matchPrice, leverage int) { values := make(map[string]string) values["symbol"] = symbol @@ -106,47 +109,48 @@ func (o *OKCoin) WebsocketFuturesTrade(symbol, contractType string, price, amoun values["type"] = strconv.Itoa(orderType) values["match_price"] = strconv.Itoa(matchPrice) values["lever_rate"] = strconv.Itoa(orderType) - o.AddChannelAuthenticated(OKCOIN_WEBSOCKET_FUTURES_TRADE, values) + o.AddChannelAuthenticated(okcoinWebsocketFuturesTrade, values) } +// WebsocketSpotCancel cancels a spot trade on the websocket client func (o *OKCoin) WebsocketSpotCancel(symbol string, orderID int64) { values := make(map[string]string) values["symbol"] = symbol values["order_id"] = strconv.FormatInt(orderID, 10) - channel := "" - if o.WebsocketURL == OKCOIN_WEBSOCKET_URL_CHINA { - channel = OKCOIN_WEBSOCKET_SPOTCNY_CANCEL_ORDER - } else { - channel = OKCOIN_WEBSOCKET_SPOTUSD_CANCEL_ORDER + channel := okcoinWebsocketSpotUSDCancelOrder + if o.WebsocketURL == okcoinWebsocketURLChina { + channel = okcoinWebsocketSpotCNYCancelOrder } o.AddChannelAuthenticated(channel, values) } +// WebsocketFuturesCancel cancels a futures contract on the websocket client func (o *OKCoin) WebsocketFuturesCancel(symbol, contractType string, orderID int64) { values := make(map[string]string) values["symbol"] = symbol values["order_id"] = strconv.FormatInt(orderID, 10) values["contract_type"] = contractType - o.AddChannelAuthenticated(OKCOIN_WEBSOCKET_FUTURES_CANCEL_ORDER, values) + o.AddChannelAuthenticated(okcoinWebsocketFuturesCancelOrder, values) } +// WebsocketSpotOrderInfo request information on an order on the websocket +// client func (o *OKCoin) WebsocketSpotOrderInfo(symbol string, orderID int64) { values := make(map[string]string) values["symbol"] = symbol values["order_id"] = strconv.FormatInt(orderID, 10) - channel := "" - if o.WebsocketURL == OKCOIN_WEBSOCKET_URL_CHINA { - channel = OKCOIN_WEBSOCKET_SPOTCNY_ORDER_INFO - } else { - channel = OKCOIN_WEBSOCKET_SPOTUSD_ORDER_INFO + channel := okcoinWebsocketSpotUSDOrderInfo + if o.WebsocketURL == okcoinWebsocketURLChina { + channel = okcoinWebsocketSpotCNYOrderInfo } o.AddChannelAuthenticated(channel, values) } +// WebsocketFuturesOrderInfo requests futures order info on the websocket client func (o *OKCoin) WebsocketFuturesOrderInfo(symbol, contractType string, orderID int64, orderStatus, currentPage, pageLength int) { values := make(map[string]string) values["symbol"] = symbol @@ -155,9 +159,10 @@ func (o *OKCoin) WebsocketFuturesOrderInfo(symbol, contractType string, orderID values["status"] = strconv.Itoa(orderStatus) values["current_page"] = strconv.Itoa(currentPage) values["page_length"] = strconv.Itoa(pageLength) - o.AddChannelAuthenticated(OKCOIN_WEBSOCKET_FUTURES_ORDER_INFO, values) + o.AddChannelAuthenticated(okcoinWebsocketFuturesOrderInfo, values) } +// ConvertToURLValues converts values to url.Values func (o *OKCoin) ConvertToURLValues(values map[string]string) url.Values { urlVals := url.Values{} for i, x := range values { @@ -166,15 +171,17 @@ func (o *OKCoin) ConvertToURLValues(values map[string]string) url.Values { return urlVals } +// WebsocketSign signs values on the webcoket client func (o *OKCoin) WebsocketSign(values map[string]string) string { values["api_key"] = o.APIKey urlVals := o.ConvertToURLValues(values) return strings.ToUpper(common.HexEncodeToString(common.GetMD5([]byte(urlVals.Encode() + "&secret_key=" + o.APISecret)))) } +// AddChannelAuthenticated adds an authenticated channel on the websocket client func (o *OKCoin) AddChannelAuthenticated(channel string, values map[string]string) { values["sign"] = o.WebsocketSign(values) - event := OKCoinWebsocketEventAuth{"addChannel", channel, values} + event := WebsocketEventAuth{"addChannel", channel, values} json, err := common.JSONEncode(event) if err != nil { log.Println(err) @@ -192,9 +199,11 @@ func (o *OKCoin) AddChannelAuthenticated(channel string, values map[string]strin } } +// RemoveChannelAuthenticated removes the added authenticated channel on the +// websocket client func (o *OKCoin) RemoveChannelAuthenticated(conn *websocket.Conn, channel string, values map[string]string) { values["sign"] = o.WebsocketSign(values) - event := OKCoinWebsocketEventAuthRemove{"removeChannel", channel, values} + event := WebsocketEventAuthRemove{"removeChannel", channel, values} json, err := common.JSONEncode(event) if err != nil { log.Println(err) @@ -212,16 +221,17 @@ func (o *OKCoin) RemoveChannelAuthenticated(conn *websocket.Conn, channel string } } +// WebsocketClient starts a websocket client func (o *OKCoin) WebsocketClient() { klineValues := []string{"1min", "3min", "5min", "15min", "30min", "1hour", "2hour", "4hour", "6hour", "12hour", "day", "3day", "week"} - currencyChan, userinfoChan := "", "" + var currencyChan, userinfoChan string - if o.WebsocketURL == OKCOIN_WEBSOCKET_URL_CHINA { - currencyChan = OKCOIN_WEBSOCKET_CNY_REALTRADES - userinfoChan = OKCOIN_WEBSOCKET_SPOTCNY_USERINFO + if o.WebsocketURL == okcoinWebsocketURLChina { + currencyChan = okcoinWebsocketCNYRealTrades + userinfoChan = okcoinWebsocketSpotCNYUserInfo } else { - currencyChan = OKCOIN_WEBSOCKET_USD_REALTRADES - userinfoChan = OKCOIN_WEBSOCKET_SPOTUSD_USERINFO + currencyChan = okcoinWebsocketUSDRealTrades + userinfoChan = okcoinWebsocketSpotUSDUserInfo } for o.Enabled && o.Websocket { @@ -241,9 +251,9 @@ func (o *OKCoin) WebsocketClient() { o.WebsocketConn.SetPingHandler(o.PingHandler) if o.AuthenticatedAPISupport { - if o.WebsocketURL == OKCOIN_WEBSOCKET_URL { - o.AddChannelAuthenticated(OKCOIN_WEBSOCKET_FUTURES_REALTRADES, map[string]string{}) - o.AddChannelAuthenticated(OKCOIN_WEBSOCKET_FUTURES_USERINFO, map[string]string{}) + if o.WebsocketURL == okcoinWebsocketURL { + o.AddChannelAuthenticated(okcoinWebsocketFuturesRealTrades, map[string]string{}) + o.AddChannelAuthenticated(okcoinWebsocketFuturesUserInfo, map[string]string{}) } o.AddChannelAuthenticated(currencyChan, map[string]string{}) o.AddChannelAuthenticated(userinfoChan, map[string]string{}) @@ -255,7 +265,7 @@ func (o *OKCoin) WebsocketClient() { if o.AuthenticatedAPISupport { o.WebsocketSpotOrderInfo(currencyUL, -1) } - if o.WebsocketURL == OKCOIN_WEBSOCKET_URL { + if o.WebsocketURL == okcoinWebsocketURL { o.AddChannel(fmt.Sprintf("ok_%s_future_index", currency)) for _, y := range o.FuturesValues { if o.AuthenticatedAPISupport { @@ -336,15 +346,15 @@ func (o *OKCoin) WebsocketClient() { case common.StringContains(channelStr, "ticker") && !common.StringContains(channelStr, "future"): tickerValues := []string{"buy", "high", "last", "low", "sell", "timestamp"} tickerMap := data.(map[string]interface{}) - ticker := OKCoinWebsocketTicker{} + ticker := WebsocketTicker{} ticker.Vol = tickerMap["vol"].(string) for _, z := range tickerValues { result := reflect.TypeOf(tickerMap[z]).String() if result == "string" { - value, err := strconv.ParseFloat(tickerMap[z].(string), 64) - if err != nil { - log.Println(err) + value, errTickVals := strconv.ParseFloat(tickerMap[z].(string), 64) + if errTickVals != nil { + log.Println(errTickVals) continue } @@ -381,7 +391,7 @@ func (o *OKCoin) WebsocketClient() { } } case common.StringContains(channelStr, "ticker") && common.StringContains(channelStr, "future"): - ticker := OKCoinWebsocketFuturesTicker{} + ticker := WebsocketFuturesTicker{} err = common.JSONDecode(dataJSON, &ticker) if err != nil { @@ -389,7 +399,7 @@ func (o *OKCoin) WebsocketClient() { continue } case common.StringContains(channelStr, "depth"): - orderbook := OKCoinWebsocketOrderbook{} + orderbook := WebsocketOrderbook{} err = common.JSONDecode(dataJSON, &orderbook) if err != nil { @@ -411,8 +421,8 @@ func (o *OKCoin) WebsocketClient() { // to-do: convert from string array to trade struct case common.StringContains(channelStr, "kline"): klines := []interface{}{} - err := common.JSONDecode(dataJSON, &klines) + err = common.JSONDecode(dataJSON, &klines) if err != nil { log.Println(err) continue @@ -421,9 +431,9 @@ func (o *OKCoin) WebsocketClient() { if string(dataJSON) == "null" { continue } - realtrades := OKCoinWebsocketRealtrades{} - err := common.JSONDecode(dataJSON, &realtrades) + realtrades := WebsocketRealtrades{} + err = common.JSONDecode(dataJSON, &realtrades) if err != nil { log.Println(err) continue @@ -432,73 +442,73 @@ func (o *OKCoin) WebsocketClient() { if string(dataJSON) == "null" { continue } - realtrades := OKCoinWebsocketFuturesRealtrades{} - err := common.JSONDecode(dataJSON, &realtrades) + realtrades := WebsocketFuturesRealtrades{} + err = common.JSONDecode(dataJSON, &realtrades) if err != nil { log.Println(err) continue } case common.StringContains(channelStr, "spot") && common.StringContains(channelStr, "trade") || common.StringContains(channelStr, "futures") && common.StringContains(channelStr, "trade"): - tradeOrder := OKCoinWebsocketTradeOrderResponse{} - err := common.JSONDecode(dataJSON, &tradeOrder) + tradeOrder := WebsocketTradeOrderResponse{} + err = common.JSONDecode(dataJSON, &tradeOrder) if err != nil { log.Println(err) continue } case common.StringContains(channelStr, "cancel_order"): - cancelOrder := OKCoinWebsocketTradeOrderResponse{} - err := common.JSONDecode(dataJSON, &cancelOrder) + cancelOrder := WebsocketTradeOrderResponse{} + err = common.JSONDecode(dataJSON, &cancelOrder) if err != nil { log.Println(err) continue } case common.StringContains(channelStr, "spot") && common.StringContains(channelStr, "userinfo"): - userinfo := OKCoinWebsocketUserinfo{} - err = common.JSONDecode(dataJSON, &userinfo) + userinfo := WebsocketUserinfo{} + err = common.JSONDecode(dataJSON, &userinfo) if err != nil { log.Println(err) continue } case common.StringContains(channelStr, "futureusd_userinfo"): - userinfo := OKCoinWebsocketFuturesUserInfo{} - err = common.JSONDecode(dataJSON, &userinfo) + userinfo := WebsocketFuturesUserInfo{} + err = common.JSONDecode(dataJSON, &userinfo) if err != nil { log.Println(err) continue } case common.StringContains(channelStr, "spot") && common.StringContains(channelStr, "order_info"): type OrderInfoResponse struct { - Result bool `json:"result"` - Orders []OKCoinWebsocketOrder `json:"orders"` + Result bool `json:"result"` + Orders []WebsocketOrder `json:"orders"` } var orders OrderInfoResponse - err := common.JSONDecode(dataJSON, &orders) + err = common.JSONDecode(dataJSON, &orders) if err != nil { log.Println(err) continue } case common.StringContains(channelStr, "futureusd_order_info"): type OrderInfoResponse struct { - Result bool `json:"result"` - Orders []OKCoinWebsocketFuturesOrder `json:"orders"` + Result bool `json:"result"` + Orders []WebsocketFuturesOrder `json:"orders"` } var orders OrderInfoResponse - err := common.JSONDecode(dataJSON, &orders) + err = common.JSONDecode(dataJSON, &orders) if err != nil { log.Println(err) continue } case common.StringContains(channelStr, "future_index"): - index := OKCoinWebsocketFutureIndex{} - err = common.JSONDecode(dataJSON, &index) + index := WebsocketFutureIndex{} + err = common.JSONDecode(dataJSON, &index) if err != nil { log.Println(err) continue @@ -512,6 +522,7 @@ func (o *OKCoin) WebsocketClient() { } } +// SetWebsocketErrorDefaults sets default errors for websocket func (o *OKCoin) SetWebsocketErrorDefaults() { o.WebsocketErrors = map[string]string{ "10001": "Illegal parameters", diff --git a/exchanges/okcoin/okcoin_wrapper.go b/exchanges/okcoin/okcoin_wrapper.go index 4fff95be..cfe10a33 100644 --- a/exchanges/okcoin/okcoin_wrapper.go +++ b/exchanges/okcoin/okcoin_wrapper.go @@ -34,7 +34,7 @@ func (o *OKCoin) UpdateTicker(p pair.CurrencyPair, assetType string) (ticker.Pri currency := exchange.FormatExchangeCurrency(o.Name, p).String() var tickerPrice ticker.Price - if assetType != ticker.Spot && o.APIUrl == OKCOIN_API_URL { + if assetType != ticker.Spot && o.APIUrl == okcoinAPIURL { tick, err := o.GetFuturesTicker(currency, assetType) if err != nil { return tickerPrice, err