Skip to content

API v1.0.0 trades

Tiny_Murky edited this page Mar 20, 2024 · 17 revisions

listCFDs

  • description: list user's cfds, will return a list of acceptedCFDOrder

Request

Request url

GET /api/v1/cfds

Headers

name type description required default
Dewt string Decentralized Web Token(DeWT) 是我們專為 TideBit-DeFi 設計的去中心化認證機制,為用戶登入時簽名的內容加上用戶簽名的結果進行 rlp 編碼 true --

Parameters

Name Type Description Required Default
instId String Filters CFDs (Contracts for Difference) belonging to a specific instId. Returns all CFDs if not provided. No --
state String The state of the CFD trade. Can be OPENING, CLOSED, or FREEZED. Returns trades of all states if undefined. No --
typeOfPosition String The type of order, can be BUY or SELL. Returns all types of CFD trades if undefined. No --
begin String Format: YYYY-MM-DD. Returns CFDs starting from the specified Begin Day (inclusive). Returns all CFDs if not provided. No --
end String Format: YYYY-MM-DD. Returns CFDs up to the specified End Day (exclusive). Returns all CFDs if not provided. No --
limit Integer The number of CFDs to return per page. Must be a positive integer if provided. No 20
page Integer The page number of CFDs to return, used for offset calculation. Must be a positive integer if provided. No 1
asc String If 'true', CFDs are sorted by creation time in ascending order. No --

Request Example

GET /api/v1/cfds?instId=ETH-USDT&state=OPENING&typeOfPosition=SELL&begin=2024-01-23&end=2024-02-12&limit=1&page=2&asc=false
Headers:
    DeWT: <DeWT>

Response

Response Parameters

name type description
success boolean request 成功或失敗
code string response code
data IAcceptedCFDOrder[] | null response data

Response Example

  • 成功的回傳
{
    "powerby": "TideBit-DeFi api 1.0.0",
    "success": true,
    "code":  "00000000",
    "message": "list user's cfd trades",
    "payload":[
        {
            "id":"TBAcceptedCFD20230317ETH",
            "ticker":"ETH",
            "orderStatus":"SUCCESS",
            "orderType":"CFD",
            "state":"CLOSED",
            "typeOfPosition":"BUY",
            "targetAsset":"ETH",
            "uniAsset":"USDT",
            "openPrice":24058,
            "amount":1.8,
            "createTimestamp":1675299651,
            "leverage":5,
            "margin":{
                "asset":"BTC",
                "amount":714.92
            },
            "takeProfit":74521,
            "stopLoss":25250,
            "fee":0,
            "guaranteedStop":false,
            "guaranteedStopFee":0.77,
            "liquidationPrice":19537,
            "liquidationTime":1675386051,
            "closePrice":19537,
            "closeTimestamp":1675386051,
            "closedType":"SCHEDULE",
            "forcedClose":true,
            "remark":""
        }
    ],
}
  • 失敗的回傳

未提供DeWT

{
    "success": false,
    "code": "40430003",
    "message": "did not receive deWT. ",
    "reason": "ERROR_MESSAGE.DEWT_IS_NOT_LEGIT",
    "data": null
}

instId 輸入 string, 只會檢查是不是string, 因此除非填空值不會回傳錯誤

/api/v1/cfds?instId=ETH-USDT

state 只能接受"OPENING, CLOSED, FREEZED"

/api/v1/cfds?state=SAD
{
    "statusCode": 400,
    "message": [
        "state must be one of the following values: OPENING, CLOSED, FREEZED"
    ],
    "error": "Bad Request"
}

typeOfPosition 只能接受"SELL, BUY"

/api/v1/cfds?typeOfPosition=SELL
{
    "statusCode": 400,
    "message": [
        "typeOfPosition must be one of the following values: BUY, SELL"
    ],
    "error": "Bad Request"
}

begin, end 格式是 YYYY-MM-DD,輸入錯誤回傳如下

/api/v1/cfds?begin=sad&end=happy
{
    "statusCode": 400,
    "message": [
        "maximal allowed date for begin is Wed Mar 20 2024 06:37:01 GMT+0000 (Coordinated Universal Time)",
        "begin must be a Date instance",
        "maximal allowed date for end is Wed Mar 20 2024 06:37:01 GMT+0000 (Coordinated Universal Time)",
        "end must be a Date instance"
    ],
    "error": "Bad Request"
}

