From 4e61864468c7a12a106c2829eaab1ca6210282c5 Mon Sep 17 00:00:00 2001 From: Adrian Gallagher Date: Wed, 1 Apr 2015 23:17:25 +1100 Subject: [PATCH] Added OKCoin error code strings. --- okcoinhttp.go | 82 ++++++++++++++++++++++++++ okcoinwebsocket.go | 141 +++++++++++++++++++++++++++++---------------- 2 files changed, 172 insertions(+), 51 deletions(-) diff --git a/okcoinhttp.go b/okcoinhttp.go index e1779707..3e540143 100644 --- a/okcoinhttp.go +++ b/okcoinhttp.go @@ -26,6 +26,8 @@ type OKCoin struct { PollingDelay time.Duration APIUrl, PartnerID, SecretKey string TakerFee, MakerFee float64 + RESTErrors map[string]string + WebsocketErrors map[string]string } type OKCoinTicker struct { @@ -63,6 +65,9 @@ type OKCoinFuturesTickerResponse struct { } func (o *OKCoin) SetDefaults() { + o.SetErrorDefaults() + o.SetWebsocketErrorDefaults() + if (o.APIUrl == OKCOIN_API_URL) { o.Name = "OKCOIN International" o.WebsocketURL = OKCOIN_WEBSOCKET_URL @@ -522,4 +527,81 @@ func (o *OKCoin) SendAuthenticatedHTTPRequest(method string, v url.Values) (err } return nil +} + +func (o *OKCoin) SetErrorDefaults() { + o.RESTErrors = map[string]string{ + "10000": "Required field, can not be null", + "10001": "Request frequency too high", + "10002": "System error", + "10003": "Not in reqest list, please try again later", + "10004": "IP not allowed to access the resource", + "10005": "'secretKey' does not exist", + "10006": "'partner' does not exist", + "10007": "Signature does not match", + "10008": "Illegal parameter", + "10009": "Order does not exist", + "10010": "Insufficient funds", + "10011": "Amount too low", + "10012": "Only btc_usd/btc_cny ltc_usd,ltc_cny supported", + "10013": "Only support https request", + "10014": "Order price must be between 0 and 1,000,000", + "10015": "Order price differs from current market price too much", + "10016": "Insufficient coins balance", + "10017": "API authorization error", + "10018": "Borrow amount less than lower limit [usd/cny:100,btc:0.1,ltc:1]", + "10019": "Loan agreement not checked", + "10020": `Rate cannot exceed 1%`, + "10021": `Rate cannot less than 0.01%`, + "10023": "Fail to get latest ticker", + "10024": "Balance not sufficient", + "10025": "Quota is full, cannot borrow temporarily", + "10026": "Loan (including reserved loan) and margin cannot be withdrawn", + "10027": "Cannot withdraw within 24 hrs of authentication information modification", + "10028": "Withdrawal amount exceeds daily limit", + "10029": "Account has unpaid loan, please cancel/pay off the loan before withdraw", + "10031": "Deposits can only be withdrawn after 6 confirmations", + "10032": "Please enabled phone/google authenticator", + "10033": "Fee higher than maximum network transaction fee", + "10034": "Fee lower than minimum network transaction fee", + "10035": "Insufficient BTC/LTC", + "10036": "Withdrawal amount too low", + "10037": "Trade password not set", + "10040": "Withdrawal cancellation fails", + "10041": "Withdrawal address not approved", + "10042": "Admin password error", + "10043": "Account equity error, withdrawal failure", + "10044": "fail to cancel borrowing order", + "10047": "This function is disabled for sub-account", + "10100": "User account frozen", + "10216": "Non-available API", + "20001": "User does not exist", + "20002": "Account frozen", + "20003": "Account frozen due to liquidation", + "20004": "Futures account frozen", + "20005": "User futures account does not exist", + "20006": "Required field missing", + "20007": "Illegal parameter", + "20008": "Futures account balance is too low", + "20009": "Future contract status error", + "20010": "Risk rate ratio does not exist", + "20011": `Risk rate higher than 90% before opening position`, + "20012": `Risk rate higher than 90% after opening position`, + "20013": "Temporally no counter party price", + "20014": "System error", + "20015": "Order does not exist", + "20016": "Close amount bigger than your open positions", + "20017": "Not authorized/illegal operation", + "20018": `Order price differ more than 5% from the price in the last minute`, + "20019": "IP restricted from accessing the resource", + "20020": "secretKey does not exist", + "20021": "Index information does not exist", + "20022": "Wrong API interface (Cross margin mode shall call cross margin API, fixed margin mode shall call fixed margin API)", + "20023": "Account in fixed-margin mode", + "20024": "Signature does not match", + "20025": "Leverage rate error", + "20026": "API Permission Error", + "20027": "No transaction record", + "20028": "No such contract", + } } \ No newline at end of file diff --git a/okcoinwebsocket.go b/okcoinwebsocket.go index 7ea46162..c2422b63 100644 --- a/okcoinwebsocket.go +++ b/okcoinwebsocket.go @@ -291,7 +291,7 @@ func (o *OKCoin) WebsocketClient(currencies []string) { OKConnWebsocket.SetPingHandler(o.PingHandler) if o.Verbose { - log.Printf("%s Collecting order and userinfo.\n") + log.Printf("%s Websocket: Collecting user information.\n", o.GetName()) } currencyChan, userinfoChan := "", "" @@ -349,8 +349,15 @@ func (o *OKCoin) WebsocketClient(currencies []string) { continue } - if o.Verbose { - log.Printf("%s Websocket channel message: %s\n", o.GetName(), channelStr) + if success != "true" && success != nil { + errorCodeStr, ok := errorcode.(string) + if !ok { + log.Printf("%s Websocket: Unable to convert errorcode to string.\n", o .GetName) + log.Printf("%s Websocket: channel %s error code: %s.\n", o.GetName(), channelStr, errorcode) + } else { + log.Printf("%s Websocket: channel %s error: %s.\n", o.GetName(), channelStr, o.WebsocketErrors[errorCodeStr]) + } + continue } dataJSON, err := JSONEncode(data) @@ -393,63 +400,48 @@ func (o *OKCoin) WebsocketClient(currencies []string) { case strings.Contains(channelStr, "kline"): // to-do case strings.Contains(channelStr, "realtrades"): - if success == "false" { - log.Printf("Error subscribing to real trades channel, error code: %s", errorcode) - } else { - if string(dataJSON) == "null" { - continue - } - realtrades := OKCoinWebsocketRealtrades{} - err := JSONDecode(dataJSON, &realtrades) + if string(dataJSON) == "null" { + continue + } + realtrades := OKCoinWebsocketRealtrades{} + err := JSONDecode(dataJSON, &realtrades) - if err != nil { - log.Println(err) - continue - } + if err != nil { + log.Println(err) + continue } case strings.Contains(channelStr, "spot") && strings.Contains(channelStr, "trade"): - if success == "false" { - log.Printf("Error placing trade, error code: %s", errorcode) - } else { - type TradeOrderResponse struct { - OrderID int64 `json:"order_id,string"` - Result bool `json:"result"` - } - tradeOrder := TradeOrderResponse{} - err := JSONDecode(dataJSON, &tradeOrder) + log.Println(string(dataJSON)) + type TradeOrderResponse struct { + OrderID int64 `json:"order_id,string"` + Result bool `json:"result,string"` + } + tradeOrder := TradeOrderResponse{} + err := JSONDecode(dataJSON, &tradeOrder) - if err != nil { - log.Println(err) - continue - } + if err != nil { + log.Println(err) + continue } case strings.Contains(channelStr, "userinfo"): - if success == "false" { - log.Printf("Error fetching user info, error code: %s", errorcode) - } else { - userinfo := OKCoinWebsocketUserinfo{} - err = JSONDecode(dataJSON, &userinfo) + userinfo := OKCoinWebsocketUserinfo{} + err = JSONDecode(dataJSON, &userinfo) - if err != nil { - log.Println(err) - continue - } + if err != nil { + log.Println(err) + continue } case strings.Contains(channelStr, "order_info"): - if success == "false" { - log.Printf("Error fetching order info, error code: %s", errorcode) - } else { - type OrderInfoResponse struct { - Result bool `json:"result"` - Orders []OKCoinWebsocketOrder `json:"orders"` - } - var orders OrderInfoResponse - err := JSONDecode(dataJSON, &orders) + type OrderInfoResponse struct { + Result bool `json:"result"` + Orders []OKCoinWebsocketOrder `json:"orders"` + } + var orders OrderInfoResponse + err := JSONDecode(dataJSON, &orders) - if err != nil { - log.Println(err) - continue - } + if err != nil { + log.Println(err) + continue } } } @@ -457,4 +449,51 @@ func (o *OKCoin) WebsocketClient(currencies []string) { } OKConnWebsocket.Close() log.Printf("%s Websocket client disconnected.", o.GetName()) -} \ No newline at end of file +} + +func (o *OKCoin) SetWebsocketErrorDefaults() { + o.WebsocketErrors = map[string]string{ + "10001": "Illegal parameters", + "10002": "Authentication failure", + "10003": "This connection has requested other user data", + "10004": "This connection did not request this user data", + "10005": "System error", + "10009": "Order does not exist", + "10010": "Insufficient funds", + "10011": "Order quantity too low", + "10012": "Only support btc_usd/btc_cny ltc_usd/ltc_cny", + "10014": "Order price must be between 0 - 1,000,000", + "10015": "Channel subscription temporally not available", + "10016": "Insufficient coins", + "10017": "WebSocket authorization error", + "10100": "User frozen", + "10216": "Non-public API", + "20001": "User does not exist", + "20002": "User frozen", + "20003": "Frozen due to force liquidation", + "20004": "Future account frozen", + "20005": "User future account does not exist", + "20006": "Required field can not be null", + "20007": "Illegal parameter", + "20008": "Future account fund balance is zero", + "20009": "Future contract status error", + "20010": "Risk rate information does not exist", + "20011": `Risk rate bigger than 90% before opening position`, + "20012": `Risk rate bigger than 90% after opening position`, + "20013": "Temporally no counter party price", + "20014": "System error", + "20015": "Order does not exist", + "20016": "Liquidation quantity bigger than holding", + "20017": "Not authorized/illegal order ID", + "20018": `Order price higher than 105% or lower than 95% of the price of last minute`, + "20019": "IP restrained to access the resource", + "20020": "Secret key does not exist", + "20021": "Index information does not exist", + "20022": "Wrong API interface", + "20023": "Fixed margin user", + "20024": "Signature does not match", + "20025": "Leverage rate error", + } +} + +