Close

POST /auth/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.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.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)

Responses

  • 200

    OK

    Hide response attributes Show response attributes object
    • code integer

      Response code

    • msg string

      Diagnostic message

    • result object

      Request result

      Hide result attributes Show result attributes
      • order object

        If your order is accepted, this field will contain information about the order

        Hide order attributes Show order attributes
      • balances object

        Account balances

        Hide balances attribute Show balances attribute
        • ETH object

          ETH balance

          Hide ETH attributes Show ETH attributes
          • free number

            Available ETH balance

          • locked number

            ETH balance in use for open orders

          • ETH balance in use for pending withdrawals

          • pnl number

            ETH P&L. This number is updated every time you close an ETH-related position.

          • margin number

            ETH position margin.

          • fees number

            Fees paid since account creation.

      • Account positions

        Hide positions attribute Show positions attribute
  • 503

    Error

    Hide response attributes Show response attributes object
POST /auth/close
curl \
 -X POST https://api.everstrike.io/auth/close \
 -H "x-api-key: $API_KEY"
Response examples (200)
{
  "code": 200,
  "msg": "string",
  "result": {
    "order": {
      "pair": "USD_BTCCALL_PERP",
      "type": "LIMIT",
      "side": "SELL",
      "price": 100,
      "qty_orig": 100,
      "qty_remaining": 100,
      "status": "ACTIVE",
      "time": 1551137077642,
      "fills": [],
      "customer_id": "5f9ca5f0-380e-11e9-bf51-91a076098e19",
      "id": "849cdea0395411e98f54b395ae9c7bb6",
      "qty_orig_usd": 0.28101585963,
      "leverage": 1,
      "post_only": false,
      "reduce_only": false,
      "hidden": false
    },
    "balances": {
      "BTC": {
        "free": 21,
        "locked": 2,
        "withdrawn": 0
      }
    },
    "position": {
      "size": 1,
      "free": 1,
      "locked": 0,
      "realized": 0,
      "fills": [],
      "stats": {
        "size": 1,
        "notional": 0.14,
        "margin": 1,
        "pnl": 0,
        "equity": 1,
        "roe": 0,
        "mark": 2.1,
        "avg_entry": 3.4,
        "leverage": 2.82,
        "lp": 3.7,
        "bankrupt": 3.78,
        "direction": "BUY"
      }
    }
  }
}
Response examples (503)
{
  "code": 503,
  "msg": "Invalid request",
  "result": {}
}