NAV Navbar
API Documentation
python javascript csharp
English 中文

概览

欢迎查看 FTX API 文档。 我们提供完整的 REST、Websocket 和 FIX API 以满足您的算法交易需求。您可以在https://github.com/ftexchange/ftx上找到每个连接选项的示例代码。

REST API

基于 HTTP 的 API,具有完整的交易和资产管理功能,包括公共委托簿和交易数据以及私人账户数据和下单管理。

REST 端点网址:https://ftx.com/api

使用 JSON 发起请求和回复。

Python, C#, C++ 示例代码

身份验证

import time
import hmac
from requests import Request

ts = int(time.time() * 1000)
request = Request('GET', '<api_endpoint>')
prepared = request.prepare()
signature_payload = f'{ts}{prepared.method}{prepared.path_url}'.encode()
signature = hmac.new('YOUR_API_SECRET'.encode(), signature_payload, 'sha256').hexdigest()

request.headers[f'FTX-KEY'] = 'YOUR_API_KEY'
request.headers[f'FTX-SIGN'] = signature
request.headers[f'FTX-TS'] = str(ts)

# Only include line if you want to access a subaccount
# request.headers[f'FTX-SUBACCOUNT'] = 'my_subaccount_nickname'
var method = HttpMethod.Get
var endpoint = $"/api/account";
var request = new HttpRequestMessage(method, endpoint);
var _nonce = (DateTime.UtcNow - start).TotalMilliseconds;

var hashMaker = new HMACSHA256(Encoding.UTF8.GetBytes(""YOUR_API_SECRET""));
var signaturePayload = $"{_nonce}{method.ToString().ToUpper()}{endpoint}";
var hash = hashMaker.ComputeHash(Encoding.UTF8.GetBytes(signaturePayload));
var hashString = BitConverter.ToString(hash).Replace("-", string.Empty);
var signature = hashString.ToLower();

request.Headers.Add("FTX-KEY", "YOUR_API_KEY");
request.Headers.Add("FTX-SIGN", signature);
request.Headers.Add("FTX-TS", _nonce.ToString());

对于经过身份验证的请求,应使用以下标题:

-“FTX-KEY”:您的 API 密钥 -“FTX-TS”:自 Unix 纪元以来的毫秒数 -“FTX-SIGN”:以下四个字符串的 SHA256 HMAC,使用您的 API 密钥,作为十六进制字符串: - 请求时间戳(例如“1528394229375”) - 大写的 HTTP 方法(例如“GET”或“POST”) - 请求路径,包括主机名称以外的所有网址参数 -(仅限 POST)请求正文(JSON-编码) -“FTX-SUBACCOUNT”(可选):要使用的子账户的名称。 如果不使用子账户,则省略。

费率限制

每秒发送请求勿超过 10 次。 频繁发送请求将导致 HTTP 429 错误。

子账户

要指定子账户,请在请求中以“FTX-SUBACCOUNT”为标题发送账户名称。

市场

获取市场

请求

GET /markets

回复


{
  "success": true,
  "result": [
    {
      "name": "BTC-0628",
      "baseCurrency": null,
      "quoteCurrency": null,
      "type": "future",
      "underlying": "BTC",
      "enabled": true,
      "ask": 3949.25,
      "bid": 3949,
      "last": 10579.52,
      "priceIncrement": 0.25,
      "sizeIncrement": 0.001
    }
  ]
}

回复格式

姓名 类型 价值 描述
type string future "future" or "spot"
name string BTC-0628
underlying string BTC 仅限期货市场
baseCurrency string BTC 仅限现货市场
quoteCurrency string USD 仅限现货市场
enabled boolean true
ask number 3949.25 最佳报价
bid number 3949.00 最佳报价
last number 3949.00 最近成交价
priceIncrement number 0.25
sizeIncrement number 0.001

获取单个市场

请求

GET /markets/{market_name}

回复

See /markets

获取委托簿

请求

GET /markets/{market_name}/orderbook?depth={depth}

回复

{
  "success": true,
  "result": {
    "asks": [
      [
        4114.25,
        6.263
      ]
    ],
    "bids": [
      [
        4112.25,
        49.29
      ]
    ]
  }
}

参数

姓名 类型 价值 描述
market_name string BTC-0628 Required. Name of the market.
depth number 35 max 100, default 20

回复格式

姓名 类型 价值 描述
asks array [4114.25, 6.263] Array with price and size
bids array [4112, 49.29] Array with price and size

获取交易

请求

GET /markets/{market_name}/trades?limit={limit}&start_time={start_time}&end_time={end_time}

回复

{
  "success": true,
  "result": [
    {
      "id": 3855995,
      "liquidation": false,
      "price": 3857.75,
      "side": "buy",
      "size": 0.111,
      "time": "2019-03-20T18:16:23.397991+00:00"
    }
  ]
}

参数

姓名 类型 价值 描述
market_name string BTC-0628 name of the market
limit number 35 optional, max 100, default 20
start_time number 1559881511 optional
end_time number 1559881711 optional

回复格式

姓名 类型 价值 描述
id number 3855995 trade id
liquidation boolean false 如果这笔交易涉及清算单
price number 3857.75
side string buy
size number 0.111
time string 2019-03-20T18:16:23.397991+00:00

获取历史价格

请求

GET /markets/{market_name}/candles?resolution={resolution}&limit={limit}&start_time={start_time}&end_time={end_time}

回复

{
  "success": true,
  "result": [
    {
      "close":11055.25,
      "high":11089.0,
      "low":11043.5,
      "open":11059.25,
      "startTime":"2019-06-24T17:15:00+00:00",
      "volume":464193.95725
    }
  ]
}

参数

姓名 类型 价值 描述
market_name string BTC-0628 name of the market
resolution number 300 窗口时长(秒为)。 选项:15, 60, 300, 900, 3600, 14400, 86400
limit number 35 optional
start_time number 1559881511 optional
end_time number 1559881711 optional

回复格式

姓名 类型 价值 描述
startTime string 2019-06-24T17:15:00+00:00 窗口开始时间
open number 11059.25 开始时间的标记价格
close number 11055.25 窗口结束时的标记价格:startTime(开始时间)+ 时间单位
high number 11089.0 窗口最高标记价格
low number 11059.25 窗口最低标记价格
volume number 464193.95725 窗口内交易量

期货

This section covers all types of futures on FTX: perpetual, expiring, and MOVE. Examples for each type are BTC-PERP, BTC1227, and BTC-MOVE-1005.

列出所有期货

请求

GET /futures

回复

{
  "success": true,
  "result": [
    {
      "ask": 4196,
      "bid": 4114.25,
      "change1h": 0,
      "change24h": 0,
      "description": "Bitcoin March 2019 Futures",
      "enabled": true,
      "expired": false,
      "expiry": "2019-03-29T03:00:00+00:00",
      "index": 3919.58841011,
      "last": 4196,
      "lowerBound": 3663.75,
      "mark": 3854.75,
      "name": "BTC-0329",
      "perpetual": false,
      "postOnly": false,
      "priceIncrement": 0.25,
      "sizeIncrement": 0.001,
      "underlying": "BTC",
      "upperBound": 4112.2,
      "type": "future"
    }
  ]
}

回复格式

