Skip to main content

Overview

This is an unofficial Python wrapper for the OKJ (OKCoin Japan) v5 API

If you came here looking to purchase cryptocurrencies from the OKJ exchange, please go here.

Make sure you update often and check the Changelog for new features and bug fixes.

Features

  • Implementation of all Rest API endpoints.
  • Private and Public Websocket implementation
  • Testnet support
  • Websocket handling with reconnection and multiplexed connections

Quick start

Prerequisites

python version:>=3.9

WebSocketAPI: websockets package advise version 6.0

Step 1: register an account on OKJ and apply for an API key

Step 2: install python-okj

pip install python-okj

Step 3: Run examples

  • Fill in API credentials in the corresponding examples
api_key = ""
secret_key = ""
passphrase = ""

Runnable usage scripts live in examples/. Each one exposes example_* functions and leaves every call commented out in its __main__ block — uncomment the one you want, then run it:

python examples/account_test.py
  • Credentials and the target environment come from examples/api_config.py. DOMAIN there defaults to production (https://api.okj.com); switch it to the staging URL before running anything that places or cancels an order.
  • RestAPI: account_test.py, trade_test.py, market_test.py, funding_test.py, public_test.py, order_example.py
  • WebSocketAPI: ws_private_test.py, ws_public_test.py
  • Pass base_url= to OkjClient to choose an environment; the URLs are listed in the OKJ API documentation

Error handling

A business error is a return value, not an exception. Only HTTP >= 400 raises; a non-zero code on an HTTP 200 comes back as an ordinary dict. So try/except alone is not enough — check code as well:

from okj.exceptions import OkjAPIError, OkjRequestError

try:
    result = client.trade.get_order(inst_id="BTC-JPY", cl_ord_id="mine-1")
except OkjAPIError as exc:      # HTTP >= 400, e.g. 50113 Invalid Sign
    ...
except OkjRequestError as exc:  # network failure, or a 2xx that was not JSON
    ...
else:
    if result["code"] != "0":   # e.g. 51603 Order does not exist — HTTP 200
        ...

Both exception types derive from OkjError, so catching that alone is enough if the distinction does not matter.

Note

  • To learn more about OKJ API, visit official OKJ API documentation

  • If you face any questions when using WebSocketAPI,you can consult the following links

    • asyncio、websockets document/github:

      https://docs.python.org/3/library/asyncio-dev.html
      https://websockets.readthedocs.io/en/stable/intro/index.html
      https://github.com/python-websockets/websockets
      
    • About code=1006:

      https://github.com/Rapptz/discord.py/issues/1996
      https://github.com/python-websockets/websockets/issues/587
      

Metadata

Release files for python-okj 1.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for python-okj 1.1.0
File Size Uploaded
python_okj-1.1.0.tar.gz 21.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for python-okj 1.1.0
File Interpreter ABI Platform
python_okj-1.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 48.6 kB

Release files / python_okj-1.1.0.tar.gz

Download URL python_okj-1.1.0.tar.gz
Size 21.5 kB
Tags Source
SHA-256 checksum
How to use checksums
d25b8b0e922eff06db35ddcdb939d2b6a2f01b16369653fcd953dd9a98009141
BLAKE2b-256 checksum
How to use checksums
820e6fac322f43ab00f9f06db144157d433e4f421b7b5371b467ca44b5d88d9f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / python_okj-1.1.0-py3-none-any.whl

Download URL python_okj-1.1.0-py3-none-any.whl
Size 27.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
119276d06435d42b1d94d9c2511feff98d17c4a5896a55500c1e295086e7ca15
BLAKE2b-256 checksum
How to use checksums
17f63021c22fe40f32b3067abf10e300058c9f4589f3e2c08cac576d3aaa1893
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release history Release notifications | RSS feed

This release

1.1.0 This release

2 release files

0.0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page