NAV Navbar
python javascript
  • introduction
  • Autennication
  • Public interface
  • Market
  • Account
  • Order
  • Positions
  • ws Push portal
  • Auto Trading
  • introduction

    You can easily access the FMex trading platform using the API provided by FMex through the following information.

    API domain name of real trading: https://api.fmex.com

    API domain name of testnet trading: https://api.fmextest.net

    API access address: https://api.fmex.com/ < path >, please note that we only support HTTPS access but not HTTP.

    API requests: only GET or POST requests are supported.

    For the GET request, all request parameters shall be transferred-in by queryString, for example: /v1/contracts/orders/open?symbol=btcusd_p

    For the POST Request, all request parameters shall be transferred-in by JSON Request as Request Body. The request Type must be content-type: application/json.

    Autennication

    FMex uses API key and API secret of FCoin for authentication,please access "settings"(https://exchange.fcoin.pro/settings/api) to obtain API key and API secret.

    FMex uses API request of FCoin, all other API require API key and signature expect public API.

    Access limitations

    The access frequency is 100 times / 10 seconds per user at present. And access frequency will be restricted according to the business in the future.

    API signature

    The data prepared before signature is as follows:

    HTTP_METHOD + HTTP_REQUEST_URI + TIMESTAMP + POST_BODY

    After the connection is completed, conduct 'Base64' encoding, sign 'hmac-sha1' for the encoded data, and conduct 'Base64' encoding twice for the signature. Each part is explained as follows:

    HTTP_METHOD

    GET, POST, DELETE, PUT must be in capital letters

    HTTP_REQUEST_URI

    https://api.fmextest.net/ is the prefix of API request

    The actual resource path to access needs to be added, such as orders?param1=value1,this final shall be https://api.fmextest.net/orders?param1=value1

    Please alphabetize the parameters in the requested URI.

    If the request URI is https://api.fmextest.net/orders?c=value1&b=value2&a=value3,then the request parameters should be alphabetized first when signing, and the final URI for signing is https://XXX/orders? a=value3&b=value2&c=value1, Please be noted that the three parameters in the original request URI are in order 'c, b, a' and 'a, b, c' after alphabetizing.

    TIMESTAMP

    The UNIX EPOCH timestamp for accessing API needs to at less than 30 seconds from the server

    POST_BODY

    If it is a 'POST' request, the 'POST' request data also needs to be signed. The signature rules are as follows: The keys of all requests are sorted alphabetically, then the url is parameterized and connected by using '&'.

    If the request data is:

    {
      "username": "username",
      "password": "passowrd"
    }
    

    therefore, first to alphabetize Key and then parameterized the url which is:

    password=password
    username=username
    

    Because 'p' is sorted before 'u' in the alphabet, 'password' should be placed before 'username' and then connected with '&', that is:

    password=password&username=username
    

    Complete example

    for the following request:

    POST https://api.fmextest.net/orders
    
    {
      "symbol":"btcusd_p",
      "type":"limit",
      "direction":"short",
      "source":"web",
      "price":5500,
      "quantity":100
    }
    
    timestamp: 1523069544359
    

    The prepared data before signing are as follows:

    POSThttps://api.fmextest.net/v3/contracts/orders1571109222426direction=short&price=5500&quantity=100&source=WEB&symbol=btcusd_p&type=limit
    

    Conduct Base64 code,then you will get:

    UE9TVGh0dHBzOi8vYXBpLnRlc3RuZXQuZm1leC5jb20vdjMvY29udHJhY3RzL29yZGVyczE1NzExMDkyMjI0MjZkaXJlY3Rpb249c2hvcnQmcHJpY2U9NTUwMCZxdWFudGl0eT0xMDAmc291cmNlPVdFQiZzeW1ib2w9YnRjdXNkX3AmdHlwZT1saW1pdA==
    

    copy SECRET (API SECRET)when applying for API Key, using ebfaeef06e2e49e1bc7e535c2766bbe6 as an example for the signature results ,

    Use private key for HMAC-SHA1 signature for the obtained result, conduct Base64 encode to the binary result then you will get: g6vFomL3T3pOhCugUNo/UcaLxTw=

    Then generates the final signature used for API server authentication

    Parameter name

    instructions

    You can use developer tool (not available yet) for online debugging,

    Public interface

    Obtain all current trading pairs on the exchange

    This API is used for obtaining all current trading pairs.

    HTTP Request

    GET /v2/public/contracts/symbols

    Obtain time

    This API is used for obtaining system time

    HTTP Request

    GET /v2/public/server-time

    Obtain currency

    This API is used for obtaining currencies

    HTTP Request

    GET /v2/public/contracts/currencies

    Obtain index list

    This API is used for obtaining index list

    HTTP Request

    GET /v2/public/indexes/symbols

    Market

    Market overview

    Market is a fully public API, HTTP and WebSocket API are available for now. WebSocket is recommended to ensure more timely access to the market. The current public part can only obtain the market of the latest period to ensure the real-time performance of the market as far as possible. If you need to obtain the full volume or historical market, please consult support@fmex.com

    All HTTP request URLs base is: https://api.fmex.com

    All WebSocket request URL is: wss://api.fmex.com/v2/ws

    Controlled terminology in following text:

    WebSocket connection established firstly

    The server sends a welcome message when the connection for the first time is successful

    The server returns information after the connection is successful:

    {
      "type":"hello",
      "ts":1523693784042
    }
    
    • ts: represents the current time of server push.

    WebSocket connection remains - heartbeat

    # WebSocket send ping - heartbeat to server end 
    import time
    import fcoin
    
    api = fcoin.authorize('key', 'secret', timestamp)
    now_ms = int(time.time())
    api.market.ping(now_ms)
    

    After the connection is established between the WebSocket Client and the WebSocket server, it is recommended that the WebSocket Client make a ping request to the server every 10s . If the server does not receive the ping request from the Client for a long time, it will actively disconnect.

    WebSocket request

    Send ping commend: {"cmd":"ping","args":[$client_ts],"id":"$client_id"}

    ping command request example:

    {"cmd":"ping","args":[1540557696867],"id":"sample.client.id"}
    

    server return successfully ping commend:

    {
      "id":"sample.client.id",
      "type":"ping",
      "ts":1523693784042,
      "gap":112
    }
    
    • gap: The time gap between the push server to process this statement and the client to transmit it.
    • ts: The current time of the push server

    WebSocket subscription

    Send sub commend: {"cmd":"sub","args":["$topic", ...],"id":"$client_id"}

    sub commend request example (single topic):

    {"cmd":"sub","args":["ticker.ethbtc"]}
    

    sub commend request example (multiple topics):

    {"cmd":"sub","args":["ticker.ethbtc", "ticker.btcusdt"]}
    

    The responding result of the successful subscription are as follows:

    {
      "type": "topics",
      "topics": ["ticker.ethbtc", "ticker.btcusdt"]
    }
    

    The responding result of the failed subscription are as follows:

    {
      "id":"invalid_topics_sample",
      "status":41002,
      "msg":"invalid sub topic, xxx.M1.xxx"
    }
    

    Obtain ticker data

    To make the ticker information group small and fast enough, we forced the use of a list format.

    Corresponding meaning description of the ticker list:

    [
      "Latest closed price",
      "Amount of last transaction",
      "Maximum price of buy 1",
      "Maximum amount of buy 1",
      "Minimum price of buy 1"",
      "Minimum amount of buy 1",
      "The closed price of 24 hours ago",
      "The highest price within 24 hours",
      "The lowest price within 24 hours",
      "Volume of base currency in 24 hours such as the btc btcusdt",
      "Volume of quota currency in 24 hours such as the used in btcusdt "
    ]
    

    HTTP request

    GET https://api.fmex.com/v2/market/ticker/$symbol

    The result of HTTP request is noticed as follow:

    {
      "status": 0,
      "data": {
        "type": "ticker.btcusdt",
        "seq": 680035,
        "ticker": [
          7140.890000000000000000,
          1.000000000000000000,
          7131.330000000,
          233.524600000,
          7140.890000000,
          225.495049866,
          7140.890000000,
          7140.890000000,
          7140.890000000,
          1.000000000,
          7140.890000000000000000
        ]
      }
    }
    

    WebSocket subscription

    Send sub commend,topic: ticker.$symbol (Please refer to WebSocket subscription)

    The result of WebSocket subscription is noticed as follow:

    {
      "type": "ticker.btcusdt",
      "seq": 680035,
      "ticker": [
        7140.890000000000000000,
        1.000000000000000000,
        7131.330000000,
        233.524600000,
        7140.890000000,
        225.495049866,
        7140.890000000,
        7140.890000000,
        7140.890000000,
        1.000000000,
        7140.890000000000000000
      ]
    }
    

    Obtain the latest depth details

    HTTP request

    GET https://api.fmex.com/v2/market/depth/$level/$symbol

    $level included types (case sensitive):

    Type Description
    L20 20-level market depth
    L150 150-level market depth.

    Among the push time of L20 will be a bit earlier than L150, and the push frequency will be a bit more than L150, please use as appropriate for specific stress and situation.

    The result of WebSocket subscription is noticed as follow:

    {
      "status":0,
      "data":{
        "type": "depth.L20.ethbtc",
        "ts": 1523619211000,
        "seq": 120,
        "bids": [0.000100000, 1.000000000, 0.000010000, 1.000000000],
        "asks": [1.000000000, 1.000000000]
      }
    }
    

    WebSocket subscription

    Send sub commend,topic: depth.$level.$symbol (please refer to WebSocket subscription)

    The result of WebSocket subscription is noticed as follow:

    {
      "type": "depth.L20.ethbtc",
      "ts": 1523619211000,
      "seq": 120,
      "bids": [0.000100000, 1.000000000, 0.000010000, 1.000000000],
      "asks": [1.000000000, 1.000000000]
    }
    

    The corresponding array between bids and asks must be even number Buy (Sell)1 price,Buy (Sell)1 quantity, in order.

    Obtain the latest transaction details

    By comparing the size of the transaction id to determine whether it is an updated transaction. It should be noted that due to the trade to transaction process, the transaction id of the public market does not actually correspond to the transaction id in the clearing system. Even if the transaction is a record, there is no guarantee that the id of the latest transaction will always be the same when retrieved.

    PS: It's guaranteed that the transaction id is kept constant in the historical market. {transaction id} is only used as a market update notification and should not be relied on for filing.

    HTTP request

    GET https://api.fmex.com/v2/market/trades/$symbol

    Request parameters(HTTP request)

    Parameters Defaults description
    before Query the history trade of a certain id
    limit 20 by default

    WebSocket request

    Send *req commend *: {"cmd":"req", "args":["$topic", limit],"id":"$client_id"}

    The result of WebSocket subscription is noticed as follow:

    {
      "id":null,
      "ts":1523693400329,
      "data":[
        {
          "amount":1.000000000,
          "ts":1523419946174,
          "id":76000,
          "side":"sell",
          "price":4.000000000
        },
        {
          "amount":1.000000000,
          "ts":1523419114272,
          "id":74000,
          "side":"sell",
          "price":4.000000000
        },
        {
          "amount":1.000000000,
          "ts":1523415182356,
          "id":71000,
          "side":"sell",
          "price":3.000000000
        }
      ]
    }
    

    WebSocket subscription

    send sub commend,topic: trade.$symbol (please refer to WebSocket subsription)

    The result of WebSocket subscription is noticed as follow:

    {
      "type":"trade.ethbtc",
      "id":76000,
      "amount":1.000000000,
      "ts":1523419946174,
      "side":"sell",
      "price":4.000000000
    }
    

    Obtain Candle information

    HTTP request

    GET https://api.fmex.com/v2/market/candles/$resolution/$symbol

    Request parameters(HTTP request)

    Parameters Defaults Description
    before Query the history Candle of a certain id
    limit 20 by defaults

    $resolution including types(case sensitive):

    Type description
    M1 1 Minute
    M3 3 Minutes
    M5 5 Minutes
    M15 15 Minutes
    M30 30 Minutes
    H1 1 Hour
    H4 4 Hours
    H6 6 Hours
    D1 1 Day
    W1 1 Week
    MN 1 Month

    WebSocket request

    Send req commend: {"cmd":"req","args":["$topic",limit,before],"id":"$client_id"}

    The responding result of the successful WebSocket request is as follow:

    {
      "id":"candle.M15.btcusdt",
      "data":[
        {
          "id":1540809840,
          "seq":24793830600000,
          "high":6491.74,
          "low":6489.24,
          "open":6491.24,
          "close":6490.07,
          "count":26,
          "base_vol":53371.531286,
          "quote_vol":8.2221
        },
        {
          "id":1540809900,
          "seq":24793879800000,
          "high":6490.47,
          "low":6487.62,
          "open":6490.09,
          "close":6487.62,
          "count":23,
          "base_vol":70430.840624,
          "quote_vol":10.8527
        }
      ]
    }
    

    WebSokcet subscription

    Send sub commend,topic: candle.$resolution.$symbol (please refer to WebSocket subsription)

    The notice of the WebSocket subscription result is as follow:

    {
      "type":"candle.M1.ethbtc",
      "id":1523691480,
      "seq":11400000,
      "open":2.000000000,
      "close":2.000000000,
      "high":2.000000000,
      "low":2.000000000,
      "count":0,
      "base_vol":0,
      "quote_vol":0
    }
    

    Obtain the current system index

    HTTP request

    GET https://api.fmex.com/v2/market/indexes

    Obtain the latest value of a certain index

    HTTP request

    GET https://api.fmex.com/v2/market/indexes/$indexname

    Obtain fee rate

    HTTP request

    GET https://api.fmex.com/v2/market/fex

    Account

    Query the balance of the current account

    This api is used for query user's asset

    HTTP Request

    API Path:GET /v3/contracts/accounts

    API Request Parameter:NON

    API Responding:

    {
      "status":0,
      "data":
            {Currency: [Available balance, frozen amount for orders, position margin]
              "BTC":[2.796888254907565438,0E-18,0E-18]
              }
            }
    }
    

    Transfer Margin to wallet

    HTTP Request

    API Path:POST /v3/contracts/transfer/out/request

    Request Parameter

    Fieldname Required or not Description
    currency Y Currency name,such as"BTC"
    transfer_from Y Transfer from,must be"contracts"
    transfer_to Y Transfer to,must be"wallet"
    amount Y Transfer amount,such as:1.024

    Request example:

    {
        "currency":"BTC",
        "transfer_from":"CONTRACTS",
        "transfer_to":"WALLET",
        "amount":1,
    }
    

    API responding:

    {
      "status": 0,
      "data": {
        "transfer_from": "contracts",
        "transfer_to": "wallet",
        "amount": 0.1,
        "transfer_id": "179363219767363",
        "currency": "BTC"
      }
    }
    
    
    

    Query the current executing state of a transfer-out operation (Contract->wallet)

    API path:GET /v3/contracts/transfer/out/{transferId}/status

    API Request Parameter:NON

    API responding:

    {
      'status': 0,
      'data': {
        'transfer_id': '179364285120578',
        'transfer_from': 'contracts',
        'transfer_to': 'wallet',
        'amount': 0.1,
        'done': True,
        'created_at': 1567682689265,
        'updated_at': 1567682689473,
        'error': False,
        'currency': 'BTC'
      }
    }
    

    Query transfer journal

    API path:GET /v3/contracts/transfer/logs

    API Request Parameter:NON

    API responding:

    {
      'status': 0,
      'data': {
        'hasMore': False,
        'nextOffsetId': 0,
        'results': [
          {
            'transfer_id': '167600369696833',
            'transfer_from': 'CONTRACTS',
            'transfer_to': 'WALLET',
            'amount': 0.01,
            'done': True,
            'created_at': 1566280321419,
            'updated_at': 1566280321851,
            'error': False,
            'currency': 'BTC'
          }
        ]
      }
    }
    

    Order

    Order mode instruction

    Order mode are composed by the following characters:

    Character Type Meaning
    id long Order ID
    sequence_id long SequencingID
    margin_currency_id long Margin Currency ID
    direction enum Position Direction LONG/SHORT
    type enum Order type LIMIT/MARKET
    status enum See order status description
    features long Order features, each bit represents a feature:0x01=FOK,0x02=post_only,0x04=Hidden,0x08=IOC,0x8000=liquidated orders
    price decimal Limit order price (if it's market-price order, here means the upper or lower limit of market-price order)
    quantity long Order quantity
    fill_price decimal Average closing price
    unfilled_quantity long Unfulfilled quantity
    maker_fee_rate decimal Fee rate for Maker
    taker_fee_rate decimal Fee rate for Taker
    fee decimal The accumulated transaction fee charged for this order
    trigger_on decimal The trigger price for Stop orders, and the trigger price for non-stop orders is always 0
    trailing_base_price decimal The base price for TrailingStop orders other than this type is always 0
    trailing_distance decimal The distance between trigger price for TrailingStop orders other than this type is always 0
    created_at long Order creation time
    updated_at long Last modified time of this order

    Description of order status:

    Attribute Meaning
    PENDING PENDING transaction
    PARTIAL_FILLED Partially fulfilled
    FULLY_FILLED Fully filled
    PARTIAL_CANCELLED Partially canceled
    FULLY_CANCELLED Fully canceled
    STOP_PENDING stop order is waiting to be triggered
    STOP_FAILED stop order was triggered but execution fails (for example: freeze failure)
    STOP_CANCELLED stop order has been canceled for not been triggered

    Create new orders

    This API is used to creating new orders.

    HTTP Request

    POST /v3/contracts/orders

    Request parameters

    Parameters Required or not Description
    symbol Y Contract code, such as"BTCUSD_P"
    type Y order type, see OrderType
    direction Y Order direction,see Direction
    source "" Order source identification, such as "WEB", "APP", letter and number combination
    price only limit orders only limit orders and only support 1 decimal place
    quantity Y order quantity, integral number no less than 1 trigger_on
    trigger_direction N Triggered conditions of Stop-win & stop-loss orders,"long","short"
    trailing_distance N The distance for being triggered of the Stop-win & stop-loss orders
    fill_or_kill N Type is string,set FoK order or not
    immediate_or_cancel N Type is string,set IOC order or not
    post_only N Type is string,set post_only order or not
    hidden N Type is string,set Hidden order or not
    reduce_only N Type is string,set reduce_only order or not

    Please note:

    If the order type is LIMIT, price must be filled in ;;

    Can not both fill in trigger_on and trailing_distance;

    If fill_or_kill=true,immediate_or_cancel, post_only、hidden or reduce_only will not be able to set;

    If immediate_or_cancel=true,fill_or_kill, post_only、hidden or reduce_only will not be able to set;

    If post_only=true,then fill_or_kill, immediate_or_cancel or reduce_only will not be able to set;

    If hidden=true,then fill_or_kill or immediate_or_cancel will not be able to set;

    Only MARKET orders and IOC order can set reduce_only=true。

    [回复 Peggy] Examples of the general stop-profit & stop-loss orders:

    {

    type: "MARKET",

    quantity: 10,

    trigger_on: 8000,

    trigger_direction: "LONG",

    direction: "LONG",

    ... }

    In this example, when the price is greater than or equal to 8000, a 10-contract market price long order will be submitted to the market. If trigger_direction is short, it indicates that if the price is less than or equal to 8000, a 10-contract market price short order will be submitted to the market.

    Trailing stop-loss: :

    {

    type: "MARKET",

    quantity: 10,

    trailing_distance: 100,

    trigger_direction: "SHORT",

    direction: "SHORT",

    ... }

    Once the user submits this typed order, the 10-contracts market price buy order will be submitted when the current market price falls beyond the trailing distance of 100.

    However, if the market price rises, the order will track the price and be executed when the market price reaches its peak and falls beyond the trailing distance of 100.

    If trigger_direction and direction are both long, it means that once the user submits this type of orders, the 10-contracts market price buy order will be submitted when the current market price increases beyond the trailing distance of 100.

    API responding :

    {
      "status": 0,
      "data": {
        "id": 167624805711936,  #Distributed id calculated by API
        "sequenceId": 260087,  #SequenceId calculated by sequence 
        "type": "LIMIT",  #Order type LIMIT/MARKET
        "status": "PENDING",  #Order status
        "direction": "SHORT", #Order direction LONG/SHORT
        "features": 0,        #Order features,combine by bit:FOK/IOC/HIDDEN/post_only
        "price": 100.0,     #Limit price, only for LIMIT orders
        "quantity": 200,    #Quantity
        "unfilled_quantity": 200, #Unfilled quantity 
        "maker_fee_rate": -0.00025,#maker fee rate
        "taker_fee_rate": 0.001,   #taker fee rate
        "fee": 0,                #Accumulated fee charged for the order 
        "trigger_direction": "LONG",# Trigger direction
        "trigger_on": 0,
        "trailing_base_price": 0,#Trigger base price
        "trailing_distance": 0,#Triggered distance
        "created_at": 1566283234499, #Order creation timestamp
        "updated_at": 1566283234499, #Update timestamp
        "frozen_margin": 0.034188034188034184,#freeze margin
        "frozen_quantity": 20000,#frozen quantity
        "hidden": false #Hidden or not 
      }
    }
    

    Cancel order

    This API is used for canceling orders

    HTTP Request

    POST /v3/contracts/orders/<order_id>/cancel

    Description: order_id is order id

    Request Parameter

    NON

    API responding:

    {
      "status": 0,
      "data": {
        "id": 167624805711936,  #Distributed ID calculated by API
        "sequenceId": 260087,  #SequenceId calculated by sequence 
        "type": "LIMIT",  #Order type is LIMIT/MARKET
        "status": "PENDING",  #Order status
        "direction": "SHORT", #Order direction LONG/SHORT
        "features": 0,        #Order features,combine by bit:FOK/IOC/HIDDEN/post_only
        "price": 100.0,     #Limit price, only for LIMIT orders
        "quantity": 200,    #Quantity
        "unfilled_quantity": 200, #Unfilled quantity 
        "maker_fee_rate": -0.00025,#maker fee rate
        "taker_fee_rate": 0.001,   #taker fee rate
        "fee": 0,                #Accumulated fee charged for the order 
        "trigger_direction": "LONG",#Trigger direction
        "trigger_on": 0,
        "trailing_base_price": 0,#Trigger base price
        "trailing_distance": 0,#Triggered distance
        "created_at": 1566283234499, #Order creation timestamp
        "updated_at": 1566283234499, #Update timestamp
        "frozen_margin": 0.034188034188034184,#Freeze margin
        "frozen_quantity": 20000,#Frozen quantity
        "hidden": false #Hidden or not
      }
    }
    

    Query activity orders

    This API is used to querying activity orders

    HTTP Request

    GET /v3/contracts/orders/open

    Request Parameter

    NON

    API responding:

    {
      'status': 0,
      'data': {
        'results': [
          {
            'id': 167560221818945,
            'sequenceId': 259092,
            'type': 'LIMIT',
            'status': 'PENDING',
            'direction': 'SHORT',
            'features': 0,
            'price': 15677.0,
            'quantity': 265,
            'unfilled_quantity': 265,
            'maker_fee_rate': -0.00025,
            'taker_fee_rate': 0.001,
            'fee': 0,
            'trigger_direction': 'LONG',
            'trigger_on': 0,
            'trailing_base_price': 0,
            'trailing_distance': 0,
            'created_at': 1566275535810,
            'updated_at': 1566275535810,
            'frozen_margin': 0.000169037443388403,
            'frozen_quantity': 265,
            'hidden': False
          }
        ]
      }
    }
    

    Query activity orders details

    This API is used to querying activity orders details

    HTTP Request

    GET /v3/contracts/orders/open/<order_id>

    Description: order_id is order id

    Request Parameter

    NON

    API responding:

    {
      'status': 0,
      'data': {
            'id': 167560221818945,
            'sequenceId': 259092,
            'type': 'LIMIT',
            'status': 'PENDING',
            'direction': 'SHORT',
            'features': 0,
            'price': 15677.0,
            'quantity': 265,
            'unfilled_quantity': 265,
            'maker_fee_rate': -0.00025,
            'taker_fee_rate': 0.001,
            'fee': 0,
            'trigger_direction': 'LONG',
            'trigger_on': 0,
            'trailing_base_price': 0,
            'trailing_distance': 0,
            'created_at': 1566275535810,
            'updated_at': 1566275535810,
            'frozen_margin': 0.000169037443388403,
            'frozen_quantity': 265,
            'hidden': False
      }
    }
    

    Obtain order details by order id

    This API is used to query all order details

    HTTP Request

    GET /v3/contracts/orders/<order_id>

    Description: order_id is order id

    Request parameters

    NON

    API responding:

    {
      'status': 0,
      'data': {
            'id': 167560221818945,
            'sequenceId': 259092,
            'type': 'LIMIT',
            'status': 'PENDING',
            'direction': 'SHORT',
            'features': 0,
            ‘fill_price':0   #Average filled price
            'price': 15677.0, #order placed price 
            'quantity': 265,
            'unfilled_quantity': 265,
            'maker_fee_rate': -0.00025,
            'taker_fee_rate': 0.001,
            'fee': 0,
            'trigger_direction': 'LONG',
            'trigger_on': 0,
            'trailing_base_price': 0,
            'trailing_distance': 0,
            'created_at': 1566275535810,
            'updated_at': 1566275535810,
            'frozen_margin': 0.000169037443388403,
            'frozen_quantity': 265,
            'hidden': False
      }
    }
    

    Query history order

    This API is used to query history orders

    HTTP Request

    GET /v3/contracts/orders/closed

    Request parameters

    Parameters Required or not Description
    range N Query the month in the form of YYYYMM, for example "201907", which by default is null to indicate the current month.
    symbol N is used to filter query conditions, filtering only orders that specify symbol, which by default is null, representing all symbols.
    offsetId N Transfer-in the starting id of the current page, which by default is 0, indicating the first page.
    limit N The maximum number of returning ResultSets, ranging from 1 to 100, which by default is 100.

    API responding:

    {
      'status': 0,
      'data': {
        'range': '201908',
        'hasMore': True,
        'nextOffsetId': 163466438508609,
        'results': [
          {
            'id': 163466455285825,
            'sequenceId': 79260,
            'type': 'LIMIT',
            'status': 'FULLY_FILLED',
            'direction': 'SHORT',
            'features': 0,
            'price': 5286.0,
            'quantity': 332,
            'unfilled_quantity': 0,
            'maker_fee_rate': -0.00025,
            'taker_fee_rate': 0.001,
            'fee': -1.570185395384e-05,
            'trigger_direction': 'LONG',
            'trigger_on': 0.0,
            'trailing_base_price': 0.0,
            'trailing_distance': 0.0,
            'created_at': 1565787520849,
            'updated_at': 1565787520849
          },
          {...}
        ]
      }
    }
    

    Query order fulfillment history

    This API is used to query order fulfillment history

    HTTP Request

    GET /v3/contracts/orders/<order_id>/matches

    Description: order_id is the order id

    Request parameters

    NON

    API responding:

    {
      'status': 0,
      'data': {
        'results': [
          {
            'taker': False,
            'price': 13403.0,
            'quantity': 994.0,
            'fee': -1.8540625233156e-05,
            'created_at': 1566275534853
          }
        ]
      }
    }
    

    Positions

    Obtain position lists

    This API is used for obtaining position list.

    HTTP Request

    GET /v3/broker/auth/contracts/positions

    Request Parameter

    NON

    API responding:

    {
      'status': 'ok',
      'data': {
        'results': [
          {
            'direction': 'SHORT',  #Position Direction
            'updated_at': 1566271860000,  #Millisecond timestamp of the latest modified Position 
            'quantity': 0,  #The number of contracts held must be positive. If it is 0, means the position is fully closed 
            'leverage': 0, #leverage ratio set for position which is not necessarily equal to actual leverage ratio
            'riskLevel': 0, #Risk level
            'max_quantity': 100000, #The maximum contract quantity held
            'realized_pnl': -0.036307524734501204, #Realized PNL, Realized PNL is only as a statistical display to the user which is the profit and loss since the opening of the position  
            'taker_fee_rate': 0.001, #Taker position closing rate determined at position opening 
            'margin': 0.0, #Position margin, must be positive 
            'bankruptcy_price': 0.0, #Bankruptcy price, the profit shall be 0 if the position has been closed at the price after deducting taker fee
            'liquidation_price': 0.0, #Liquidation price, the profit shall be position value x margin rate if the position has been closed at this price after deducting taker fee        'entry_price': 11017.0, #Average opening price, the average opening price will be adjusted  each time a position is increased or decreased
            'symbol': 'BTCUSD_P', #Position contract code, such asBTCUSD_P
            'closed': True, #Close the position or not
            'minimum_maintenance_margin_rate': 0.005 #The minimum maintenance margin. If the margin is lowered to this level, the liquidation will be triggered immediately.      }
        ]
      }
    }
    

    Set position leverage

    HTTP Request

    POST /v3/contracts/positions/$symbol/leverage

    symbol:URL Parameter, Symbol name of the position

    Request Parameters

    Parameters Required or not Description
    leverage Required 0~the maximum allowable value,0 = full position,1~the maximum allowable value = Isolated margin leverage

    Request example

    { 'leverage': 0 }

    API responding:

    {
      'status': 0,
      'data': {
        'leverage': 0
      }
    }
    

    Set position margin

    HTTP Request

    POST /v3/contracts/positions/$symbol/margin

    symbol:URL Parameter, Symbol name of the position

    Request Parameters

    Parameters Required or not Description
    margin Required Set new position margin

    Request example

    { 'margin': 0 }

    API responding:

    {
      'status': 0,
      'data': {
        'margin': 0
      }
    }
    

    Set risk level of the position

    HTTP Request

    POST /v3/contracts/positions/$symbol/riskLevel

    symbol:URL Parameter, Symbol name of the position

    Request Parameters

    Parameters Required or not Description
    risk_level Required 0~the maximum allowable value

    Request example

    { 'risk_level': 0 }

    API responding:

    {
      'status': 0,
      'data': {
        'risk_level': 0
      }
    }
    

    ws Push portal

    Signing method :
    1.Only sign to http address
    For example,only sign to this character string:GEThttps://api.fmex.com/v2/user/ws1579154149629,and get the same signing result, the signing method is same with http request
    2. Pass the signing result to the server by ws
    For example:wss://api.fmex.com/v2/user/ws?FC-ACCESS-KEY=f8wersd4sdfc7121cbdd81986&FC-ACCESS-TIMESTAMP=1579147466690&FC-ACCESS-SIGNATURE=aKx/DMQ6j75JwegtfDVuJaXRxoxA=
    3.Commands can be sent through ws to get the information once the connection is successful

    Among,http address:https://api.fmex.com/v2/user/ws
    ws address:wss://api.fmex.com/v2/user/ws

    Note: this portal is the Incremental push, which means the information will be pushed to users only changes happened after success subscription.

    Obtain the account information

    websocket the requested data is:

    send sub commend,topic: account (please refer to WebSocket subsription)

    {
        "id":"11111",
        "cmd":"sub",
        "args":["account"],
    }
    

    The responding result of the successful WebSocket request is as follow:

    
    {
        "type": "account", 
        "account": 
        {
            "currency": "BTC", 
            "available": 1.34242880408925, 
            "frozen": 0.0, 
            "position": 9.747280117178e-06, 
            "updated_at": 1580802053643
        }, 
        "ts": 1580802053662  # Update time
    }
    

    Obtain the order

    websocket the requested data is:

    send sub commend, topic: order.$symbol (please refer to WebSocket subsription)

    {
        "id":"11111",
        "cmd":"sub",
        "args":["order.btcusd_p"],
    }
    

    The responding result of the successful WebSocket request is as follow:

    {
        "type": "order.btcusd_p", 
        "order": 
        {
            "id": 849758102002, 
            "quantity": 1, 
            "direction": "LONG", 
            "features": 8, 
            "price": 10210, 
            "fill_price": 9288.0, 
            "unfilled_quantity": 0, 
            "symbol": "BTCUSD_P", 
            "margin_currency": "BTC", 
            "fee": 4.8449612403e-08, 
            "type": "MARKET", 
            "status": "FULLY_FILLED", 
            "trigger_direction": "LONG", 
            "trigger_on": 0, 
            "trailing_base_price": 0, 
            "trailing_distance": 0, 
            "created_at": 1580802204215
            }, 
        "ts": 1580802204232
    }
    

    Obtain the position

    websocket the requested data is:

    send sub commend, topic: position.$symbol(please refer to WebSocket subsription)

    {
        "id":"11111",
        "cmd":"sub",
        "args":["position.btcusd_p"],
    }
    

    The responding result of the successful WebSocket request is as follow:

    {
        "type": "position.btcusd_p", 
        "position": 
        {
             "symbol": "BTCUSD_P", 
             "quantity": 1, 
             "direction": "LONG", 
             "leverage": 50, 
             "risk_level": 0, 
             "margin": 9.749658727683e-06,
              "taker_fee_rate": 0.00045, 
              "realized_pnl": -4.8499218623e-08, 
              "entry_price": 9278.5, 
              "liquidation_price": 9363.483892761602, 
              "bankruptcy_price": 8512.606170669584, 
              "minimum_maintenance_margin_rate": 0.1, 
              "updated_at": 1580802507384
        },
         "ts": 1580802507401
    }
    

    Auto Trading

    Below are the automated trading software and services support FMex.

    -FMZ Inventor Quantification
    Inventor Quantification (fmz.com) is the only quantitative trading platform in Asia that supports commodity futures and digital currency. It focuses on the development of quantitative software platform and the research and service of the quantitative trading strategies, and provides support for more than 50 mainstream exchanges in the market. Support JavaScript/Python/C++/My language/Visual five programming languages.