The Luno API gives you the ability to:
The Luno API makes Bitcoin and Ethereum available to anyone.
Make sure to always use HTTPS when calling the API. Non-TLS HTTP requests cause error 403 to be returned. Using non-TLS requests can leak your authentication credentials.
Make sure that your client validates the server's SSL certificate. Many libraries (e.g. urllib2 in Python2) don't validate server certificates by default. Failing to verify the server certificate makes your application vulnerable to man-in-the-middle attack.
Timestamps are always represented as an integer number of milliseconds since the UTC Epoch (a Unix timestamp).
Prices and volumes are always represented as a decimal strings e.g. "123.3432". We use strings instead of floats to preserve the precision.
Parameters for POST calls are sent as URL-encoded forms (application/x-www-form-urlencoded).
Calls to the Market Data APIs are rate limited to 1 call per second per IP address. All other API calls are rate limited to 1 call per second per customer. API call rate limits allow bursts of up to five consecutive calls. Exceeding the limit causes HTTP error code 429 to be returned.
The Go library is the recommended way to access the API: view it on GitHub.
The following libraries were implemented by third parties or are no longer under active development and are listed here for convenience. No support for them is provided by Luno and they may be out of date. A thorough review of the code is recommended before including them in any project.
Market data API calls can be accessed by anyone without authentication. The data returned may be cached for up to 1 second. The Streaming API can be used if lower latency market data is needed.
Returns the latest ticker indicators.
GET https://api.mybitx.com/api/1/ticker
pair |
string | required | Currency pair e.g. XBTZAR or ETHXBT |
$ curl https://api.mybitx.com/api/1/ticker?pair=XBTZAR
{
"ask": "1050.00",
"timestamp": 1366224386716,
"bid": "924.00",
"rolling_24_hour_volume": "12.52",
"last_trade": "950.00"
}
Returns the latest ticker indicators from all active Luno exchanges.
GET https://api.mybitx.com/api/1/tickers
$ curl https://api.mybitx.com/api/1/tickers
{
"tickers": [
{
"timestamp": 1405413955793,
"bid": "6801.00",
"ask": "6900.00",
"last_trade": "6900.00",
"rolling_24_hour_volume": "12.455579",
"pair":"XBTZAR"
},
{
"timestamp": 1405413955337,
"bid": "5000.00",
"ask":"6968.00",
"last_trade": "6830.00",
"rolling_24_hour_volume": "0.00",
"pair":"XBTNAD"
}
]
}
Returns a list of the top 100 bids and asks in the order book. Ask orders are sorted by price ascending. Bid orders are sorted by price descending. Orders of the same price are aggregated.
GET https://api.mybitx.com/api/1/orderbook_top
pair |
string | required | Currency pair e.g. XBTZAR or ETHXBT |
$ curl https://api.mybitx.com/api/1/orderbook_top?pair=XBTZAR
{
"timestamp": 1366305398592,
"bids": [
{
"volume": "0.10",
"price": "1100.00"
},
{
"volume": "0.10",
"price": "1000.00"
},
{
"volume": "0.10",
"price": "900.00"
}
],
"asks": [
{
"volume": "0.10",
"price": "1180.00"
},
{
"volume": "0.10",
"price": "2000.00"
}
]
}
Returns a list of all bids and asks in the order book. Ask orders are sorted by price ascending. Bid orders are sorted by price descending. Multiple orders at the same price are not aggregated.
Warning: This may return a large amount of data. Generally you should rather use GetOrderBook or the Streaming API.
GET https://api.mybitx.com/api/1/orderbook
pair |
string | required | Currency pair e.g. XBTZAR or ETHXBT |
$ curl https://api.mybitx.com/api/1/orderbook?pair=XBTZAR
{
"timestamp": 1366305398592,
"bids": [
{
"volume": "0.10",
"price": "1100.00"
},
{
"volume": "0.10",
"price": "1000.00"
},
{
"volume": "0.10",
"price": "900.00"
}
],
"asks": [
{
"volume": "0.10",
"price": "1180.00"
},
{
"volume": "0.10",
"price": "2000.00"
}
]
}
Returns a list of the most recent trades. At most 100 results are returned per call.
GET https://api.mybitx.com/api/1/trades
pair |
string | required | Currency pair e.g. XBTZAR or ETHXBT |
since |
integer | optional | Fetch trades executed after this time, specified as a Unix timestamp in milliseconds. |
$ curl https://api.mybitx.com/api/1/trades?pair=XBTZAR
{
"trades": [
{
"volume": "0.10",
"timestamp": 1366052621774,
"price": "1000.00",
"is_buy": true
},
{
"volume": "1.20",
"timestamp": 1366052621770,
"price": "1020.50",
"is_buy": false
}
]
}
Some API calls require your application to authenticate itself. This is done using an API key associated with your account. You can create an API key by visiting the API Keys section on the settings page.
An API key consists of an id and a secret. For example: cnz2yjswbv3jd (key id) and 0hydMZDb9HRR3Qq-iqALwZtXLkbLR4fWxtDZvkB9h4I (key secret).
API requests are authenticated using HTTP basic authentication with the key id as the username and the key secret as the password. A missing, incorrect or revoked key causes error 401 to be returned.
Each API key is granted a set of permissions when it is created. The key can only be used to call the permitted API functions.
Here is a list of the possible permissions:
Perm_R_Balance = 1
(View balance)Perm_R_Transactions = 2
(View transactions)Perm_W_Send = 4
(Send to any address)Perm_R_Addresses = 8
(View addresses)Perm_W_Addresses = 16
(Create addresses)Perm_R_Orders = 32
(View orders)Perm_W_Orders = 64
(Create orders)Perm_R_Withdrawals = 128
(View withdrawals)Perm_W_Withdrawals = 256
(Create withdrawals)Perm_R_Merchant = 512
(View merchant invoices)Perm_W_Merchant = 1024
(Create merchant invoices)Perm_W_ClientDebit = 8192
(Debit accounts)Perm_W_ClientCredit = 16384
(Credit accounts)Perm_R_Beneficiaries = 32768
(View beneficiaries)Perm_W_Beneficiaries = 65536
(Create and delete beneficiaries)A set of permissions is represented as the bitwise OR of each permission in the set. For example the set of permissions required to view balances and orders is Perm_R_Balance | Perm_R_Orders = 33
.
All transactions on the Luno platform operate on accounts. Each account is denominated in a single currency and contains an ordered list of entries that track its running balance.
Each account has a separate balance and available balance. The available balance may be lower than the balance if some funds have been reserved (e.g. for a open limit order). Account entries affect the balance and available balance independently.
Account entries are numbered sequentially. It is guaranteed that entries are never reordered or deleted. It is also guaranteed that the core attributes of the entry (the running balances and index) are never modified. Therefore, an account acts as an append-only log of transactions.
Create an additional account for the specified currency.
POST https://api.mybitx.com/api/1/accounts
currency |
string | required | The currency code for the account you want to create e.g. XBT, IDR, MYR, ZAR |
name |
string | required | The label to use for this account e.g. "Trading ACC". |
You must be verified to trade currency
in order to be able to create an account. A user has a limit of 4 accounts per currency.
$ curl -u keyid:keysecret -X POST -d currency=XBT -d name=Moon https://api.mybitx.com/api/1/accounts
{
"id": "319323232",
"name": "Moon",
"currency": "XBT"
}
Perm_W_Addresses
Return the list of all accounts and their respective balances.
GET https://api.mybitx.com/api/1/balance
$ curl -u keyid:keysecret https://api.mybitx.com/api/1/balance
{
"balance": [
{
"account_id": "1224342323",
"asset": "XBT",
"balance": "1.012423",
"reserved": "0.01",
"unconfirmed": "0.421",
"name": "XBT Account"
},
{
"account_id": "2997473",
"asset": "ZAR",
"balance": "1000.00",
"reserved": "0.00",
"unconfirmed": "0.00",
"name": "ZAR Account"
}
]
}
Perm_R_Balance
Return a list of transaction entries from an account.
Transaction entry rows are numbered sequentially starting from 1, where 1 is the oldest entry. The range of rows to return are specified with the min_row
(inclusive) and max_row
(exclusive) parameters. At most 1000 rows can be requested per call.
If min_row
or max_row
is non-positive, the range wraps around the most recent row. For example, to fetch the 100 most recent rows, use min_row=-100
and max_row=0
.
GET https://api.mybitx.com/api/1/accounts/:id/transactions
id |
string | required | Account ID |
min_row |
int | required | Minimum of the row range to return (inclusive) |
max_row |
int | required | Maximum of the row range to return (exclusive) |
$ curl -u keyid:keysecret https://api.mybitx.com/api/1/accounts/319232323/transactions?min_row=1&max_row=100
{
"id": "319232323",
"transactions": [
{
"row_index": 2,
"timestamp": 1429908835000,
"balance": 0.08,
"available": 0.08,
"balance_delta": -0.02,
"available_delta": -0.02,
"currency": "XBT",
"description": "Sold 0.02 BTC"
},
{
"row_index": 1,
"timestamp": 1429908701000,
"balance": 0.1,
"available": 0.1,
"balance_delta": 0.1,
"available_delta": 0.1,
"currency": "XBT",
"description": "Bought 0.1 BTC"
}
]
}
Perm_R_Transactions
Return a list of all pending transactions related to the account.
Unlike account entries, pending transactions are not numbered, and may be reordered, deleted or updated at any time.
GET https://api.mybitx.com/api/1/accounts/:id/pending
id |
string | required | Account ID |
$ curl -u keyid:keysecret https://api.mybitx.com/api/1/accounts/319232323/pending
{
"id": "319232323",
"pending": [
{
"timestamp": 1429908835000,
"balance": 0.03,
"available": 0.03,
"balance_delta": 0.03,
"available_delta": 0.03,
"currency": "XBT",
"description": "Received Bitcoin - 1 of 3 confirmations"
}
]
}
Perm_R_Transactions
Trading on the market is done by submitting trade orders. After a new order has been created, it is submitted for processing by the order matching engine. The order then either matches against an existing order in the order book and is filled or it rests in the order book until it is stopped.
Click here to read more about how order matching works.
Returns a list of the most recently placed orders. You can specify an optional state=PENDING
parameter to restrict the results to only open orders. You can also specify the market by using the optional pair parameter. The list is truncated after 100 items.
GET https://api.mybitx.com/api/1/listorders
state |
string | optional | Filter to only orders of this state e.g. PENDING |
pair |
string | optional | Filter to only orders of this currency pair e.g. XBTZAR or ETHXBT |
$ curl -u keyid:keysecret https://api.mybitx.com/api/1/listorders
{
"orders": [
{
"base": "0.027496",
"counter": "81.140696",
"creation_timestamp": 1423990327333,
"expiration_timestamp": 0,
"completed_timestamp": 1423991515534,
"fee_base": "0.00",
"fee_counter": "0.00",
"limit_price": "2951.00",
"limit_volume": "0.027496",
"order_id": "BXF3J88PZAYGXH7",
"pair": "XBTZAR",
"state": "COMPLETE",
"type": "ASK",
}
]
}
The base
and counter
amounts are the principal amounts that were traded, ignoring fees. For example, if the order resulted in a single trade of 1 BTC for 1000 ZAR, then base=1 BTC
and counter=1000 ZAR
.
The fee_base
and fee_counter
amounts are the fees debited after the trade principal amounts.
For example, for a buy order, base - base_fee
would be credited to the BTC account and counter + counter_fee
would be debited from the ZAR account. Similarly, for a sell order, counter - counter_fee
would be credited to the ZAR account and base + base_fee
would be debited from the BTC account.
The pair
specifies the market.
Perm_R_Orders
Create a new trade order.
Warning! Orders cannot be reversed once they have executed. Please ensure your program has been thoroughly tested before submitting orders.
If no base_account_id
or counter_account_id
are specified, your default base currency or counter currency account will be used. You can find your account IDs by calling the Balances API.
POST https://api.mybitx.com/api/1/postorder
pair |
string | required | The currency pair to trade e.g. XBTZAR or ETHXBT |
type |
string | required | "BID" for a bid (buy) limit order or "ASK" for an ask (sell) limit order. |
volume |
string | required | Amount of Bitcoin or Ethereum to buy or sell as a decimal string in units of BTC e.g. "1.423". |
price |
string | required | Limit price as a decimal string in units of ZAR/BTC e.g. "1200". |
base_account_id |
string | optional | The base currency account to use in the trade. |
counter_account_id |
string | optional | The counter currency account to use in the trade. |
post_only |
boolean | optional | Post-only orders will be cancelled if they would otherwise have traded immediately. For example, if there's a bid at ZAR 100,000 and you place a post-only ask at ZAR 100,000, your order will be cancelled instead of trading. If the best bid is ZAR 100,000 and you place a post-only ask at ZAR 101,000, your order won't trade but will go into the order book. |
$ curl -u keyid:keysecret -X POST -d pair=XBTZAR -d type=BID -d volume=0.1 -d price=1000 https://api.mybitx.com/api/1/postorder
{
"order_id": "BXMC2CJ7HNB88U4"
}
Perm_W_Orders
Create a new market order.
Warning! Orders cannot be reversed once they have executed. Please ensure your program has been thoroughly tested before submitting orders.
If no base_account_id
or counter_account_id
are specified, your default base currency or counter currency account will be used. You can find your account IDs by calling the Balances API.
A market order executes immediately, and either buys as much bitcoin that can be bought for a set amount of fiat currency, or sells a set amount of bitcoin for as much fiat as possible.
POST https://api.mybitx.com/api/1/marketorder
pair |
string | required | The currency pair to trade e.g. XBTZAR or ETHXBT |
type |
string | required | "BUY" to buy Bitcoin or Ethereum, or "SELL" to sell Bitcoin or Ethereum. |
counter_volume |
string | required - if type is "BUY" | For a "BUY" order: amount of local currency (e.g. ZAR, MYR) to spend as a decimal string in units of the local currency e.g. "100.50". |
base_volume |
string | required - if type is "SELL" | For a "SELL" order: amount of Bitcoin to sell as a decimal string in units of BTC e.g. "1.423". |
base_account_id |
string | optional | The base currency account to use in the trade. |
counter_account_id |
string | optional | The counter currency account to use in the trade. |
$ curl -u keyid:keysecret -X POST -d pair=XBTZAR -d type=BUY -d counter_volume=100.50 https://api.mybitx.com/api/1/marketorder
{
"order_id": "BXMC2CJ7HNB88U4"
}
Perm_W_Orders
Request to stop an order.
POST https://api.mybitx.com/api/1/stoporder
order_id |
string | required | The order reference as a string e.g. BXMC2CJ7HNB88U4 |
$ curl -u keyid:keysecret -X POST -d order_id=BXMC2CJ7HNB88U4 https://api.mybitx.com/api/1/stoporder
{
"success": true
}
Perm_W_Orders
Get an order by its id.
GET https://api.mybitx.com/api/1/orders/:id
id |
string | required | The order ID |
$ curl -u keyid:keysecret https://api.mybitx.com/api/1/orders/BXHW6PFRRXKFSB4
{
"order_id": "BXHW6PFRRXKFSB4",
"creation_timestamp": 1402866878367,
"expiration_timestamp": 0,
"completed_timestamp": 0,
"type": "ASK",
"state": "PENDING",
"limit_price": "6500.00",
"limit_volume": "0.05",
"base": "0.03",
"counter": "195.02",
"fee_base":"0.000",
"fee_counter":"0.00"
}
Perm_R_Orders
Returns a list of your recent trades for a given pair, sorted by oldest first. If before
is specified, then the trades are returned sorted by most-recent first.
type
in the response indicates the type of order that you placed in order to participate in the trade. Possible types: BID
, ASK
.
If is_buy
in the response is true, then the order which completed the trade (market taker) was a bid order.
Results of this query may lag behind the latest data.
GET https://api.mybitx.com/api/1/listtrades
pair |
string | required | Filter to trades of this currency pair e.g. XBTZAR or ETHXBT |
since |
integer | optional | Filter to trades on or after this timestamp, e.g. 1470810728478 |
limit |
integer | optional | Limit to this number of trades (min 1, max 100, default 100) |
$ curl -u keyid:keysecret https://api.mybitx.com/api/1/listtrades?pair=XBTZAR
{
"trades": [
{
"base": "0.147741",
"counter": "1549.950831",
"fee_base": "0.00",
"fee_counter": "0.00",
"is_buy": false,
"order_id": "BXMC2CJ7HNB88U4",
"pair": "XBTZAR",
"price": "10491.00",
"timestamp": 1467138492909,
"type": "BID",
"volume": "0.147741"
}
]
}
Perm_R_Orders
Returns your fees and 30 day trading volume (as of midnight) for a given pair.
GET https://api.mybitx.com/api/1/fee_info
pair |
string | required | Filter to trades of this currency pair e.g. XBTZAR or ETHXBT |
$ curl -u keyid:keysecret https://api.mybitx.com/api/1/fee_info?pair=XBTZAR
{
"maker_fee": "0.00",
"taker_fee": "0.10",
"thirty_day_volume": "0.894342"
}
Perm_R_Orders
Returns the default receive address associated with your account and the amount received via the address. You can specify an optional address parameter to return information for a non-default receive address. In the response, total_received is the total confirmed Bitcoin amount received excluding unconfirmed transactions. total_unconfirmed is the total sum of unconfirmed receive transactions.
GET https://api.mybitx.com/api/1/funding_address
asset |
string | required | Currency code of the asset e.g. XBT |
address |
string | optional | Specific Bitcoin or Ethereum address to retrieve. If not provided, the default address will be used. |
$ curl -u keyid:keysecret https://api.mybitx.com/api/1/funding_address?asset=XBT&address=B1tC0InExAMPL3fundIN6AdDreS5t0Use
{
"asset": "XBT",
"address": "B1tC0InExAMPL3fundIN6AdDreS5t0Use",
"total_received": "1.234567",
"total_unconfirmed": "0.00"
}
Perm_R_Addresses
Allocates a new receive address to your account. There is a rate limit of 1 address per hour, but bursts of up to 10 addresses are allowed. Only 1 Ethereum receive address can be created.
POST https://api.mybitx.com/api/1/funding_address
$ curl -u keyid:keysecret -X POST -d asset=XBT https://api.mybitx.com/api/1/funding_address
{
"asset": "XBT",
"address": "B1tC0InExAMPL3fundIN6AdDreS5t0Use",
"total_received": "0.00",
"total_unconfirmed": "0.00"
}
Perm_W_Addresses
Returns a list of withdrawal requests.
GET https://api.mybitx.com/api/1/withdrawals
$ curl -u keyid:keysecret https://api.mybitx.com/api/1/withdrawals
{
"withdrawals": [
{
"status": "PENDING",
"id": "2221"
},
{
"status": "COMPLETED",
"id": "1121"
}
]
}
Perm_R_Withdrawals
Creates a new withdrawal request.
POST https://api.mybitx.com/api/1/withdrawals
type |
string | required | Withdrawal types e.g.
ZAR_EFT ,
NAD_EFT ,
KES_MPESA ,
MYR_IBG ,
IDR_LLG
|
amount |
string | required | Amount to withdraw. The currency depends on the type. |
beneficiary_id |
string | optional | The beneficiary ID of the bank account the withdrawal will be paid out to. This parameter is required if you have multiple bank accounts. Your bank account beneficiary ID can be found by clicking on the beneficiary name on the Beneficiaries page. |
$ curl -u keyid:keysecret -X POST -d type=ZAR_EFT -d amount=1000 https://api.mybitx.com/api/1/withdrawals
{
"status": "PENDING",
"id": "1212"
}
Perm_W_Withdrawals
Returns the status of a particular withdrawal request.
GET https://api.mybitx.com/api/1/withdrawals/:id
id |
string | required | Withdrawal ID to retrieve. |
$ curl -u keyid:keysecret https://api.mybitx.com/api/1/withdrawals/1212
{
"status": "COMPLETED",
"id": "1212"
}
Perm_R_Withdrawals
Cancel a withdrawal request. This can only be done if the request is still in state PENDING
.
DELETE https://api.mybitx.com/api/1/withdrawals/:id
id |
string | required | ID of the withdrawal to cancel. |
$ curl -u keyid:keysecret -X DELETE https://api.mybitx.com/api/1/withdrawals/1212
{
"status": "CANCELLED",
"id": "1212"
}
Perm_W_Withdrawals
Send Bitcoin from your account to a Bitcoin address or email address. Send Ethereum from your account to an Ethereum address.
If the email address is not associated with an existing Luno account, an invitation to create an account and claim the funds will be sent.
Warning! Cryptocurrency transactions are irreversible. Please ensure your program has been thoroughly tested before using this call.
POST https://api.mybitx.com/api/1/send
amount |
string | required | Amount to send as a decimal string. |
currency |
string | required | Currency to send e.g. XBT |
address |
string | required | Destination Bitcoin address or email address, or Ethereum address to send to. Note:
|
description |
string | optional | Description for the transaction to record on the account statement. |
message |
string | optional | Message to send to the recipient. This is only relevant when sending to an email address. |
curl \
-u keyid:keysecret \
-X POST \
-d amount=0.001 \
-d currency=XBT \
-d [email protected] \
-d description=Your+reference \
-d message=Message+for+recipient \
https://api.mybitx.com/api/1/send
{"success":true}
Perm_W_Send
Quotes allow you to lock in an exchange rate for a short time with the option of either accepting or rejecting the quote.
Quotes can be useful for various customer-facing applications where price fluctuations would be confusing.
The API is used as follows: First create a quote for the transaction that you want to perform. If you decide to accept the quote before it expires, you will exercise the quote. If you decide not to accept it, you will discard the quote. You can also retrieve the status of a quote at any time.
Creates a new quote to buy or sell a particular amount.
You can specify either the exact amount that you want to pay or the exact amount that you want too receive.
For example, to buy exactly 0.1 Bitcoin using ZAR, you would create a quote to BUY 0.1 XBTZAR. The returned quote includes the appropriate ZAR amount. To buy Bitcoin using exactly ZAR 100, you would create a quote to SELL 100 ZARXBT. The returned quote specifies the Bitcoin as the counter amount that will be returned.
An error is returned if your account is not verified for the currency pair, or if your account would have insufficient balance to ever exercise the quote.
POST https://api.mybitx.com/api/1/quotes
type |
string | required | Possible types: BUY , SELL |
base_amount |
string | required | Amount to buy or sell in the pair base currency. |
pair |
string | required | Currency pair to trade e.g. XBTZAR , XBTMYR , ETHXBT . The pair can also be flipped if you want to buy or sell the counter currency (e.g. ZARXBT ). |
curl \
-u keyid:keysecret \
-X POST \
-d type=BUY \
-d pair=XBTZAR \
-d base_amount=0.1 \
https://api.mybitx.com/api/1/quotes
{
"id": "1324",
"type": "BUY",
"pair": "XBTZAR",
"base_amount": "0.1",
"counter_amount": "1234.24",
"created_at": 1418377612342,
"expires_at": 1418377912342,
"discarded": false,
"exercised": false
}
Perm_W_Orders
Get the latest status of a quote.
GET https://api.mybitx.com/api/1/quotes/:id
id |
string | required | ID of the quote to retrieve. |
$ curl -u keyid:keysecret https://api.mybitx.com/api/1/quotes/1324
{
"id": "1324",
"type": "BUY",
"pair": "XBTZAR",
"base_amount": "0.1",
"counter_amount": "1234.24",
"created_at": 1418377612342,
"expires_at": 1418377912342,
"discarded": false,
"exercised": false
}
Perm_R_Orders
Exercise a quote to perform the trade. If there is sufficient balance available in your account, it will be debited and the counter amount credited.
An error is returned if the quote has expired or if you have insufficient available balance.
PUT https://api.mybitx.com/api/1/quotes/:id
id |
string | required | ID of the quote to exercise. |
$ curl -u keyid:keysecret -X PUT https://api.mybitx.com/api/1/quotes/1324
{
"id": "1324",
"type": "BUY",
"pair": "XBTZAR",
"base_amount": "0.1",
"counter_amount": "1234.24",
"created_at": 1418377612342,
"expires_at": 1418377912342,
"discarded": false,
"exercised": true
}
Perm_W_Orders
Discard a quote. Once a quote has been discarded, it cannot be exercised even if it has not expired yet.
DELETE https://api.mybitx.com/api/1/quotes/:id
id |
string | required | ID of the quote to discard. |
$ curl -u keyid:keysecret -X DELETE https://api.mybitx.com/api/1/quotes/1324
{
"id": "1324",
"type": "BUY",
"pair": "XBTZAR",
"base_amount": "0.1",
"counter_amount": "1234.24",
"created_at": 1418377612342,
"expires_at": 1418377912342,
"discarded": true,
"exercised": false
}
Perm_W_Orders
Beta warning: This API is still in beta phase. This means that it may still undergo incompatible changes.
The websocket API provides streaming access to market data. It is more efficient and provides lower latency information than repeatedly polling the orderbook and recent trades but is more complicated to implement.
The streaming protocol works by requiring the client to keep an in-memory record of the order book. Update messages are then sent from the server and the client uses these to update its copy of the order book. If they are applied correctly and fully, the client's view of the order book will be identical to the server's view.
The client state consists of the following data:
Each update message transmitted from the server has a unique increasing sequence number. The message with sequence number n can be applied to state sequence n-1 to produce state sequence n.
A message may contain multiple updates which must be applied atomically and in order.
If an update is received out-of-sequence (for example update sequence n+2 or n-1 received after update sequence n), the client cannot continue and must reinitialize the state.
There are three types of update:
Create
Add a bid or ask order to the order book with a given id, price and volume.
{
"order_id": "12345678",
"type": "BID",
"price": "1234.00",
"volume": "1.23"
}
Delete
Remove the order from the order book with a given id.
{
"order_id": "12345678"
}
Trade
Reduce the outstanding volume of an order in the order book (maker_order_id
) and append a trade to the trades list.
{
"base": "0.1",
"counter": "5232.00",
"maker_order_id": "12345678",
"taker_order_id": "87654321",
}
A new order is placed below market
In this case, an update message would be sent with a single create update.
A market order is placed that is immediately filled
In this case, an update message would be sent containing multiple trade updates. There will be no create update since the new order never enters the order book.
An order is placed that is partially filled
In this case, the update message contains multiple trade updates and a create update. The volume in the create update is the remaining volume for the order.
An order is stopped
In this case, the update message contains a single delete update.
The streaming updates protocol described above can be accessed using websockets. The server first sends the current order book state and thereafter sends update messages as quickly as possible. Both the client and server must send regular keep alive messages to avoid disconnection during periods of low update message activity.
Connect to the websocket server at: wss://ws.luno.com/api/1/stream/:pair
Beta warning: This API is still in beta phase. This means that it may still undergo incompatible changes.
The client must start by sending API key credentials:
{
"api_key_id": "abcdef",
"api_key_secret": "api_key_secret_goes_here"
}
The server will then send the current order book in this format:
{
"sequence": "24352",
"asks": [
{
"id": "23298343",
"price": "1234.00",
"volume": "0.93",
}
],
"bids": [
{
"id": "3498282",
"price": "1201.00",
"volume": "1.22"
}
],
"timestamp": 1528884331021
}
Thereafter the server sends messages like these:
{
"sequence": "24353",
"trade_updates": null, // array of 0 or more trade updates
"create_update": null, // null or 1 create update
"delete_update": null, // null or 1 delete update
"timestamp": 1528884332021
}
An empty message is a keep alive message.
If there is any error while processing an update (e.g. an out-of-order update) or there is a network error or timeout (e.g. keep alive message not received in time), the client should close the connection and reconnect in order to reinitialize its state. It is critical that clients implement exponential backoff for all reconnections to avoid overloading the server in case of errors.
before
parameter to GET /api/1/listtrades
.post_only
parameter to POST /api/1/postorder
.timestamp
to the orderbook streamer response.maker_order_id
and taker_order_id
to streaming trade updates. Deprecated order_id
./api/1/trades
to only return BID
or ASK
types and it may now lag behind latest data./api/1/fee_info
which returns your fees and 30 day trading volume./api/1/trades
now returns at most 100 results per call.POST /api/1/funding_address
to allow unlimited receive addresses per account. Address creation is rate limited to 1 per hour, allowing for bursts of up to 10 consecutive calls.GET /api/1/listtrades
to allow listing of recent trades. Please note that trades will soon be removed from the response of GET /api/1/listorders
GET /api/1/orders/:id
.beneficiary_id
parameter to POST /api/1/withdrawals
.completed_timestamp
field to GET /api/1/listorders
and GET /api/1/orders/:id
responses.since
parameter to GET /api/1/trades
and added is_buy
field to the response.POST /api/1/marketorder
to allow placing of market orders.Perm_R_Beneficiaries
and Perm_W_Beneficiaries
permissions. You will have to generate a new API key if you require these permissions.GET /api/1/withdrawals/
to GET /api/1/withdrawals
and POST /api/1/withdrawals/
to POST /api/1/withdrawals
to be more consistent with other endpoints. The old URLs are now deprecated.POST accounts
for creating additional accounts in specified currencies.POST /api/1/funding_address.
GET orders/:id
if the order has any trades.base
, counter
, base_fee
and counter_fee
in the list_orders
response in the case where counter_fee
is nonzero for buy orders and where base_fee
is nonzero for sell orders.transactions
beta call has beendeprecated.balance
method can now be called with no arguments to return all account balances.api.mybitx.com
.listorders
to return only the list of open orders.funding_address
call has been added to get the bitcoin address you need to fund your trade account balance.balance
call has been added to query the trading account balance./api/1/BTCZAR/x
to /api/1/x?pair=XBTZAR
. The old URLs are now deprecated.balance
call instead.currency
field is now deprecated.currency
field is now deprecated.currency
field is now deprecated.btc
, zar
, fee_btc
and fee_zar
fields are now deprecated. Please use base
, counter
, fee_base
, fee_counter
fields instead.