姓名 类型 价值 描述
ask number 4196.0 委托簿最佳报价
bid number 4114.25 委托簿最佳报价
change1h number 0.0 最近一小时的价格变动
change24h number 0.0 过去 24 小时内的价格变动
description string Bitcoin March 2019 Futures
enabled boolean true
expired boolean false
expiry string 2019-03-29T03:00:00+00:00
index number 3919.58841011 指数成分市场的平均市价
last number 4196.0 期货最近成交价
lowerBound number 3663.75 期货可以交易的最低价
mark number 3854.75 期货标记价格
name string BTC-0329
perpetual boolean false 此合约是否为永续合约
postOnly boolean false
priceIncrement number 0.25
sizeIncrement number 0.001
underlying string BTC
upperBound number 4112.2 期货可以交易的最高价
type string future “合约”,“永续”或“波动”之一

获取期货

请求

GET /futures/{future_name}

回复

{
  "success": true,
  "result": {
    "ask": 4196,
    "bid": 4114.25,
    "change1h": 0,
    "change24h": 0,
    "description": "Bitcoin March 2019 Futures",
    "enabled": true,
    "expired": false,
    "expiry": "2019-03-29T03:00:00+00:00",
    "index": 3919.58841011,
    "last": 4196,
    "lowerBound": 3663.75,
    "mark": 3854.75,
    "name": "BTC-0329",
    "perpetual": false,
    "postOnly": false,
    "priceIncrement": 0.25,
    "sizeIncrement": 0.001,
    "underlying": "BTC",
    "upperBound": 4112.2,
    "type": "future"
  }
}

回复格式

姓名 类型 价值 描述
ask number 4196.0 委托簿最佳报价
bid number 4114.25 委托簿最佳报价
change1h number 0.0 最近一小时的价格变动
change24h number 0.0 过去 24 小时内的价格变动
description string Bitcoin March 2019 Futures
enabled boolean true
expired boolean false
expiry string 2019-03-29T03:00:00+00:00
index number 3919.58841011 指数成分市场的平均市价
last number 4196.0 期货最近成交价
lowerBound number 3663.75 期货可以交易的最低价
mark number 3854.75 期货标记价格
name string BTC-0329
perpetual boolean false 此合约是否为永续合约
postOnly boolean false
priceIncrement number 0.25
sizeIncrement number 0.001
underlying string BTC
upperBound number 4112.2 期货可以交易的最高价
type string future “合约”,“永续”或“波动”之一

获取期货统计数据

请求

GET /futures/{future_name}/stats

回复

{
  "success": true,
  "result": {
    "volume": 1000.23,
    "nextFundingRate": 0.00025,
    "nextFundingTime": "2019-03-29T03:00:00+00:00",
    "expirationPrice": 3992.1,
    "predictedExpirationPrice": 3993.6,
    "strikePrice": 8182.35,
    "openInterest": 21124.583
  }
}

回复格式

姓名 类型 价值 描述
volume number 1000.23 过去 24 小时内的交易量
nextFundingRate number 0.00025 后续融资费率(只适用于永续合约)
nextFundingTime string 2019-03-29T03:00:00+00:00 后续融资时间(仅适用于永续合约)
expirationPrice number 3992.1 期货到期的价格(仅在期货到期时适用)
predictedExpirationPrice number 3993.0 仅适用于期货未到期的情况
openInterest number 21124.583 本期货持仓合约数量
strikePrice number 8182.35009484 到期日开始时标的价格(仅适用于MOVE合约)

获取融资利率

请求

GET /funding_rates

参数

姓名 类型 价值 描述
start_time number 1559881511 optional
end_time number 1559881711 optional

回复


{
  "success": true,
  "result": [
    {
      "future": "BTC-PERP",
      "rate": 0.0025,
      "time": "2019-06-02T08:00:00+00:00"
    }
  ]
}

回复格式

姓名 类型 价值 描述
future string BTC-PERP
rate number 0.0025
time string 2019-06-02T08:00:00+00:00

账户

获取账户信息

请求

GET /account

回复

{
  "success": true,
  "result": {
    "backstopProvider": true,
    "collateral": 3568181.02691129,
    "freeCollateral": 1786071.456884368,
    "initialMarginRequirement": 0.12222384240257728,
    "liquidating": false,
    "maintenanceMarginRequirement": 0.07177992558058484,
    "makerFee": 0.0002,
    "marginFraction": 0.5588433331419503,
    "openMarginFraction": 0.2447194090423075,
    "takerFee": 0.0005,
    "totalAccountValue": 3568180.98341129,
    "totalPositionSize": 6384939.6992,
    "username": "[email protected]",
    "positions": [
      {
        "cost": -31.7906,
        "entryPrice": 138.22,
        "future": "ETH-PERP",
        "initialMarginRequirement": 0.1,
        "longOrderSize": 1744.55,
        "maintenanceMarginRequirement": 0.04,
        "netSize": -0.23,
        "openSize": 1744.32,
        "realizedPnl": 3.39441714,
        "shortOrderSize": 1732.09,
        "side": "sell",
        "size": 0.23,
        "unrealizedPnl": 0
      }
    ]
  }
}

需要验证身份。

回复格式

姓名 类型 价值 描述
backstopProvider boolean true 该账户是否为是注册的流动性支持提供者
collateral number 3568181.02691129 抵押金额
freeCollateral number 1786071.456884368 免费抵押金额
initialMarginRequirement number 0.12222384240257728 单个期货品种的 initialMarginRequirement(初始保证金要求),按名义头寸加权。 如果 openMarginFraction(开仓保证金比例)低于该值则无法新开头寸。
liquidating boolean false 如果账户正在清算则为是
maintenanceMarginRequirement number 0.07177992558058484 单个期货品种的 maintenanceMarginRequirement(持仓保证金要求)平均金额,按名义头寸加权。 如果保证金比例低于该值,则进入清算模式。
makerFee number 0.0002 -
marginFraction number 0.5588433331419503 - 账户总值和账户名义头寸总额之比
openMarginFraction number 0.2447194090423075 已实现账户价值总额和已建立名义头寸总额之比
takerFee number 0.0005
totalAccountValue number 3568180.98341129 以头寸标记价格计算的账户总值
totalPositionSize number 6384939.6992 以标记价格计算的账户持有头寸总额
username string [email protected]
positions array See Get positions for details

获取头寸

请求

GET /positions

回复

{
  "success": true,
  "result": [
    {
      "cost": -31.7906,
      "entryPrice": 138.22,
      "future": "ETH-PERP",
      "initialMarginRequirement": 0.1,
      "longOrderSize": 1744.55,
      "maintenanceMarginRequirement": 0.04,
      "netSize": -0.23,
      "openSize": 1744.32,
      "realizedPnl": 3.39441714,
      "shortOrderSize": 1732.09,
      "side": "sell",
      "size": 0.23,
      "unrealizedPnl": 0
    }
  ]
}

需要验证身份。

参数

姓名 类型 价值 描述
showAvgPrice boolean false optional

回复格式

