English
NAV
go python

更新日志

2024-01-20

2023-09-27

2023-05-04

2022-10-28

2022-09-27

2022-08-27

2022-05-27

2022-04-13



介绍

欢迎阅读DeGate SDK文档,我们提供支持Python和Go两种语言的SDK来满足交易者的多种需求,本文档是帮助交易者访问这些服务的指南。

什么是资产私钥(AssetPrivateKey)

用户开通DeGate账户后,可通过钱包私钥签名派生出一个资产私钥用于交易。交易下单、取消订单、链上撤单等操作都可以使用资产私钥进行签名,从而保护钱包私钥。 资产私钥保存在用户浏览器的LocalStorage中,每次关闭浏览器都会清除,并在下次登录DeGate时恢复。 用户也可通过账户安全-重置资产私钥的方式来重新生成一个资产私钥。

如何获取资产私钥(AssetPrivateKey)

用户可以通过账户安全 - 查看资产私钥来导出资产私钥,用于DeGate API的调用。 在弹出的Json文本中,手动复制privateKey项的值即可得到您的资产私钥。 image 请务必注意保护资产私钥的安全,否则您的财产可能面临风险:攻击者得到用户的资产私钥后,并不能提现给自己的地址,但是可以通过交易的方式,将用户的资产转移。

权限

资产私钥(AssetPrivateKey)具备的操作权限有:交易下单、取消订单、链上撤单;

不具备的操作权限:开通账户、提现(包括提现给自己和第三方账户)、转账、重置密钥、导出密钥。

代码库及资产私钥使用

代码示例:

{
import (
    "encoding/json"
    "github.com/degatedev/degate-sdk-golang/conf"
    "github.com/degatedev/degate-sdk-golang/degate/spot"
    "github.com/degatedev/degate-sdk-golang/log"
)
client := &spot.Client{}
var appConfig = &conf.AppConfig{}
client.SetAppConfig(appConfig)
response,err := client.Time()
if err != nil {
    log.Error("error: %v",err)
} else if !response.Success() {
    log.Error("fail: %v",response.Code)
} else {
    log.Info("success: %v",response.Data.ServerTime)
}
client = &spot.Client{}
// 需要填入AccountAddress、AssetPrivateKey、AccountId 来使用SDK
var appConfig = &conf.AppConfig{
    AccountId: <accountId>,
    AccountAddress: <accountAddress>,
    AssetPrivateKey:<DeGate AssetPrivateKey>,
}
client.SetAppConfig(appConfig)
// 获取账户余额信息
response,err := client.Account()
if err != nil {
    log.Error("error: %v",err)
} else if !response.Success() {
    log.Error("fail: %v",response.Code)
} else {
    account,_ := json.Marshal(response.Data)
    log.Info("success: %v",string(account))
}
}
from degate.spot import Spot as Client

ETH = {
    "id": 0,
    "symbol": "ETH",
}
USDC = {
    "id": 2,
    "symbol": "USDC",
}
client = Client(tokens=[ETH,USDC])
# 获取服务器时间
print(client.time())
# 需要填入AccountAddress、AssetPrivateKey、AccountId 来使用SDK
client = Client(accountAddress='<account_address>',assetPrivateKey='<DeGate AssetPrivateKey>',accountId=<account_id>,tokens=[ETH,USDC])
# 获取账户余额信息
print(client.account())

Go connector

一个轻量级的Go代码库,提供让用户直接调用SDK的方法。支持所有现货的接口。

按照右侧代码示例,在appconfig中依次配置账号ID(accountId)、账号地址(accountAddress)、资产私钥(AssetPrivateKey)即可使用基于Go的DeGate SDK。完成配置后即可根据后续代码示例完成交易下单、取消订单、链上撤单等操作。

点击链接查看更多详细用例以及安装方法。

https://github.com/degatedev/degate-sdk-golang

Python connector

一个轻量级的Python代码库,提供让用户直接调用SDK的方法。支持所有现货的接口。
按照右侧代码示例,在Client中依次配置账号ID(accountId)、账号地址(accountAddress)、资产私钥(AssetPrivateKey)即可使用基于Python的DeGate SDK。完成配置后即可根据后续代码示例完成交易下单、取消订单、链上撤单等操作。

点击链接查看更多详细用例以及安装方法。

https://github.com/degatedev/degate-sdk-python

基本信息

API基本信息

更改baseurl来访问其他环境:

var appConfig = &conf.AppConfig{
    BaseUrl:"https://v1-mainnet-backend.degate.com/",
}
from degate.spot import Spot as Client

client = Client(baseUrl='https://v1-mainnet-backend.degate.com/')
print(client.time())

HTTP 返回代码

错误代码返回形式如下:

{
  "code": -1121,
  "msg": "Invalid symbol."
}

接口错误代码

访问限制

访问限制基本信息


IP 访问限制


权重(Weight)
每一个接口均有一个相应的权重(Weight)。越消耗资源的接口权重就会越大。在时间范围内的权重消耗,如果收到429返回,则说明在时间范围内用户拥有的权重配额全部被消耗,用户需要等待权重配额恢复后再进行下一次请求。请求ExchangeInfo 即可获取交易所关于REQUEST_WEIGHT和REQUEST_ORDER_WEIGHT的限制数量。


如何使用SDK查看IP的已使用的权重
每个响应将包含一个X-MBX-USED-WEIGHT-(intervalNum)(intervalLetter)的响应头,其中包含当前IP所有请求的已使用权重。

查看请求返回的header

import (
    "encoding/json"
    "github.com/degatedev/degate-sdk-golang/conf"
    "github.com/degatedev/degate-sdk-golang/degate/spot"
    "github.com/degatedev/degate-sdk-golang/log"
)
client := &spot.Client{}
var appConfig = &conf.AppConfig{
    ShowHeader:true,
}
client.SetAppConfig(appConfig)
response,err := client.Time()
data,_ := json.Marshal(response)
log.Info("%v",string(data))
from degate.spot import Spot as Client
client = Client(show_header=True)
print(client.time())

Response

{
   "header":{
      "Content-Length":"42",
      "Content-Type":"application/json; charset=utf-8",
      "Date":"Thu, 29 Sep 2022 09:24:51 GMT",
      "Server":"openresty/1.15.8.1",
      "X-Mbx-Used-Weight-1m":"24"
   },
   "data":{
      "serverTime":1664443491000
   }
}











下单频率限制


WEB SOCKET 连接限制

数据来源

系统一共有3个数据来源,按照更新速度的先后排序。排在前面的数据最新,在后面就有可能存在延迟。

基本配置与示例

在使用本SDK前,需要进行一些基本的配置

Token配置

完整配置 Example(Token、config配置):

import (
    "encoding/json"
    "github.com/degatedev/degate-sdk-golang/conf"
    "github.com/degatedev/degate-sdk-golang/degate/spot"
    "github.com/degatedev/degate-sdk-golang/log"
)
client := &spot.Client{}
conf.Conf.AddToken(&model.TokenInfo{
    Id:     8,
    Symbol: "USDC",
})  //配置 USDC, tokenid = 8
conf.Conf.AddToken(&model.TokenInfo{
    Id:     0,
    Symbol: "ETH",
})  //配置eth, tokenid = 0
var appConfig = &conf.AppConfig{
    AccountId:        7,
    AccountAddress:   "0xBA2b5FEae299808b119FD410370D388B2fBF744b",
    AssetPrivateKey:       "1847400602630773084619040126809609832041801865548758092656011856772473440678",
    BaseUrl:          "https://v1-mainnet-backend.degate.com/",
    WebsocketBaseUrl: "wss://v1-mainnet-ws.degate.com/",
}
from degate.spot import Spot as Client
ETH = {
    "id": 0,
    "symbol": "ETH",
} # 配置 USDC, tokenid = 8
USDC = {
    "id": 2,
    "symbol": "USDC",
}  # 配置eth, tokenid = 0

AccountAddress = "0xba2b5feae299808b119fd410370d388b2fbf744b"
AssetPrivateKey =  "1847400602630773084619040126809609832041801865548758092656011856772473440678"
AccountId = 2475
client = Client(AccountAddress, AssetPrivateKey, AccountId, baseUrl="https://v1-mainnet-backend.degate.com/", tokens=[ETH,USDC])

参数: 由于DeGate为 Permissionless listing,可能出现多个名字一样的token,我们使用token ID来指代token,所以在使用SDK时需要先定义token 和token ID 才能继续使用。在测试环境与正式环境下,即使是相同的合约地址也可能会有不同的token ID。

名称 类型 是否必需 描述
Id INT YES 币种id 如何获取
Symbol STRING YES 币种symbol

config配置

正确设置以下参数从而与DeGate进行交互 参数:

名称 类型 是否必需 描述
BaseUrl STRING YES 接口的BaseUrl
正式网:https://v1-mainnet-backend.degate.com(默认)
测试网: https://v1-testnet-backend.degate.com/
WebsocketBaseUrl STRING NO wss接口的BaseUrl 调用推送接口时需要配置
正式网: wss://v1-mainnet-ws.degate.com(默认)
测试网: wss://v1-testnet-ws.degate.com
AccountId INT NO DeGate账户ID为用户钱包地址在DeGate注册后获取的唯一ID,每个AccountId均对应一个钱包地址。 如何获取
AccountAddress STRING NO 钱包地址
AssetPrivateKey STRING NO 用户DeGate账户的AssetPrivateKey 接口需要EdDSA签名时需要配置

POST NewOrder 的示例

这是一个调用SDK下单的示例(其中accountId,accountAddress,AssetPrivateKey仅供示范)

Example

import (
    "encoding/json"
    "github.com/degatedev/degate-sdk-golang/conf"
    "github.com/degatedev/degate-sdk-golang/degate/spot"
    "github.com/degatedev/degate-sdk-golang/log"
)
conf.Conf.AddToken(&model.TokenInfo{
    Symbol: "USDC",
    Id:     8,
})
conf.Conf.AddToken(&model.TokenInfo{
    Id:     0,
    Symbol: "ETH",
})
var appConfig = &conf.AppConfig{
    AccountId:      7,
    AccountAddress: "0xBA2b5FEae299808b119FD410370D388B2fBF744b",
    AssetPrivateKey:     <DeGate AssetPrivateKey>,
}
c := new(spot.Client)
c.SetAppConfig(appConfig)
c.NewOrder(&model.OrderParam{
    Symbol:   "ETHUSDC",
    Side:     "BUY",
    Quantity: 1,
    Price:    0.1,
    Type: LIMIT,
})
from degate.spot import Spot as Client
AccountAddress = "0xba2b5feae299808b119fd410370d388b2fbf744b"
AssetPrivateKey =  <DeGate AssetPrivateKey>
AccountId = 2475
ETH = {
    "id": 0,
    "symbol": "ETH",
}
USDC = {
    "id": 2,
    "symbol": "USDC",
}
client = Client(AccountAddress, AssetPrivateKey, AccountId,tokens=[ETH,USDC])
try:
    params = {
        "symbol": "ETHUSDC",
        "side": "SELL",
        "type": "LIMIT",
        "quantity": 0.1,
        "price": 3000,
    }
    response = client.newOrder(**params)