page 和 limit 需要是正整數,輸入錯誤回傳如下

/api/v1/cfds?page=sad&limit=happy
{
    "statusCode": 400,
    "message": [
        "limit must be a positive number",
        "limit must be a number conforming to the specified constraints",
        "page must be a positive number",
        "page must be a number conforming to the specified constraints"
    ],
    "error": "Bad Request"
}

asc 只可以填true or false, default 是 false

/api/v1/cfds?asc=SAD
{
    "statusCode": 400,
    "message": [
        "asc must be one of the following values: true, false"
    ],
    "error": "Bad Request"
}

getCFDTrade

  • description: get user cfd trade by id

Request

Request url

GET /api/v1/cfds/[:id]

Headers

name type description required default
Dewt string Decentralized Web Token(DeWT) 是我們專為 TideBit-DeFi 設計的去中心化認證機制,為用戶登入時簽名的內容加上用戶簽名的結果進行 rlp 編碼 true --

Parameters

name type description required default

Request Example

GET /api/v1/cfds/TBAcceptedCFD20230317ETH
Headers:
    DeWT: <DeWT>

Response

Response Parameters

name type description
powerby string TideBit-DeFi api 1.0.0
success boolean request 成功或失敗
code string response code
message string description of response data
payload IAcceptedCFDOrder | null response data

Response Example

  • 成功的回傳
{
    "powerby": "TideBit-DeFi api 1.0.0",
    "success": true,
    "code":  "00000000",
    "message": "get user's cfd trades by id",
    "payload":{
        "id":"TBAcceptedCFD20230317ETH",
        "ticker":"ETH",
        "orderStatus":"SUCCESS",
        "orderType":"CFD",
        "state":"CLOSED",
        "typeOfPosition":"BUY",
        "targetAsset":"ETH",
        "uniAsset":"USDT",
        "openPrice":24058,
        "amount":1.8,
        "createTimestamp":1675299651,
        "leverage":5,
        "margin":{
            "asset":"BTC",
            "amount":714.92
        },
        "takeProfit":74521,
        "stopLoss":25250,
        "fee":0,
        "guaranteedStop":false,
        "guaranteedStopFee":0.77,
        "liquidationPrice":19537,
        "liquidationTime":1675386051,
        "closePrice":19537,
        "closeTimestamp":1675386051,
        "closedType":"SCHEDULE",
        "forcedClose":true,
        "remark":""
    }
}
  • 失敗的回傳
{
    "powerby": "TideBit-DeFi api 1.0.0",
    "success": false,
    "code":  "09000000",
    "message": "bad input parameterr",
    "payload": null
}

createCFDTrade

  • description: create cfd trade

Request

Request url

POST /api/v1/users/cfds

Headers

name type description required default
Dewt string Decentralized Web Token(DeWT) 是我們專為 TideBit-DeFi 設計的去中心化認證機制,為用戶登入時簽名的內容加上用戶簽名的結果進行 rlp 編碼 true --

body

name type description required default
type string operation on CFD trade, can be CREATE、UPDATE、CLOSE true CREATE
data IApplyCreateCFDOrderData create cfd data true -
signature string signature of eip712 create CFD order contract true -

Request Example

POST /api/v1/users/cfds

const body = {
    type: "CREATE",
    data: {
        ticker: "ETH",
        amount: 1.8,
        typeOfPosition: "BUY",
        leverage: 5,
        price: 24058,
        targetAsset: "ETH",
        uniAsset: "USDT",
        margin: {
            asset: 'BTC', 
            amount: 714.92,
        },
        stopLoss: 25250,
        takeProfit: 74521,
        fee: 0,
        quotation: {
            ticker: "ETH",
            targetAsset: "ETH",
            uniAsset: "USDT",
            price: 19537,
            deadline: 1675299666,
            signature: '0x64ff12aefbd0fbf8e6dbfa88885b7126a96fc2e983edb7b14eafbe9cc13b89e456ed84696b5d350ae40b35e8b789abe62d6459082eb67a461c660b2435da098f21',
        },
        liquidationPrice: 19537,
        liquidationTime: 1675386051,
        remark: "",
    },
    signature: "0x75cc63d3fbd0fbf8e6dbfa88885b7126a96fc2e983edb7b14eafbe9cc13b89e456ed84696b5d350ae40b35e8b51c8a262d6459082eb67a461c660b2435da82da1b"
}