姓名 类型 价值 描述
cost number -31.7906 建立此头寸所支付的金额等于头寸大小*建仓价格。 做多为正,做空为负。
entryPrice number 138.22 Average cost of this position after pnl was last realized: whenever unrealized pnl gets realized, this field gets set to mark price, unrealizedPnL is set to 0, and realizedPnl changes by the previous value for unrealizedPnl.
future string ETH-PERP 期货名称
initialMarginRequirement number 0.1 建立新头寸的最低保证金比例
longOrderSize number 1744.55 所有未执行报价累计数额
maintenanceMarginRequirement number 0.04 避免清算的最低保证金比例
netSize number -0.23 头寸大小。 做多为正,做空为负。
openSize number 1744.32 未执行挂单得到部分执行时可能的最大绝对头寸
realizedPnl number 3.39441714
shortOrderSize number 1732.09 所有未执行挂单累计数额
side string sell 做空为“卖出”,做多为“买入”
size number 0.23 netSize 的绝对价值
unrealizedPnl number 0.0

更改账户杠杆倍数

请求

POST /account/leverage
{
  "leverage": 10,
}

需要验证身份。

净荷格式

姓名 类型 价值 描述
leverage number 10 desired acccount-wide leverage setting

钱包

获取币

请求

GET /wallet/coins

回复


{
  "success": true,
  "result": [
    {
      "canDeposit": true,
      "canWithdraw": true,
      "hasTag": false,
      "id": "USDTBEAR",
      "name": "3X Short Tether Token"
    }
  ]
}

需要验证身份。

回复格式

姓名 类型 价值 描述
canDeposit boolean true
canWithdraw boolean true
hasTag boolean false True if addresses for this coin have a tag
id string USDTBEAR
name string 3X Short Tether Token

获取余额

请求

GET /wallet/balances

回复


{
  "success": true,
  "result": [
    {
      "coin": "USDTBEAR",
      "free": 2320.2,
      "total": 2340.2
    }
  ]
}

需要验证身份。

回复格式

姓名 类型 价值 描述
coin string USDTBEAR coin id
free number 2320.2 free amount
total number 2340.2 total amount

获取存款地址

请求

GET /wallet/deposit_address/{coin}

回复

{
  "success": true,
  "result": {
    "address": "0x83a127952d266A6eA306c40Ac62A4a70668FE3BE",
    "tag": "null"
  }
}

需要验证身份。

回复格式

姓名 类型 价值 描述
address string 0x83a127952d266A6eA306c40Ac62A4a70668FE3BE
tag string null optional

获取存入记录

请求

GET /wallet/deposits

回复

{
  "success": true,
  "result": {
    "coin": "TUSD",
    "confirmations": 64,
    "confirmedTime": "2019-03-05T09:56:55.728933+00:00",
    "fee": 0,
    "id": 1,
    "sentTime": "2019-03-05T09:56:55.735929+00:00",
    "size": "99.0",
    "status": "confirmed",
    "time": "2019-03-05T09:56:55.728933+00:00",
    "txid": "0x8078356ae4b06a036d64747546c274af19581f1c78c510b60505798a7ffcaf1"
  }
}

需要验证身份。

回复格式

姓名 类型 价值 描述
coin string TUSD coin id
confirmations number 64 number of blockchain confirmations
confirmedTime string 2019-03-05T09:56:55.728933+00:00
fee number 0.0 fee, not included in size
id number 1 deposit id
sentTime string 2019-03-05T09:56:55.735929+00:00
size string 99.0
status string confirmed one of "confirmed", "unconfirmed", or "cancelled"
time string 2019-03-05T09:56:55.728933+00:00
txid string 0x8078356ae4b06a036d64747546c274af19581f1c78c510b60505798a7ffcaf1

获取提现历史记录

请求

GET /wallet/withdrawals

回复

{
  "success": true,
  "result": {
    "coin": "TUSD",
    "address": "0x83a127952d266A6eA306c40Ac62A4a70668FE3BE",
    "tag": "null",
    "fee": 0,
    "id": 1,
    "size": "99.0",
    "status": "complete",
    "time": "2019-03-05T09:56:55.728933+00:00",
    "txid": "0x8078356ae4b06a036d64747546c274af19581f1c78c510b60505798a7ffcaf1"
  }
}

需要验证身份。

回复格式

姓名 类型 价值 描述
coin string TUSD coin id
address string 0x83a127952d266A6eA306c40Ac62A4a70668FE3BE deposit address the withdrawal was setnt to
tag string null
fee number 0.0 fee, not included in size
id number 1 withdrawal id
size string 99.0
status string complete one of "requested", "processing", "complete", or "cancelled"
time string 2019-03-05T09:56:55.728933+00:00
txid string 0x8078356ae4b06a036d64747546c274af19581f1c78c510b60505798a7ffcaf1

请求提现

请求

POST /wallet/withdrawals
{
  "coin": "USDTBEAR",
  "size": 20.2,
  "address": "0x83a127952d266A6eA306c40Ac62A4a70668FE3BE",
  "tag": null,
  "password": "my_withdrawal_password",
  "code": "152823
}

回复

{
  "success": true,
  "result": {
    "coin": "USDTBEAR",
    "address": "0x83a127952d266A6eA306c40Ac62A4a70668FE3BE",
    "tag": "null",
    "fee": 0,
    "id": 1,
    "size": "20.2",
    "status": "requested",
    "time": "2019-03-05T09:56:55.728933+00:00",
    "txid": "null"
  }
}

需要验证身份。

净荷格式

姓名 类型 价值 描述
coin string USDTBEAR coin to withdraw
size number 20.2 amount to withdraw
address string 0x83a127952d266A6eA306c40Ac62A4a70668FE3BE address to send to
tag string null optional
password string null optional; withdrawal password if it is required for your account
code string null optiona; 2fa code if it is required for your account

回复格式

姓名 类型 价值 描述
coin string USDTBEAR coin id
address string 0x83a127952d266A6eA306c40Ac62A4a70668FE3BE deposit address the withdrawal was setnt to
tag string null
fee number 0.0 fee, not included in size
id number 1 withdrawal id
size string 20.2
status string requested one of "requested", "processing", "complete", or "cancelled"
time string 2019-03-05T09:56:55.728933+00:00
txid string null

买卖盘

获取未执行的挂单

请求

GET /orders?market={market}

回复

{
  "success": true,
  "result": [
    {
      "createdAt": "2019-03-05T09:56:55.728933+00:00",
      "filledSize": 10,
      "future": "XRP-PERP",
      "id": 9596912,
      "market": "XRP-PERP",
      "price": 0.306525,
      "avgFillPrice": 0.306526,
      "remainingSize": 31421,
      "side": "sell",
      "size": 31431,
      "status": "open",
      "type": "limit",
      "reduceOnly": false,
      "ioc": false,
      "postOnly": false,
      "clientId": null
    }
  ]
}

需要验证身份。

请求参数

姓名 类型 价值 描述
market string BTC-0329 optional; market to limit orders

回复格式

姓名 类型 价值 描述
id number 9596912
market string XRP-PERP
type string limit
side string sell
price number 0.306525
size number 31431.0
filledSize number 10.0
remainingSize number 31421.0
avgFillPrice number 0.306526
status string new (accepted but not processed yet), open, or closed (filled or cancelled)
createdAt string 2019-03-05T09:56:55.728933+00:00
reduceOnly boolean false
ioc boolean false
postOnly boolean false
clientId string optional; client order id

获取订单历史记录

请求

GET /orders/history?market={market}