except Exception as e:
    logging.error(e)
参数 取值
Symbol ETHUSDC
Side BUY
Type LIMIT
Quantity 1
Price 0.1



高级

本文中大部分内容仅需正确配置并调用SDK即可完成,较少涉及到直接的接口访问。如果进行直接的接口访问,则会涉及接口鉴权以及签名相关内容。

接口鉴权类型

每个接口都有自己的鉴权类型,鉴权类型决定了访问时应当进行何种鉴权。

鉴权类型会在本文档中各个接口名称旁声明,如果没有特殊声明即默认为 NONE。

默认 AssetPrivateKey 可访问所有鉴权路径.

SIGNED Endpoint Security

调用SIGNED 接口时,除了接口本身所需的参数外,还需要在headerrequest body中传递 signature, 即签名参数。

签名使用波塞冬EdDSA算法。

签名 大小写不敏感.

公开参数

术语

这里的术语适用于全部文档,特别是新手建议熟读,以便于理解。

枚举定义

交易对状态 (状态 status):

交易对类型:

订单状态 (状态 status):

状态 描述
NEW 订单被交易引擎接受
PARTIALLY_FILLED 部分订单被成交
FILLED 订单完全成交
CANCELED 用户撤销了订单
EXPIRED 订单过期并且没有成交 被交易系统取消


订单类型 (orderTypes, type):

订单返回类型 (newOrderRespType):

订单方向 (方向 side):

K线间隔:

m -> 分钟; h -> 小时; d -> 天; w -> 周; M -> 月; y-> 年

限制种类 (rateLimitType)

REQUEST_WEIGHT

{
    "rateLimitType": "REQUEST_WEIGHT",
    "interval": "MINUTE",
    "intervalNum": 1,
    "limit": 2400
}

REQUEST_ORDER_WEIGHT

{
    "rateLimitType": "REQUEST_ORDER_WEIGHT",
    "interval": "MINUTE",
    "intervalNum": 1,
    "limit": 1200
}



限制间隔 (interval)



钱包接口

Gas Fee

Example

var appConfig = &conf.AppConfig{
    BaseUrl:          "https://v1-mainnet-backend.degate.com",
}
c := new(spot.Client)
c.SetAppConfig(appConfig)
response, err := c.GasFee()
client = Client()
try:
    logging.info(client.gasFee())
except Exception as e:
    logging.error(e)

响应

{
    "withdrawal_gas_fees": [{  //提现到自己的地址
        "symbol": "ETH",
        "token_id": 0,
        "quantity": "0.00185",
        "decimals": 18
    }, {
        "symbol": "USDC",
        "token_id": 2,
        "quantity": "3.36",
        "decimals": 18
    }, {
        "symbol": "USDT",
        "token_id": 9,
        "quantity": "3.36",
        "decimals": 18
    }],
    "withdrawal_other_gas_fees": [{ //提现到其他地址
        "symbol": "ETH",
        "token_id": 0,
        "quantity": "0.00185",
        "decimals": 18
    }, {
        "symbol": "USDC",
        "token_id": 2,
        "quantity": "3.36",
        "decimals": 18
    }, {
        "symbol": "USDT",
        "token_id": 9,
        "quantity": "3.36",
        "decimals": 18
    }],
    "transfer_gas_fees": [{     //转账给已经开户的地址
        "symbol": "ETH",
        "token_id": 0,
        "quantity": "0.0000704",
        "decimals": 18
    }, {
        "symbol": "USDC",
        "token_id": 2,
        "quantity": "0.128",
        "decimals": 18
    }, {
        "symbol": "USDT",
        "token_id": 9,
        "quantity": "0.128",
        "decimals": 18
    }],
    "transfer_no_id_gas_fees": [{ //转帐给未开户的地址
        "symbol": "ETH",
        "token_id": 0,
        "quantity": "0.000709",
        "decimals": 18
    }, {
        "symbol": "USDC",
        "token_id": 2,
        "quantity": "1.29",
        "decimals": 18
    }, {
        "symbol": "USDT",
        "token_id": 9,
        "quantity": "1.29",
        "decimals": 18
    }],
    "on_chain_cancel_order_gas_fees": [{ //链上取消订单
        "symbol": "ETH",
        "token_id": 0,
        "quantity": "0.0000757",
        "decimals": 18
    }, {
        "symbol": "USDC",
        "token_id": 2,
        "quantity": "0.138",
        "decimals": 18
    }, {
        "symbol": "USDT",
        "token_id": 9,
        "quantity": "0.138",
        "decimals": 18
    }],
}

查看提现、转账、链上取消订单所需 gas fee,每个操作均会返回多币种的所需Gas,用户可以自行选择GasFee的支付币种

调用方法: GasFee

权重(IP): 1

参数: None

提币

Example

conf.Conf.AddToken(&model.TokenInfo{
    Id:       0,
    Symbol:   "ETH",
    Decimals: 18,
})
var appConfig = &conf.AppConfig{
    AccountId:        7,
    AccountAddress:   "0xBA2b5FEae299808b119FD410370D388B2fBF744b",
    AssetPrivateKey:       <DeGate AssetPrivateKey>,
}
client := new(spot.Client)
client.SetAppConfig(appConfig)
response, err := client.Withdraw(&model.WithdrawParam{
    Address:    "0xBA2b5FEae299808b119FD410370D388B2fBF744b",
    Coin:       "ETH",
    Amount:     0.001,
    PrivateKey: <Wallet Private Key>,
})
AccountAddress = "0xba2b5feae299808b119fd410370d388b2fbf744b"
AssetPrivateKey =  <DeGate AssetPrivateKey>
AccountId = 2475
ETH = {
    "id": 0,
    "symbol": "ETH",
}

client = Client(AccountAddress, AssetPrivateKey, AccountId,tokens=[ETH])

try:
    response = client.withdraw(coin="ETH", amount=0.0001, address="0xba2b5feae299808b119fd410370d388b2fbf744b",privateKey=<Wallet Private Key>)
    logging.info(response)
except Exception as e:
    logging.error(e)

响应

{
    "id":"7213fea8e94b4a5593d507237e5a555b"
}

调用方法: Withdraw

权重(IP): 10

参数:

名称 类型 是否必需 描述
Coin STRING YES 币种Symbol
Address STRING YES 提币地址
Amount DECIMAL YES 数量
PrivateKey STRING YES 以太坊钱包私钥(非Asset Private Key)
ValidUntil LONG NO 有效期 默认30天
Fee STRING NO 支付的gas fee token 默认ETH 查看

转账

Example

conf.Conf.AddToken(&model.TokenInfo{
    Id:       0,
    Symbol:   "ETH",
    Decimals: 18,
})
var appConfig = &conf.AppConfig{
    AccountId:        7,
    AccountAddress:   "0xBA2b5FEae299808b119FD410370D388B2fBF744b",
    AssetPrivateKey:       <DeGate AssetPrivateKey>,
}
client := new(spot.Client)
client.SetAppConfig(appConfig)
response, err := client.Transfer(&model.TransferParam{
    PrivateKey: <Wallet Private Key>,
    Address:    "0x6C6697C44b71A769482a701b3539C97952E424ef",
    Asset:      "ETH",
    Amount:     1.123456,
})
AccountAddress = "0xba2b5feae299808b119fd410370d388b2fbf744b"
AssetPrivateKey =  <DeGate AssetPrivateKey>
AccountId = 2475
ETH = {
    "id": 0,
    "symbol": "ETH",
}

client = Client(AccountAddress, AssetPrivateKey, AccountId,tokens=[ETH])

try:
    response = client.transfer(asset="ETH", amount=0.0001, address="0x5ddc2c634954e7e1133aeff98e6c7e7b034e00d4", privateKey=<Wallet Private Key>)
    logging.info(response)
except Exception as e:
    logging.error(e)

响应

{
    "tranId":"7213fea8e94b4a5593d507237e5a555b"
}

调用方法: Transfer

权重(IP): 10

参数:

名称 类型 是否必需 描述
Asset STRING YES 币种Symbol
Address STRING YES 转账地址
Amount DECIMAL YES 数量
PrivateKey STRING YES 以太坊钱包私钥(非Asset Private Key)
ValidUntil LONG NO 有效期 默认30天
Fee STRING NO 支付的gas fee token 默认ETH 查看

获取充值历史

Example

conf.Conf.AddToken(&model.TokenInfo{
    Id:       0,
    Symbol:   "ETH",
    Decimals: 18,
})
var appConfig = &conf.AppConfig{
    AccountId:        7,
    AccountAddress:   "0xBA2b5FEae299808b119FD410370D388B2fBF744b",
    AssetPrivateKey:       <DeGate AssetPrivateKey>,
}
client := new(spot.Client)
client.SetAppConfig(appConfig)
response, err := client.DepositHistory(&model.DepositsParam{
    Coin: "ETH",
    Limit: 20,
})
AccountAddress = "0xba2b5feae299808b119fd410370d388b2fbf744b"
AssetPrivateKey =  <DeGate AssetPrivateKey>
AccountId = 2475

client = Client(AccountAddress,AssetPrivateKey,AccountId)

try:
    param = {"limit":10}
    logging.info(client.depositHistory(**param))
except Exception as e:
    logging.error(e)

响应

[
    {
        "amount":"0.00999800",
        "coin":"ETH",
        "network":"ETH",
        "status":1,
        "address":"0x788cabe9236ce061e5a892e1a59395a81fc8d62c",
        "txId":"0xaad4654a3234aa6118af9b4b335f5ae81c360b2394721c019b5d1e75328b09f3",
        "insertTime":1599621997000,
        "transferType":0,
        "confirmTimes":"12/12"
    }
]

调用方法: DepositHistory

权重(IP): 1

参数:

名称 类型 是否必需 描述
Coin STRING NO 币种Symbol
Status INT NO 1:完成并上链 2:成功但未上链 3:充值失败 4:取消 6:正在处理
StartTime LONG NO
EndTime LONG NO
Offset INT NO 默认: 0
Limit INT NO 默认: 1000,最大: 1000
TxId STRING NO

获取提币历史

Example