Headers:
    DeWT: <DeWT>

Response

Response Parameters

name type description
powerby string TideBit-DeFi api 1.0.0
success boolean request 成功或失敗
code string response code
message string description of response data
payload IAcceptedCFDOrder | null response data

Response Example

  • 成功的回傳
{
    "powerby": "TideBit-DeFi api 1.0.0",
    "success": true,
    "code":  "00000000",
    "message": "result of create CFD trade",
    "payload":{
        "id":"TBAcceptedCFD20230317ETH",
        "ticker":"ETH",
        "orderStatus":"PROCESSING",
        "orderType":"CFD",
        "state":"OPENING",
        "typeOfPosition":"BUY",
        "targetAsset":"ETH",
        "uniAsset":"USDT",
        "openPrice":24058,
        "amount":1.8,
        "createTimestamp":1675299651,
        "leverage":5,
        "margin":{
            "asset":"BTC",
            "amount":714.92
        },
        "takeProfit":74521,
        "stopLoss":25250,
        "fee":0,
        "guaranteedStop":false,
        "guaranteedStopFee":0.77,
        "liquidationPrice":19537,
        "liquidationTime":1675386051,
        "closePrice":19537,
        "closeTimestamp":1675386051,
        "closedType":"SCHEDULE",
        "forcedClose":true,
        "remark":""
    }
}
  • 失敗的回傳
{
    "powerby": "TideBit-DeFi api 1.0.0",
    "success": false,
    "code":  "09000000",
    "message": "bad input parameterr",
    "payload": null
}

updateCFDTrade

  • description: update cfd trade

Request

Request url

PUT /api/v1/cfds/[:id]

Headers

name type description required default
Dewt string Decentralized Web Token(DeWT) 是我們專為 TideBit-DeFi 設計的去中心化認證機制,為用戶登入時簽名的內容加上用戶簽名的結果進行 rlp 編碼 true --

body

name type description required default
type string operation on CFD trade, can be CREATE、UPDATE、CLOSE true UPDATE
data IApplyUpdateCFDOrderData update cfd data true -
signature string signature of eip712 update CFD order contract true -

Request Example

PUT /api/v1/trades/cfds/TBAcceptedCFD20230317ETH

const body = {
    type: "UPDATE",
    data: {
        orderId: "TBAcceptedCFD20230317ETH",
        takeProfit: 74521,
        stopLoss: 25250,
        guaranteedStop: false,
        guaranteedStopFee: 0.77,
    },
    signature: "0x75cc63d3fbd0fbf8e6dbfa88885b7126a96fc2e983edb7b14eafbe9cc13b89e456ed84696b5d350ae40b35e8b51c8a262d6459082eb67a461c660b2435da82da1b"
}

Headers:
    DeWT: <DeWT>

Response

Response Parameters

name type description
powerby string TideBit-DeFi api 1.0.0
success boolean request 成功或失敗
code string response code
message string description of response data
payload IAcceptedCFDOrder | null response data

Response Example

  • 成功的回傳
{
    "powerby": "TideBit-DeFi api 1.0.0",
    "success": true,
    "code":  "00000000",
    "message": "result of update CFD trade",
    "payload":{
        "id":"c",
        "ticker":"ETH",
        "orderStatus":"PROCESSING",
        "orderType":"CFD",
        "state":"CLOSED",
        "typeOfPosition":"BUY",
        "targetAsset":"ETH",
        "uniAsset":"USDT",
        "openPrice":24058,
        "amount":1.8,
        "createTimestamp":1675299651,
        "leverage":5,
        "margin":{
            "asset":"BTC",
            "amount":714.92
        },
        "takeProfit":74521,
        "stopLoss":25250,
        "fee":0,
        "guaranteedStop":false,
        "guaranteedStopFee":0.77,
        "liquidationPrice":19537,
        "liquidationTime":1675386051,
        "closePrice":19537,
        "closeTimestamp":1675386051,
        "closedType":"SCHEDULE",
        "forcedClose":true,
        "remark":""
    }
}
  • 失敗的回傳
{
    "powerby": "TideBit-DeFi api 1.0.0",
    "success": false,
    "code":  "09000000",
    "message": "bad input parameterr",
    "payload": null
}