回复

{
  "success": true,
  "result": [
    {
      "avgFillPrice": 10135.25,
      "clientId": null,
      "createdAt": "2019-06-27T15:24:03.101197+00:00",
      "filledSize": 0.001,
      "future": "BTC-PERP",
      "id": 257132591,
      "ioc": false,
      "market": "BTC-PERP",
      "postOnly": false,
      "price": 10135.25,
      "reduceOnly": false,
      "remainingSize": 0.0,
      "side": "buy",
      "size": 0.001,
      "status": "closed",
      "type": "limit"
    }
  "hasMoreData": false,
  ]
}

需要验证身份。

请求参数

姓名 类型 价值 描述
market string BTC-0329 optional; market to limit orders
start_time number 1559881511 optional; only fetch orders created after this time
end_time number 1559901511 optional; only fetch orders created before this time
limit number 100 optional; default 100, maximum 100

回复格式

姓名 类型 价值 描述
id number 257132591
market string BTC-PERP
type string limit
side string buy
price number 10135.25
size number 0.001
filledSize number 0.001
remainingSize number 0.0
avgFillPrice number 10135.25
status string new (accepted but not processed yet), open, or closed (filled or cancelled)
createdAt string 2019-06-27T15:24:03.101197+00:00
reduceOnly boolean false
ioc boolean false
postOnly boolean false
clientId string optional; client order id

获取未完成触发挂单

请求

GET /conditional_orders?market={market}

回复