conf.Conf.AddToken(&model.TokenInfo{
    Id:       0,
    Symbol:   "ETH",
    Decimals: 18,
})
var appConfig = &conf.AppConfig{
    AccountId:        7,
    AccountAddress:   "0xBA2b5FEae299808b119FD410370D388B2fBF744b",
    AssetPrivateKey:       <DeGate AssetPrivateKey>,
}
client := new(spot.Client)
client.SetAppConfig(appConfig)
response, err := client.WithdrawHistory(&model.WithdrawsParam{
    Coin: "ETH",
})
AccountAddress = "0xba2b5feae299808b119fd410370d388b2fbf744b"
AssetPrivateKey =  <DeGate AssetPrivateKey>
AccountId = 2475

client = Client(AccountAddress,AssetPrivateKey,AccountId)

try:
    logging.info(client.withdrawHistory())
except Exception as e:
    logging.error(e)

响应

[
    {
        "address": "0x94df8b352de7f46f64b01d3666bf6e936e44ce60",
        "amount": "8.91000000",   // 提现转出金额
        "applyTime": "2019-10-12 11:12:02",  // UTC 时间
        "coin": "USDT",
        "id": "b6ae22b3aa844210a7041aee7589627c",  // 该笔提现在币安的id
        "network": "ETH",
        "transferType": 0 // 1: 站内转账, 0: 站外转账    
        "status": 4,
        "transactionFee": "0.004", // 手续费
        "info": "The address is not valid. Please confirm with the recipient",  // 提币失败原因
        "txId": "0xb5ef8c13b968a406cc62a93a8bd80f9e9a906ef1b3fcf20a2e48573c17659268"   // 提现交易id
    }
]

调用方法: WithdrawHistory

权重(IP): 1

参数:

名称 类型 是否必需 描述
Coin STRING NO 币种Symbol
Status INT NO 4:处理中 5:失败 6:提现完成
StartTime LONG NO
EndTime LONG NO
Offset INT NO 默认: 0
Limit INT NO 默认: 1000,最大: 1000

获取转账历史

Example

conf.Conf.AddToken(&model.TokenInfo{
    Id:       0,
    Symbol:   "ETH",
    Decimals: 18,
})
conf.Conf.AddToken(&model.TokenInfo{
    Id:       8,
    Symbol:   "USDC",
    Decimals: 18,
})
var appConfig = &conf.AppConfig{
    AccountId:        7,
    AccountAddress:   "0xBA2b5FEae299808b119FD410370D388B2fBF744b",
    AssetPrivateKey:       <DeGate AssetPrivateKey>,
}
client := new(spot.Client)
client.SetAppConfig(appConfig)
response, err := client.TransferHistory(&model.TransfersParam{
    Coin: "ETH,USDC",
})
AccountAddress = "0xba2b5feae299808b119fd410370d388b2fbf744b"
AssetPrivateKey =  <DeGate AssetPrivateKey>
AccountId = 2475

client = Client(AccountAddress,AssetPrivateKey,AccountId)

try:
    logging.info(client.transferHistory())
except Exception as e:
    logging.error(e)

响应:

{
    "rows":[
        {
            "asset":"ETH",
            "amount":"1",
            "status": "CONFIRMED",
            "tranId": 11415955596,
            "timestamp":1544433328000,
            "fromAccount": "",
            "toAccount": "",        
        },
        {
            "asset":"USDC",
            "amount":"2",
            "status": "CONFIRMED",
            "tranId": 11366865406,
            "timestamp":1544433328000,
            "fromAccount": "",
            "toAccount": "", 
        }
    ]
}

调用方法: TransferHistory

权重(IP): 1

参数:

名称 类型 是否必需 描述
Coin STRING NO 币种Symbol
StartTime LONG NO
EndTime LONG NO
Offset INT NO 默认: 0
Limit INT NO 默认: 1000,最大: 1000

资产余额

Example

conf.Conf.AddToken(&model.TokenInfo{
    Id:       0,
    Symbol:   "ETH",
    Decimals: 18,
})
conf.Conf.AddToken(&model.TokenInfo{
    Id:       8,
    Symbol:   "USDC",
    Decimals: 18,
})
var appConfig = &conf.AppConfig{
    AccountId:        7,
    AccountAddress:   "0xBA2b5FEae299808b119FD410370D388B2fBF744b",
    AssetPrivateKey:       <DeGate AssetPrivateKey>,
}
client := new(spot.Client)
client.SetAppConfig(appConfig)
response, err := client.GetBalance(&model.AccountBalanceParam{
    Asset: "ETH,USDC",
})
AccountAddress = "0xba2b5feae299808b119fd410370d388b2fbf744b"
AssetPrivateKey =  <DeGate AssetPrivateKey>
AccountId = 2475

client = Client(AccountAddress,AssetPrivateKey,AccountId)

try:
    logging.info(client.getBalance())
except Exception as e:
    logging.error(e)

响应

[
    {
        "asset": "ETH",
        "free": "1",    // 可用余额
        "locked": "0",  // 锁定资金
        "freeze": "0",  //冻结资金
        "withdrawing": "0",  // 正在提币中的数量
    },
    {
        "asset": "USDC",
        "free": "1",    // 可用余额
        "locked": "0",  // 锁定资金
        "freeze": "0",  //冻结资金
        "withdrawing": "0",  // 正在提币中的数量
    }
]

调用方法: GetBalance

权重(IP): 5

参数:

名称 类型 是否必需 描述
Asset STRING NO 币种Symbol,不传返回所有有余额的资产

行情接口

测试服务器连通性

Example

var appConfig = &conf.AppConfig{
    BaseUrl:          "https://v1-mainnet-backend.degate.com",
}
client := new(spot.Client)
client.SetAppConfig(appConfig)
response, err := client.Ping()
client = Client()

try:
    logging.info(client.ping())
except Exception as e:
    logging.error(e)

响应

{}

调用方法: Ping

权重(IP): 1

参数: None

数据源: 缓存

获取服务器时间

Example

var appConfig = &conf.AppConfig{
    BaseUrl:  "https://v1-mainnet-backend.degate.com",
}
c := new(spot.Client)
c.SetAppConfig(appConfig)
response, err := c.Time()
client = Client()

try:
    logging.info(client.time())
except Exception as e:
    logging.error(e)

响应

{
  "serverTime": 1499827319559
}

测试能否联通 Rest API 并 获取服务器时间

调用方法: Time

权重(IP): 1

参数: None

数据源: 缓存

交易规范信息

Example

var appConfig = &conf.AppConfig{
    BaseUrl:          "https://v1-mainnet-backend.degate.com",
}
c := new(spot.Client)
c.SetAppConfig(appConfig)
response, err := c.ExchangeInfo()
client = Client()
try:
    logging.info(client.exchangeInfo())
except Exception as e:
    logging.error(e)

响应

{
  "chain_id":4,
  "minLimitOrderUSDValue":100,
  "timezone":"UTC",
  "serverTime":1649239409289,
  "rateLimits": [
        {
            //这些在"限制种类 (rateLimitType)"下的"枚举定义"部分中定义
            //所有限制都是可选的
        }
  ],
}

获取交易规则信息。

调用方法: ExchangeInfo

权重(IP): 1

参数: None

数据源: 缓存

深度信息

Example

conf.Conf.AddToken(&model.TokenInfo{
  Id:     8,
  Symbol: "USDC",
})
conf.Conf.AddToken(&model.TokenInfo{
  Id:     0,
  Symbol: "ETH",
})
var appConfig = &conf.AppConfig{
    BaseUrl:          "https://v1-mainnet-backend.degate.com",
}
client := new(spot.Client)
client.SetAppConfig(appConfig)
response, err := client.Depth(&model.DepthParam{
  Symbol: "ETHUSDC",
})
ETH = {
    "id": 0,
    "symbol": "ETH",
}
USDC = {
    "id": 2,
    "symbol": "USDC",
}

client = Client(tokens=[ETH,USDC])

try:
    logging.info(client.depth("ETHUSDC", limit=10))
except Exception as e:
    logging.error(e)

响应

{
  "lastUpdateId": 1027024,
  "bids": [
    [
      "4.00000000",     // 价位
      "431.00000000"    // 挂单量
    ]
  ],
  "asks": [
    [
      "4.00000200",
      "12.00000000"
    ]
  ]
}

调用方法: Depth

权重(IP): 5

参数:

名称 类型 是否必需 描述
Symbol STRING YES
Limit INT NO 默认 100(ask 100 bid 100),最大5000;
如果 limit > 5000, 最多返回5000条数据.

近期成交列表

Example

conf.Conf.AddToken(&model.TokenInfo{
  Id:     8,
  Symbol: "USDC",
})
conf.Conf.AddToken(&model.TokenInfo{
  Id:     0,
  Symbol: "ETH",
})
var appConfig = &conf.AppConfig{
    BaseUrl:          "https://v1-mainnet-backend.degate.com",
}
client := new(spot.Client)
client.SetAppConfig(appConfig)
response, err := client.Trades(&model.TradeLastedParam{
  Symbol: "ETHUSDC",
  Limit:  0,
})
ETH = {
    "id": 0,
    "symbol": "ETH",
}
USDC = {
    "id": 2,
    "symbol": "USDC",
}

client = Client(tokens=[ETH,USDC])

try:
    logging.info(client.trades("ETHUSDC", limit=20))
except Exception as e:
    logging.error(e)

响应

[
  {
    "id": "28457",
    "price": "4.00000100",
    "qty": "12.00000000",
    "time": 1499865549590, // 交易成交时间, 和websocket中的T一致.
    "isBuyerMaker": true,
  }
]

调用方法: Trades

权重(IP): 10

参数:

名称 类型 是否必需 描述
Symbol STRING YES
Limit INT NO 默认 500; 最大值 1000.

数据源: 数据库

查询历史成交

Example

conf.Conf.AddToken(&model.TokenInfo{
  Id:     8,
  Symbol: "USDC",
})
conf.Conf.AddToken(&model.TokenInfo{
  Id:     0,
  Symbol: "ETH",
})
var appConfig = &conf.AppConfig{
    BaseUrl:          "https://v1-mainnet-backend.degate.com",
}
client := new(spot.Client)
client.SetAppConfig(appConfig)
response, err := client.TradesHistory(&model.TradeHistoryParam{
  Symbol: "ETHUSDC",
  Limit:  20,
})
ETH = {
    "id": 0,
    "symbol": "ETH",
}
USDC = {
    "id": 2,
    "symbol": "USDC",
}

client = Client(tokens=[ETH,USDC])

try:
    logging.info(client.tradesHistory("ETHUSDC", limit=20))
except Exception as e:
    logging.error(e)

响应

