okcoin: Remove exchange implementation (#1626)

* okcoin: Remove exchange implementation

* exchanges/order: Rid TradeMode from Submit type
This commit is contained in:
Adrian Gallagher
2024-08-24 12:19:04 +10:00
committed by GitHub
parent 1cabba73b9
commit 74f4df6348
31 changed files with 2 additions and 8846 deletions

View File

@@ -1,140 +0,0 @@
# GoCryptoTrader package Okcoin
<img src="/common/gctlogo.png?raw=true" width="350px" height="350px" hspace="70">
[![Build Status](https://github.com/thrasher-corp/gocryptotrader/actions/workflows/tests.yml/badge.svg?branch=master)](https://github.com/thrasher-corp/gocryptotrader/actions/workflows/tests.yml)
[![Software License](https://img.shields.io/badge/License-MIT-orange.svg?style=flat-square)](https://github.com/thrasher-corp/gocryptotrader/blob/master/LICENSE)
[![GoDoc](https://godoc.org/github.com/thrasher-corp/gocryptotrader?status.svg)](https://godoc.org/github.com/thrasher-corp/gocryptotrader/exchanges/okcoin)
[![Coverage Status](http://codecov.io/github/thrasher-corp/gocryptotrader/coverage.svg?branch=master)](http://codecov.io/github/thrasher-corp/gocryptotrader?branch=master)
[![Go Report Card](https://goreportcard.com/badge/github.com/thrasher-corp/gocryptotrader)](https://goreportcard.com/report/github.com/thrasher-corp/gocryptotrader)
This okcoin package is part of the GoCryptoTrader codebase.
## This is still in active development
You can track ideas, planned features and what's in progress on this Trello board: [https://trello.com/b/ZAhMhpOy/gocryptotrader](https://trello.com/b/ZAhMhpOy/gocryptotrader).
Join our slack to discuss all things related to GoCryptoTrader! [GoCryptoTrader Slack](https://join.slack.com/t/gocryptotrader/shared_invite/enQtNTQ5NDAxMjA2Mjc5LTc5ZDE1ZTNiOGM3ZGMyMmY1NTAxYWZhODE0MWM5N2JlZDk1NDU0YTViYzk4NTk3OTRiMDQzNGQ1YTc4YmRlMTk)
## Okcoin Exchange
### Current Features
+ REST Support
+ Websocket Support
### How to enable
+ [Enable via configuration](https://github.com/thrasher-corp/gocryptotrader/tree/master/config#enable-exchange-via-config-example)
+ Individual package example below:
```go
// Exchanges will be abstracted out in further updates and examples will be
// supplied then
```
### How to do REST public/private calls
+ If enabled via "configuration".json file the exchange will be added to the
IBotExchange array in the ```go var bot Bot``` and you will only be able to use
the wrapper interface functions for accessing exchange data. View routines.go
for an example of integration usage with GoCryptoTrader. Rudimentary example
below:
main.go
```go
var o exchange.IBotExchange
for i := range bot.Exchanges {
if bot.Exchanges[i].GetName() == "Okcoin" {
o = bot.Exchanges[i]
}
}
// Public calls - wrapper functions
// Fetches current ticker information
tick, err := o.FetchTicker()
if err != nil {
// Handle error
}
// Fetches current orderbook information
ob, err := o.FetchOrderbook()
if err != nil {
// Handle error
}
// Private calls - wrapper functions - make sure your APIKEY and APISECRET are
// set and AuthenticatedAPISupport is set to true
// Fetches current account information
accountInfo, err := o.GetAccountInfo()
if err != nil {
// Handle error
}
```
+ If enabled via individually importing package, rudimentary example below:
```go
// Public calls
// Fetches current ticker information
ticker, err := o.GetTicker()
if err != nil {
// Handle error
}
// Fetches current orderbook information
ob, err := o.GetOrderBook()
if err != nil {
// Handle error
}
// Private calls - make sure your APIKEY and APISECRET are set and
// AuthenticatedAPISupport is set to true
// GetUserInfo returns account info
accountInfo, err := o.GetUserInfo(...)
if err != nil {
// Handle error
}
// Submits an order and the exchange and returns its tradeID
tradeID, err := o.Trade(...)
if err != nil {
// Handle error
}
```
### How to do Websocket public/private calls
```go
// Exchanges will be abstracted out in further updates and examples will be
// supplied then
```
### Please click GoDocs chevron above to view current GoDoc information for this package
## Contribution
Please feel free to submit any pull requests or suggest any desired features to be added.
When submitting a PR, please abide by our coding guidelines:
+ Code must adhere to the official Go [formatting](https://golang.org/doc/effective_go.html#formatting) guidelines (i.e. uses [gofmt](https://golang.org/cmd/gofmt/)).
+ Code must be documented adhering to the official Go [commentary](https://golang.org/doc/effective_go.html#commentary) guidelines.
+ Code must adhere to our [coding style](https://github.com/thrasher-corp/gocryptotrader/blob/master/doc/coding_style.md).
+ Pull requests need to be based on and opened against the `master` branch.
## Donations
<img src="https://github.com/thrasher-corp/gocryptotrader/blob/master/web/src/assets/donate.png?raw=true" hspace="70">
If this framework helped you in any way, or you would like to support the developers working on it, please donate Bitcoin to:
***bc1qk0jareu4jytc0cfrhr5wgshsq8282awpavfahc***

File diff suppressed because it is too large Load Diff

View File

@@ -1,50 +0,0 @@
package okcoin
import (
"encoding/json"
"fmt"
"strconv"
"time"
)
type okcoinTime time.Time
// UnmarshalJSON deserializes timestamp information to time.Time
func (o *okcoinTime) UnmarshalJSON(data []byte) error {
var timeMilliSecond interface{}
err := json.Unmarshal(data, &timeMilliSecond)
if err != nil {
return err
}
var timestamp int64
switch value := timeMilliSecond.(type) {
case string:
if value == "" {
*o = okcoinTime(time.Time{}) // in case timestamp information is empty string("") reset okcoinTime to zero.
return nil
}
timestamp, err = strconv.ParseInt(value, 10, 64)
if err != nil {
return err
}
case int64:
timestamp = value
case float64:
timestamp = int64(value)
case float32:
timestamp = int64(value)
default:
return fmt.Errorf("cannot unmarshal %T into okcoinTime", value)
}
if timestamp > 9999999999 {
*o = okcoinTime(time.UnixMilli(timestamp))
} else {
*o = okcoinTime(time.Unix(timestamp, 0))
}
return nil
}
// Time returns a time.Time instance from okcoinMilliSec instance
func (o *okcoinTime) Time() time.Time {
return time.Time(*o)
}

View File

@@ -1,465 +0,0 @@
package okcoin
import "errors"
// SetErrorDefaults sets the full error default list
func (o *Okcoin) SetErrorDefaults() {
o.ErrorCodes = map[string]error{
"1": errors.New(`operation failed`),
"2": errors.New(`bulk operation partially succeeded`),
"50000": errors.New(`body cannot be empty`),
"50001": errors.New(`service temporarily unavailable, please try again later`),
"50002": errors.New(`json data format error`),
"50004": errors.New(`endpoint request timeout (does not mean that the request was successful or failed, please check the request result)`),
"50005": errors.New(`api is offline or unavailable`),
"50006": errors.New(`invalid content_Type, please use "application/json" format`),
"50007": errors.New(`account blocked`),
"50008": errors.New(`user does not exist`),
"50009": errors.New(`account is suspended due to ongoing liquidation`),
"50010": errors.New(`user id cannot be empty`),
"50011": errors.New(`requests too frequent`),
"50012": errors.New(`account status invalid`),
"50013": errors.New(`system is busy, please try again later`),
"50026": errors.New(`system error, please try again later`),
"50027": errors.New(`the account is restricted from trading`),
"50028": errors.New(`unable to take the order, please reach out to support center for details`),
"50030": errors.New(`no permission to use this API`),
"50032": errors.New(`this asset is blocked, allow its trading and try again`),
"50033": errors.New(`this instrument is blocked, allow its trading and try again`),
"50035": errors.New(`this endpoint requires that APIKey must be bound to IP`),
"50036": errors.New(`invalid expTime`),
"50037": errors.New(`order expired`),
"50038": errors.New(`this feature is temporarily unavailable in demo trading`),
"50039": errors.New(`the before parameter is not available for implementing timestamp pagination`),
"50041": errors.New(`you are not currently on the whitelist, please contact customer service`),
"50100": errors.New(`aPI frozen, please contact customer service`),
"50101": errors.New(`aPIKey does not match current environment`),
"50102": errors.New(`timestamp request expired`),
"50103": errors.New(`request header "OK-ACCESS-KEY" cannot be empty`),
"50104": errors.New(`request header "OK-ACCESS-PASSPHRASE" cannot be empty`),
"50105": errors.New(`request header "OK-ACCESS-PASSPHRASE" incorrect`),
"50106": errors.New(`request header "OK-ACCESS-SIGN" cannot be empty`),
"50107": errors.New(`request header "OK-ACCESS-TIMESTAMP" cannot be empty`),
"50108": errors.New(`exchange ID does not exist`),
"50109": errors.New(`exchange domain does not exist`),
"50111": errors.New(`invalid OK-ACCESS-KEY`),
"50112": errors.New(`invalid OK-ACCESS-TIMESTAMP`),
"50113": errors.New(`invalid signature`),
"50114": errors.New(`invalid authorization`),
"50115": errors.New(`invalid request method`),
"51001": errors.New(`instrument ID does not exist`),
"51003": errors.New(`either client order ID or order ID is required`),
"51005": errors.New(`order amount exceeds the limit`),
"51006": errors.New(`order price is not within the price limit (max buy price: {0} min sell price: {1})`),
"51008": errors.New(`order failed. insufficient account balance, and the adjusted equity in USD is less than IMR`),
"51009": errors.New(`order placement function is blocked by the platform`),
"51010": errors.New(`operation is not supported under the current account mode`),
"51011": errors.New(`duplicated order ID`),
"51012": errors.New(`token does not exist`),
"51014": errors.New(`index does not exist`),
"51015": errors.New(`instrument ID does not match instrument type`),
"51016": errors.New(`duplicated client order ID`),
"51020": errors.New(`order amount should be greater than the min available amount`),
"51023": errors.New(`position does not exist`),
"51024": errors.New(`trading account is blocked`),
"51025": errors.New(`order count exceeds the limit`),
"51026": errors.New(`instrument type does not match underlying index`),
"51030": errors.New(`funding fee is being settled`),
"51031": errors.New(`this order price is not within the closing price range`),
"51032": errors.New(`closing all positions at market price`),
"51033": errors.New(`the total amount per order for this pair has reached the upper limit`),
"51037": errors.New(`the current account risk status only supports you to place IOC orders that can reduce the risk of your account`),
"51038": errors.New(`there is already an IOC order under the current risk module that reduces the risk of the account`),
"51046": errors.New(`the take profit trigger price should be higher than the order price`),
"51047": errors.New(`the stop loss trigger price should be lower than the order price`),
"51048": errors.New(`the take profit trigger price should be lower than the order price`),
"51049": errors.New(`the stop loss trigger price should be higher than the order price`),
"51050": errors.New(`the take profit trigger price should be higher than the best ask price`),
"51051": errors.New(`the stop loss trigger price should be lower than the best ask price`),
"51052": errors.New(`the take profit trigger price should be lower than the best bid price`),
"51053": errors.New(`the stop loss trigger price should be higher than the best bid price`),
"51054": errors.New(`getting information timed out, please try again later`),
"51056": errors.New(`action not allowed`),
"51058": errors.New(`no available position for this algo order`),
"51059": errors.New(`strategy for the current state does not support this operation`),
"51101": errors.New(`entered amount exceeds the max pending order amount (Cont) per transaction`),
"51103": errors.New(`entered amount exceeds the max pending order count of the underlying asset`),
"51104": errors.New(`entered amount exceeds the max pending order amount (Cont) of the underlying asset`),
"51106": errors.New(`entered amount exceeds the max order amount (Cont) of the underlying asset`),
"51107": errors.New(`entered amount exceeds the max holding amount (Cont)`),
"51109": errors.New(`no available offer`),
"51110": errors.New(`you can only place a limit order after call auction has started`),
"51112": errors.New(`close order size exceeds your available size`),
"51113": errors.New(`market-price liquidation requests too frequent`),
"51115": errors.New(`cancel all pending close-orders before liquidation`),
"51117": errors.New(`pending close-orders count exceeds limit`),
"51121": errors.New(`order count should be the integer multiples of the lot size`),
"51124": errors.New(`you can only place limit orders during call auction`),
"51127": errors.New(`available balance is 0`),
"51129": errors.New(`the value of the position and buy order has reached the position limit, and no further buying is allowed`),
"51131": errors.New(`insufficient balance`),
"51132": errors.New(`your position amount is negative and less than the minimum trading amount`),
"51134": errors.New(`closing position failed. Please check your holdings and pending orders`),
"51139": errors.New(`reduce-only feature is unavailable for the spot transactions by simple account`),
"51143": errors.New(`there is no valid quotation in the market, and the order cannot be filled in USDT mode, please try to switch to currency mode`),
"51148": errors.New(`reduce-only cannot increase the position quantity`),
"51149": errors.New(`order timed out, please try again later`),
"51150": errors.New(`the precision of the number of trades or the price exceeds the limit`),
"51201": errors.New(`value of per market order cannot exceed 1,000,000 USDT`),
"51202": errors.New(`market - order amount exceeds the max amount`),
"51204": errors.New(`the price for the limit order cannot be empty`),
"51205": errors.New(`reduce-only is not available`),
"51250": errors.New(`algo order price is out of the available range`),
"51251": errors.New(`algo order type error (when user place an iceberg order)`),
"51252": errors.New(`algo order amount is out of the available range`),
"51253": errors.New(`average amount exceeds the limit of per iceberg order`),
"51254": errors.New(`iceberg average amount error (when user place an iceberg order)`),
"51255": errors.New(`limit of per iceberg order: Total amount/1000 < x <= Total amount`),
"51256": errors.New(`iceberg order price variance error`),
"51257": errors.New(`trail order callback rate error`),
"51258": errors.New(`trail - order placement failed. The trigger price of a sell order should be higher than the last transaction price`),
"51259": errors.New(`trail - order placement failed. The trigger price of a buy order should be lower than the last transaction price`),
"51264": errors.New(`average amount exceeds the limit of per time-weighted order`),
"51265": errors.New(`time-weighted order limit error`),
"51267": errors.New(`time-weighted order strategy initiative rate error`),
"51268": errors.New(`time-weighted order strategy initiative range error`),
"51270": errors.New(`the limit of time-weighted order price variance is 0 < x <= 1%`),
"51271": errors.New(`sweep ratio should be 0 < x <= 100%`),
"51272": errors.New(`price variance should be 0 < x <= 1%`),
"51274": errors.New(`total quantity of time-weighted order must be larger than single order limit`),
"51275": errors.New(`the amount of single stop-market order cannot exceed the upper limit`),
"51276": errors.New(`stop - Market orders cannot specify a price`),
"51277": errors.New(`tp trigger price cannot be higher than the last price`),
"51278": errors.New(`sl trigger price cannot be lower than the last price`),
"51279": errors.New(`tp trigger price cannot be lower than the last price`),
"51280": errors.New(`sl trigger price cannot be higher than the last price`),
"51281": errors.New(`trigger not support the tgtCcy parameter`),
"51288": errors.New(`we are stopping the Bot. Please do not click it multiple times`),
"51289": errors.New(`bot configuration does not exist. Please try again later`),
"51290": errors.New(`the Bot engine is being upgraded. Please try again later`),
"51291": errors.New(`this Bot does not exist or has been stopped`),
"51292": errors.New(`this Bot type does not exist`),
"51293": errors.New(`this Bot does not exist`),
"51294": errors.New(`this Bot cannot be created temporarily. Please try again later`),
"51300": errors.New(`tp trigger price cannot be higher than the mark price`),
"51302": errors.New(`sl trigger price cannot be lower than the mark price`),
"51303": errors.New(`tp trigger price cannot be lower than the mark price`),
"51304": errors.New(`sl trigger price cannot be higher than the mark price`),
"51305": errors.New(`tp trigger price cannot be higher than the index price`),
"51306": errors.New(`sl trigger price cannot be lower than the index price`),
"51307": errors.New(`tp trigger price cannot be lower than the index price`),
"51308": errors.New(`sl trigger price cannot be higher than the index price`),
"51309": errors.New(`cannot create trading bot during call auction`),
"51313": errors.New(`manual transfer in isolated mode does not support bot trading`),
"51341": errors.New(`position closing not allowed`),
"51342": errors.New(`closing order already exists. Please try again later`),
"51343": errors.New(`tp price must be less than the lower price`),
"51344": errors.New(`sl price must be greater than the upper price`),
"51345": errors.New(`policy type is not grid policy`),
"51346": errors.New(`the highest price cannot be lower than the lowest price`),
"51347": errors.New(`no profit available`),
"51348": errors.New(`stop loss price should be less than the lower price in the range`),
"51349": errors.New(`stop profit price should be greater than the highest price in the range`),
"51350": errors.New(`no recommended parameters`),
"51351": errors.New(`single income must be greater than 0`),
"51400": errors.New(`cancellation failed as the order does not exist`),
"51401": errors.New(`cancellation failed as the order is already canceled`),
"51402": errors.New(`cancellation failed as the order is already completed`),
"51403": errors.New(`cancellation failed as the order type does not support cancellation`),
"51404": errors.New(`order cancellation unavailable during the second phase of call auction`),
"51405": errors.New(`cancellation failed as you do not have any pending orders`),
"51407": errors.New(`either order ID or client order ID is required`),
"51408": errors.New(`pair id or name does not match the order info`),
"51409": errors.New(`either pair id or pair name id is required`),
"51410": errors.New(`cancellation pending. duplicate order rejected`),
"51411": errors.New(`account does not have permission for mass cancellation`),
"51412": errors.New(`the order has been triggered and cannot be canceled`),
"51413": errors.New(`cancellation failed as the order type is not supported by endpoint`),
"51415": errors.New(`unable to place order. spot trading only supports using the last price as trigger price. please select "Last" and try again`),
"51500": errors.New(`either order price or amount is required`),
"51503": errors.New(`order modification failed as the order does not exist`),
"51506": errors.New(`order modification unavailable for the order type`),
"51508": errors.New(`orders are not allowed to be modified during the call auction`),
"51509": errors.New(`modification failed as the order has been canceled`),
"51510": errors.New(`modification failed as the order has been completed`),
"51511": errors.New(`operation failed as the order price did not meet the requirement for post only`),
"51512": errors.New(`failed to amend orders in batches. you cannot have duplicate orders in the same amend-batch-orders request`),
"51513": errors.New(`number of modification requests that are currently in progress for an order cannot exceed 3`),
"51600": errors.New(`status not found`),
"51601": errors.New(`order status and order ID cannot exist at the same time`),
"51602": errors.New(`either order status or order ID is required`),
"51603": errors.New(`order does not exist`),
"51607": errors.New(`the file is generating`),
"52000": errors.New(`no market data found`),
"54000": errors.New(`margin trading is not supported`),
"58002": errors.New(`please activate Savings Account first`),
"58003": errors.New(`currency type is not supported by Savings Account`),
"58004": errors.New(`account blocked`),
"58007": errors.New(`abnormal Assets interface. Please try again later`),
"58008": errors.New(`you do not have assets in this currency`),
"58009": errors.New(`currency pair do not exist`),
"58100": errors.New(`the trading product triggers risk control, and the platform has suspended the fund transfer-out function with related users. Please wait patiently`),
"58101": errors.New(`transfer suspended`),
"58102": errors.New(`too frequent transfer (transfer too frequently)`),
"58104": errors.New(`since your P2P transaction is abnormal, you are restricted from making fund transfers. Please contact customer support to remove the restriction`),
"58105": errors.New(`since your P2P transaction is abnormal, you are restricted from making fund transfers. Please transfer funds on our website or app to complete identity verification`),
"58112": errors.New(`your fund transfer failed. Please try again later`),
"58114": errors.New(`transfer amount must be more than 0`),
"58115": errors.New(`sub-account does not exist`),
"58116": errors.New(`transfer amount exceeds the limit`),
"58117": errors.New(`account assets are abnormal, please deal with negative assets before transferring`),
"58120": errors.New(`the transfer service is temporarily unavailable, please try again later`),
"58121": errors.New(`this transfer will result in a high-risk level of your position, which may lead to forced liquidation. You need to re-adjust the transfer amount to make sure the position is at a safe level before proceeding with the transfer`),
"58123": errors.New(`parameter from cannot equal to parameter to`),
"58201": errors.New(`withdrawal amount exceeds the daily limit`),
"58202": errors.New(`the minimum withdrawal amount for NEO is 1, and the amount must be an integer`),
"58203": errors.New(`please add a withdrawal address`),
"58204": errors.New(`withdrawal suspended`),
"58205": errors.New(`withdrawal amount exceeds the upper limit`),
"58206": errors.New(`withdrawal amount is less than the lower limit`),
"58207": errors.New(`withdrawal address is not in the verification-free whitelist`),
"58208": errors.New(`withdrawal failed. Please link your email`),
"58209": errors.New(`sub-accounts cannot be deposits or withdrawals`),
"58210": errors.New(`withdrawal fee exceeds the upper limit`),
"58211": errors.New(`withdrawal fee is lower than the lower limit (withdrawal endpoint: incorrect fee)`),
"58213": errors.New(`please set a trading password before withdrawing`),
"58215": errors.New(`withdrawal id does not exist`),
"58216": errors.New(`operation not allowed`),
"58217": errors.New(`you cannot withdraw your asset at the moment due to a risk detected in your withdrawal address, contact customer support for details`),
"58218": errors.New(`your saved withdrawal account has expired`),
"58220": errors.New(`the withdrawal order is already canceled`),
"58221": errors.New(`missing label of withdrawal address`),
"58222": errors.New(`temporarily unable to process withdrawal address`),
"58224": errors.New(`this type of coin does not support on-chain withdrawals. please use internal transfers`),
"58300": errors.New(`deposit-address count exceeds the limit`),
"58301": errors.New(`deposit-address not exist`),
"58302": errors.New(`deposit-address needs tag`),
"58304": errors.New(`failed to create invoice`),
"58350": errors.New(`insufficient balance`),
"58351": errors.New(`invoice expired`),
"58352": errors.New(`invalid invoice`),
"58353": errors.New(`deposit amount must be within limits`),
"58354": errors.New(`you have reached the limit of 10,000 invoices per day`),
"58355": errors.New(`permission denied. Please contact your account manager`),
"58356": errors.New(`the accounts of the same node do not support the Lightning network deposit or withdrawal`),
"58358": errors.New(`fromCcy should not be the same as toCcy`),
"58370": errors.New(`the daily usage of small assets convert exceeds the limit`),
"58371": errors.New(`small assets exceed the maximum limit`),
"58372": errors.New(`insufficient small assets`),
"59000": errors.New(`your settings failed as you have positions or open orders`),
"59002": errors.New(`sub-account settings failed as it has positions, open orders, or trading bots`),
"59004": errors.New(`only ids with the same instrument type are supported`),
"59200": errors.New(`insufficient account balance`),
"59201": errors.New(`negative account balance`),
"59401": errors.New(`holdings already reached the limit`),
"59402": errors.New(`none of the passed instId is in live state, please check them separately`),
"59500": errors.New(`only the APIKey of the main account has permission`),
"59501": errors.New(`only 50 APIKeys can be created per account`),
"59502": errors.New(`note name cannot be duplicate with the currently created APIKey note name`),
"59503": errors.New(`each APIKey can bind up to 20 IP addresses`),
"59504": errors.New(`the sub account does not support the withdrawal function`),
"59505": errors.New(`the passphrase format is incorrect`),
"59506": errors.New(`aPIKey does not exist`),
"59507": errors.New(`the two accounts involved in a transfer must be two different sub accounts under the same parent account`),
"59510": errors.New(`sub-account does not exist`),
"59601": errors.New(`this sub-account name already exists, try another name`),
"59602": errors.New(`number of api keys exceeds the limit`),
"59603": errors.New(`number of sub accounts exceeds the limit`),
"59604": errors.New(`only the main account APIkey can access this api`),
"59605": errors.New(`this API key does not exist in your sub-account, try another API key`),
"59606": errors.New(`transfer funds to your main account before deleting your sub-account`),
"59612": errors.New(`cannot convert time format`),
"59613": errors.New(`there is currently no escrow relationship established with the sub account`),
"59614": errors.New(`managed sub account do not support this operation`),
"59615": errors.New(`the time interval between the begin date and end date cannot exceed 180 days`),
"59616": errors.New(`begin date cannot be greater than end date`),
"59617": errors.New(`sub-account created. failed to set up account level`),
"59618": errors.New(`failed to create sub-account`),
}
}
var websocketErrorCodes = map[string]string{
"1": "Operation failed.",
"2": "Bulk operation partially succeeded.",
"50000": "Body cannot be empty.",
"50001": "Service temporarily unavailable, please try again later.",
"50002": "Json data format error.",
"50004": "Endpoint request timeout (does not mean that the request was successful or failed, please check the request result).",
"50005": "API is offline or unavailable.",
"50006": "Invalid Content_Type, please use 'application/json' format.",
"50007": "Account blocked.",
"50008": "User does not exist.",
"50009": "Account is suspended due to ongoing liquidation.",
"50010": "User ID cannot be empty.",
"50011": "Requests too frequent.",
"50012": "Account status invalid.",
"50013": "System is busy, please try again later.",
"50026": "System error, please try again later.",
"50027": "The account is restricted from trading.",
"50028": "Unable to take the order, please reach out to support center for details.",
"50030": "No permission to use this API",
"50032": "This asset is blocked, allow its trading and try again",
"50033": "This instrument is blocked, allow its trading and try again",
"50035": "This endpoint requires that APIKey must be bound to IP",
"50036": "Invalid expTime",
"50037": "Order expired",
"50038": "This feature is temporarily unavailable in demo trading",
"50039": "The before parameter is not available for implementing timestamp pagination",
"50041": "You are not currently on the whitelist, please contact customer service",
"50100": `API frozen, please contact customer service`,
"50101": `APIKey does not match current environment`,
"50102": `Timestamp request expired`,
"50103": `Request header "OK-ACCESS-KEY" cannot be empty`,
"50104": `Request header "OK-ACCESS-PASSPHRASE" cannot be empty`,
"50105": `Request header "OK-ACCESS-PASSPHRASE" incorrect`,
"50106": `Request header "OK-ACCESS-SIGN" cannot be empty`,
"50107": `Request header "OK-ACCESS-TIMESTAMP" cannot be empty`,
"50108": `Exchange ID does not exist`,
"50109": `Exchange domain does not exist`,
"50111": `Invalid OK-ACCESS-KEY`,
"50112": `Invalid OK-ACCESS-TIMESTAMP`,
"50113": `Invalid signature`,
"50114": `Invalid authorization`,
"50115": `Invalid request method`,
"51001": `Instrument ID does not exist`,
"51003": `Either client order ID or order ID is required`,
"51005": `Order amount exceeds the limit`,
"51009": `Order placement function is blocked by the platform`,
"51010": `Operation is not supported under the current account mode`,
"51011": `Duplicated order ID`,
"51012": `Token does not exist`,
"51014": `Index does not exist`,
"51015": `Instrument ID does not match instrument type`,
"51016": `Duplicated client order ID`,
"51020": `Order amount should be greater than the min available amount`,
"51023": `Position does not exist`,
"51024": `Trading account is blocked`,
"51025": `Order count exceeds the limit`,
"51026": `Instrument type does not match underlying index`,
"51030": `Funding fee is being settled`,
"51031": `This order price is not within the closing price range`,
"51032": `Closing all positions at market price`,
"51033": `The total amount per order for this pair has reached the upper limit`,
"51037": `The current account risk status only supports you to place IOC orders that can reduce the risk of your account`,
"51038": `There is already an IOC order under the current risk module that reduces the risk of the account`,
"51046": `The take profit trigger price should be higher than the order price`,
"51047": `The stop loss trigger price should be lower than the order price`,
"51048": `The take profit trigger price should be lower than the order price`,
"51049": `The stop loss trigger price should be higher than the order price`,
"51050": `The take profit trigger price should be higher than the best ask price`,
"51051": `The stop loss trigger price should be lower than the best ask price`,
"51052": `The take profit trigger price should be lower than the best bid price`,
"51053": `The stop loss trigger price should be higher than the best bid price`,
"51054": `Getting information timed out, please try again later`,
"51056": `Action not allowed`,
"51058": `No available position for this algo order`,
"51059": `Strategy for the current state does not support this operation`,
"51101": `Entered amount exceeds the max pending order amount (Cont) per transaction`,
"51103": `Entered amount exceeds the max pending order count of the underlying asset`,
"51104": `Entered amount exceeds the max pending order amount (Cont) of the underlying asset`,
"51106": `Entered amount exceeds the max order amount (Cont) of the underlying asset`,
"51107": `Entered amount exceeds the max holding amount (Cont)`,
"51109": `No available offer`,
"51110": `You can only place a limit order after Call Auction has started`,
"51112": `Close order size exceeds your available size`,
"51113": `Market-price liquidation requests too frequent`,
"51115": `Cancel all pending close-orders before liquidation`,
"51117": `Pending close-orders count exceeds limit`,
"51121": `Order count should be the integer multiples of the lot size`,
"51124": `You can only place limit orders during call auction`,
"51127": `Available balance is 0`,
"51129": `The value of the position and buy order has reached the position limit, and no further buying is allowed`,
"51131": `Insufficient balance`,
"51132": `Your position amount is negative and less than the minimum trading amount`,
"51134": `Closing position failed. Please check your holdings and pending orders`,
"51139": `Reduce-only feature is unavailable for the spot transactions by simple account`,
"51143": `There is no valid quotation in the market, and the order cannot be filled in USDT mode, please try to switch to currency mode`,
"51148": `ReduceOnly cannot increase the position quantity`,
"51149": `Order timed out, please try again later`,
"51150": `The precision of the number of trades or the price exceeds the limit`,
"51201": `Value of per market order cannot exceed 1,000,000 USDT`,
"51202": `Market - order amount exceeds the max amount`,
"51204": `The price for the limit order cannot be empty`,
"51205": `Reduce-Only is not available`,
"51250": `Algo order price is out of the available range`,
"51251": `Algo order type error (when user place an iceberg order)`,
"51252": `Algo order amount is out of the available range`,
"51253": `Average amount exceeds the limit of per iceberg order`,
"51254": `Iceberg average amount error (when user place an iceberg order)`,
"51255": `Limit of per iceberg order: Total amount/1000 < x <= Total amount`,
"51256": `Iceberg order price variance error`,
"51257": `Trail order callback rate error`,
"51258": `Trail - order placement failed. The trigger price of a sell order should be higher than the last transaction price`,
"51259": `Trail - order placement failed. The trigger price of a buy order should be lower than the last transaction price`,
"51264": `Average amount exceeds the limit of per time-weighted order`,
"51265": `Time-weighted order limit error`,
"51267": `Time-weighted order strategy initiative rate error`,
"51268": `Time-weighted order strategy initiative range error`,
"51270": `The limit of time-weighted order price variance is 0 < x <= 1%`,
"51271": `Sweep ratio should be 0 < x <= 100%`,
"51272": `Price variance should be 0 < x <= 1%`,
"51274": `Total quantity of time-weighted order must be larger than single order limit`,
"51275": `The amount of single stop-market order cannot exceed the upper limit`,
"51276": `Stop - Market orders cannot specify a price`,
"51277": `TP trigger price cannot be higher than the last price`,
"51278": `SL trigger price cannot be lower than the last price`,
"51279": `TP trigger price cannot be lower than the last price`,
"51280": `SL trigger price cannot be higher than the last price`,
"51281": `trigger not support the tgtCcy parameter`,
"51288": `We are stopping the Bot. Please do not click it multiple times`,
"51289": `Bot configuration does not exist. Please try again later`,
"51290": `The Bot engine is being upgraded. Please try again later`,
"51291": `This Bot does not exist or has been stopped`,
"51292": `This Bot type does not exist`,
"51293": `This Bot does not exist`,
"51294": `This Bot cannot be created temporarily. Please try again later`,
"51300": `TP trigger price cannot be higher than the mark price`,
"51302": `SL trigger price cannot be lower than the mark price`,
"51303": `TP trigger price cannot be lower than the mark price`,
"51304": `SL trigger price cannot be higher than the mark price`,
"51305": `TP trigger price cannot be higher than the index price`,
"51306": `SL trigger price cannot be lower than the index price`,
"51307": `TP trigger price cannot be lower than the index price`,
"51308": `SL trigger price cannot be higher than the index price`,
"51309": `Cannot create trading bot during call auction`,
"51313": `Manual transfer in isolated mode does not support bot trading`,
"51341": `Position closing not allowed`,
"51342": `Closing order already exists. Please try again later`,
"51343": `TP price must be less than the lower price`,
"51344": `SL price must be greater than the upper price`,
"51345": `Policy type is not grid policy`,
"51346": `The highest price cannot be lower than the lowest price`,
"51347": `No profit available`,
"51348": `Stop loss price should be less than the lower price in the range`,
"51349": `Stop profit price should be greater than the highest price in the range`,
"51350": `No recommended parameters`,
"51351": `Single income must be greater than 0`,
"51400": `cancellation failed as the order does not exist`,
"51401": `cancellation failed as the order is already canceled`,
"51402": `cancellation failed as the order is already completed`,
"51403": `cancellation failed as the order type does not support cancellation`,
"51404": `Order cancellation unavailable during the second phase of call auction`,
"51405": `cancellation failed as you do not have any pending orders`,
"51407": `Either order ID or client order ID is required`,
"51408": `Pair ID or name does not match the order info`,
"51409": `Either pair ID or pair name ID is required`,
"51410": `cancellation pending. Duplicate order rejected`,
"51411": `Account does not have permission for mass cancellation`,
"51412": `The order has been triggered and cannot be canceled`,
"51413": `cancellation failed as the order type is not supported by endpoint`,
"51415": `Unable to place order. Spot trading only supports using the last price as trigger price. Please select "Last" and try again`,
"51500": `Either order price or amount is required`,
"51503": `Order modification failed as the order does not exist`,
"51506": `Order modification unavailable for the order type`,
"51508": `Orders are not allowed to be modified during the call auction`,
"51509": `Modification failed as the order has been canceled`,
"51510": `Modification failed as the order has been completed`,
"51511": `Operation failed as the order price did not meet the requirement for Post Only`,
"51512": `Failed to amend orders in batches. You cannot have duplicate orders in the same amend-batch-orders request`,
"51513": `Number of modification requests that are currently in progress for an order cannot exceed 3`,
"51600": `Status not found`,
"51601": `Order status and order ID cannot exist at the same time`,
"51602": `Either order status or order ID is required`,
"51603": `Order does not exist`,
"51607": `The file is generating`,
}

View File

@@ -1,239 +0,0 @@
package okcoin
import (
"time"
"github.com/thrasher-corp/gocryptotrader/exchanges/request"
)
// Interval instances
const (
oneSecondInterval = time.Second
twoSecondsInterval = time.Second * 2
fiveSecondsInterval = time.Second * 5
)
// Rate of requests per interval for each end point
const (
placeTradeOrderRate = 60
placeTradeMultipleOrdersRate = 300
cancelTradeOrderRate = 60
cancelMultipleOrderRate = 300
amendTradeOrderRate = 60
amendMultipleOrdersRate = 300
getOrderDetailsRate = 60
getOrderListRate = 60
getOrderHistoryRate = 40
getOrderhistory3MonthsRate = 20
getTransactionDetails3DaysRate = 60
getTransactionDetails3MonthsRate = 10
placeAlgoOrderRate = 20
cancelAlgoOrderRate = 20
cancelAdvancedAlgoOrderRate = 20
getAlgoOrderListRate = 20
getAlgoOrderHistoryRate = 20
getFundingCurrenciesRate = 6
getFundingAccountBalanceRate = 6
getAccountAssetValuationRate = 1
fundingTransferRate = 1
getFundsTransferStateRate = 1
assetBillsDetailRate = 6
lightningDepositsRate = 2
getAssetDepositAddressRate = 6
getDepositHistoryRate = 6
postWithdrawalRate = 6
postLightningWithdrawalRate = 2
cancelWithdrawalRate = 6
getAssetWithdrawalHistoryRate = 6
getAccountBalanceRate = 10
getBillsDetailLast3MonthRate = 6
getBillsDetailRate = 6
getAccountConfigurationRate = 5
getMaxBuySellAmountOpenAmountRate = 20
getMaxAvailableTradableAmountRate = 20
getFeeRatesRate = 5
getMaxWithdrawalsRate = 20
getAvailablePairsRate = 6
requestQuotesRate = 3
placeRFQOrderRate = 3
getRFQTradeOrderDetailsRate = 6
getRFQTradeOrderHistoryRate = 6
fiatDepositRate = 6
fiatCancelDepositRate = 100
fiatDepositHistoryRate = 6
fiatWithdrawalRate = 6
fiatCancelWithdrawalRate = 100
fiatGetWithdrawalsRate = 6
fiatGetChannelInfoRate = 6
subAccountsListRate = 2
getAPIKeyOfASubAccountRate = 1
getSubAccountTradingBalanceRate = 2
getSubAccountFundingBalanceRate = 2
subAccountTransferHistoryRate = 6
masterAccountsManageTransfersBetweenSubaccountRate = 1
getTickersRate = 20
getTickerRate = 20
getOrderbookRate = 20
getCandlesticksRate = 40
getCandlestickHistoryRate = 20
getPublicTradesRate = 100
getPublicTradeHistroryRate = 10
get24HourTradingVolumeRate = 2
getOracleRate = 1
getExchangeRateRate = 1
getInstrumentsRate = 20
getSystemTimeRate = 10
getSystemStatusRate = 1
)
const (
placeTradeOrderEPL request.EndpointLimit = iota
placeTradeMultipleOrdersEPL
cancelTradeOrderEPL
cancelMultipleOrderEPL
amendTradeOrderEPL
amendMultipleOrdersEPL
getOrderDetailsEPL
getOrderListEPL
getOrderHistoryEPL
getOrderhistory3MonthsEPL
getTransactionDetails3DaysEPL
getTransactionDetails3MonthsEPL
placeAlgoOrderEPL
cancelAlgoOrderEPL
cancelAdvancedAlgoOrderEPL
getAlgoOrderListEPL
getAlgoOrderHistoryEPL
getFundingCurrenciesEPL
getFundingAccountBalanceEPL
getAccountAssetValuationEPL
fundingTransferEPL
getFundsTransferStateEPL
assetBillsDetailEPL
lightningDepositsEPL
getAssetDepositAddressEPL
getDepositHistoryEPL
postWithdrawalEPL
postLightningWithdrawalEPL
cancelWithdrawalEPL
getAssetWithdrawalHistoryEPL
getAccountBalanceEPL
getBillsDetailLast3MonthEPL
getBillsDetailEPL
getAccountConfigurationEPL
getMaxBuySellAmountOpenAmountEPL
getMaxAvailableTradableAmountEPL
getFeeRatesEPL
getMaxWithdrawalsEPL
getAvailablePairsEPL
requestQuotesEPL
placeRFQOrderEPL
getRFQTradeOrderDetailsEPL
getRFQTradeOrderHistoryEPL
fiatDepositEPL
fiatCancelDepositEPL
fiatDepositHistoryEPL
fiatWithdrawalEPL
fiatCancelWithdrawalEPL
fiatGetWithdrawalsEPL
fiatGetChannelInfoEPL
subAccountsListEPL
getAPIKeyOfASubAccountEPL
getSubAccountTradingBalanceEPL
getSubAccountFundingBalanceEPL
subAccountTransferHistoryEPL
masterAccountsManageTransfersBetweenSubaccountEPL
getTickersEPL
getTickerEPL
getOrderbookEPL
getCandlesticksEPL
getCandlestickHistoryEPL
getPublicTradesEPL
getPublicTradeHistroryEPL
get24HourTradingVolumeEPL
getOracleEPL
getExchangeRateEPL
getInstrumentsEPL
getSystemTimeEPL
getSystemStatusEPL
)
// GetRateLimit returns a new RateLimit instance which implements request.Limiter interface.
func GetRateLimit() request.RateLimitDefinitions {
return request.RateLimitDefinitions{
placeTradeOrderEPL: request.NewRateLimitWithWeight(twoSecondsInterval, placeTradeOrderRate, 1),
placeTradeMultipleOrdersEPL: request.NewRateLimitWithWeight(twoSecondsInterval, placeTradeMultipleOrdersRate, 1),
cancelTradeOrderEPL: request.NewRateLimitWithWeight(twoSecondsInterval, cancelTradeOrderRate, 1),
cancelMultipleOrderEPL: request.NewRateLimitWithWeight(twoSecondsInterval, cancelMultipleOrderRate, 1),
amendTradeOrderEPL: request.NewRateLimitWithWeight(twoSecondsInterval, amendTradeOrderRate, 1),
amendMultipleOrdersEPL: request.NewRateLimitWithWeight(twoSecondsInterval, amendMultipleOrdersRate, 1),
getOrderDetailsEPL: request.NewRateLimitWithWeight(twoSecondsInterval, getOrderDetailsRate, 1),
getOrderListEPL: request.NewRateLimitWithWeight(twoSecondsInterval, getOrderListRate, 1),
getOrderHistoryEPL: request.NewRateLimitWithWeight(twoSecondsInterval, getOrderHistoryRate, 1),
getOrderhistory3MonthsEPL: request.NewRateLimitWithWeight(twoSecondsInterval, getOrderhistory3MonthsRate, 1),
getTransactionDetails3DaysEPL: request.NewRateLimitWithWeight(twoSecondsInterval, getTransactionDetails3DaysRate, 1),
getTransactionDetails3MonthsEPL: request.NewRateLimitWithWeight(twoSecondsInterval, getTransactionDetails3MonthsRate, 1),
placeAlgoOrderEPL: request.NewRateLimitWithWeight(twoSecondsInterval, placeAlgoOrderRate, 1),
cancelAlgoOrderEPL: request.NewRateLimitWithWeight(twoSecondsInterval, cancelAlgoOrderRate, 1),
cancelAdvancedAlgoOrderEPL: request.NewRateLimitWithWeight(twoSecondsInterval, cancelAdvancedAlgoOrderRate, 1),
getAlgoOrderListEPL: request.NewRateLimitWithWeight(twoSecondsInterval, getAlgoOrderListRate, 1),
getAlgoOrderHistoryEPL: request.NewRateLimitWithWeight(twoSecondsInterval, getAlgoOrderHistoryRate, 1),
getFundingCurrenciesEPL: request.NewRateLimitWithWeight(oneSecondInterval, getFundingCurrenciesRate, 1),
getFundingAccountBalanceEPL: request.NewRateLimitWithWeight(oneSecondInterval, getFundingAccountBalanceRate, 1),
getAccountAssetValuationEPL: request.NewRateLimitWithWeight(twoSecondsInterval, getAccountAssetValuationRate, 1),
fundingTransferEPL: request.NewRateLimitWithWeight(oneSecondInterval, fundingTransferRate, 1),
getFundsTransferStateEPL: request.NewRateLimitWithWeight(oneSecondInterval, getFundsTransferStateRate, 1),
assetBillsDetailEPL: request.NewRateLimitWithWeight(oneSecondInterval, assetBillsDetailRate, 1),
lightningDepositsEPL: request.NewRateLimitWithWeight(oneSecondInterval, lightningDepositsRate, 1),
getAssetDepositAddressEPL: request.NewRateLimitWithWeight(oneSecondInterval, getAssetDepositAddressRate, 1),
getDepositHistoryEPL: request.NewRateLimitWithWeight(oneSecondInterval, getDepositHistoryRate, 1),
postWithdrawalEPL: request.NewRateLimitWithWeight(oneSecondInterval, postWithdrawalRate, 1),
postLightningWithdrawalEPL: request.NewRateLimitWithWeight(oneSecondInterval, postLightningWithdrawalRate, 1),
cancelWithdrawalEPL: request.NewRateLimitWithWeight(oneSecondInterval, cancelWithdrawalRate, 1),
getAssetWithdrawalHistoryEPL: request.NewRateLimitWithWeight(oneSecondInterval, getAssetWithdrawalHistoryRate, 1),
getAccountBalanceEPL: request.NewRateLimitWithWeight(twoSecondsInterval, getAccountBalanceRate, 1),
getBillsDetailLast3MonthEPL: request.NewRateLimitWithWeight(oneSecondInterval, getBillsDetailLast3MonthRate, 1),
getBillsDetailEPL: request.NewRateLimitWithWeight(oneSecondInterval, getBillsDetailRate, 1),
getAccountConfigurationEPL: request.NewRateLimitWithWeight(twoSecondsInterval, getAccountConfigurationRate, 1),
getMaxBuySellAmountOpenAmountEPL: request.NewRateLimitWithWeight(twoSecondsInterval, getMaxBuySellAmountOpenAmountRate, 1),
getMaxAvailableTradableAmountEPL: request.NewRateLimitWithWeight(twoSecondsInterval, getMaxAvailableTradableAmountRate, 1),
getFeeRatesEPL: request.NewRateLimitWithWeight(twoSecondsInterval, getFeeRatesRate, 1),
getMaxWithdrawalsEPL: request.NewRateLimitWithWeight(twoSecondsInterval, getMaxWithdrawalsRate, 1),
getAvailablePairsEPL: request.NewRateLimitWithWeight(oneSecondInterval, getAvailablePairsRate, 1),
requestQuotesEPL: request.NewRateLimitWithWeight(oneSecondInterval, requestQuotesRate, 1),
placeRFQOrderEPL: request.NewRateLimitWithWeight(oneSecondInterval, placeRFQOrderRate, 1),
getRFQTradeOrderDetailsEPL: request.NewRateLimitWithWeight(oneSecondInterval, getRFQTradeOrderDetailsRate, 1),
getRFQTradeOrderHistoryEPL: request.NewRateLimitWithWeight(oneSecondInterval, getRFQTradeOrderHistoryRate, 1),
fiatDepositEPL: request.NewRateLimitWithWeight(oneSecondInterval, fiatDepositRate, 1),
fiatCancelDepositEPL: request.NewRateLimitWithWeight(twoSecondsInterval, fiatCancelDepositRate, 1),
fiatDepositHistoryEPL: request.NewRateLimitWithWeight(oneSecondInterval, fiatDepositHistoryRate, 1),
fiatWithdrawalEPL: request.NewRateLimitWithWeight(oneSecondInterval, fiatWithdrawalRate, 1),
fiatCancelWithdrawalEPL: request.NewRateLimitWithWeight(twoSecondsInterval, fiatCancelWithdrawalRate, 1),
fiatGetWithdrawalsEPL: request.NewRateLimitWithWeight(oneSecondInterval, fiatGetWithdrawalsRate, 1),
fiatGetChannelInfoEPL: request.NewRateLimitWithWeight(oneSecondInterval, fiatGetChannelInfoRate, 1),
subAccountsListEPL: request.NewRateLimitWithWeight(twoSecondsInterval, subAccountsListRate, 1),
getAPIKeyOfASubAccountEPL: request.NewRateLimitWithWeight(oneSecondInterval, getAPIKeyOfASubAccountRate, 1),
getSubAccountTradingBalanceEPL: request.NewRateLimitWithWeight(twoSecondsInterval, getSubAccountTradingBalanceRate, 1),
getSubAccountFundingBalanceEPL: request.NewRateLimitWithWeight(twoSecondsInterval, getSubAccountFundingBalanceRate, 1),
subAccountTransferHistoryEPL: request.NewRateLimitWithWeight(oneSecondInterval, subAccountTransferHistoryRate, 1),
masterAccountsManageTransfersBetweenSubaccountEPL: request.NewRateLimitWithWeight(oneSecondInterval, masterAccountsManageTransfersBetweenSubaccountRate, 1),
getTickersEPL: request.NewRateLimitWithWeight(twoSecondsInterval, getTickersRate, 1),
getTickerEPL: request.NewRateLimitWithWeight(twoSecondsInterval, getTickerRate, 1),
getOrderbookEPL: request.NewRateLimitWithWeight(twoSecondsInterval, getOrderbookRate, 1),
getCandlesticksEPL: request.NewRateLimitWithWeight(twoSecondsInterval, getCandlesticksRate, 1),
getCandlestickHistoryEPL: request.NewRateLimitWithWeight(twoSecondsInterval, getCandlestickHistoryRate, 1),
getPublicTradesEPL: request.NewRateLimitWithWeight(twoSecondsInterval, getPublicTradesRate, 1),
getPublicTradeHistroryEPL: request.NewRateLimitWithWeight(twoSecondsInterval, getPublicTradeHistroryRate, 1),
get24HourTradingVolumeEPL: request.NewRateLimitWithWeight(twoSecondsInterval, get24HourTradingVolumeRate, 1),
getOracleEPL: request.NewRateLimitWithWeight(fiveSecondsInterval, getOracleRate, 1),
getExchangeRateEPL: request.NewRateLimitWithWeight(twoSecondsInterval, getExchangeRateRate, 1),
getInstrumentsEPL: request.NewRateLimitWithWeight(twoSecondsInterval, getInstrumentsRate, 1),
getSystemTimeEPL: request.NewRateLimitWithWeight(twoSecondsInterval, getSystemTimeRate, 1),
getSystemStatusEPL: request.NewRateLimitWithWeight(fiveSecondsInterval, getSystemStatusRate, 1),
}
}

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -1,184 +0,0 @@
package okcoin
import (
"context"
"encoding/json"
"errors"
"fmt"
"reflect"
"strconv"
"github.com/thrasher-corp/gocryptotrader/exchanges/stream"
)
// WsPlaceOrder place trade order through the websocket channel.
func (o *Okcoin) WsPlaceOrder(arg *PlaceTradeOrderParam) (*TradeOrderResponse, error) {
err := arg.validateTradeOrderParameter()
if err != nil {
return nil, err
}
var resp []TradeOrderResponse
err = o.SendWebsocketRequest("order", arg, &resp, true)
if err != nil {
return nil, err
}
if len(resp) == 0 {
return nil, errNoValidResponseFromServer
}
if resp[0].SCode != "0" {
return nil, fmt.Errorf("code: %s msg: %s", resp[0].SCode, resp[0].SMsg)
}
return &resp[0], nil
}
// WsPlaceMultipleOrder place orders in batches through the websocket stream. Maximum 20 orders can be placed per request. Request parameters should be passed in the form of an array.
func (o *Okcoin) WsPlaceMultipleOrder(args []PlaceTradeOrderParam) ([]TradeOrderResponse, error) {
var err error
if len(args) == 0 {
return nil, fmt.Errorf("%w, 0 length place order requests", errNilArgument)
}
for x := range args {
err = args[x].validateTradeOrderParameter()
if err != nil {
return nil, err
}
}
var resp []TradeOrderResponse
return resp, o.SendWebsocketRequest("batch-orders", args, &resp, true)
}
// WsCancelTradeOrder cancels a single trade order through the websocket stream.
func (o *Okcoin) WsCancelTradeOrder(arg *CancelTradeOrderRequest) (*TradeOrderResponse, error) {
if arg == nil {
return nil, errNilArgument
}
if arg.InstrumentID == "" {
return nil, errMissingInstrumentID
}
if arg.OrderID == "" && arg.ClientOrderID == "" {
return nil, errOrderIDOrClientOrderIDRequired
}
var resp []TradeOrderResponse
err := o.SendWebsocketRequest("cancel-order", &arg, &resp, true)
if err != nil {
return nil, err
}
if len(resp) == 0 {
return nil, errNoValidResponseFromServer
}
if resp[0].SCode != "0" {
return nil, fmt.Errorf("code: %s msg: %s", resp[0].SCode, resp[0].SMsg)
}
return &resp[0], nil
}
// WsCancelMultipleOrders cancel incomplete orders in batches through the websocket stream. Maximum 20 orders can be canceled per request.
// Request parameters should be passed in the form of an array.
func (o *Okcoin) WsCancelMultipleOrders(args []CancelTradeOrderRequest) ([]TradeOrderResponse, error) {
var err error
if len(args) == 0 {
return nil, fmt.Errorf("%w, 0 length place order requests", errNilArgument)
}
for x := range args {
err = args[x].validate()
if err != nil {
return nil, err
}
}
var resp []TradeOrderResponse
return resp, o.SendWebsocketRequest("batch-cancel-orders", args, &resp, true)
}
// WsAmendOrder amends an incomplete order through the websocket connection
func (o *Okcoin) WsAmendOrder(arg *AmendTradeOrderRequestParam) (*AmendTradeOrderResponse, error) {
err := arg.validate()
if err != nil {
return nil, err
}
var resp []AmendTradeOrderResponse
err = o.SendWebsocketRequest("amend-order", &arg, &resp, true)
if err != nil {
if len(resp) > 0 && resp[0].StatusCode != "0" && resp[0].StatusCode != "" {
return nil, fmt.Errorf("%w, code: %s msg: %s", err, resp[0].StatusCode, resp[0].StatusMessage)
}
return nil, err
}
if len(resp) == 0 {
return nil, errNoValidResponseFromServer
}
if resp[0].StatusCode != "0" {
return nil, fmt.Errorf("code: %s msg: %s", resp[0].StatusCode, resp[0].StatusMessage)
}
return &resp[0], nil
}
// WsAmendMultipleOrder amends multiple trade orders.
func (o *Okcoin) WsAmendMultipleOrder(args []AmendTradeOrderRequestParam) ([]AmendTradeOrderResponse, error) {
if len(args) == 0 {
return nil, fmt.Errorf("%w, please provide at least one trade order amendment request", errNilArgument)
}
for x := range args {
err := args[x].validate()
if err != nil {
return nil, err
}
}
var resp []AmendTradeOrderResponse
return resp, o.SendWebsocketRequest("batch-amend-orders", args, &resp, true)
}
// SendWebsocketRequest send a request through the websocket connection.
func (o *Okcoin) SendWebsocketRequest(operation string, data, result interface{}, authenticated bool) error {
switch {
case !o.Websocket.IsEnabled():
return stream.ErrWebsocketNotEnabled
case !o.Websocket.IsConnected():
return stream.ErrNotConnected
case !o.Websocket.CanUseAuthenticatedEndpoints() && authenticated:
return errors.New("websocket connection not authenticated")
}
req := &struct {
ID string `json:"id"`
Operation string `json:"op"`
Arguments interface{} `json:"args"`
}{
ID: strconv.FormatInt(o.Websocket.Conn.GenerateMessageID(false), 10),
Operation: operation,
}
if reflect.TypeOf(data).Kind() == reflect.Slice {
req.Arguments = data
} else {
req.Arguments = []interface{}{data}
}
var byteData []byte
var err error
// TODO: ratelimits for websocket
if authenticated {
byteData, err = o.Websocket.AuthConn.SendMessageReturnResponse(context.TODO(), req.ID, req)
} else {
byteData, err = o.Websocket.Conn.SendMessageReturnResponse(context.TODO(), req.ID, req)
}
if err != nil {
return err
}
response := struct {
ID string `json:"id"`
Operation string `json:"op"`
Data interface{} `json:"data"`
Code string `json:"code"`
Message string `json:"msg"`
}{
Data: &result,
}
err = json.Unmarshal(byteData, &response)
if err != nil {
return err
}
if response.Code != "" && response.Code != "0" && response.Code != "1" && response.Code != "2" {
if response.Message == "" {
response.Message = websocketErrorCodes[response.Code]
}
return fmt.Errorf("%s websocket error code: %s message: %s", o.Name, response.Code, response.Message)
}
return nil
}

View File

@@ -89,8 +89,6 @@ type Submit struct {
// Hidden when enabled orders not displaying in order book.
Hidden bool
// TradeMode specifies the trading mode for margin and non-margin orders: see okcoin_wrapper.go
TradeMode string
}
// SubmitResponse is what is returned after submitting an order to an exchange

View File

@@ -35,7 +35,6 @@ var Exchanges = []string{
"kraken",
"kucoin",
"lbank",
"okcoin",
"okx",
"poloniex",
"yobit",

View File

@@ -81,7 +81,6 @@ _b in this context is an `IBotExchange` implemented struct_
| Kraken | Yes | Yes | No |
| Kucoin | Yes | No | Yes |
| Lbank | Yes | No | Yes |
| Okcoin | Yes | Yes | Yes |
| Okx | Yes | Yes | Yes |
| Poloniex | Yes | Yes | Yes |
| Yobit | Yes | NA | No |