{
  "success": true,
  "result": [
    {
      "createdAt": "2019-03-05T09:56:55.728933+00:00",
      "error": null,
      "future": "XRP-PERP",
      "id": 50001,
      "market": "XRP-PERP",
      "orderId": null,
      "orderPrice": null,
      "reduceOnly": false,
      "side": "buy",
      "size": 0.003,
      "status": "open",
      "trailStart": null,
      "trailValue": null,
      "triggerPrice": 0.49,
      "triggeredAt": null,
      "type": "stop"
  ]
}

需要验证身份。

请求参数

姓名 类型 价值 描述
market string XRP-PERP optional; market to limit orders
type string stop optional; type of trigger order (stop, trailing_stop, or take_profit)

回复格式

姓名 类型 价值 描述
createdAt string 2019-03-05T09:56:55.728933+00:00
error string null Always null for this endpoint
future string XRP-PERP
id number 50001
market string XRP-PERP
orderId number null Always null for this endpoint
orderPrice number 0.50 Limit price for stop limit and take profit limit orders; otherwise null
reduceOnly boolean false
side string buy
size number 31431.0
status string open Always open for this endpoint
trailStart number null trigger price - trail value; only for trailing stop orders
trailValue number null only for trailing stop orders
triggerPrice number 0.49 market price at which this order will trigger
type string stop Values are stop, trailing_stop, and take_profit

获取触发挂单历史记录

请求

GET /conditional_orders/history?market={market}

回复

{
  "success": true,
  "result": [
    {
      "createdAt": "2019-03-05T09:56:55.728933+00:00",
      "error": null,
      "future": "XRP-PERP",
      "id": 50000,
      "market": "XRP-PERP",
      "orderId": 2800000,
      "orderPrice": null,
      "reduceOnly": false,
      "side": "buy",
      "size": 31431,
      "status": "triggered",
      "trailStart": null,
      "trailValue": null,
      "triggerPrice": 0.37,
      "triggeredAt": 2019-03-06T03:26:53.268723+00:00,
      "type": "stop",
      "orderType": "market",
      "filledSize": 31431,
      "avgFillPrice": 0.3701,
      "orderStatus": "closed"
    },
  "hasMoreData": false
  ""
  ]
}

需要验证身份。

请求参数

姓名 类型 价值 描述
market string BTC-0329 optional; market to limit orders
start_time number 1559881511 optional; only fetch orders created after this time
end_time number 1559881511 optional; only fetch orders created before this time
side string buy optional; valid values are buy and sell.
type string trailing_stop optional; valid values are stop, trailing_stop, and take_profit.
orderType string limit optional; valid values are market and limit.
limit number 100 optional; default 100, maximum 100

回复格式

姓名 类型 价值 描述
createdAt string 2019-03-05T09:56:55.728933+00:00
error string null error that occurred on triggering; otherwise null
future string XRP-PERP
id number 50001
market string XRP-PERP
orderId number null order ID if this order has triggered; otherwise null
orderPrice number 0.50 Limit price for stop limit and take profit limit orders; otherwise null
reduceOnly boolean false
side string buy
size number 31431.0
status string open Values are open, cancelled, and triggered
trailStart number null trigger price - trail value; only for trailing stop orders
trailValue number null only for trailing stop orders
triggerPrice number 0.49 market price at which this order will trigger
type string stop Values are stop, trailing_stop, and take_profit
orderType string market Values are market and limit
filledSize number 31431
avgFillPrice number 0.3701
orderStatus string closed Values are new, openandclosed`

下单

请求

POST /orders
{
  "market": "XRP-PERP",
  "side": "sell",
  "price": 0.306525,
  "type": "limit",
  "size": 31431.0,
  "reduceOnly": false,
  "ioc": false,
  "postOnly": false,
  "clientId": null,
}

回复

{
  "success": true,
  "result": {
    "createdAt": "2019-03-05T09:56:55.728933+00:00",
    "filledSize": 0,
    "future": "XRP-PERP",
    "id": 9596912,
    "market": "XRP-PERP",
    "price": 0.306525,
    "remainingSize": 31431,
    "side": "sell",
    "size": 31431,
    "status": "open",
    "type": "limit",
    "reduceOnly": false,
    "ioc": false,
    "postOnly": false,
    "clientId": null,
  }
}

需要验证身份。

净荷格式

姓名 类型 价值 描述
market string XRP-PERP
side string sell "buy" or "sell"
price number 0.306525 Send null for market orders.
type string limit "limit" or "market"
size number 31431.0
reduceOnly boolean false optional; default is false
ioc boolean false optional; default is false
postOnly boolean false optional; default is false
clientId string null optional; client order id

回复格式

姓名 类型 价值 描述
createdAt string 2019-03-05T09:56:55.728933+00:00
filledSize number 0.0
future string XRP-PERP
id number 9596912
market string XRP-PERP
price number 0.306525
remainingSize number 31431.0
side string sell
size number 31431.0
status string new (accepted but not processed yet), open, or closed (filled or cancelled)
type string limit
reduceOnly boolean false
ioc boolean false
postOnly boolean false
clientId string optional; client order id, if supplied

设置计划委托

计划委托包括了止损,移动止损以及止盈等委托。

请求

POST /conditional_orders
  • 止损
{
  "market": "XRP-PERP",
  "side": "sell",
  "triggerPrice": 0.306525,
  "size": 31431.0,
  "type": "stop",
  "reduceOnly": false
}
  • 移动止损
{
  "market": "XRP-PERP",
  "side": "sell",
  "trailValue": -0.05,
  "size": 31431.0,
  "type": "trailingStop",
  "reduceOnly": false
}
  • 止盈
{
  "market": "XRP-PERP",
  "side": "buy",
  "triggerPrice": 0.367895,
  "size": 31431.0,
  "type": "takeProfit",
  "reduceOnly": false
}

回复

{
  "success": true,
  "result": {
    "createdAt": "2019-03-05T09:56:55.728933+00:00",
    "future": "XRP-PERP",
    "id": 9596912,
    "market": "XRP-PERP",
    "triggerPrice": 0.306525,
    "orderId": null,
    "side": "sell",
    "size": 31431,
    "status": "open",
    "type": "stop",
    "orderPrice": null,
    "error": null,
    "triggeredAt": null,
    "reduceOnly": false
  }
}

需要验证身份。

净荷格式

姓名 类型 价值 描述
market string XRP-PERP
side string sell "buy" or "sell"
size number 31431.0
type string stop one of "stop", "trailingStop", or "takeProfit"; default is stop
reduceOnly boolean false optional; default is false

为止损委托增加的参数

姓名 类型 价值 描述
triggerPrice number 0.306525
orderPrice number 0.3063 optional; order type is limit if this is specified; otherwise market

为移动止损委托增加的参数

姓名 类型 价值 描述
trailValue number -0.05 negative for "sell"; positive for "buy"

为止盈委托增加的参数

姓名 类型 价值 描述
triggerPrice number 0.306525
orderPrice number 0.3067 optional; order type is limit if this is specified; otherwise market

回复格式

姓名 类型 价值 描述
createdAt string 2019-03-05T09:56:55.728933+00:00
future string XRP-PERP
id number 9596912
market string XRP-PERP
triggerPrice number 0.306525
orderId number 123123 ID of the order sent when this stop loss order triggered
side string sell
size number 31431.0
status string new (accepted but not processed yet), open, or closed (filled or cancelled)
type string stop
orderPrice number null price of the order sent when this stop loss triggered
error string null error message for unsuccessful order placement when this stop loss triggered
triggeredAt string null time at which this stop loss order triggered
reduceOnly boolean false

获取订单状态

请求

GET /orders/{order_id}

回复

{
  "success": true,
  "result": {
    "createdAt": "2019-03-05T09:56:55.728933+00:00",
    "filledSize": 10,
    "future": "XRP-PERP",
    "id": 9596912,
    "market": "XRP-PERP",
    "price": 0.306525,
    "avgFillPrice": 0.306526,
    "remainingSize": 31421,
    "side": "sell",
    "size": 31431,
    "status": "open",
    "type": "limit",
    "reduceOnly": false,
    "ioc": false,
    "postOnly": false,
    "clientId": null
  }
}

通过客户编号获取订单状态

请求

GET /orders/by_client_id/{client_order_id}

回复

{
  "success": true,
  "result": {
    "createdAt": "2019-03-05T09:56:55.728933+00:00",
    "filledSize": 10,
    "future": "XRP-PERP",
    "id": 9596912,
    "market": "XRP-PERP",
    "price": 0.306525,
    "avgFillPrice": 0.306526,
    "remainingSize": 31421,
    "side": "sell",
    "size": 31431,
    "status": "open",
    "type": "limit",
    "reduceOnly": false,
    "ioc": false,
    "postOnly": false,
    "clientId": "your_client_order_id"
  }
}

需要验证身份。

回复格式

姓名 类型 价值 描述
id number 9596912
market string XRP-PERP
type string limit
side string sell
price number 0.306525
size number 31431.0
filledSize number 10.0
remainingSize number 31421.0
avgFillPrice number 0.306526
status string new (accepted but not processed yet), open, or closed (filled or cancelled)
createdAt string 2019-03-05T09:56:55.728933+00:00
reduceOnly boolean false
ioc boolean false
postOnly boolean false
clientId string client order id

撤单

请求

DELETE /orders/{order_id}

回复

{
  "success": true,
  "result": "Order queued for cancelation"
}

需要验证身份。

通过客户编号取消订单

请求

DELETE /orders/by_client_id/{client_order_id}

回复

{
  "success": true,
  "result": "Order queued for cancellation"
}

需要验证身份。

取消未完成触发挂单

请求

DELETE /conditional_orders/{id}

回复

{
  "success": true,
  "result": "Order cancelled"
}

需要验证身份。

取消所有挂单

此操作会取消您设置的条件委托(止损委托和跟踪止损委托)。

请求

DELETE /orders
{
  "market": "BTC-PERP",
}

回复

{
  "success": true,
  "result": "Orders queued for cancelation"
}

需要验证身份。

净荷格式

姓名 类型 价值 描述
market string USDTBEAR optional; restrict to cancelling orders only on this market
conditionalOrdersOnly boolean false optional; restrict to cancelling conditional orders only
limitOrdersOnly boolean false optional; restrict to cancelling existing limit orders (non-conditional orders) only

执行

请求

GET /fills?market={market}

回复

{
  "success": true,
  "result": [
    {
      "fee": 20.1374935,
      "feeRate": 0.0005,
      "future": "EOS-0329",
      "id": 11215,
      "liquidity": "taker",
      "market": "EOS-0329",
      "baseCurrency": null,
      "quoteCurrency": null,
      "orderId": 8436981,
      "price": 4.201,
      "side": "buy",
      "size": 9587,
      "time": "2019-03-27T19:15:10.204619+00:00",
      "type": "order"
    }
  ]
}

需要验证身份。

请求参数

姓名 类型 价值 描述
market string BTC-0329 optional; market to limit fills
limit number 20 optional; number of fills to return
start_time number 1564146934 optional; minimum time of fills to return, in Unix time (seconds since 1970-01-01)
end_time number 1564233334 optional; maximum time of fills to return, in Unix time (seconds since 1970-01-01)

回复格式

姓名 类型 价值 描述
fee number 20.1374935
feeRate number 0.0005
future string EOS-0329
id number 11215 fill id
liquidity string taker "taker" or "maker"
market string EOS-0329
baseCurrency string BTC 仅限现货市场
quoteCurrency string USD 仅限现货市场
orderId number 8436981
price number 4.201
side string buy
size number 9587.0
time string 2019-03-27T19:15:10.204619+00:00
type string order

融资付款

请求

GET /funding_payments
姓名 类型 价值 描述
start_time number 1559881511 optional
end_time number 1559881711 optional

回复

{
  "success": true,
  "result": [
    {
      "future": "ETH-PERP",
      "id": 33830,
      "payment": 0.0441342,
      "time": "2019-05-15T18:00:00+00:00",
      "rate": 0.0001
    }
  ]
}

需要验证身份。

回复格式

姓名 类型 价值 描述
future string ETH-PERP
id number 33830
payment number 0.0441342
time string 2019-05-15T18:00:00+00:00

杠杆代币

列出杠杆代币

请求

GET /lt/tokens

回复

{
  "success": true,
  "result": [
    {
      "name": "HEDGE",
      "description": "1x Short Bitcoin Token",
      "underlying": "BTC-PERP",
      "leverage": -1,
      "outstanding": 1100.72231577,
      "pricePerShare": 2736.375887408888,
      "positionPerShare": -0.35783866135616976,
      "underlyingMark": 7605.25,
      "contractAddress": "0x1FA3bc860bF823d792f04F662f3AA3a500a68814",
      "change1h": 0.00035975425246481245,
      "change24h": 0.02595729864870652
    }
  ]
}

回复格式

姓名 类型 价值 描述
name string HEDGE 代币名称
description string 1x Short Bitcoin Token
underlying string BTC-PERP 此代币使用的标的期货合约名称
leverage number -1
outstanding number 1100.72231577 未偿付的代币数量
pricePerShare number 2736.375887408888 以标的期货当前标记价格计算的每种代币价格
positionPerShare number -0.35783866135616976 每种代币的标的期货头寸
underlyingMark number 7605.25 标的期货当前标记价格
contractAddress string 0x1FA3bc860bF823d792f04F662f3AA3a500a68814 代币 ERC20 智能合约地址
change1h number 0.00035975425246481245 过去一小时内代币价格变化
change24h number 0.02595729864870652 过去一天代币价格变化

获取代币信息

请求

GET /lt/{token_name}

回复

{
  "success": true,
  "result": {
    "name": "HEDGE",
    "description": "1x Short Bitcoin Token",
    "underlying": "BTC-PERP",
    "leverage": -1,
    "outstanding": 1100.72231577,
    "pricePerShare": 2736.375887408888,
    "positionPerShare": -0.35783866135616976,
    "underlyingMark": 7605.25,
    "contractAddress": "0x1FA3bc860bF823d792f04F662f3AA3a500a68814",
    "change1h": 0.00035975425246481245,
    "change24h": 0.02595729864870652
  }
}

参数

姓名 类型 价值 描述
token_name string HEDGE Required. Name of the token.

回复格式

姓名 类型 价值 描述
name string HEDGE 代币名称
description string 1x Short Bitcoin Token
underlying string BTC-PERP 此代币使用的标的期货合约名称
leverage number -1
outstanding number 1100.72231577 未偿付的代币数量
pricePerShare number 2736.375887408888 以标的期货当前标记价格计算的每种代币价格
positionPerShare number -0.35783866135616976 每种代币的标的期货头寸
underlyingMark number 7605.25 标的期货当前标记价格
contractAddress string 0x1FA3bc860bF823d792f04F662f3AA3a500a68814 代币 ERC20 智能合约地址
change1h number 0.00035975425246481245 过去一小时内代币价格变化
change24h number 0.02595729864870652 过去一天代币价格变化

获取加杠杆代币余额

请求

GET /lt/balances

回复

{
  "success": true,
  "result": [
    {
      "token": "HEDGE",
      "balance": 8.8
    }
  ]
}

需要验证身份。

回复格式

姓名 类型 价值 描述
token string HEDGE
balance number 8.8

列出杠杆代币创建请求

请求

GET /lt/creations

回复

{
  "success": true,
  "result": [
    {
      "id": 123,
      "token": "HEDGE",
      "requestedSize": 10,
      "pending": false,
      "createdSize": 10,
      "price": 1234,
      "cost": 12340,
      "fee": 12.34,
      "requestedAt": "2019-03-05T09:56:55.728933+00:00",
      "fulfilledAt": "2019-03-05T09:56:55.728933+00:00"
    }
  ]
}

需要验证身份。

回复格式

姓名 类型 价值 描述
id number 123
token string HEDGE 代币名称
requestedSize number 10 最初请求的代币数量
pending boolean false
createdSize number 10 创建的代币数量;可能小于请求数量
price number 1234 创建请求执行价格
cost number 12340 不含费用的代币创建成本
fee number 12.34 代币创建费用
requestedAt string 2019-03-05T09:56:55.728933+00:00 请求提交时间
fulfilledAt string 2019-03-05T09:56:55.728933+00:00 处理请求的时间

请求创建杠杆代币

请求

POST /lt/{token_name}/create
{
  "size": 31431.0
}

回复

{
  "success": true,
  "result": {
    "id": 123,
    "token": "HEDGE",
    "requestedSize": 10,
    "cost": 12340,
    "pending": true,
    "requestedAt": "2019-03-05T09:56:55.728933+00:00"
  }
}

需要验证身份。

请求参数

姓名 类型 价值 描述
token_name string HEDGE required; name of the token

净荷格式

姓名 类型 价值 描述
size number 31431.0 number of tokens to create

回复格式

姓名 类型 价值 描述
id number 123
token string HEDGE 代币名称
requestedSize number 10 请求的代币数量
cost number 12340 创建请求扣除的抵押金额
pending boolean true
requestedAt string 2019-03-05T09:56:55.728933+00:00 请求提交时间

列出杠杆代币兑换请求

请求

GET /lt/redemptions

回复

{
  "success": true,
  "result": [
    {
      "id": 123,
      "token": "HEDGE",
      "size": 10,
      "pending": false,
      "price": 1234,
      "proceeds": 12340,
      "fee": 12.34,
      "requestedAt": "2019-03-05T09:56:55.728933+00:00",
      "fulfilledAt": "2019-03-05T09:56:55.728933+00:00"
    }
  ]
}

需要验证身份。

回复格式

姓名 类型 价值 描述
id number 123
token string HEDGE 代币名称
size number 10 已兑换代币总量
pending boolean false
price number 1234 赎回请求执行价格
proceeds number 12340 赎回收益,未扣费
fee number 12.34 代币兑换费用
requestedAt string 2019-03-05T09:56:55.728933+00:00 请求提交时间
fulfilledAt string 2019-03-05T09:56:55.728933+00:00 处理请求的时间

请求兑换杠杆代币

请求

POST /lt/{token_name}/redeem
{
  "size": 31431.0
}

回复

{
  "success": true,
  "result": {
    "id": 123,
    "token": "HEDGE",
    "size": 10,
    "projectedProceeds": 12340,
    "pending": true,
    "requestedAt": "2019-03-05T09:56:55.728933+00:00"
  }
}

需要验证身份。

请求参数

姓名 类型 价值 描述
token_name string HEDGE required; name of the token

净荷格式

姓名 类型 价值 描述
size number 31431.0 number of tokens to create

回复格式

姓名 类型 价值 描述
id number 123
token string HEDGE - name of the token
size number 10 - number of tokens requsted to be redeemed
projectedProceeds number 12340 - estimated proceeds from the redemption
pending boolean true
requestedAt string 2019-03-05T09:56:55.728933+00:00 - time the request was submitted

Websocket API

Streaming API,包含最新的市场和账户挂单数据。 使用此 API,您可以将消息发送到服务器并收到以事件为基础的回复,无需轮询服务器获得回复。

Websocket 端点网址:wss://ftx.com/ws/

使用 JSON 发起请求和回复。

您可以在此找到示例代码:https://github.com/ftexchange/ftx

请求流程

Websocket connections go through the following lifecycle:

请求格式

发送到服务器的消息应包含以下字典项:

-“频道”:您希望获取数据的频道。 应该是下列之一 -“委托簿”为委托簿的市场数据 -“交易”为交易的市场数据 -“滚动信息区”为最佳报价和市场数据 -“市场”:您希望获取数据的市场。 例如:“BTC-PERP” -“操作”:您想要执行的操作。 应该是下列之一 -“订阅”用于订阅频道 -“取消订阅”用于取消频道订阅

回复格式

-“频道” -“市场” -“类型”:消息的类型 -“错误”:发生错误时显示。 当“类型”为“错误”时,还会有“代码”和“消息”字段。 “代码”采用标准 HTTP 错误代码值。 -“已订阅”:表示成功订阅了频道和市场。 -“已取消订阅”:表示成功取消频道和市场订阅。 -“信息”:用于向用户传达信息。 附带“代码”和“消息”字段。 - 服务器重新启动时,您可能会看到一条代码为“20001”的“信息”消息。 如果您看到此消息,请重新连接。 -“部分”:包含当前市场数据的快照。 数据快照可以在随附的“数据”字段中找到。 -“更新”:包含有关当前市场数据的更新。 更新可在随附的“数据”字段中找到。 -“代码”(可选) -“消息”(可选) -“数据”(可选)

公有市场行情接口

代号

“滚动信息区”频道提供最新的最佳报价和市场数据。 所有消息都是快照(“部分”),“数据”字段包含:

-“买入”:如有买入报价则为最佳报价,否则为“无” -“卖出”:如有卖出报价则为最佳报价,否则为“无” -“最新”:最新成交价格(如有),否则为“无” -“时间”:时间戳

交易

“交易”频道提供市场内的所有交易数据。 所有消息都是新交易的快照(“部分”),“数据”字段包含:

-“价格”:交易价格 -“规模”:交易规模 -“清算”:如果交易涉及清算单,则为“是”,否则为“否” -“时间”:时间戳

委托簿

“盘口”查询提供盘口双边最优的100报价的数据。

初始快照

订阅后,您将收到委托簿(“部分”)的快照,其中包含“数据”字段,其中包含:

-“操作”:“部分“ -“买入” -“卖出” -“校验和”:见下方 -“时间”:时间戳

“买入”和“卖出”的格式如下:“[[最佳价格,该价格数额大小],[下一个最佳价格,该价格数额大小],...]”

更新

收到您的快照后,将会向您流式传输更新(消息“类型”为“更新”),“数据”字段带有:

-“操作”:“更新” -“买入” -“卖出” -“校验和”:见下方 -“时间”:时间戳

“买入”和“卖出”字段包含对委托簿的更新。

校验和

每条消息都包含来自委托簿的已签名 32 位整数校验和。 您可以在客户端上得到相同的校验和

私有接口

身份验证

您可以通过发送类似 %{code} 的消息登录

{
  "args": {
    "key": "<api_key>",
    "sign": "<signature>",
    "time": "<ts>"
  },
  "op": "login"
}

As an example, if:

sign would be d10b5a67a1a941ae9463a60b285ae845cdeac1b11edc7da9977bef0228b96de9

一个 websocket 连接最多可登录一名用户。 如果连接已通过身份验证,再次尝试登录会导致 400 错误。

执行

您很快将收到消息:

{
  "channel": "fills",
  "data": {
    "fee": 78.05799225,
    "feeRate": 0.0014,
    "future": "BTC-PERP",
    "id": 7828307,
    "liquidity": "taker",
    "market": "BTC-PERP",
    "orderId": 38065410,
    "price": 3723.75,
    "side": "buy",
    "size": 14.973,
    "time": "2019-05-07T16:40:58.358438+00:00",
    "type": "order"
  },
  "type": "update"
}

该频道将向所有市场流式传输您的执行价 您可以在经过身份验证的连接上发送 {'op': 'subscribe', 'channel': 'fills'} 进行订阅。

买卖盘

您很快将收到消息:

{
  "channel": "orders",
  "data": {
    "id": 24852229,
    "clientId": null,
    "market": "XRP-PERP",
    "type": "limit",
    "side": "buy",
    "size": 42353.0,
    "price": 0.2977,
    "reduceOnly": false,
    "ioc": false,
    "postOnly": false,
    "status": "closed",
    "filledSize": 0.0,
    "remainingSize": 0.0,
    "avgFillPrice": 0.2978
  },
  "type": "update"
}

此频道可为您在所有市场中的挂单流式传输更新。 您可以在经过身份验证的连接上发送 {'op': 'subscribe', 'channel': 'orders'} 进行订阅。

FIX API

FIX ( 金融信息交换协议)是一个标准的电子信息协议,可用于下单,获取订单状态更新及执行,或者取消订单。 我们的FIX api是基于FIX 4.2规格,借鉴其他主流数字货币交易平台的FIX应用,做出了优化和调整。 您可以在用户代码处查看示例: https://github.com/ftexchange/ftx FIX 终端 URL:tcp+ssl://fix.ftx.com:4363 用户需要使用SSL连接终端。 每次连接数字序列都会重置。暂不支持重发请求及序列重置信息。

消息

8=FIX.4.2|9=162|35=A|49=zyfvB4QPg0A3kkVgqUE9V1fOA-Y6jhdG3seqIIZx|56=FTX

所有信息都应该包含以下header: 这个文档使用“|”表示FIX的修改字段分隔符(byte 0x01)。真实的信息中,它可以被 0x01替换。

标签 姓名 示例 描述
8 BeginString FIX.4.2 Must be set to "FIX.4.2"
9 BodyLength 162 Length of the message body in bytes
35 MsgType 8 Message type
49 SenderCompID zyfvB4QPg0A3kkVgqUE9V1fOA-Y6jhdG3seqIIZx Client API key (for messages from the client)
56 TargetCompID FTX Must be set to "FTX" (for messages from the client)
34=1|52=20190525-07:17:48

消息还应包括序列号 MsgSeqNum (34) 和时间戳 SendingTime (52)。 序列号从 1 开始,必须随每条消息递增。 序列号重复或 不正确的邮件将被拒收。 序列号会在新连接重置。

Logon (A)

由客户端发送用于发起 FIX 会话。 必须在连接 建立后首先发送该消息。 每个连接只能建立一个会话;其他登录消息会 被拒收。

请求

8=FIX.4.2|9=162|35=A|49=zyfvB4QPg0A3kkVgqUE9V1fOA-Y6jhdG3seqIIZx|56=FTX|34=1|52=20190525-07:51:51|98=0|108=30|96=8f7e7d37f8033ad249c1833687c230b6f4663f0dd72752899776bab9aa064783|10=237|
标签 姓名 示例 描述
35 MsgType A
98 EncryptMethod 0 Must be set to "0" (None)
108 HeartBInt 30 Must be set to "30"
96 RawData 8f7e...4783 Signature (see below)
8013 CancelOrdersOnDisconnect Y "Y": all account orders will be cancelled at the end of the session. "S": all orders placed during the session will be cancelled at the end of the session. Default: no orders will be cancelled.
1 Account "my_subaccount" Optional subaccount name; can be omitted if authenticating for main account

签名

from datetime import datetime
import hmac

api_key = 'YOUR_API_KEY'
api_secret = 'YOUR_API_SECRET'

sending_time = datetime.now().strftime('%Y%m%d-%H:%M:%S')

sign_target = '\x01'.join([
    sending_time,  # SendingTime
    'A',  # MsgType
    '1',  # MsgSeqNum
    api_key,  # SenderCompID
    'FTX',  # TargetCompID
])

signature = hmac.new(api_secret.encode(), sign_target.encode(), 'sha256').hexdigest()

let crypto = require('crypto');

let apiKey = 'YOUR_API_KEY';
let apiSecret = 'YOUR_API_SECRET';

let sendingTime = '20190525-07:51:51';

let signTarget = [
    sendingTime,  // SendingTime
    'A',  // MsgType
    '1',  // MsgSeqNum
    apiKey,  // SenderCompID
    'FTX',  // TargetCompID
].join('\x01');

let hmac = crypto.createHmac('sha256', apiSecret);
let signature = hmac.update(signTarget).digest('hex');

为了安全起见,登录消息必须由客户端签名。 要计算签名,请连接 以下字段,由 FIX 字段分隔符(字节 0x01)连接,并计算 SHA256 HMAC 使用 API 密钥:

生成的哈希应该为十六进制编码。








回复

8=FIX.4.2|9=98|35=A|49=FTX|56=zyfvB4QPg0A3kkVgqUE9V1fOA-Y6jhdG3seqIIZx|34=1|98=0|108=30|52=20190525-07:51:51.838|10=099
Tag Name Value
35 MsgType A
98 EncryptMethod 0
108 HeartBInt 30

Heartbeat (0)

如果过去 30 秒内未收到消息,则由任一方发送。 也应发送 用于回复 TestRequest (1)(测试请求)。

8=FIX.4.2|9=86|35=1|49=zyfvB4QPg0A3kkVgqUE9V1fOA-Y6jhdG3seqIIZx|56=FTX|34=2|52=20190525-07:52:24.029|10=049|
Tag Name Value Description
35 MsgType 0
112 TestReqID 123 If this heartbeat is in response to a TestRequest, copied from the TestRequest.

测试请求 (1)

可由任何一方随时发送。

8=FIX.4.2|9=112|35=1|49=zyfvB4QPg0A3kkVgqUE9V1fOA-Y6jhdG3seqIIZx|56=FTX|34=3|112=20190525-08:26:38.989|52=20190525-08:26:38.989|10=140|
Tag Name Value Description
35 MsgType 1
112 TestReqID 123 Arbitrary string, to be echoed back by a Heartbeat.

Logout (5)

由任何一方发送用于终止会话。 另一方应再发送一条“退出” 消息以确认会话终止。 连接将随后关闭。

Tag Name Value
35 MsgType 5

New Order Single (D)

由客户发送用于提交新挂单。 FIX API 目前仅支持限价挂单。

Tag Name Value Description
35 MsgType D
21 HandlInst 1 Must be set to "1" (AutomatedExecutionNoIntervention)
11 ClOrdID order123 Arbituary client-selected string to identify the order; must be unique within the session
55 Symbol BTC-PERP Symbol name
40 OrdType 2 Must be set to "2" (Limit)
38 OrderQty 1.1 Order size in base units
44 Price 8000 Limit price
54 Side 1 "1": buy; "2": sell
59 TimeInForce 1 Must be set to "1" (Good Till Cancel) or "3" (Immediate or Cancel)
18 ExecInst E This paramter is optional. "E": reduce only, "6": post only, not supplied: standard

If the order is accepted, an ExecutionReport (8) with ExecType=A (Pending New) will be returned. Otherwise, an ExecutionReport with ExecType=8 (Rejected) will be returned.

Order Cancel Request (F)

由客户发送用于请求撤单。

Tag Name Value Description
35 MsgType F
37 OrderID 123456 System-assigned order ID of the order
41 OrigClOrdID order123 Client-assigned order ID of the order

Only one of OrderID (37) and OrigClOrdID (41) should be provided.

If the order is successfully cancelled, an ExecutionReport (8) with ExecType=6 (Pending Cancel) will be returned. Otherwise, an OrderCancelReject (9) will be returned.

Order Cancel Reject (9)

服务器向客户端通知 OrderCancelRequest (F),即撤单请求失败。

Tag Name Value Description
35 MsgType 9
11 ClOrdID cancel123 Copied from OrderCancelRequest
37 OrderID 123456 Copied from OrderCancelRequest
41 OrigClOrdID order123 Copied from OrderCancelRequest
39 OrdStatus 4 "4" (Canceled) if the order was already cancelled
102 CxlRejReason 1 "0": order already cancelled, "1": unknown order
434 CxlRejResponseTo 1 Always set to "1"

Order Status Request (H)

由客户发送用于请求挂单状态。

Tag Name Value Description
35 MsgType H
37 OrderID 123456 OrderID of the order to request, or "*" to request all pending orders
41 OrigClOrdID order123 Client-assigned order ID of the order

The server will respond with an ExecutionReport (8) with ExecType=I (OrderStatus) with the requested order or orders. Only one of OrderID (37) and OrigClOrdID (41) should be provided.

Execution Report (8)

由服务器在下列情况发送:挂单已执行、挂单变更或 回复来自客户端的 NewOrderSingle (D)(新下单)、OrderCancelRequest (F)(撤单请求)、或 OrderStatusRequest (H)(挂单状态请求) 消息。

Tag Name Value Description
35 MsgType 8
11 ClOrdID order123 Client-selected order ID.
37 OrderID 123456 Server-assigned order ID
55 Symbol BTC-PERP Symbol name
54 Side 1 "1": buy; "2": sell
38 OrderQty 1.2 Original order quantity
44 Price 8000 Original order price
150 ExecType 1 Reason for this message (see below)
39 OrdStatus 0 Order status (see below)
14 CumQty 0.4 Quantity of order that has already been filled
151 LeavesQty 0.8 Quantity of order that is still open
60 TransactTime 20190525-08:26:38.989 Time of the order update. Only present on order updates
31 LastPx 7999.25 Fill price. Only present if this message was the result of a fill
32 LastQty 0.4 Fill quantity. Only present if this message was the result of a fill
1057 AggressorIndicator Y "Y": taker fill; "N": maker fill. Only present if this message was the result of a fill
103 OrdRejReason 3 Reason the order was rejected (see below). Only present on rejected NewOrderSignle (D) requests
58 Text 58 Description of the reason the order was rejected.Only present on rejected NewOrderSignle (D) requests

ExecType values

ExecType (150)(执行类型)字段表明发送此 ExecutionReport(执行报告)的原因。

ExecType Description
0 New order
1 New fill for order
3 Order done (fully filled)
4 Order cancelled
5 Order resized (possible for reduce-only orders)
A Response to a successful NewOrderSingle (D) request
8 Response to a rejected NewOrderSingle (D) request
6 Response to a successful OrderCancelRequest (F) request
I Response to a OrderStatusRequest (H) request

Note that every fill will generate a new ExecType=1 message. If a fill causes an order to be fully filled, both a ExecType=1 message and a ExecType=3 message will be generated. Similarly, a newly placed order that is immediately matched against an opposing order will generate both a ExecType=0 message and a ExecType=1 message.

OrdStatus values

OrdStatus Description
0 New order
1 Partially filled order
3 Fully filled order
4 Cancelled order
5 Resized order

OrdRejReason values

OrdRejReason Description
3 Risk limits exceeded
0 Other errors

Reject (3)

由服务器发送用于回复无效消息。

Tag Name Value Description
35 MsgType 3
45 RefSeqNum 2 Sequence number of the rejected message
371 RefTagID 38 Tag number of the rejected field
372 RefMsgType D Message type of the rejected message
58 Text Missing quantity Human-readable description of the reason for the rejection
373 SessionRejectReason 1 Code to identify the rejection reason (see below)

Rejection reason codes

SessionRejectReason Description
1 Required tag missing
5 Value incorrect for this tag
6 Incorrect data format for value
11 Invalid MsgType