[
  {
    "id": "28457",
    "price": "4.00000100",
    "qty": "12.00000000",
    "quoteQty": "48.000012",
    "time": 1499865549590,
    "isBuyerMaker": true,
  }
]

调用方法: TradesHistory

权重(IP): 10

参数:

名称 类型 是否必需 描述
Symbol STRING YES
Limit INT NO 默认 500; 最大值 1000.
FromId STRING NO 开始返回的成交记录id. 缺省返回最近的成交记录。

数据源: 数据库

K线数据

Example

conf.Conf.AddToken(&model.TokenInfo{
  Id:     8,
  Symbol: "USDC",
})
conf.Conf.AddToken(&model.TokenInfo{
  Id:     0,
  Symbol: "ETH",
})
var appConfig = &conf.AppConfig{
    BaseUrl:          "https://v1-mainnet-backend.degate.com",
}
client := new(spot.Client)
client.SetAppConfig(appConfig)
response, err := client.Klines(&model.KlineParam{
  Symbol: "ETHUSDC",
  Limit:  20,
})
ETH = {
    "id": 0,
    "symbol": "ETH",
}
USDC = {
    "id": 2,
    "symbol": "USDC",
}

client = Client(tokens=[ETH,USDC])

try:
    logging.info(client.klines("ETHUSDC", "1m", limit=10))
except Exception as e:
    logging.error(e)

响应

[
  [
    1499040000000,      // 开盘时间
    "0.01634790",       // 开盘价
    "0.80000000",       // 最高价
    "0.01575800",       // 最低价
    "0.01577100",       // 收盘价(当前K线未结束的即为最新价)
    "148976.11427815",  // 成交量
    1499644799999,      // 收盘时间
    "2434.19055334",    // 成交额
    308,                // 成交笔数
    "1756.87402397",    // 主动买入成交量
    "28.46694368",      // 主动买入成交额
    "17928899.62484339" // 请忽略该参数
  ]
]

一个交易对一根K线,每根K线的开盘时间可视为唯一ID。

调用方法: Klines

权重(IP): 1

参数:

名称 类型 是否必需 描述
Symbol STRING YES
Interval ENUM YES 详见枚举定义:K线间隔
StartTime LONG NO
EndTime LONG NO
Limit INT NO 默认 500; 最大 1000.

数据源: 缓存

24hr 价格变动情况

Example

conf.Conf.AddToken(&model.TokenInfo{
  Id:     8,
  Symbol: "USDC",
})
conf.Conf.AddToken(&model.TokenInfo{
  Id:     0,
  Symbol: "ETH",
})
var appConfig = &conf.AppConfig{
    BaseUrl:          "https://v1-mainnet-backend.degate.com",
}
client := new(spot.Client)
client.SetAppConfig(appConfig)
response, err := client.Ticker24(&model.TickerParam{
  Symbol: "ETHUSDC",
})
ETH = {
    "id": 0,
    "symbol": "ETH",
}
USDC = {
    "id": 2,
    "symbol": "USDC",
}

client = Client(tokens=[ETH,USDC])

try:
    logging.info(client.ticker24("ETHUSDC"))
except Exception as e:
    logging.error(e)

响应

{
  "symbol": "ETHUSDC",
  "priceChange": "-94.99999800",
  "priceChangePercent": "-95.960",
  "weightedAvgPrice": "0.29628482",
  "prevClosePrice": "0.10002000",
  "lastPrice": "4.00000200",
  "lastQty": "200.00000000",
  "bidPrice": "4.00000000",
  "bidQty": "100.00000000",
  "askPrice": "4.00000200",
  "askQty": "100.00000000",
  "openPrice": "99.00000000",
  "highPrice": "100.00000000",
  "lowPrice": "0.10000000",
  "volume": "8913.30000000",
  "quoteVolume": "15.30000000",
  "openTime": 1499783499040,
  "closeTime": 1499869899040,
  "firstId": 28385,   // 首笔成交id
  "lastId": 28460,    // 末笔成交id
  "count": 76,         // 成交笔数
  "makerFee": "0",
  "takerFee": "1.0",
  "pairId": 1
}

24 小时滚动窗口价格变动数据

调用方法: Ticker24

权重(IP): 5

参数:

名称 类型 是否必需 描述
Symbol STRING YES

数据源: 缓存

最新价格

Example

conf.Conf.AddToken(&model.TokenInfo{
  Id:     8,
  Symbol: "USDC",
})
conf.Conf.AddToken(&model.TokenInfo{
  Id:     0,
  Symbol: "ETH",
})
conf.Conf.AddToken(&model.TokenInfo{
  Id:     9,
  Symbol: "USDT",
})
var appConfig = &conf.AppConfig{
    BaseUrl:          "https://v1-mainnet-backend.degate.com",
}
client := new(spot.Client)
client.SetAppConfig(appConfig)
response, err := client.TickerPrice(&model.PairPriceParam{
  Symbol: "ETHUSDC,ETHUSDT",
})
ETH = {
    "id": 0,
    "symbol": "ETH",
}
USDC = {
    "id": 2,
    "symbol": "USDC",
}
USDT = {
    "id": 9,
    "symbol": "USDT",
}

spot_client = Client(tokens=[ETH,USDC,USDT])

try:
    logging.info(spot_client.tickerPrice("ETHUSDC,ETHUSDT"))
except Exception as e:
    logging.error(e)

响应

[
  {
    "symbol": "ETHUSDC",
    "price": "4.00000200",
    "pairId": 1,
  },
  {
    "symbol": "ETHUSDT",
    "price": "4.00000200",
    "pairId": 2,
  }
]

获取交易对最新价格

调用方法: TickerPrice

权重(IP): 1

参数:

名称 类型 是否必需 描述
Symbol STRING YES 使用’,‘分隔

数据源: 缓存

当前最优挂单

Example

conf.Conf.AddToken(&model.TokenInfo{
  Id:     8,
  Symbol: "USDC",
})
conf.Conf.AddToken(&model.TokenInfo{
  Id:     0,
  Symbol: "ETH",
})
var appConfig = &conf.AppConfig{
    BaseUrl:          "https://v1-mainnet-backend.degate.com",
}
client := new(spot.Client)
client.SetAppConfig(appConfig)
response, err := client.BookTicker(&model.BookTickerParam{
  Symbol: "ETHUSDC",
})
ETH = {
    "id": 0,
    "symbol": "ETH",
}
USDC = {
    "id": 2,
    "symbol": "USDC",
}

client = Client(tokens=[ETH,USDC])

try:
    logging.info(client.bookTicker("ETHUSDC"))
except Exception as e:
    logging.error(e)

响应

{
  "symbol": "ETHUSDC",
  "bidPrice": "4.00000000",
  "bidQty": "431.00000000",
  "askPrice": "4.00000200",
  "askQty": "9.00000000"
}

返回当前最优的挂单(最高买单,最低卖单)

调用方法: BookTicker

权重(IP): 1

参数:

名称 类型 是否必需 描述
Symbol STRING YES

数据源: 缓存

现货和交易接口

查询Token

Example

var appConfig = &conf.AppConfig{
    BaseUrl:          "https://v1-mainnet-backend.degate.com",
}
c := new(spot.Client)
c.SetAppConfig(appConfig)
response, err := c.TokenList(&model.TokenListParam{
  Symbols: "eth,usdc",
})
client = Client()

try:
    logging.info(client.tokenList("ETH,USDC"))
except Exception as e:
    logging.error(e)

响应

[
  {
    "id": 0,         // token id
    "symbol": "ETH",
    "code": "",      // token合约地址
    "decimals":18,   
  },
  {
    "id": 2,         // token id
    "symbol": "USDC",
    "code": "0x953873a4e0b57179d88a9275cfb5243d3e631f1b", // token合约地址
    "decimals":18,   
  }
]

调用方法: TokenList

权重(IP): 1

参数:

名称 类型 是否必需 描述
Symbols STRING YES 使用','分割

下单

Example

conf.Conf.AddToken(&model.TokenInfo{
  Symbol: "ETH",
  Id:     0,
})
conf.Conf.AddToken(&model.TokenInfo{
  Symbol: "USDC",
  Id:     8,
})
var appConfig = &conf.AppConfig{
    AccountId:        7,
    AccountAddress:   "0xBA2b5FEae299808b119FD410370D388B2fBF744b",
    AssetPrivateKey:       <DeGate AssetPrivateKey>,
}
c := new(spot.Client)
c.SetAppConfig(appConfig)
response, err := c.NewOrder(&model.OrderParam{
  Symbol:   "ETHUSDC",
  Side:     "sell",
  Quantity: 1,
  Price:    5000,
  Type:     "LIMIT",
})
AccountAddress = "0xba2b5feae299808b119fd410370d388b2fbf744b"
AssetPrivateKey =  <DeGate AssetPrivateKey>
AccountId = 2475
ETH = {
    "id": 0,
    "symbol": "ETH",
}
USDC = {
    "id": 2,
    "symbol": "USDC",
}

client = Client(AccountAddress, AssetPrivateKey, AccountId,tokens=[ETH,USDC])

try:
    params = {
        "symbol": "ETHUSDC",
        "side": "SELL",
        "type": "LIMIT",
        "quantity": 0.1,
        "price": 3000,
    }
    response = client.newOrder(**params)
    logging.info(response)
except Exception as e:
    logging.error(e)

try:
    params = {
        "symbol": "ETHUSDC",
        "side": "SELL",
        "type": "MARKET",
        "quantity": 0.1,
    }
    response = client.newOrder(**params)
    logging.info(response)
except Exception as e:
    logging.error(e)

Response ACK:

{
  "symbol": "ETHUSDC",
  "orderId": "28",
  "clientOrderId": "6gCrw2kRUAF9CvJDGP16IP",
  "transactTime": 1507725176595
}

Response RESULT:

{
  "symbol": "ETHUSDC",
  "orderId": "28",
  "clientOrderId": "6gCrw2kRUAF9CvJDGP16IP",
  "transactTime": 1507725176595,
  "price": "1.00000000",
  "origQty": "10.00000000",
  "executedQty": "10.00000000",
  "cummulativeQuoteQty": "10.00000000",
  "status": "FILLED",
  "timeInForce": "GTC",
  "type": "MARKET",
  "side": "SELL"
}

Response FULL:

{
  "symbol": "ETHUSDC",
  "orderId": "28",
  "clientOrderId": "6gCrw2kRUAF9CvJDGP16IP",
  "transactTime": 1507725176595,
  "price": "1.00000000",
  "origQty": "10.00000000",
  "executedQty": "10.00000000",
  "cummulativeQuoteQty": "10.00000000",
  "status": "FILLED",
  "timeInForce": "GTC",
  "type": "MARKET",
  "side": "SELL",
  "fills": [
    {
      "price": "4000.00000000",
      "qty": "1.00000000",
      "commission": "4.00000000",
      "commissionAsset": "USDT",
      "tradeId": 56
    },
    {
      "price": "3999.00000000",
      "qty": "5.00000000",
      "commission": "19.99500000",
      "commissionAsset": "USDT",
      "tradeId": 57
    }
  ]
}

