Margin Trading

TH
Last updated 7 days ago

Endpoint URL

https://api.wcex.com/trading

Authenticated Endpoints

post
Place a New Order

https://api.wcex.com/trading
/trade/new
Request
Response
Body Parameters
product
required
string
A valid product.
side
required
string
Can be buy or sell.
type
required
string
Can be market or pending.
leverage
required
number
Leverage to use.
amount
required
integer
Amount in contracts.
base_currency
required
string
Must be BTC.
price
optional
string
Required only if type is pending.
take_profit
optional
string
The trade's take-profit price.
stop_loss
optional
string
The trade's stop-loss price.
200: OK
Order successfully submitted.
{
"id": "bf2b704c-010a-48ca-93fb-d0193f24420a",
"product": "EUR-USD",
"price": "1.26635",
"side": "buy",
"leverage": "300",
"amount": 1000000,
"margin": "3.33333333",
"base_size": "1000",
"base_currency": "BTC",
"type": "market",
"liquidation_price": "1.26354",
"decay_rate": "0.0002",
"created_at": 1511482279492,
"opened_at": 1511482876413
}

A trade with type market will result in an open position.

A trade with type pending will result in a pending order and behaves as either a limit or stop order depending on its price (it works in both directions).

Response

A trade accepted by the engine will be assigned a trade idwhich will appear in the response.

post
Cancel Order

https://api.wcex.com/trading
/trade/cancel
Request
Response
Body Parameters
id
required
string
The ID of the order to cancel.
200: OK
{
"id": "9d335cce-d581-45f6-8efc-bdab3d61c6e2"
}

Response

If successful, the response will contain the ID of the cancelled order.

If an order could not be cancelled (if it has been already filled, does not exist, etc.), an error is returned.

post
Update Order

https://api.wcex.com/trading
/trade/update
Updates an order or position.
Request
Response
Body Parameters
id
required
string
The ID of the order or position to update.s
price
optional
number
New price for the order.
take_profit
optional
number
New take-profit price for the order.
stop_loss
optional
number
New stop-loss price for the order.
margin
optional
number
Updated margin amount for the order.
leverage
optional
number
Updated leverage multiplier for the order.
200: OK
{
"id": "bf2b704c-010a-48ca-93fb-d0193f24420a",
"product": "EUR-USD",
"price": "1.26635",
"side": "buy",
"leverage": "300",
"amount": 1000000,
"margin": "3.33333333",
"base_size": "1000",
"base_currency": "BTC",
"type": "market",
"liquidation_price": "1.26354",
"take_profit": "1.28898",
"stop_loss": "1.26477",
"decay_rate": "0.0002",
"created_at": 1511482279492,
"updated_at": 1511482476135
}

For pending orders, price, margin, leverage, amount, take_profit, and stop_loss can be updated.

For open positions, margin, leverage, take_profit, and stop_loss can be updated.

To remove a take_profit or stop_loss, simply set it to 0.

You can set both margin and leverage in the same request, but margin will always take precedence.

Margin can only be increased, not decreased. Accordingly, leverage can only be decreased, not increased.

post
Close Position

https://api.wcex.com/trading
/trade/close
Closes a position at market price. Sells close at the ask, buys at the bid.
Request
Response
Body Parameters
id
required
string
The ID of the position to close.
200: OK
{
"id": "bf2b704c-010a-48ca-93fb-d0193f24420a",
"product": "EUR-USD",
"price": "1.26635",
"side": "buy",
"leverage": "300",
"amount": 1000000,
"margin": "3.33333333",
"base_size": "1000",
"base_currency": "BTC",
"type": "market",
"liquidation_price": "1.26354",
"decay_rate": "0.0002",
"close_price": "1.26995",
"pnl": "2.84281590",
"pnl_percent": "85.2845",
"reason": "manual",
"decay": "0",
"created_at": 1511482279492,
"opened_at": 1511482876413,
"closed_at": 1511483816212
}

