Place Stop Market Order

Stop market orders are only available in Perp Markets

Requires an authenticated websocket connection. Please also subscribe to the User Order Channel to receive push notifications for all message updates in relation to an account or sub-account (e.g. OrderOpened, OrderMatched etc......).

One account can only place up to 50 orders per second via websocket.

Curl

Request format

{
  "op": "placeorder",
  "tag": 123,
  "data": {
            "timestamp": 1679907302693,
            "recvWindow": 500,
            "clientOrderId": 1679907301552,
            "marketCode": "BTC-USD-SWAP-LIN",
            "side": "SELL",
            "orderType": "STOP_MARKET",
            "quantity": 0.012,
            "stopPrice": 22279.29
         }
}

Success response format

{
  "event": "placeorder",
  "submitted": True,
  "tag": "123",
  "timestamp": "1607639739098",
  "data": {
            "clientOrderId": "1679907301552",
            "marketCode": "BTC-USD-SWAP-LIN",
            "side": "SELL",
            "orderType": "STOP_MARKET",
            "quantity": "0.012",
            "timeInForce": "IOC",
            "price": "25000",
            "limitPrice": "25000",
            "stopPrice": "22279.29",
            "orderId": "1000001680990",
            "triggerType": "MARK_PRICE",
            "source": 0
          }
}

Failure response format

{
  "event": "placeorder",
  "submitted": False,
  "tag": "123",
  "message": "<errorMessage>",
  "code": "<errorCode>",
  "timestamp": "1679907302693",
  "data": {
           "clientOrderId": "1679907301552",
           "marketCode": "BTC-USD-SWAP-LIN",
           "side": "SELL",
           "orderType": "STOP_MARKET",
           "quantity": "0.012",
           "timeInForce": "IOC",
           "price": "25000",
           "limitPrice": "25000",
           "stopPrice": "22279.29"
           "triggerType": "MARK_PRICE",
           "source": 0
          }
}
Python

Request format

import websockets
import asyncio
import time
import hmac
import base64
import hashlib
import json

api_key = ''
api_secret = ''
ts = str(int(time.time() * 1000))
sig_payload = (ts+'GET/auth/self/verify').encode('utf-8')
signature = base64.b64encode(hmac.new(api_secret.encode('utf-8'), sig_payload, hashlib.sha256).digest()).decode('utf-8')

auth = \
{
  "op": "login",
  "tag": 1,
  "data": {
           "apiKey": api_key,
           "timestamp": ts,
           "signature": signature
          }
}
place_order = \
{
  "op": "placeorder",
  "tag": 123,
  "data": {
            "timestamp": 1679907302693,
            "recvWindow": 500,
            "clientOrderId": 1679907301552,
            "marketCode": "BTC-USD-SWAP-LIN",
            "side": "SELL",
            "orderType": "STOP_MARKET",
            "quantity": 0.001,
            "stopPrice": 22279.29
         }
}


url= 'wss://api.ox.fun/v2/websocket'
async def subscribe():
    async with websockets.connect(url) as ws:
        while True:
            if not ws.open:
                print("websocket disconnected")
                ws = await websockets.connect(url)
            response = await ws.recv()
            data = json.loads(response)
            print(data)

            if 'nonce' in data:
                    await ws.send(json.dumps(auth))
            elif 'event' in data and data['event'] == 'login':
                if data['success'] == True:
                    await ws.send(json.dumps(place_order))
            elif 'event' in data and data['event'] == 'placeorder':
                continue
asyncio.get_event_loop().run_until_complete(subscribe())

Request Parameters

Parameters
Type
Required
Description

op

STRING

Yes

placeorder

tag

INTEGER or STRING

No

If given it will be echoed in the reply and the max size of tag is 32

data

DICTIONARY object

Yes

clientOrderId

ULONG

No

Client assigned ID to help manage and identify orders with max value 9223372036854775807

marketCode

STRING

Yes

Market code e.g. BTC-USD-SWAP-LIN

orderType

STRING

Yes

STOP_MARKET

quantity

FLOAT

Yes

Quantity (denominated by contractValCurrency)

side

STRING

Yes

BUY or SELL

stopPrice

FLOAT

Yes

Stop price for the stop-market order.

Triggered by the best bid price for the SELL stop-market order.

Triggered by the best ask price for the BUY stop-market order.

timestamp

LONG

NO

In milliseconds. If an order reaches the matching engine and the current timestamp exceeds timestamp + recvWindow, then the order will be rejected. If timestamp is provided without recvWindow, then a default recvWindow of 1000ms is used. If recvWindow is provided with no timestamp, then the request will not be rejected. If neither timestamp nor recvWindow are provided, then the request will not be rejected.

recvWindow

LONG

NO

In milliseconds. If an order reaches the matching engine and the current timestamp exceeds timestamp + recvWindow, then the order will be rejected. If timestamp is provided without recvWindow, then a default recvWindow of 1000ms is used. If recvWindow is provided with no timestamp, then the request will not be rejected. If neither timestamp nor recvWindow are provided, then the request will not be rejected.

selfTradePreventionMode

STRING

No

NONE, EXPIRE_MAKER, EXPIRE_TAKER, EXPIRE_BOTH

Last updated