调用方法: NewOrder

权重(IP): 10

参数:

名称 类型 是否必需 描述
Symbol STRING YES
Side ENUM YES 详见枚举定义:订单方向
Type ENUM YES 详见枚举定义:订单种类
Quantity DECIMAL NO 下单数量,最大有效数字6位,示范:0.123456,1.23456,123456
QuoteOrderQty DECIMAL NO 下单金额,最大有效数字6位,Quantity和QuoteOrderQty两者都传时,以Quantity为准。
Price DECIMAL NO 下单价格,普通交易对默认最大有效数字5位,当整数部分>=5时,最大有效数字6位;稳定币交易对默认最大有效数字4位,当数字>1时,最大有效数字5位。正确:0.12345,12345.6,错误:0.123456,1.23456
NewClientOrderId STRING NO 用户自定义的orderid,如空缺系统会自动赋
NewOrderRespType ENUM NO 指定响应类型 ACK, RESULT, or FULL; MARKETLIMIT 订单默认为FULL, 其他默认为ACK.
ValidUntil LONG NO 订单有效期,默认为60天。超过有效期后,挂单剩余未成交的部分会自动取消。如果用户没有发起链上撤单,则订单签名将永久有效,设置订单有效期可起到防止节点作恶(如恢复挂单)的作用。

根据 order type的不同,某些参数强制要求,具体如下:

类型 强制要求的参数
LIMIT quantity, price
MARKET quantity

其他信息:

关于 newOrderRespType的三种选择

数据源: 交易系统

撤销订单

Example

var appConfig = &conf.AppConfig{
    AccountId:        7,
    AccountAddress:   "0xBA2b5FEae299808b119FD410370D388B2fBF744b",
    AssetPrivateKey:       <DeGate AssetPrivateKey>,
}
c := new(spot.Client)
c.SetAppConfig(appConfig)
response, err := c.CancelOrder(&model.CancelOrderParam{
  OrderId: "188759499725809833483796742269",
})
AccountAddress = "0xba2b5feae299808b119fd410370d388b2fbf744b"
AssetPrivateKey =  <DeGate AssetPrivateKey>
AccountId = 2475

client = Client(AccountAddress, AssetPrivateKey, AccountId)

try:
    response = client.cancelOrder(orderId="196120192698583504448505788760278")
    logging.info(response)
except Exception as e:
    logging.error(e)

响应

{
  "symbol": "ETHUSDC",
  "origClientOrderId": "myOrder1",
  "orderId": "4",
  "price": "2.00000000",
  "origQty": "1.00000000",
  "executedQty": "0.00000000",
  "cummulativeQuoteQty": "0.00000000",
  "status": "CANCELED",
  "timeInForce": "GTC",
  "type": "LIMIT",
  "side": "BUY"
}

调用方法: CancelOrder

权重(IP): 10

参数:

名称 类型 是否必需 描述
OrderId STRING NO
OrigClientOrderId STRING NO 用户自定义的orderid

orderIdorigClientOrderId 必须至少发送一个

撤销所有挂单

Example

var appConfig = &conf.AppConfig{
    AccountId:        7,
    AccountAddress:   "0xBA2b5FEae299808b119FD410370D388B2fBF744b",
    AssetPrivateKey:       <DeGate AssetPrivateKey>,
}
c := new(spot.Client)
c.SetAppConfig(appConfig)
response, err := c.CancelOpenOrders(false)
AccountAddress = "0xba2b5feae299808b119fd410370d388b2fbf744b"
AssetPrivateKey =  <DeGate AssetPrivateKey>
AccountId = 2475

client = Client(AccountAddress, AssetPrivateKey, AccountId)

try:
    response = client.cancelOpenOrders()
    logging.info(response)
except Exception as e:
    logging.error(e)

Response

{}

撤销所有挂单, 网格订单可选。

调用方法: CancelOpenOrders

权重(IP): 1

名称 类型 是否必需 描述
IncludeGrid Bool NO 是否包含网格订单 默认:false

数据源: 交易系统

链上撤销订单

Example

var appConfig = &conf.AppConfig{
    AccountId:        7,
    AccountAddress:   "0xBA2b5FEae299808b119FD410370D388B2fBF744b",
    AssetPrivateKey:       <DeGate AssetPrivateKey>,
}
c := new(spot.Client)
c.SetAppConfig(appConfig)
response, err := c.CancelOrderOnChain(&model.CancelOrderParam{
  OrderId: "188820328196434284078497267922",
})
AccountAddress = "0xba2b5feae299808b119fd410370d388b2fbf744b"
AssetPrivateKey =  <DeGate AssetPrivateKey>
AccountId = 2475

client = Client(AccountAddress, AssetPrivateKey, AccountId)

try:
    response = client.cancelOrderOnChain(orderId="196120192698583504448505788760278")
    logging.info(response)
except Exception as e:
    logging.error(e)

Response

{}

链上取消订单,订单在orderBook中必须已经取消。

调用方法: CancelOrderOnChain

权重(IP): 10

参数:

名称 类型 是否必需 描述
OrderId STRING NO
OrigClientOrderId STRING NO

orderIdorigClientOrderId 必须至少发送一个

查询订单

Example

var appConfig = &conf.AppConfig{
    AccountId:        7,
    AccountAddress:   "0xBA2b5FEae299808b119FD410370D388B2fBF744b",
    AssetPrivateKey:       <DeGate AssetPrivateKey>,
}
c := new(spot.Client)
c.SetAppConfig(appConfig)
_, response, err := c.GetOrder(&model.OrderDetailParam{
  OrderId: "1297850191237108107827054903296",
})
AccountAddress = "0xba2b5feae299808b119fd410370d388b2fbf744b"
AssetPrivateKey =  <DeGate AssetPrivateKey>
AccountId = 2475

client = Client(AccountAddress, AssetPrivateKey, AccountId)

try:
    response = client.getOrder(orderId="196120192698583504448505788760278")
    logging.info(response)
except Exception as e:
    logging.error(e)

响应

{
  "symbol": "ETHUSDC", // 交易对
  "orderId": "1", // 系统的订单ID
  "clientOrderId": "myOrder1", // 客户自己设置的ID
  "price": "0.1", // 订单价格
  "origQty": "1.0", // 用户设置的原始订单数量
  "executedQty": "0.0", // 交易的订单数量
  "cummulativeQuoteQty": "0.0", // 累计交易的金额
  "status": "NEW", // 订单状态
  "timeInForce": "GTC",
  "type": "LIMIT", // 订单类型, 比如市价单,现价单等
  "side": "BUY", // 订单方向,买还是卖
  "time": 1499827319559, // 订单时间
  "updateTime": 1499827319559, // 最后更新时间
  "isWorking": true, // 订单是否出现在orderbook中
  "origQuoteOrderQty": "0.000000" // 原始的交易金额
}

调用方法: GetOrder

权重(IP): 5

参数:

名称 类型 是否必需 描述
OrderId STRING NO
OrigClientOrderId STRING NO

orderIdorigClientOrderId 必须至少发送一个

当前挂单

Example

conf.Conf.AddToken(&model.TokenInfo{
  Symbol: "ETH",
  Id:     0,
})
conf.Conf.AddToken(&model.TokenInfo{
  Symbol: "USDC",
  Id:     8,
})
var appConfig = &conf.AppConfig{
    AccountId:        7,
    AccountAddress:   "0xBA2b5FEae299808b119FD410370D388B2fBF744b",
    AssetPrivateKey:       <DeGate AssetPrivateKey>,
}
c := new(spot.Client)
c.SetAppConfig(appConfig)
response, err := c.GetOpenOrders(&model.OrdersParam{
  Symbol: "ETHUSDC",
})
AccountAddress = "0xba2b5feae299808b119fd410370d388b2fbf744b"
AssetPrivateKey =  <DeGate AssetPrivateKey>
AccountId = 2475
ETH = {
    "id": 0,
    "symbol": "ETH",
}
USDC = {
    "id": 2,
    "symbol": "USDC",
}

client = Client(AccountAddress, AssetPrivateKey, AccountId,tokens=[ETH,USDC])

try:
    response = client.getOpenOrders("ETHUSDC")
    logging.info(response)
except Exception as e:
    logging.error(e)

响应

[
  {
    "symbol": "ETHUSDC",
    "orderId": "1",
    "clientOrderId": "myOrder1",
    "price": "0.1",
    "origQty": "1.0",
    "executedQty": "0.0",
    "cummulativeQuoteQty": "0.0",
    "status": "NEW",
    "timeInForce": "GTC",
    "type": "LIMIT",
    "side": "BUY",
    "time": 1499827319559,
    "updateTime": 1499827319559,
    "isWorking": true,
    "origQuoteOrderQty": "0.000000"
  }
]

获取交易对的所有当前挂单,请小心使用不带交易对参数的调用。

调用方法: GetOpenOrders

权重(IP): 10

参数:

名称 类型 是否必需 描述
Symbol STRING NO

数据源:数据库

查询历史订单

Example

conf.Conf.AddToken(&model.TokenInfo{
  Symbol: "ETH",
  Id:     0,
})
conf.Conf.AddToken(&model.TokenInfo{
  Symbol: "USDC",
  Id:     8,
})
var appConfig = &conf.AppConfig{
    AccountId:        7,
    AccountAddress:   "0xBA2b5FEae299808b119FD410370D388B2fBF744b",
    AssetPrivateKey:       <DeGate AssetPrivateKey>,
}
c := new(spot.Client)
c.SetAppConfig(appConfig)
response, err := c.GetHistoryOrders(&model.OrdersParam{
  Symbol:    "ETHUSDC",
  Limit: 20,
})
AccountAddress = "0xba2b5feae299808b119fd410370d388b2fbf744b"
AssetPrivateKey =  <DeGate AssetPrivateKey>
AccountId = 2475
ETH = {
    "id": 0,
    "symbol": "ETH",
}
USDC = {
    "id": 2,
    "symbol": "USDC",
}

client = Client(AccountAddress, AssetPrivateKey, AccountId,tokens=[ETH,USDC])

try:
    response = client.getHistoryOrders("ETHUSDC",limit=20)
    logging.info(response)
except Exception as e:
    logging.error(e)

响应