closeCFDTrade

  • description: close cfd trade

Request

Request url

PUT /api/v1/users/cfds/[:id]

Headers

name type description required default
Dewt string Decentralized Web Token(DeWT) 是我們專為 TideBit-DeFi 設計的去中心化認證機制,為用戶登入時簽名的內容加上用戶簽名的結果進行 rlp 編碼 true --

body

name type description required default
type string operation on CFD trade, can be CREATE、UPDATE、CLOSE true CLOSE
data IApplyCloseCFDOrderData close cfd data true -
signature string signature of eip712 close CFD order contract true -

Request Example

PUT /api/v1/users/cfds/TBAcceptedCFD20230317ETH

const body = {
    type: "CLOSE",
    data: {
        orderId: "TBAcceptedCFD20230317ETH",
        closePrice: 19537,
        quotation: {
            ticker: "ETH",
            targetAsset: "ETH",
            uniAsset: "USDT",
            price: 19537,
            deadline: 1675299666,
            signature: '0x64ff12aefbd0fbf8e6dbfa88885b7126a96fc2e983edb7b14eafbe9cc13b89e456ed84696b5d350ae40b35e8b789abe62d6459082eb67a461c660b2435da098f21',
        },
        closeTimestamp: 1675386051,
    },
    signature: "0x75cc63d3fbd0fbf8e6dbfa88885b7126a96fc2e983edb7b14eafbe9cc13b89e456ed84696b5d350ae40b35e8b51c8a262d6459082eb67a461c660b2435da82da1b"
}

Headers:
    DeWT: <DeWT>

Response

Response Parameters

name type description
powerby string TideBit-DeFi api 1.0.0
success boolean request 成功或失敗
code string response code
message string description of response data
payload IAcceptedCFDOrder[] | null response data

Response Example

  • 成功的回傳
{
    "powerby": "TideBit-DeFi api 1.0.0",
    "success": true,
    "code":  "00000000",
    "message": "result of close CFD trade",
    "payload":{
        "id":"TBAcceptedCFD20230317ETH",
        "ticker":"ETH",
        "orderStatus":"PROCESSING",
        "orderType":"CFD",
        "state":"CLOSED",
        "typeOfPosition":"BUY",
        "targetAsset":"ETH",
        "uniAsset":"USDT",
        "openPrice":24058,
        "amount":1.8,
        "createTimestamp":1675299651,
        "leverage":5,
        "margin":{
            "asset":"BTC",
            "amount":714.92
        },
        "takeProfit":74521,
        "stopLoss":25250,
        "fee":0,
        "guaranteedStop":false,
        "guaranteedStopFee":0.77,
        "liquidationPrice":19537,
        "liquidationTime":1675386051,
        "closePrice":19537,
        "closeTimestamp":1675386051,
        "closedType":"SCHEDULE",
        "forcedClose":true,
        "remark":""
    }
}
  • 失敗的回傳
{
    "powerby": "TideBit-DeFi api 1.0.0",
    "success": false,
    "code":  "09000000",
    "message": "bad input parameterr",
    "payload": null
}

listDepositTrades

  • description: list user deposits, will return a list of acceptedDepositOrder

Request

Request url

GET /api/v1/users/deposits

Headers

name type description required default
Dewt string Decentralized Web Token(DeWT) 是我們專為 TideBit-DeFi 設計的去中心化認證機制,為用戶登入時簽名的內容加上用戶簽名的結果進行 rlp 編碼 true --

Parameters

name type description required default

Request Example

GET /api/v1/users/deposits
Headers:
    DeWT: <DeWT>

Response

Response Parameters

name type description
powerby string TideBit-DeFi api 1.0.0
success boolean request 成功或失敗
code string response code
message string description of response data
payload IAcceptedDepositOrder[] | null response data