post
Split Position

https://api.wcex.com/trading
/trade/split
Splits a position into two positions that can be managed separately.
Request
Response
Body Parameters
id
required
string
The ID of the position to split.
ratio
required
string
A ratio of percents. E.g. 40:60
200: OK
{
success: true,
data: {
parent_id: "bf2b704c-010a-48ca-93fb-d0193f24420a",
first_position: {...},
second_position: {...}
}
}

get
Get Orders

https://api.wcex.com/trading
/orders
Lists your pending orders, sorted by submission time (most recent first).
Request
Response
Query Parameters
limit
optional
integer
Number of orders to return (max is 100).
200: OK
[
{
"id": "bf2b704c-010a-48ca-93fb-d0193f24420a",
"product": "EUR-USD",
"price": "1.26635",
"side": "buy",
"leverage": "300",
"amount": 1000000,
"margin": "3.33333333",
"base_size": "1000",
"base_currency": "BTC",
"type": "market",
"liquidation_price": "1.26354",
"decay_rate": "0.0002",
"created_at": 1511482279492
}
]

You can optionally pass a limit query parameter to limit the number of orders returned. By default, 100 items are returned.

E.g. /orders?limit=50.

Keeping track of your orders

We recommend listening to streaming WebSocket order events to maintain an up-to-date view of your open orders. It's faster and in many cases more accurate than polling this endpoint, because an order's state may change between the time you make an HTTP request and receive a response.

Polling this endpoint is highly discouraged.

Response

An array of your pending orders.

get
Get Positions

https://api.wcex.com/trading
/positions
Lists your open positions, sorted by opening time.
Request
Response
Query Parameters
limit
optional
integer
Number of positions to return (max is 100).
200: OK
[
{
"id": "bf2b704c-010a-48ca-93fb-d0193f24420a",
"product": "EUR-USD",
"price": "1.26635",
"side": "buy",
"leverage": "300",
"amount": 1000000,
"margin": "3.33333333",
"base_size": "1000",
"base_currency": "BTC",
"type": "market",
"liquidation_price": "1.26354",
"decay_rate": "0.0002",
"created_at": 1511482279492,
"opened_at": 1511483479492
}
]

get
Get History

https://api.wcex.com/trading
/history/:product?
List your recent trades (closed positions), ordered by close time.
Request
Response
Path Parameters
product
optional
string
Limit trades returned to this product.
Query Parameters
timestamp
optional
number
Return trades that occurred before this time.
limit
optional
number
Number of trades to return (max is 100).
200: OK
[
{
"id": "bf2b704c-010a-48ca-93fb-d0193f24420a",
"product": "EUR-USD",
"price": "1.26635",
"side": "buy",
"leverage": "300",
"amount": 1000000,
"margin": "3.33333333",
"base_size": "1000",
"base_currency": "BTC",
"type": "market",
"liquidation_price": "1.26354",
"decay_rate": "0.0002",
"created_at": 1511482279492,
"opened_at" 1511483479492,
"closed_at" 1511483979492
}
]

Omitting product will return trades across all products.

E.g. /history?limit=50&timestamp=1511481127561

Keeping track of your trades

We recommend listening to streaming WebSocket match events to maintain an up-to-date view of your closed positions. It's faster and more accurate than polling this endpoint.

Polling this endpoint is highly discouraged.

Response

An array of your recent trades.

get
Get Balances

https://api.wcex.com/trading
/balances/:asset?
Lists your balances.
Request
Response
Path Parameters
asset
optional
string
Limits balances returned to this asset.
200: OK
{
"BTC": "11.88900211",
"ETH": "2218.99900000"
}

Omitting asset will return all balances on your account. Only non-zero balances, or assets for which you have made at least one deposit will be returned.

get
Get Transactions