[
  {
    "symbol": "ETHUSDC",
    "orderId": "1",
    "clientOrderId": "myOrder1",
    "price": "0.1",
    "origQty": "1.0",
    "executedQty": "0.0",
    "cummulativeQuoteQty": "0.0",
    "status": "NEW",
    "timeInForce": "GTC",
    "type": "LIMIT",
    "side": "BUY",
    "time": 1499827319559,
    "updateTime": 1499827319559,
    "isWorking": true,
    "origQuoteOrderQty": "0.000000"
  }
]

订单状态包括:已取消和已完成。

调用方法: GetHistoryOrders

权重(IP): 10

参数:

名称 类型 是否必需 描述
Symbol STRING YES
OrderId STRING NO
StartTime LONG NO
EndTime LONG NO
Limit INT NO 默认 500; 最大 1000.

注意:

数据源: 数据库

账户成交历史

Example

conf.Conf.AddToken(&model.TokenInfo{
  Symbol: "ETH",
  Id:     0,
})
conf.Conf.AddToken(&model.TokenInfo{
  Symbol: "USDC",
  Id:     8,
})
var appConfig = &conf.AppConfig{
    AccountId:        7,
    AccountAddress:   "0xBA2b5FEae299808b119FD410370D388B2fBF744b",
    AssetPrivateKey:       <DeGate AssetPrivateKey>,
}
client := new(spot.Client)
client.SetAppConfig(appConfig)
response, err := client.MyTrades(&model.AccountTradesParam{
  Symbol: "ETHUSDC",
  Limit:  20,
})
AccountAddress = "0xba2b5feae299808b119fd410370d388b2fbf744b"
AssetPrivateKey =  <DeGate AssetPrivateKey>
AccountId = 2475
ETH = {
    "id": 0,
    "symbol": "ETH",
}
USDC = {
    "id": 2,
    "symbol": "USDC",
}

client = Client(AccountAddress, AssetPrivateKey, AccountId,tokens=[ETH,USDC])

try:
    logging.info(client.myTrades("ETHUSDC", limit=20))
except Exception as e:
    logging.error(e)

响应

[
  {
    "symbol": "ETHUSDC", // 交易对
    "id": "28457",       // tradeID
    "orderId": "100234", // 订单ID
    "price": "4.00000100", // 成交价格
    "qty": "12.00000000", // 成交量
    "quoteQty": "48.000012", // 成交金额
    "commission": "10.10000000", // 交易费金额
    "commissionAsset": "BTC", // 交易费资产类型
    "time": 1499865549590, // 交易时间
    "isBuyer": true, // 是否是买家
    "isMaker": false, // 是否是挂单方
  }
]

获取账户指定交易对的成交历史

调用方法: MyTrades

权重(IP): 10

参数:

名称 类型 是否必需 描述
Symbol STRING YES
OrderId STRING NO 必须要和参数symbol一起使用.
StartTime LONG NO
EndTime LONG NO
FromId STRING NO 起始Trade id。 默认获取最新交易。
Limit INT NO 默认 500; 最大 1000.

注意:

数据源:数据库

账户信息

用户可使用此方法获取AccountId

Example

var appConfig = &conf.AppConfig{
    AccountAddress:   "0xBA2b5FEae299808b119FD410370D388B2fBF744b",
    AssetPrivateKey:       <DeGate AssetPrivateKey>,
}
client := new(spot.Client)
client.SetAppConfig(appConfig)
response, err := client.Account()
AccountAddress = "0xba2b5feae299808b119fd410370d388b2fbf744b"
AssetPrivateKey =  <DeGate AssetPrivateKey>

client = Client(AccountAddress,AssetPrivateKey)

try:
    logging.info(client.account())
except Exception as e:
    logging.error(e)

响应

{'id': 655,
 'owner': '0x79e106a68dba9b432718a65d0dd2798024104231',
 'public_key_x': '0x230b3f70e830d82fb946e7c940886bba3d86a67daa80894d297aa2ea015a580f',
 'public_key_y': '0x01484c45c6e3e2dce8221e699a5bd87aeb1b2e02cb6c8149937480cc326311f0',
 'referrer_id': 0,
 'nonce': 0,
 'makerCommission': 0,
 'takerCommission': 0,
 'buyerCommission': 0,
 'sellerCommission': 0,
 'canTrade': False,
 'canWithdraw': False,
 'canDeposit': False,
 'updateTime': 0,
 'accountType': 'SPOT',
 'balances': [{'asset': 'USDT',
   'free': '12416.2884578',
   'locked': '',
   'freeze': '0',
   'withdrawing': ''},
  {'asset': 'ETH',
   'free': '8.384506045504639607',
   'locked': '',
   'freeze': '0',
   'withdrawing': ''}],
 'permissions': ['SPOT']}

调用方法: Account

权重(IP): 1

参数:

名称 类型 是否必需 描述
AccountAddress STRING YES
AssetPrivateKey STRING YES

数据源: 缓存 => 数据库

错误代码

错误由两部分组成:错误代码和消息。 代码是通用的,但是消息可能会有所不同。

100000

100001

100004

100006

100007

100008

100009

100010

100012

100013

101001

101002

101003

101004

102001

102002

102003

102007

102008

102011

102012

102013

102014

102015

102016

102023

102024

102026

102027

102028

102029

102030

102032

102033

102035

102117

102118

103000

104005

105000

106000

107004



行情推送

SDK 行情推送

逐笔交易

Example:

conf.Conf.AddToken(&model.TokenInfo{
  Symbol: "ETH",
  Id:     0,
})
conf.Conf.AddToken(&model.TokenInfo{
  Symbol: "USDC",
  Id:     8,
})
var appConfig = &conf.AppConfig{
    WebsocketBaseUrl: "wss://v1-mainnet-ws.degate.com",
}
c := websocket.WebSocketClient{}
c.Init(appConfig)
err := c.SubscribeTrade(&model.SubscribeTradeParam{
  Symbol: "ETHUSDC",
}, func(message string) {
  log.Info(message)
})
ETH = {
    "id": 0,
    "symbol": "ETH",
}
USDC = {
    "id": 2,
    "symbol": "USDC",
}

def message_handler(message):
    if message is not None:
        print(message.decode("utf-8"))

wsClient = SpotWebsocketClient(tokens=[ETH,USDC])
wsClient.start()
wsClient.subscribeTrade(
    symbol="ETHUSDC",
    interval="1m",
    id=1,
    callback=message_handler,
)

Payload:

{
  "e": "trade",     // 事件类型
  "E": 123456789,   // 事件时间
  "s": "ETHUSDC",    // 交易对
  "t": 12345,       // 交易ID
  "p": "0.001",     // 成交价格
  "q": "100",       // 成交数量
  "b": 88,          // 买方的订单ID
  "a": 50,          // 卖方的订单ID
  "T": 123456785,   // 成交时间
  "m": true,        // 买方是否是做市方。如true,则此次成交是一个主动卖出单,否则是一个主动买入单。
  "M": true         // 请忽略该字段
}

逐笔交易推送每一笔成交信息。成交交易的定义是指仅有一个吃单者与一个挂单者相互交易。

调用方法: SubscribeTrade

参数:

名称 类型 是否必需 描述
Symbol STRING YES

K线 Streams

Example:

conf.Conf.AddToken(&model.TokenInfo{
  Symbol: "ETH",
  Id:     0,
})
conf.Conf.AddToken(&model.TokenInfo{
  Symbol: "USDC",
  Id:     8,
})
var appConfig = &conf.AppConfig{
    WebsocketBaseUrl: "wss://v1-mainnet-ws.degate.com",
}
c := &websocket.WebSocketClient{}
c.Init(appConfig)
err := c.SubscribeKline(&model.SubscribeKlineParam{
  Symbol:   "ETHUSDC",
  Interval: "1m",
}, func(message string) {
  log.Info(message)
})
ETH = {
    "id": 0,
    "symbol": "ETH",
}
USDC = {
    "id": 2,
    "symbol": "USDC",
}

def message_handler(message):
    if message is not None:
        print(message.decode("utf-8"))

wsClient = SpotWebsocketClient(tokens=[ETH,USDC])
wsClient.start()
try:
    wsClient.subscribeKline(symbol="ETHUSDC", id=10, interval="1m", callback=message_handler)
except Exception as e:
    logging.error(e)

Payload:

{
  "e": "kline",     // 事件类型
  "E": 123456789,   // 事件时间
  "s": "ETHUSDC",    // 交易对
  "k": {
    "t": 123400000, // 这根K线的起始时间
    "T": 123460000, // 这根K线的结束时间
    "s": "ETHUSDC",  // 交易对
    "i": "1m",      // K线间隔
    "f": 100,       // 这根K线期间第一笔成交ID
    "L": 200,       // 这根K线期间末一笔成交ID
    "o": "0.0010",  // 这根K线期间第一笔成交价
    "c": "0.0020",  // 这根K线期间末一笔成交价
    "h": "0.0025",  // 这根K线期间最高成交价
    "l": "0.0015",  // 这根K线期间最低成交价
    "v": "1000",    // 这根K线期间成交量
    "n": 100,       // 这根K线期间成交笔数
    "x": false,     // 这根K线是否完结(是否已经开始下一根K线)
    "q": "1.0000",  // 这根K线期间成交额
    "V": "500",     // 主动买入的成交量
    "Q": "0.500",   // 主动买入的成交额
    "B": "123456"   // 忽略此参数
  }
}

K线stream逐秒推送所请求的K线种类(最新一根K线)的更新。

调用方法: SubscribeKline

Update Speed: 2000ms

参数:

名称 类型 是否必需 描述
Symbol STRING YES
Interval STRING YES K线间隔 参考枚举定义

按Symbol的完整Ticker

Example:

conf.Conf.AddToken(&model.TokenInfo{
  Symbol: "ETH",
  Id:     0,
})
conf.Conf.AddToken(&model.TokenInfo{
  Symbol: "USDC",
  Id:     8,
})
var appConfig = &conf.AppConfig{
    WebsocketBaseUrl: "wss://v1-mainnet-ws.degate.com",
}
c := websocket.WebSocketClient{}
c.Init(appConfig)
err := c.SubscribeTicker(&model.SubscribeTickerParam{
  Symbol: "ETHUSDC",
}, func(message string) {
  log.Info(message)
})
ETH = {
    "id": 0,
    "symbol": "ETH",
}
USDC = {
    "id": 2,
    "symbol": "USDC",
}

def message_handler(message):
    if message is not None:
        print(message.decode("utf-8"))

wsClient = SpotWebsocketClient(tokens=[ETH,USDC])
wsClient.start()
wsClient.subscribeTicker(
    symbol="ETHUSDC",
    id=1,
    callback=message_handler,
)

