API Access Guide
This guide explains how partners connect to the OSL Indonesia API. Before integrating, log in to the web platform, apply for an API key and set its permissions, then develop and trade by following this guide.
Access preparation
You can create API keys under API Key Management.
Each sub-account can create up to 10 API keys, and each key can be given read and trading permissions. Each permission is described below:
- Read-Only: Read access, e.g. for market data.
- Spot Trading: Spot trading permission, used to place and cancel spot orders.
- Futures Trading: Futures trading permission, used to place and cancel futures orders.
After your API key is created, store the following information carefully. When you create an API key, the system automatically generates the API Key and the Private Key, described below:
- API Key: Identifies you on API calls; generated by the system.
- Private Key: Random private key generated by the system, used to sign requests.
- Passphrase: A password you set. It cannot be recovered; if lost, create a new API key.
For security, we strongly recommend binding IP addresses when you create an API key.
Environments
To keep integration smooth, we provide a separate test environment to support joint testing in the early stage. Once joint testing is complete and all functions are confirmed to work, you can switch to the production environment for official use. Full environment details are as follows:
Indonesia platform
Production environment:
- HTTP API domain:
https://api.koinsayang.com - WebSocket API domain:
wss://stream-api.koinsayang.com
Interface types
This chapter divides interfaces into the following two categories:
- Public interface
- Private interface
Public interface
Public interfaces are used to fetch configuration and market data. Requests to them need no authentication.
Private interface
Private interfaces are used for order and account management. Every request to a private interface must be signed using the specified verification method. Private interfaces must be verified with your API key.
WebSocket interface
WebSocket is a new HTML5 protocol that enables full-duplex communication between client and server. After a single simple handshake, the client and server are connected, and the server can actively push data to the client as the system requires.
Advantages of WebSocket:
- Data exchanged between client and server carries a very small header (about 2 bytes), which makes it more efficient.
- Both client and server can actively send data at any time.
- There is no need to repeatedly open and close TCP connections, which saves bandwidth and server resources.
- Developers are strongly encouraged to use the WebSocket API for data such as market movements and buy/sell order depth (order book).
| Domain | WebSocket API |
|---|---|
| Public WebSocket | wss://stream-api.koinsayang.com/v2/ws/public |
| Private WebSocket | wss://stream-api.koinsayang.com/v2/ws/private |
Connection guide:
Connection limit: 300 connection requests/IP/5 minutes; one IP can open at most 100 connections.
Subscription limit: 240 times/hour/connection; one connection can subscribe to up to 1,000 channels.
To keep the connection alive and stable, we recommend the following:
- Send the string "ping" every 30 seconds and expect "pong"; reconnect if none arrives.
- The server closes the connection if it receives no "ping" for 2 minutes.
- The WebSocket server accepts at most 10 messages per second per connection. Messages include: the string "ping"; JSON messages, such as subscribe or unsubscribe requests.
- If you send more messages than the limit, the connection is closed. IPs that disconnect repeatedly may be blocked by the server.
- For stability, keep each connection to at most 50 channels. The fewer channels you subscribe to, the more stable the connection.
For example, subscribing to the ticker on the public channel takes the following two steps:
- Connection address: wss://stream-api.koinsayang.com/v2/ws/public
- Send a request to subscribe to the channel
{"op":"subscribe","args":[{"channel":"ticker","instType":"SPOT","instId":"BTCUSDT"}]}