NAV Navbar
python javascript
  • Introduction
  • Certification
  • Public interface
  • Market
  • Accounts and assets
  • Orders
  • Order error code
  • Introduction

    By understanding the following information, you can easily use the API provided by FCoin to access the FCoin trading platform.

    Certification

    Execute the following code for user identification:

    import fcoin
    
    api = fcoin.authorize('key', 'secret', timestamp)
    
    const fcoin = require('fcoin');
    
    let api = fcoin.authorize('key', 'secret', timestamp);
    

    FCoin uses API key and API secret for identification,Please visit the settings center and register as a developer to obtain API key and API secret.

    In addition to the public API, API key and signature are also included in FCoin's API request

    Access restrictions

    The current access frequency is 100 times / 10 seconds per user, and the access frequency limit will be differentiated according to the service in the future.

    API signature

    The data prepared before signing is as follows:

    HTTP_METHOD + HTTP_REQUEST_URI + TIMESTAMP + POST_BODY

    After the connection is established, Base64 encoding is performed. The encoded data is HMAC-SHA1 signed, and the signature is subjected to secondary Base64 encoding. The various parts are explained as follows:

    HTTP_METHOD

    GET, POST, DELETE, PUT requires capitalization

    HTTP_REQUEST_URI

    https://api.fcoin.com/v2/ is the prefix for v2 API request

    Add the resource path you really want to access, such as orders?param1=value1, and finally https://api.fcoin.com/v2/orders?param1=value1

    The parameters in the requested URI need to be sorted by alphabetically.

    That is, if the requested URI is https://api.fcoin.com/v2/orders?c=value1&b=value2&a=value3, then the request parameters should be sorted alphabetically before signing, and the final signed URI is https://api.fcoin.com/v2/orders?a=value3&b=value2&c=value1. Please note that the order of the three parameters in the original request URI is c, b, a, and then a, b, c after ordering.

    TIMESTAMP

    When accessing the API, the time difference between the UNIX EPOCH timestamp and the server should be no more than 30 seconds.

    POST_BODY

    If it is a POST request, the POST request data also needs to be signed:

    All the requested keys are sorted in alphabetical order, followed by url parameterization, and connected with &.

    If the requested data is:

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

    then sort the key alphabetically and parameterize the url, ie:

    password=password
    username=username
    

    Because p is sorted before u in the alphabet, password is placed before username and then connected with &, ie:

    password=password&username=username
    

    Full example

    For the following requests:

    POST https://api.fcoin.com/v2/orders
    
    {
      "type": "limit",
      "side": "buy",
      "amount": "100.0",
      "price": "100.0",
      "symbol": "btcusdt"
    }
    
    timestamp: 1523069544359
    

    The preparated data before signing is as follows:

    POSThttps://api.fcoin.com/v2/orders1523069544359amount=100.0&price=100.0&side=buy&symbol=btcusdt&type=limit
    

    Perform Base64 encoding to obtain:

    UE9TVGh0dHBzOi8vYXBpLmZjb2luLmNvbS92Mi9vcmRlcnMxNTIzMDY5NTQ0MzU5YW1vdW50PTEwMC4wJnByaWNlPTEwMC4wJnNpZGU9YnV5JnN5bWJvbD1idGN1c2R0JnR5cGU9bGltaXQ=
    

    Copy the key obtained when applying for the API Key (API SECRET). The following signature result is taken 3600d0a74aa3410fb3b1996cca2419c8 as an example,

    The obtained result is HMAC-SHA1 signed with the secret key, and the binary result is Base64 encoded, to obtain:

    DeP6oftldIrys06uq3B7Lkh3a0U=
    

    That is, the final signature is generated for verification to the API server

    Parameter name

    Description

    You can use the developer tools (not yet open) for online joint debugging testing

    Public interface

    Query server time

    import fcoin
    
    api = fcoin.authorize('key', 'secret', timestamp)
    server_time = api.server_time()
    
    const fcoin = require('fcoin');
    
    let api = fcoin.authorize('key', 'secret', timestamp);
    let serverTime = api.serverTime();
    

    The response results are as follows:

    {
      "status": 0,
      "data": 1523430502977
    }
    

    The API is used to obtain the server time。

    HTTP Request

    GET https://api.fcoin.com/v2/public/server-time

    Query available currencies

    import fcoin
    
    api = fcoin.authorize('key', 'secret', timestamp)
    currencies = api.currencies()
    
    const fcoin = require('fcoin');
    
    let api = fcoin.authorize('key', 'secret', timestamp);
    let currencies = api.currencies();
    

    The response results are as follows:

    {
      "status": 0,
      "data": [
        "btc",
        "eth"
      ]
    }
    

    This API is used to obtain the available currencies。

    HTTP Request

    GET https://api.fcoin.com/v2/public/currencies

    Query available trading pairs

    import fcoin
    
    api = fcoin.authorize('key', 'secret', timestamp)
    symbols = api.symbols()
    
    const fcoin = require('fcoin');
    
    let api = fcoin.authorize('key', 'secret', timestamp);
    let symbols = api.symbols();
    

    The response results are as follows:

    {
      "status": 0,
      "data": [
        {
          "name": "btcusdt",
          "base_currency": "btc",
          "quote_currency": "usdt",
          "price_decimal": 2,
          "amount_decimal": 4
        },
        {
          "name": "ethusdt",
          "base_currency": "eth",
          "quote_currency": "usdt",
          "price_decimal": 2,
          "amount_decimal": 4
        }
      ]
    }
    

    This API is used to get available trading pairs。

    HTTP Request

    GET https://api.fcoin.com/v2/public/symbols

    Market

    Market overview

    The market is a fully public API, which currently provides both HTTP and WebSocket APIs. In order to ensure more timely access to the market, it is recommended to use WebSocket to access. For the real-time performance of the market as much as possible, the current public part can only obtain the most recent market information. If there is a need to obtain the full amount or historical market information, please consult support@fcoin.com

    The URL base for all HTTP requests is: https://api.fcoin.com/v2/market

    The requested URL for all WebSocket is: wss://api.fcoin.com/v2/ws

    Terminology will be consistent below:

    WebSocket’s first connection is established.

    The server sends a welcome message

    Server return

    {
      "type":"hello",
      "ts":1523693784042
    }
    

    WebSocket connection retention - heartbeat

    After the WebSocket client establishes a connection with the WebSocket server, it is recommended that the WebSocket Client initiate a ping request to the server every 30 seconds (this frequency may change). If the server does not receive the client's ping request for a long time, it will actively disconnect (300s).

    WebSocket requests

    import time
    import fcoin
    
    api = fcoin.authorize('key', 'secret', timestamp)
    now_ms = int(time.time())
    api.market.ping(now_ms)
    

    Server return

    {
      "type":"ping",
      "ts":1523693784042,
      "gap":112
    }
    

    Get push server time

    The gap between the push server time and data transfer time can be obtained by the ts and gap values returned by the server at the time of the ping request

    Get ticker data

    To make the ticker Information Group small and fast enough, we enforced the list format.

    The description of the corresponding field of the ticker list:

    [
      "Latest transaction price",
      "the most recent trading volume",
      "The highest buy 1 price",
      "The biggest buy 1 volume",
      "The lowest sell 1 price",
      "The smallest sell 1 volume",
      "The transaction price before 24 hours",
      "The highest price in 24 hours",
      "The lowest price in 24 hours",
      "The base currency volume within 24 hours, such as the amount of btc in btcusdt",
      "Priced currency volume within 24 hours, such as the amount of usdt in btcusdt"
    ]
    

    HTTP requests

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

    import fcoin
    
    api = fcoin.authorize('key', 'secret', timestamp)
    api.market.get_ticker("ethbtc")
    
    
    {
      "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

    topic: ticker.$symbol

    import fcoin
    
    fcoin_ws = fcoin.init_ws()
    topics = ["ticker.ethbtc", "ticker.btcusdt"]
    fcoin_ws.handle(print)
    fcoin_ws.sub(topics)
    

    The results of a successful response to the subscription are as follows:

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

    Regular push results:

    {
      "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
      ]
    }
    

    Get the latest trading details

    HTTP Request

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

    types of $level included:

    Type Description
    L20 20 -level market depth.
    L150 150 -level market depth.
    full full market depth, no time guarantee or push guarantee.

    The L20 push time will be slightly earlier than L100, and the push frequency will be slightly more than L100, depending on the specified pressure and situation.

    WebSocket subscription

    subscription topic: depth.$level.$symbol

    import fcoin
    
    fcoin_ws = fcoin.init_ws()
    topics = ["depth.L20.ethbtc", "depth.L100.btcusdt"]
    fcoin_ws.handle(print)
    fcoin_ws.sub(topics)
    
    const fcoin = require('fcoin');
    
    let fcoin_ws = fcoin.init_ws()
    topics = ["depth.L20.ethbtc", "depth.L100.btcusdt"]
    fcoin_ws.handle(print)
    fcoin_ws.sub(topics)
    

    The results of a successful response to the subscription are as follows:

    {
      "type": "topics",
      "topics": ["depth.L20.ethbtc", "depth.L100.btcusdt"]
    }
    

    Regular push results

    The array corresponding to bids and asks must be an even number, buy (sell) 1 price, buy (sell) 1 volume, and arrange them one after the other.

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

    Get the latest trading details

    By comparing the size of the transaction id to determine whether it is an updated transaction. {trade id} Note that the transaction id of the public market does not actually correspond to the transaction id in the clearing system due to the existence of the trade to transaction process. Even if the transaction is a record, there is no guarantee that the id will always be consistent when the latest transaction is re-acquired

    PS: in the historical market, the trading id remains constant. {transaction id} is only used as a market update notification and should not be used depending on the archive.

    HTTP Request

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

    Query parameters(HTTP Query)

    Parameter Default Description
    before Query a trade before a specified id
    limit the default is 20

    WebSocket gets the most recent deal

    topic: trade.$symbol limit: the number of most recent transactions args: [topic, limit]

    import fcoin
    
    fcoin_ws = fcoin.init_ws()
    topic = "trade.ethbtc"
    limit = 3
    args = [topic, limit]
    fcoin_ws.req(args, rep_handler)
    

    The result of a successful response to the request is as follows:

    {"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

    import fcoin
    
    fcoin_ws = fcoin.init_ws()
    topics = ["trade.ethbtc", "trade.btcusdt"]
    fcoin_ws.handle(print)
    fcoin_ws.sub(topics)
    

    The results of a successful response to the subscription are as follows:

    {
      "type": "topics",
      "topics": ["trade.ethbtc"]
    }
    

    Regular push results

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

    Get Candle information

    HTTP Request

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

    Query parameters(HTTP Query)

    Parameter default description
    before Query a candle before a specified id
    limit the default is 20

    Types contained in $resolution

    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

    Candle data subscribed in Weboskcet

    topic: candle.$resolution.$symbol

    import fcoin
    
    fcoin_ws = fcoin.init_ws()
    topics = ["candle.M1.ethbtc", "depth.L20.ethbtc", "trade.ethbtc"]
    fcoin_ws.handle(print)
    fcoin_ws.sub(topics)
    

    The results of a successful response to the subscription are as follows:

    {
      "type": "topics",
      "topics": ["candle.M1.ethbtc"]
    }
    

    The notification message format for a regular subscription is as follows:

    {
      "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
    }
    

    Accounts and assets

    Query account assets

    import fcoin
    
    api = fcoin.authorize('key', 'secret', timestamp)
    api.accounts_balance
    
    const fcoin = require('fcoin');
    
    let api = fcoin.authorize('key', 'secret', timestamp);
    let orders = api.accountsBalance;
    

    The response results are as follows:

    {
      "status": 0,
      "data": [
        {
          "currency": "btc",
          "available": "50.0",
          "frozen": "50.0",
          "balance": "100.0"
        }
      ]
    }
    

    This API is used to query a user's list of assets.

    HTTP Request

    GET https://api.fcoin.com/v2/accounts/balance

    Orders

    Description of the order model

    The order model consists of the following properties:

    Property type interpretation
    id String Order ID
    symbol String Trading pairs
    side String Trading direction(buy, sell
    type String Order type(limitmarket
    price String Order Price
    amount String Order quantity
    state String State of order
    executed_value String Traded
    filled_amount String Trading volume
    fill_fees String service fee
    created_at Long Creation time
    source String Source

    Description of state of order:

    Property Description
    submitted Submission completed
    partial_filled Partially traded
    partial_canceled Partial_filled canceled
    filled wholly traded
    canceled cancellation completed
    pending_cancel the canceling is submitted

    Create a new order

    import fcoin
    
    api = fcoin.authorize('key', 'secret', timestamp)
    order_create_param = fcoin.order_create_param('btcusdt', 'buy', 'limit', '8000.0', '1.0')
    api.orders.create(order_create_param)
    
    const fcoin = require('fcoin');
    
    let api = fcoin.authorize('key', 'secret', timestamp);
    let orderCreateParam = fcoin.orderCreateParam('btcusdt', 'buy', 'limit', '8000.0', '1.0');
    let orders = api.orders.create(orderCreateParam);
    

    The response results are as follows:

    {
      "status": 0,
      "data": "9d17a03b852e48c0b3920c7412867623"
    }
    

    This API is used to create new orders。

    HTTP Request

    POST https://api.fcoin.com/v2/orders

    Request parameters

    Parameter Default Description
    symbol Null trading pairs
    side Null trading direction
    type Null order type
    price Null price
    amount Null order volume

    Query order list

    import fcoin
    
    api = fcoin.authorize('key', 'secret', timestamp)
    api.orders.get()
    
    const fcoin = require('fcoin');
    
    let api = fcoin.authorize('key', 'secret', timestamp);
    let orders = api.orders.get();
    

    The response results are as follows:

    {
      "status": 0,
      "data": [
        {
          "id": "string",
          "symbol": "string",
          "type": "limit",
          "side": "buy",
          "price": "string",
          "amount": "string",
          "state": "submitted",
          "executed_value": "string",
          "fill_fees": "string",
          "filled_amount": "string",
          "created_at": 0,
          "source": "web"
        }
      ]
    }
    

    This API is used to query the order list.

    HTTP Request

    GET https://api.fcoin.com/v2/orders

    Query parameters

    Parameter Default Description
    symbol Trading pairs
    states State of Orders
    before query orders before a specified page
    after query orders after a specified page
    limit the number of orders in each page, the default is 20

    Get the specified order

    import fcoin
    
    api = fcoin.authorize('key', 'secret', timestamp)
    api.orders.get('9d17a03b852e48c0b3920c7412867623')
    
    const fcoin = require('fcoin');
    
    let api = fcoin.authorize('key', 'secret', timestamp);
    let max = api.orders.get('9d17a03b852e48c0b3920c7412867623');
    

    The response results are as follows:

    {
      "status": 0,
      "data": {
        "id": "9d17a03b852e48c0b3920c7412867623",
        "symbol": "string",
        "type": "limit",
        "side": "buy",
        "price": "string",
        "amount": "string",
        "state": "submitted",
        "executed_value": "string",
        "fill_fees": "string",
        "filled_amount": "string",
        "created_at": 0,
        "source": "web"
      }
    }
    

    This API is used to return the specified order details。

    HTTP Request

    GET https://api.fcoin.com/v2/orders/{order_id}

    URL Parameters

    Parameter Description
    order_id order ID

    Application for cancellation of order

    import fcoin
    
    api = fcoin.authorize('key', 'secret', timestamp)
    api.orders.submit_cancel(2)
    
    const fcoin = require('fcoin');
    
    let api = fcoin.authorize('key', 'secret', timestamp);
    let max = api.orders.submitCancel(2);
    

    The response results are as follows:

    {
      "status": 0,
      "msg": "string",
      "data": true
    }
    

    This API is used to cancel the specified order. The order canceling process is asynchronous. That is, the successful call of this API represents that the order has entered the revocation request. Further processing of matching is required before the confirmation of order canceling.

    HTTP Request

    POST https://api.fcoin.com/v2/orders/{order_id}/submit-cancel

    URL Parameters

    Parameters Description
    order_id order ID

    Query trading records of a specified order

    import fcoin
    
    api = fcoin.authorize('key', 'secret', timestamp)
    api.orders.get('9d17a03b852e48c0b3920c7412867623').match_results()
    
    const fcoin = require('fcoin');
    
    let api = fcoin.authorize('key', 'secret', timestamp);
    let max = api.orders.get('9d17a03b852e48c0b3920c7412867623').matchResults();
    

    The response results are as follows:

    {
      "status": 0,
      "data": [
        {
          "price": "string",
          "fill_fees": "string",
          "filled_amount": "string",
          "side": "buy",
          "type": "limit",
          "created_at": 0
        }
      ]
    }
    

    This API is used to get the trading record of the specified order

    HTTP Request

    GET https://api.fcoin.com/v2/orders/{order_id}/match-results

    URL Parameters

    Parameters Description
    order_id order ID

    Order error code

    Error code Explanation
    2000 Account error

    Order error code

    Error Code Interpretation
    400 Bad Request -- 错误的请求
    401 Unauthorized -- API key 或者签名,时间戳有误
    403 Forbidden -- 禁止访问
    404 Not Found -- 未找到请求的资源
    405 Method Not Allowed -- 使用的 HTTP 方法不适用于请求的资源
    406 Not Acceptable -- 请求的内容格式不是 JSON
    429 Too Many Requests -- 请求受限,请降低请求频率
    500 Internal Server Error -- 服务内部错误,请稍后再进行尝试
    503 Service Unavailable -- 服务不可用,请稍后再进行尝试