Payload:

{
  "e": "24hrTicker",  // 事件类型
  "E": 123456789,     // 事件时间
  "s": "ETHUSDC",      // 交易对
  "p": "0.0015",      // 24小时价格变化
  "P": "250.00",      // 24小时价格变化(百分比)
  "w": "0.0018",      // 平均价格
  "x": "0.0009",      // 整整24小时之前,向前数的最后一次成交价格
  "c": "0.0025",      // 最新成交价格
  "Q": "10",          // 最新成交交易的成交量
  "b": "0.0024",      // 目前最高买单价
  "B": "10",          // 目前最高买单价的挂单量
  "a": "0.0026",      // 目前最低卖单价
  "A": "100",         // 目前最低卖单价的挂单量
  "o": "0.0010",      // 整整24小时前,向后数的第一次成交价格
  "h": "0.0025",      // 24小时内最高成交价
  "l": "0.0010",      // 24小时内最低成交价
  "v": "10000",       // 24小时内成交量
  "q": "18",          // 24小时内成交额
  "O": 0,             // 统计开始时间
  "C": 86400000,      // 统计结束时间
  "F": "0",           // 24小时内第一笔成交交易ID
  "L": "18150",       // 24小时内最后一笔成交交易ID
  "n": 18151          // 24小时内成交数
}

每秒推送单个交易对的过去24小时滚动窗口标签统计信息。

调用方法: SubscribeTicker

Update Speed: 1000ms

参数:

名称 类型 是否必需 描述
Symbol STRING YES

按Symbol的最优挂单信息

Example:

conf.Conf.AddToken(&model.TokenInfo{
  Symbol: "ETH",
  Id:     0,
})
conf.Conf.AddToken(&model.TokenInfo{
  Symbol: "USDC",
  Id:     8,
})
var appConfig = &conf.AppConfig{
    WebsocketBaseUrl: "wss://v1-mainnet-ws.degate.com",
}
c := websocket.WebSocketClient{}
c.Init(appConfig)
err := c.SubscribeBookTicker(&model.SubscribeBookTickerParam{
  Symbol: "ETHUSDC",
}, func(message string) {
  log.Info(message)
})
ETH = {
    "id": 0,
    "symbol": "ETH",
}
USDC = {
    "id": 2,
    "symbol": "USDC",
}

def message_handler(message):
    if message is not None:
        print(message.decode("utf-8"))

wsClient = SpotWebsocketClient(tokens=[ETH,USDC])
wsClient.start()
wsClient.subscribeBookTicker(
    symbol="ETHUSDC",
    id=18,
    callback=message_handler,
)

Payload:

{
  "e":"bookTicker",  // Event type
  "s":"ETHUSDC",     // 交易对
  "b":"25.35190000", // 买单最优挂单价格
  "B":"31.21000000", // 买单最优挂单数量
  "a":"25.36520000", // 卖单最优挂单价格
  "A":"40.66000000"  // 卖单最优挂单数量
}

实时推送指定交易对最优挂单信息

调用方法: SubscribeBookTicker

Update Speed: 实时

参数:

名称 类型 是否必需 描述
Symbol STRING YES

有限档深度信息

Example:

conf.Conf.AddToken(&model.TokenInfo{
  Symbol: "ETH",
  Id:     0,
})
conf.Conf.AddToken(&model.TokenInfo{
  Symbol: "USDC",
  Id:     8,
})
var appConfig = &conf.AppConfig{
    WebsocketBaseUrl: "wss://v1-mainnet-ws.degate.com",
}
c := websocket.WebSocketClient{}
c.Init(appConfig)
err := c.SubscribeDepth(&model.SubscribeDepthParam{
  Symbol: "ETHUSDC",
  Level:  5,
  Speed:  100,
}, func(message string) {
  log.Info(message)
})
ETH = {
    "id": 0,
    "symbol": "ETH",
}
USDC = {
    "id": 2,
    "symbol": "USDC",
}

def message_handler(message):
    if message is not None:
        print(message.decode("utf-8"))

wsClient = SpotWebsocketClient(tokens=[ETH,USDC])
wsClient.start()
wsClient.subscribeDepth(
    symbol="ETHUSDC",
    level=5,
    speed=100,
    id=39,
    callback=message_handler,
)

Payload:

{
  "lastUpdateId": 160,  // Last update ID
  "bids": [             // Bids to be updated
    [
      "0.0024",         // Price level to be updated
      "10"              // Quantity
    ]
  ],
  "asks": [             // Asks to be updated
    [
      "0.0026",         // Price level to be updated
      "100"             // Quantity
    ]
  ]
}

推送有限档深度信息

调用方法: SubscribeDepth

参数:

名称 类型 是否必需 描述
Symbol STRING YES
Level INT YES levels表示几档买卖单信息, 可选 5/10/20档
Speed INT YES 1000ms 或 100ms

增量深度信息

Example:

conf.Conf.AddToken(&model.TokenInfo{
  Symbol: "ETH",
  Id:     0,
})
conf.Conf.AddToken(&model.TokenInfo{
  Symbol: "USDC",
  Id:     8,
})
var appConfig = &conf.AppConfig{
    WebsocketBaseUrl: "wss://v1-mainnet-ws.degate.com",
}
c := websocket.WebSocketClient{}
c.Init(appConfig)
err := c.SubscribeDepthUpdate(&model.SubscribeDepthUpdateParam{
  Symbol: "ETHUSDC",
  Speed:  100,
}, func(message string) {
  log.Info(message)
})
ETH = {
    "id": 0,
    "symbol": "ETH",
}
USDC = {
    "id": 2,
    "symbol": "USDC",
}

def message_handler(message):
    if message is not None:
        print(message.decode("utf-8"))

wsClient = SpotWebsocketClient(tokens=[ETH,USDC])
wsClient.start()
wsClient.subscribeDepthUpdate(
    symbol="ETHUSDC",
    speed=100,
    id=20,
    callback=message_handler,
)

Payload:

{
  "e": "depthUpdate", // 事件类型
  "E": 123456789,     // 事件时间
  "s": "ETHUSDC",      // 交易对
  "U": 157,           // 从上次推送至今新增的第一个 update Id
  "u": 160,           // 从上次推送至今新增的最后一个 update Id
  "b": [              // 变动的买单深度
    [
      "0.0024",       // 变动的价格档位
      "10"            // 数量
    ]
  ],
  "a": [              // 变动的卖单深度
    [
      "0.0026",       // 变动的价格档位
      "100"           // 数量
    ]
  ]
}

每秒或每100毫秒推送orderbook的变化部分(如果有)

调用方法: SubscribeDepthUpdate

参数:

名称 类型 是否必需 描述
Symbol STRING YES
Speed INT YES 1000ms 或 100ms

Websocket 行情推送

实时订阅/取消数据流

订阅一个信息流

响应

  {
    "result": null,
    "id": 1
  }

在测试网中ETH的token ID为0,USDC的token ID为2,所以在请求中需要传入ETH和USDC的Token ID '0.2'
* 请求

{
"method": "SUBSCRIBE",
"params":
[
"0.2@aggTrade",
"0.2@depth"
],
"id": 1
}

取消订阅一个信息流

响应

  {
    "result": null,
    "id": 312
  }

{
"method": "UNSUBSCRIBE",
"params":
[
"0.2@depth"
],
"id": 312
}

已订阅信息流

响应

  {
    "result": [
      "ethusdc@aggTrade"
    ],
    "id": 3
  }

{
"method": "LIST_SUBSCRIPTIONS",
"id": 3
}

逐笔交易

Payload:

{
  "e": "trade",     // 事件类型
  "E": 123456789,   // 事件时间
  "s": "ETHUSC",    // 交易对
  "t": 12345,       // 交易ID
  "p": "0.001",     // 成交价格
  "q": "100",       // 成交数量
  "b": 88,          // 买方的订单ID
  "a": 50,          // 卖方的订单ID
  "T": 123456785,   // 成交时间
  "m": true,        // 买方是否是做市方。如true,则此次成交是一个主动卖出单,否则是一个主动买入单。
  "M": true         // 请忽略该字段
}

Stream Name: <symbol>@trade

逐笔交易推送每一笔成交信息。成交交易的定义是指仅有一个吃单者与一个挂单者相互交易。

K线 Streams

Payload:

{
  "e": "kline",     // 事件类型
  "E": 123456789,   // 事件时间
  "s": "ETHUSDC",    // 交易对
  "k": {
    "t": 123400000, // 这根K线的起始时间
    "T": 123460000, // 这根K线的结束时间
    "s": "ETHUSDC",  // 交易对
    "i": "1m",      // K线间隔
    "f": 100,       // 这根K线期间第一笔成交ID
    "L": 200,       // 这根K线期间末一笔成交ID
    "o": "0.0010",  // 这根K线期间第一笔成交价
    "c": "0.0020",  // 这根K线期间末一笔成交价
    "h": "0.0025",  // 这根K线期间最高成交价
    "l": "0.0015",  // 这根K线期间最低成交价
    "v": "1000",    // 这根K线期间成交量
    "n": 100,       // 这根K线期间成交笔数
    "x": false,     // 这根K线是否完结(是否已经开始下一根K线)
    "q": "1.0000",  // 这根K线期间成交额
    "V": "500",     // 主动买入的成交量
    "Q": "0.500",   // 主动买入的成交额
    "B": "123456"   // 忽略此参数
  }
}

K线stream逐秒推送所请求的K线种类(最新一根K线)的更新。

Stream Name: <symbol>@kline_<interval>

Update Speed: 2000ms

K线图间隔参数: 参考枚举定义

按Symbol的完整Ticker

Payload:

{
  "e": "24hrTicker",  // 事件类型
  "E": 123456789,     // 事件时间
  "s": "ETHUSDC",      // 交易对
  "p": "0.0015",      // 24小时价格变化
  "P": "250.00",      // 24小时价格变化(百分比)
  "w": "0.0018",      // 平均价格
  "x": "0.0009",      // 整整24小时之前,向前数的最后一次成交价格
  "c": "0.0025",      // 最新成交价格
  "Q": "10",          // 最新成交交易的成交量
  "b": "0.0024",      // 目前最高买单价
  "B": "10",          // 目前最高买单价的挂单量
  "a": "0.0026",      // 目前最低卖单价
  "A": "100",         // 目前最低卖单价的挂单量
  "o": "0.0010",      // 整整24小时前,向后数的第一次成交价格
  "h": "0.0025",      // 24小时内最高成交价
  "l": "0.0010",      // 24小时内最低成交价
  "v": "10000",       // 24小时内成交量
  "q": "18",          // 24小时内成交额
  "O": 0,             // 统计开始时间
  "C": 86400000,      // 统计结束时间
  "F": 0,             // 24小时内第一笔成交交易ID
  "L": 18150,         // 24小时内最后一笔成交交易ID
  "n": 18151          // 24小时内成交数
}