https://api.wcex.com/trading
/transactions/:type
Lists your deposits and withdrawals, sorted by most recent first.
Request
Response
Path Parameters
type
optional
string
Can be deposit or withdraw.
Query Parameters
asset
optional
string
Limits transactions returned to this asset.
limit
optional
string
Number of transactions to return (max 100).
timestamp
optional
string
Return transactions that occurred before this time.
200: OK
[
{
"asset": "BTC",
"amount": "0.2000000",
"type": "deposit",
"address": "2MzeJNyp47Cugv85aq361AwBmaC4kxHofuu",
"txid": "8a0a2cd49b3bbcabc5a4066783e3aad47ea745a849450a865977b668ce514ec2",
"timestamp": 1511482279491,
"confirmed_at": 1511482379491
},
{
"asset": "ETH",
"amount": "200.00990000",
"type": "withdraw",
"address": "0xa93fae849449d2f9ddca15b861fcb329d39ad47c",
"txid": "0xaaec962c014ab72eec8d4abb58326dca1c5c8a9425cd851ef8b9c390f2ad050e",
"timestamp": 1511482279491,
"confirmed_at": 1511482379491
}
]

Omitting type will return all transactions on your account.

E.g. /transactions?asset=BTC&limit=50&timestamp=1511481127561

get
Get Deposit Address

https://api.wcex.com/trading
/deposit/:asset
Returns a deposit address for the provided asset.
Request
Response
Path Parameters
asset
required
string
A valid asset.
200: OK
{
"address": "2MzeJNyp47Cugv85aq361AwBmaC4kxHofuu",
"asset": "BTC",
"confirmations_needed": 2
}

Public Endpoints

get
Get Products

https://api.wcex.com/trading
/products/:product?
Lists products available to trade.
Request
Response
Path Parameters
product
optional
string
Limits results returned to this products.
200: OK
{
"forex": [
[
"EUR-USD", // product
"300", // max leverage
"0.00001", // tick
"-0.0001", // decay rate
{
"BTC": "600000" // max size
}
"EUR/USD" // name
],
...
}

get
Get Quotes

https://api.wcex.com/trading
/quotes/:product(s)
Returns quotes for the provided products(s).
Request
Response
Path Parameters
product(s)
required
string
One or more comma-separated products.
200: OK
{
"EUR-USD": [
"1.12442", // mid price
"1.12439", // bid price
"1.12445", // ask price
151143431932 // timestamp
],
...
}

E.g. /quotes/EUR-USD,AAPL,SNAP,ETH-USD

Polling this endpoint is highly discouraged in favor of subscribing to WebSocket events.

E.g. /book/XT-BTC?limit=50.

Polling this endpoint is discouraged in favor of subscribing to WebSocket events.

get
Get Candles

https://api.wcex.com/trading
/candles/:product/:resolution
Lists historical candles for a product. Candles returned are grouped by resolution.
Request
Response
Path Parameters
product
required
string
A valid product.
resolution
required
string
Can be 1, 5, 15, 60, 240, or 1D.
Query Parameters
signal
optional
string
Can be mid, bid, or ask. Defaults to mid.
start
optional
number
The time after which to fetch candles, in ms.
end
optional
number
The time before which to fetch candles, in ms.
limit
optional
number
Number of candles to return (max 150).
200: OK
[
[
"1511481600",
"0.051323",
"0.051323",
"0.05132",
"0.05132"
],
[
"1511467200",
"0.051323",
"0.051323",
"0.051323",
"0.051323"
],
[
"1511251200",
"0.044683",
"0.053744",
"0.042048",
"0.045321"
]
]

E.g. /candles/EUR-USD/60?signal=bid&start=1511480127561&end=1511480129513 fetches 1h bid candles on EUR/BTC between the start and end timestamps.

Response

Each item in the array returned represents a candle with granularity resolution:

  • timestamp (in seconds)

  • open (first trade in this interval)

  • high (highest trade in this interval)

  • low (lowest trade in this interval)

  • close (last trade in this interval)

If the candle is active, close is the last price.