Response Example

  • 成功的回傳
{
    "powerby": "TideBit-DeFi api 1.0.0",
    "success": true,
    "code":  "00000000",
    "message": "list user deposits records",
    "payload": [
        {
            "id": "TBAcceptedDeposit20230317ETH",
            "orderType": "DEPOSIT",
            "createTimestamp": 1679023233,
            "orderStatus": "SUCCESS",
            "targetAsset": "ETH",
            "decimals": "18",
            "targetAmount": "7.91",
            "to": "0xb54898DB1250A6a629E5B566367E9C60a7Dd6C30",
            "fee": "0",
        }
    ],
}
  • 失敗的回傳
{
    "powerby": "TideBit-DeFi api 1.0.0",
    "success": false,
    "code":  "09000000",
    "message": "bad input parameterr",
    "payload": null
}

createDepositTrade

  • description: create deposit trade

Request

Request url

POST /api/v1/users/deposits

Headers

name type description required default
Dewt string Decentralized Web Token(DeWT) 是我們專為 TideBit-DeFi 設計的去中心化認證機制,為用戶登入時簽名的內容加上用戶簽名的結果進行 rlp 編碼 true --

body

name type description required default
data IApplyDepositOrder create deposit data true -
txHash string transaction hash return from lunar true -

Request Example

POST /api/v1/users/deposits

const body = {
    data: {
      orderType: "DEPOSIT",
      createTimestamp: 1679023233,
      targetAsset: "ETH",
      targetAmount: 7.91,
      decimals: 18,
      to: "0xb54898DB1250A6a629E5B566367E9C60a7Dd6C30",
      remark: "",
      fee: 0,
    },
    txHash: "0x75cc63d3fbd0fbf8e6dbfa88885b7126a96fc2e983edb7b14eafbe9cc13b89e45"
}

Headers:
    DeWT: <DeWT>

Response

Response Parameters

name type description
powerby string TideBit-DeFi api 1.0.0
success boolean request 成功或失敗
code string response code
message string description of response data
payload IAcceptedDepositOrder[] | null response data

Response Example

  • 成功的回傳
{
    "powerby": "TideBit-DeFi api 1.0.0",
    "success": true,
    "code":  "00000000",
    "message": "result of deposit trade",
    "payload": {
        "id": "TBAcceptedDeposit20230317ETH",
        "orderType": "DEPOSIT",
        "createTimestamp": 1679023233,
        "orderStatus": "SUCCESS",
        "targetAsset": "ETH",
        "decimals": "18",
        "targetAmount": "7.91",
        "to": "0xb54898DB1250A6a629E5B566367E9C60a7Dd6C30",
        "fee": "0",
    },
}
  • 失敗的回傳
{
    "powerby": "TideBit-DeFi api 1.0.0",
    "success": false,
    "code":  "09000000",
    "message": "bad input parameterr",
    "payload": null
}

listWithdrawTrades

  • description: list user withdraws, will return a list of acceptedWithdrawOrder

Request

Request url

GET /api/v1/users/withdraws

Headers

name type description required default
Dewt string Decentralized Web Token(DeWT) 是我們專為 TideBit-DeFi 設計的去中心化認證機制,為用戶登入時簽名的內容加上用戶簽名的結果進行 rlp 編碼 true --

Parameters

name type description required default

Request Example

GET /api/v1/users/withdraws
Headers:
    DeWT: <DeWT>

Response

Response Parameters

name type description
powerby string TideBit-DeFi api 1.0.0
success boolean request 成功或失敗
code string response code
message string description of response data
payload IAcceptedWithdrawOrder[] | null response data

Response Example

  • 成功的回傳
{
    "powerby": "TideBit-DeFi api 1.0.0",
    "success": true,
    "code":  "00000000",
    "message": -,
    "payload": -,
}
  • 失敗的回傳
{
    "powerby": "TideBit-DeFi api 1.0.0",
    "success": false,
    "code":  "09000000",
    "message": "bad input parameterr",
    "payload": null
}

createWithdrawTrade

  • description: create withdraw trade

Request

Request url

POST /api/v1/users/withdraws

Headers

name type description required default
Dewt string Decentralized Web Token(DeWT) 是我們專為 TideBit-DeFi 設計的去中心化認證機制,為用戶登入時簽名的內容加上用戶簽名的結果進行 rlp 編碼 true --

