Close
Close a position. Requires a signed payload in HMAC form to be appended to the x-signature header. The signed payload must be base64-encoded.
Javascript example:
const formurlencoded = require('form-urlencoded').default;
const crypto = require("crypto-js");
const fetch = require("node-fetch");
const API_KEY = "<YOUR_API_KEY>";
const SECRET_KEY = "<YOUR_SECRET_KEY>";
(async function() {
const payload = {pair: 'USD_BTCCALL_PERP', qty: 100, price: 100, timestamp: Date.now()};
const payload_url_encoded = formurlencoded(payload);
const HMAC = crypto.HmacSHA256(payload_url_encoded, SECRET_KEY).toString(crypto.enc.Base64);
const submitted = await fetch('https://api.testnet.everstrike.io/auth/close', {method: 'POST', body: payload_url_encoded, headers: {'content-type': 'application/x-www-form-urlencoded', 'x-api-key': API_KEY, 'x-signature': HMAC}});
const response = await submitted.json();
console.log(response);
})();
Python example (Python3):
import requests
import urllib
import hmac
import hashlib
import base64
from time import time
api_key = '<YOUR_API_KEY>'
secret_key = '<YOUR_SECRET_KEY>'
url='https://api.testnet.everstrike.io/auth/close'
payload = {'pair': 'USD_BTCCALL_PERP', 'qty': 0.001, 'price': 1, 'timestamp': time()*1000.0}
urlencoded_payload = urllib.parse.urlencode(payload)
hmac_signature = hmac.new(bytes(secret_key , 'utf-8'), msg = bytes(urlencoded_payload , 'utf-8'), digestmod = hashlib.sha256).digest()
hmac_signature_base64 = base64.b64encode(hmac_signature)
headers = {'content-type': 'application/x-www-form-urlencoded', 'x-api-key': api_key, 'x-signature': hmac_signature_base64}
response = requests.post(url, data=payload, headers=headers)
print(response.text)
print(response.status_code, response.reason)
Body Required
-
Market of position (e.g. "USD_BTCCALL_PERP")
-
qty integer(int32)
Quantity to close. To close the entire position, exclude this field.
-
price integer(int32)
The price to close the position at. To close at market, exclude this field.
-
trigger_price integer(int32)
The stop price to close the position at. To submit the close immediately, exclude this field.
-
trigger_event string
The price event that triggers the stop. Can be either MARK_PRICE, INDEX_PRICE or LAST_PRICE. The default is MARK_PRICE.
-
close_on_trigger boolean
Whether to submit the close order as a Close on Trigger order. Close on Trigger orders cancel open reduce-only orders upon being triggered in an attempt to free up margin, making them less likely to fail due to an insufficient balance.
-
Timestamp in milliseconds. As trading is all about timing, orders that reach the API 15 seconds or more after this timestamp will be rejected.
-
recv_window integer(int32)
A custom time window. Order is accepted if timestamp + recv_window <= now
curl \
-X POST https://api.testnet.everstrike.io/auth/close \
-H "x-api-key: $API_KEY" \
-H "Content-Type: application/x-www-form-urlencoded" \
-d 'pair=string&qty=42&price=42&trigger_price=42&trigger_event=string&close_on_trigger=true×tamp=42&recv_window=42'
{
"code": 200,
"msg": "null",
"result": {
"order": {
"id": "849cdea0395411e98f54b395ae9c7bb6",
"pair": "USD_BTCCALL_PERP",
"side": "SELL",
"time": 1551137077642,
"type": "LIMIT",
"fills": [],
"price": 100,
"hidden": false,
"status": "ACTIVE",
"leverage": 1,
"qty_orig": 100,
"post_only": false,
"customer_id": "5f9ca5f0-380e-11e9-bf51-91a076098e19",
"reduce_only": false,
"qty_orig_usd": 0.28101585963,
"qty_remaining": 100
},
"balances": {
"BTC": {
"free": 21,
"locked": 2,
"withdrawn": 0
}
},
"position": {
"free": 1,
"size": 1,
"fills": [],
"stats": {
"lp": 3.7,
"pnl": 0,
"roe": 0,
"mark": 2.1,
"size": 1,
"equity": 1,
"margin": 1,
"bankrupt": 3.78,
"leverage": 2.82,
"notional": 0.14,
"avg_entry": 3.4,
"direction": "BUY"
},
"locked": 0,
"realized": 0
}
}
}
{
"code": 503,
"msg": "Invalid request",
"result": {}
}