每秒推送单个交易对的过去24小时滚动窗口标签统计信息。

Stream 名称: <symbol>@ticker

Update Speed: 1000ms

按Symbol的最优挂单信息

Payload:

{
  "u":400900217,     // order book updateId
  "s":"ETHUSDC",     // 交易对
  "b":"25.35190000", // 买单最优挂单价格
  "B":"31.21000000", // 买单最优挂单数量
  "a":"25.36520000", // 卖单最优挂单价格
  "A":"40.66000000"  // 卖单最优挂单数量
}

实时推送指定交易对最优挂单信息

Stream Name: <symbol>@bookTicker

Update Speed: 实时

有限档深度信息

Payload:

{
  "lastUpdateId": 160,  // Last update ID
  "bids": [             // Bids to be updated
    [
      "0.0024",         // Price level to be updated
      "10"              // Quantity
    ]
  ],
  "asks": [             // Asks to be updated
    [
      "0.0026",         // Price level to be updated
      "100"             // Quantity
    ]
  ]
}

每秒或每100毫秒推送有限档深度信息。levels表示几档买卖单信息, 可选 5/10/20档。

Stream Names: <symbol>@depth<levels><symbol>@depth<levels>_100ms.

Update Speed: 1000ms 或 100ms

增量深度信息

Payload:

{
  "e": "depthUpdate", // 事件类型
  "E": 123456789,     // 事件时间
  "s": "ETHUSDC",      // 交易对
  "U": 157,           // 从上次推送至今新增的第一个 update Id
  "u": 160,           // 从上次推送至今新增的最后一个 update Id
  "b": [              // 变动的买单深度
    [
      "0.0024",       // 变动的价格档位
      "10"            // 数量
    ]
  ],
  "a": [              // 变动的卖单深度
    [
      "0.0026",       // 变动的价格档位
      "100"           // 数量
    ]
  ]
}

每秒或每100毫秒推送orderbook的变化部分(如果有)

Stream Name: <symbol>@depth<symbol>@depth@100ms

Update Speed: 1000ms 或 100ms

账户信息推送

Listen Key

Example:

var appConfig = &conf.AppConfig{
    AccountId:        7,
    AccountAddress:   "0xBA2b5FEae299808b119FD410370D388B2fBF744b",
    AssetPrivateKey:       <DeGate AssetPrivateKey>,
}
c := new(spot.Client)
c.SetAppConfig(appConfig)
response, err := c.NewListenKey()
AccountAddress = "0xba2b5feae299808b119fd410370d388b2fbf744b"
AssetPrivateKey =  <DeGate AssetPrivateKey>
AccountId = 2475

client = Client(AccountAddress, AssetPrivateKey, AccountId)
try:
    response = client.newListenKey()
    logging.info(response["listenKey"])
except Exception as e:
    logging.error(e)

响应

{
  "listenKey": "pqia91ma19a5s61cv6a81va65sdf19v8a65a1a5s61cv6a81va65sdf19v8a65a1"
}

生成 Listen Key

调用方法: NewListenKey

开始一个新的数据流。除非发送 keepalive,否则数据流于60分钟后关闭。如果该帐户具有有效的listenKey,则将返回该listenKey并将其有效期延长60分钟。

权重(IP): 1

参数:

NONE

数据源: 缓存


延长 Listen Key 有效期

调用方法: ReNewListenKey

有效期延长至本次调用后60分钟,建议每30分钟发送一个 ping 。

权重(IP): 1

参数:

名称 类型 是否必需 描述
ListenKey STRING YES

数据源: 缓存

Example

var appConfig = &conf.AppConfig{
    AccountId:        7,
    AccountAddress:   "0xBA2b5FEae299808b119FD410370D388B2fBF744b",
    AssetPrivateKey:       <DeGate AssetPrivateKey>,
}
c := new(spot.Client)
c.SetAppConfig(appConfig)
response, err := c.ReNewListenKey(&model.ListenKeyParam{
        ListenKey: "",
})
AccountAddress = "0xba2b5feae299808b119fd410370d388b2fbf744b"
AssetPrivateKey =  <DeGate AssetPrivateKey>
AccountId = 2475
client = Client(AccountAddress, AssetPrivateKey, AccountId)
try:
    response = client.reNewListenKey("")
    logging.info(response)
except Exception as e:
    logging.error(e)

响应

{}


关闭 Listen Key

调用方法: DeleteListenKey

关闭用户数据流。

权重(IP): 1

参数:

名称 类型 是否必需 描述
ListenKey STRING YES

数据源: 缓存

Example

var appConfig = &conf.AppConfig{
    AccountId:        7,
    AccountAddress:   "0xBA2b5FEae299808b119FD410370D388B2fBF744b",
    AssetPrivateKey:       <DeGate AssetPrivateKey>,
}
c := new(spot.Client)
c.SetAppConfig(appConfig)
response, err := c.DeleteListenKey(&model.ListenKeyParam{
        ListenKey: "",
})
AccountAddress = "0xba2b5feae299808b119fd410370d388b2fbf744b"
AssetPrivateKey =  <DeGate AssetPrivateKey>
AccountId = 2475
client = Client(AccountAddress, AssetPrivateKey, AccountId)
try:
    response = client.deleteListenKey("")
    logging.info(response)
except Exception as e:
    logging.error(e)

响应

{}

订阅

Example

var appConfig = &conf.AppConfig{
    WebsocketBaseUrl: "wss://v1-mainnet-ws.degate.com",
}
c := websocket.WebSocketClient{}
c.Init(appConfig)
c.SubscribeUserData(&model.SubscribeUserDataParam{
  ListenKey: "",
}, func(message string) {
  log.Info(message)
})
def message_handler(message):
    if message is not None:
        print(message.decode("utf-8"))

AccountAddress = "0xba2b5feae299808b119fd410370d388b2fbf744b"
AssetPrivateKey =  <DeGate AssetPrivateKey>
AccountId = 2475

client = Client(AccountAddress, AssetPrivateKey, AccountId)
response = client.new_listen_key()
print("Receive listen key : {}".format(response["listenKey"]))

ws_client = SpotWebsocketClient()
ws_client.start()

ws_client.user_data(
    listen_key=response["listenKey"],
    id=87,
    callback=message_handler,
)

调用方法: SubscribeUserData

参数:

名称 类型 是否必需 描述
ListenKey STRING YES

Payload: 账户更新

Payload

{
  "e": "outboundAccountPosition", // 事件类型
  "E": 1564034571105,             // 事件时间
  "u": 1564034571073,             // 账户末次更新时间戳
  "B": [                          // 余额
    {
      "a": "ETH",                 // 资产名称
      "f": "10000.000000",        // 可用余额
      "l": "0.000000"             // 冻结余额
      "i": 0,                     //token id
    }
  ]
}

每当帐户余额发生更改时,都会发送一个事件outboundAccountPosition,其中包含可能由生成余额变动的事件而变动的资产。

Payload: 余额更新

Payload

{
  "e": "balanceUpdate",         //Event Type
  "E": 1573200697110,           //Event Time
  "a": "ABC",                   //Asset
  "v": "100.00000000",          //Balance available
  "T": 1573200697068            //Clear Time
  "i": 0,                       //token id
}

Payload: 订单更新

Payload

{
  "e": "executionReport",        // 事件类型
  "E": 1499405658658,            // 事件时间
  "s": "ETHUSDC",                // 交易对
  "c": "mUvoqJxFIILMdfAW5iGSOW", // clientOrderId
  "S": "BUY",                    // 订单方向
  "o": "LIMIT",                  // 订单类型
  "q": "1.00000000",             // 订单原始数量
  "p": "0.10264410",             // 订单原始价格
  "x": "NEW",                    // 本次事件的具体执行类型
  "X": "NEW",                    // 订单的当前状态
  "r": "",                       // 订单被拒绝的原因
  "i": "4293153",                // orderId
  "z": "0.00000000",             // 订单累计已成交量
  "n": "0",                      // 手续费数量
  "N": null,                     // 手续费资产类别
  "T": 1499405658657,            // 成交时间
  "t": "",                       // 成交ID
  "w": true,                     // 订单是否在订单簿上?
  "O": 1499405658657,            // 订单创建时间
  "Z": "0.00000000",             // 订单累计已成交金额
  "Q": "0.00000000"              // Quote Order Qty
  "l": "0.00000000",             // 订单末次成交量
  "L": "0.00000000",             // 订单末次成交价格
  "m": true,                     // 该成交是作为挂单成交吗?
  "Y": "",                       // 订单末次成交金额
  "W": 1499405658657,            // Working Time; 订单被添加到 order book 的时间
  "P": 1,                        // pair id
  "B": 0,                        // base token id
  "U": 2,                        // quote token id 
}

订单通过executionReport事件进行更新。

请查阅文档公开API参数以及以下文档,以获取相关的枚举定义。

通过将Z(订单累计已成交金额)除以z(订单累计已成交量)即可得到平均价格。

执行类型:

Payload: 逐笔交易

Payload

{
  "e": "accountTrade", // 事件类型
  "E": 123456789,   // 事件时间
  "s": "ETHUSDC",   // 交易对
  "B": 1,           // baseTokenID
  "U": 0,           // quoteTokenID
  "P": 10,          // 交易对ID
  "t": 12345,       // 交易ID
  "p": "0.001",     // 成交价格
  "q": "100",       // 成交数量
  "Q": "10",        // quote成交数量
  "b": 88,          // 买方的订单ID
  "y": 0,           // 买方的订单类型 0 限价单,1 市价单, 6 网格卖单, 7 网格买单
  "c": "100",       // 买方的数量
  "o": 10,          // 买方的token id
  "k": true,        // 买方是否为market
  "a": 50,          // 卖方的订单ID
  "Y": 0,           // 卖方的订单类型 0 限价单,1 市价单, 6 网格卖单, 7 网格买单
  "C": "100",       // 卖方的数量
  "O": 11,          // 卖方的token id
  "K": false,       // 卖方是否为market
  "f":"10",         // gas fee
  "x":"10",         // 最大收取的gas Fee
  "i": 20,          // 手续费比例 万分之几
  "r": "20"         // 手续费
  "T": 123456785,   // 成交时间
  "m": true,        // 买方是否是做市方。如true,则此次成交是一个主动卖出单,否则是一个主动买入单。
  "M": true,        // is buy
}

逐笔交易推送每一笔成交信息。成交交易的定义是指仅有一个吃单者与一个挂单者相互交易。