body

name type description required default
data IApplyWithdrawOrder create cfd data true -
signature string signature of eip712 withdraw order contract true -

Request Example

POST /api/v1/users/withdraws

const body = {
    data: {
      orderType: "WITHDRAW",
      createTimestamp: 1679023233,
      targetAsset: "ETH",
      targetAmount: 1,
      decimals: 18,
      to: "0xdAC17F958D2ee523a2206206994597C13D831ec7",
      remark: "",
      fee: 0,
    },
    signature: "0x75cc63d3fbd0fbf8e6dbfa88885b7126a96fc2e983edb7b14eafbe9cc13b89e456ed84696b5d350ae40b35e8b51c8a262d6459082eb67a461c660b2435da82da1b"
}

Headers:
    DeWT: <DeWT>

Response

Response Parameters

name type description
powerby string TideBit-DeFi api 1.0.0
success boolean request 成功或失敗
code string response code
message string description of response data
payload IAcceptedWithdrawOrder[] | null response data

Response Example

  • 成功的回傳
{
    "powerby": "TideBit-DeFi api 1.0.0",
    "success": true,
    "code":  "00000000",
    "message": "result of withdraw trade",
    "payload": {
        "id": "TBAcceptedWithdraw20230317ETH",
        "orderType": "WITHDRAW",
        "createTimestamp": "1679023233",
        "targetAsset": "ETH",
        "targetAmount": "1",
        "decimals": "18",
        "to": "0xdAC17F958D2ee523a2206206994597C13D831ec7",
        "remark": "",
        "fee": "0",
    }
}
  • 失敗的回傳
{
    "powerby": "TideBit-DeFi api 1.0.0",
    "success": false,
    "code":  "09000000",
    "message": "bad input parameterr",
    "payload": null
}

Enable Share CFD

  • description: enable Share CFD

Request

Request url

PUT /api/v1/cfds/share/:id

Headers

name type description required default
Dewt string Decentralized Web Token(DeWT) 是我們專為 TideBit-DeFi 設計的去中心化認證機制,為用戶登入時簽名的內容加上用戶簽名的結果進行 rlp 編碼 true --

body

name type description required default
share boolean 是否要開啟 share 功能,只有狀態為 close 的 CFD 可以被開啟 share 功能 true -

Request Example

PUT /cfds/share/0x7b00fb9554119
const body = {
    share: true,
    }
Headers:
    DeWT: <DeWT>

Response

Response Parameters

name type description
powerby string TideBit-DeFi api 1.0.0
success boolean request 成功或失敗
code string response code
message string description of response data
payload CFDOrder | null response data

Response Example

  • 成功的回傳
{
    "powerby": "TideBit-DeFi api 1.0.0",
    "success": true,
    "code":  "00000000",
    "message": "result of enable shared CFD trade",
    "payload":{
        "orderType": "CFD",
        "id": "0x7b00fb9554119",
        "txhash": "0xe7a77f1a7baab",
        "orderStatus": "PROCESSING",
        "state": "CLOSED",
        "ticker": "ETH-USDT",
        "userAddress": "0xfc657dAf7D901982a75ee4eCD4bDCF93bd767CA4",
        "targetAsset": "ETH",
        "unitAsset": "USDT",
        "margin": {
            "amount": 1,
            "asset": "USDT"
        },
        "openPrice": 1995,
        "amount": 0.00075,
        "fee": 0,
        "typeOfPosition": "SELL",
        "leverage": 5,
        "guaranteedStop": false,
        "liquidationPrice": 1706.0036283,
        "liquidationTime": 1682586722,
        "share": true,
        "updatedTimestamp": 1684229674,
        "createTimestamp": 1684225444,
        "closePrice": 1885.8700549999999,
        "closedType": "TAKE_PROFIT",
        "closeTimestamp": 1684229674,
        "forcedClose": false,
        "pnl": {
            "type": "PROFIT",
            "value": 0.08184745875000021
        }
    }
}
  • 失敗的回傳
{
    "powerby": "TideBit-DeFi api 1.0.0",
    "success": false,
    "code":  "09000000",
    "message": "bad input parameter",
    "payload": null
}
Clone this wiki locally