Skip to content

Commit

Permalink
Add Okex exchange (#28)
Browse files Browse the repository at this point in the history
Co-authored-by: dgerasko <[email protected]>
  • Loading branch information
DGerasko and dgerasko authored Apr 17, 2024
1 parent f0c4ddc commit 55c24c4
Show file tree
Hide file tree
Showing 13 changed files with 652 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "CryptoAPIs"
uuid = "5e3d4798-c815-4641-85e1-deed530626d3"
version = "0.13.0"
version = "0.14.0"

[deps]
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ Then, to install CryptoAPIs, simply use the Julia package manager:
<td><a href="src/Gateio/Spot">CryptoAPIs.Gateio.Spot</a></td>
<td><a href="https://bhftbootcamp.github.io/CryptoAPIs.jl/stable/pages/Gateio/#Spot">Spot</a></td>
</tr>
<tr>
<td><img src="docs/src/assets/okex.png" alt="Okex Logo" width="20" height="20"></td>
<td><a href="https://www.okx.com/">Okex</a></td>
<td><a href="https://www.okx.com/docs-v5/en/">Spot</a></td>
<td><a href="src/Okex/Spot">CryptoAPIs.Okex.Spot</a></td>
<td><a href="https://bhftbootcamp.github.io/CryptoAPIs.jl/stable/pages/Okex/#Spot">Spot</a></td>
</tr>
<tr>
<td><img src="docs/src/assets/upbit.png" alt="Upbit Logo" width="20" height="20"></td>
<td><a href="https://upbit.com/">Upbit</a></td>
Expand Down
1 change: 1 addition & 0 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ makedocs(;
"pages/Bybit.md",
"pages/Coinbase.md",
"pages/Gateio.md",
"pages/Okex.md",
"pages/Upbit.md",
"For Developers" => [
"pages/docs_miniguide.md",
Expand Down
7 changes: 7 additions & 0 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ CryptoAPIs is a library written in Julia that combines API wrappers from various
<td><a href="src/Gateio/Spot">CryptoAPIs.Gateio.Spot</a></td>
<td><a href="https://bhftbootcamp.github.io/CryptoAPIs.jl/stable/pages/Gateio/#Spot">Spot</a></td>
</tr>
<tr>
<td><img src="assets/okex.png" alt="Okex Logo" width="20" height="20"></td>
<td><a href="https://www.okx.com/">Okex</a></td>
<td><a href="https://www.okx.com/docs-v5/en/">Spot</a></td>
<td><a href="src/Okex/Spot">CryptoAPIs.Okex.Spot</a></td>
<td><a href="https://bhftbootcamp.github.io/CryptoAPIs.jl/stable/pages/Okex/#Spot">Spot</a></td>
</tr>
<tr>
<td><img src="assets/upbit.png" alt="Upbit Logo" width="20" height="20"></td>
<td><a href="https://upbit.com/">Upbit</a></td>
Expand Down
18 changes: 18 additions & 0 deletions docs/src/pages/Okex.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Okex

```@docs
CryptoAPIs.Okex.OkexClient
CryptoAPIs.Okex.OkexAPIError
CryptoAPIs.Okex.Data
```

## Spot

```@docs
CryptoAPIs.Okex.Spot.public_client
```

```@docs
CryptoAPIs.Okex.Spot.candle
CryptoAPIs.Okex.Spot.currency
```
20 changes: 20 additions & 0 deletions examples/Okex/Spot.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Okex/Spot
# https://www.okx.com/docs-v5/en/

using Dates
using CryptoAPIs
using CryptoAPIs.Okex

CryptoAPIs.Okex.Spot.candle(;
instId = "BTC-USDT",
bar = Okex.Spot.Candle.d1,
)

okex_client = OkexClient(;
base_url = "https://www.okex.com",
public_key = ENV["OKEX_PUBLIC_KEY"],
secret_key = ENV["OKEX_SECRET_KEY"],
passphrase = ENV["OKEX_PASSPHRASE"],
)

CryptoAPIs.Okex.Spot.currency(okex_client; ccy = "BTC")
1 change: 1 addition & 0 deletions src/CryptoAPIs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ include("Binance/Binance.jl")
include("Bybit/Bybit.jl")
include("Coinbase/Coinbase.jl")
include("Gateio/Gateio.jl")
include("Okex/Okex.jl")
include("Upbit/Upbit.jl")

end
168 changes: 168 additions & 0 deletions src/Okex/Errors.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
# Errors
# https://www.okx.com/docs-v5/en/#error-code-rest-api-public

import ..CryptoAPIs: APIsResult, APIsUndefError
import ..CryptoAPIs: isretriable, retry_maxcount, retry_timeout

# UNDEF
isretriable(::APIsResult{OkexAPIError}) = true

# SUCCESS
isretriable(e::APIsResult{OkexAPIError{0}}) = false

# Operation failed.
isretriable(e::APIsResult{OkexAPIError{1}}) = false

# Bulk operation partially succeeded.
isretriable(e::APIsResult{OkexAPIError{2}}) = false

# Body for POST request cannot be empty.
isretriable(e::APIsResult{OkexAPIError{50000}}) = false

# Service temporarily unavailable. Try again later
isretriable(e::APIsResult{OkexAPIError{50001}}) = true

# JSON syntax error
isretriable(e::APIsResult{OkexAPIError{50002}}) = false

# API endpoint request timeout (does not mean that the request was successful or failed, please check the request result).
isretriable(e::APIsResult{OkexAPIError{50004}}) = true
retry_timeout(e::APIsResult{OkexAPIError{50004}}) = 5

# API is offline or unavailable.
isretriable(e::APIsResult{OkexAPIError{50005}}) = true
retry_timeout(e::APIsResult{OkexAPIError{50005}}) = 5

# Invalid Content-Type. Please use "application/JSON".
isretriable(e::APIsResult{OkexAPIError{50006}}) = false

# Account blocked.
isretriable(e::APIsResult{OkexAPIError{50007}}) = false

# User does not exist.
isretriable(e::APIsResult{OkexAPIError{50008}}) = false

# Account is suspended due to ongoing liquidation.
isretriable(e::APIsResult{OkexAPIError{50009}}) = false

# User ID cannot be empty.
isretriable(e::APIsResult{OkexAPIError{50010}}) = false

# Rate limit reached. Please refer to API documentation and throttle requests accordingly
isretriable(e::APIsResult{OkexAPIError{50011}}) = true
retry_timeout(e::APIsResult{OkexAPIError{50011}}) = 2
retry_maxcount(e::APIsResult{OkexAPIError{50011}}) = 50

# Account status invalid. Check account status
isretriable(e::APIsResult{OkexAPIError{50012}}) = false

# Systems are busy. Please try again later.
isretriable(e::APIsResult{OkexAPIError{50013}}) = true

# Parameter {param0}} cannot be empty.
isretriable(e::APIsResult{OkexAPIError{50014}}) = false

# Either parameter {param0}} or {param1}} is required.
isretriable(e::APIsResult{OkexAPIError{50015}}) = false

# Parameter {param0}} and {param1}} is an invalid pair.
isretriable(e::APIsResult{OkexAPIError{50016}}) = false

# Position frozen and related operations restricted due to auto-deleveraging (ADL). Try again later
isretriable(e::APIsResult{OkexAPIError{50017}}) = false

# {param0}} frozen and related operations restricted due to auto-deleveraging (ADL). Try again later
isretriable(e::APIsResult{OkexAPIError{50018}}) = false

# Account frozen and related operations restricted due to auto-deleveraging (ADL). Try again later
isretriable(e::APIsResult{OkexAPIError{50019}}) = false

# Position frozen and related operations are restricted due to liquidation. Try again later
isretriable(e::APIsResult{OkexAPIError{50020}}) = false

# {param0}} frozen and related operations are restricted due to liquidation. Try again later
isretriable(e::APIsResult{OkexAPIError{50021}}) = false

# Account frozen and related operations are restricted due to liquidation. Try again later
isretriable(e::APIsResult{OkexAPIError{50022}}) = false

# Funding fees frozen and related operations are restricted. Try again later
isretriable(e::APIsResult{OkexAPIError{50023}}) = false

# Either parameter {param0}} or {param1}} should be submitted.
isretriable(e::APIsResult{OkexAPIError{50024}}) = false

# Parameter {param0}} count exceeds the limit {param1}}.
isretriable(e::APIsResult{OkexAPIError{50025}}) = false

# System error. Try again later
isretriable(e::APIsResult{OkexAPIError{50026}}) = true
retry_timeout(e::APIsResult{OkexAPIError{50026}}) = 5

# This account is restricted from trading. Please contact customer support for assistance.
isretriable(e::APIsResult{OkexAPIError{50027}}) = false

# Unable to take the order, please reach out to support center for details.
isretriable(e::APIsResult{OkexAPIError{50028}}) = false

# Your account has triggered OKX risk control and is temporarily restricted from conducting transactions. Please check your email registered with OKX for contact from our customer support team.
isretriable(e::APIsResult{OkexAPIError{50029}}) = false

# You don't have permission to use this API endpoint
isretriable(e::APIsResult{OkexAPIError{50030}}) = false

# Your account has been set to prohibit transactions in this currency. Please confirm and try again
isretriable(e::APIsResult{OkexAPIError{50032}}) = false

# Instrument blocked. Please verify trading this instrument is allowed under account settings and try again.
isretriable(e::APIsResult{OkexAPIError{50033}}) = false

# This endpoint requires that APIKey must be bound to IP
isretriable(e::APIsResult{OkexAPIError{50035}}) = false

# The expTime can't be earlier than the current system time. Please adjust the expTime and try again.
isretriable(e::APIsResult{OkexAPIError{50036}}) = false

# Order expired.
isretriable(e::APIsResult{OkexAPIError{50037}}) = false

# This feature is unavailable in demo trading
isretriable(e::APIsResult{OkexAPIError{50038}}) = false

# Parameter "before" isn't supported for timestamp pagination
isretriable(e::APIsResult{OkexAPIError{50039}}) = false

# Too frequent operations, please try again later
isretriable(e::APIsResult{OkexAPIError{50040}}) = true

# Your user ID hasn't been whitelisted. Please contact customer service for assistance.
isretriable(e::APIsResult{OkexAPIError{50041}}) = false

# Must select one broker type
isretriable(e::APIsResult{OkexAPIError{50044}}) = false

# {param0}} has already settled. To check the relevant candlestick data, please use {param1}}
isretriable(e::APIsResult{OkexAPIError{50047}}) = false

# No information on the position tier. The current instrument doesn’t support margin trading.
isretriable(e::APIsResult{OkexAPIError{50049}}) = false

# You’ve already activated options trading. Please don’t activate it again.
isretriable(e::APIsResult{OkexAPIError{50050}}) = false

# Due to compliance restrictions in your country or region, you cannot use this feature.
isretriable(e::APIsResult{OkexAPIError{50051}}) = false

# Due to local compliance requirements, trading of this pair is restricted
isretriable(e::APIsResult{OkexAPIError{50052}}) = false

# Instrument ID does not exist.
isretriable(e::APIsResult{OkexAPIError{51001}}) = false

# Timestamp request expired.
isretriable(e::APIsResult{OkexAPIError{50102}}) = true

# Request timed out. Please try again.
isretriable(e::APIsResult{OkexAPIError{51054}}) = true
retry_timeout(e::APIsResult{OkexAPIError{51054}}) = 5
retry_maxcount(e::APIsResult{OkexAPIError{51054}}) = 50
Loading

0 comments on commit 55c24c4

Please sign in to comment.