Skip to content

Instantly share code, notes, and snippets.

@Sagleft
Last active September 26, 2020 11:33
Show Gist options
  • Save Sagleft/6078fb4f9014f9d0fcf030c515460e3b to your computer and use it in GitHub Desktop.
Save Sagleft/6078fb4f9014f9d0fcf030c515460e3b to your computer and use it in GitHub Desktop.

Let's look at the ZG.com exchange API to get data about Crypton.

We will make GET requests to the REST API. Let's use the CRPUSDT trading pair as an example.

reference

1. Market depth

https://api.zg.com/openapi/quote/v1/depth?symbol=CRPUSDT&limit=10

response example:

{"time":1601045223157,"bids":[["0.11","5555.67"],["0.1071","88.25"],["0.107","9.8"],["0.1019","183.9"],["0.1001","1368.33"],["0.0901","56.01"],["0.09","275.77"],["0.08","619"],["0.076","30"],["0.0701","204.88"]],"asks":[["0.1232","93.03"],["0.125","17.8"],["0.13","500"],["0.135","500"],["0.14","500"],["0.145","500"],["0.15","500"],["0.155","500"],["0.16","500"],["0.165","500"]]}

2. Recent trades list

https://api.zg.com/openapi/quote/v1/trades?symbol=CRPUSDT&limit=10

response example:

[{"price":"0.1122","time":1601045251276,"qty":"85.04","isBuyerMaker":false},{"price":"0.1204","time":1601045257621,"qty":"65.72","isBuyerMaker":true},{"price":"0.1153","time":1601045269979,"qty":"25.98","isBuyerMaker":true},{"price":"0.1171","time":1601045279329,"qty":"43.05","isBuyerMaker":true},{"price":"0.1159","time":1601045290677,"qty":"33.35","isBuyerMaker":false},{"price":"0.1135","time":1601045295047,"qty":"23.28","isBuyerMaker":false},{"price":"0.116","time":1601045305773,"qty":"64.99","isBuyerMaker":false},{"price":"0.1154","time":1601045310132,"qty":"77.35","isBuyerMaker":false},{"price":"0.1151","time":1601045319452,"qty":"77.7","isBuyerMaker":false},{"price":"0.1154","time":1601045334032,"qty":"78.36","isBuyerMaker":true}]

3. Kline/Candlestick data

https://api.zg.com/openapi/quote/v1/klines?symbol=CRPUSDT&limit=20&interval=4h

Name Type Mandatory Description
symbol STRING YES
interval ENUM YES
startTime LONG NO
endTime LONG NO
limit INT NO Default 500; max 1000.

response exampe:

[[1600761600000,"0.125","0.1294","0.1016","0.1128","54435.3",0,"6441.902546",966,"0","0"],[1600776000000,"0.1128","0.1241","0.111","0.1155","50654.51",0,"6025.558982",943,"0","0"],[1600790400000,"0.1155","0.1236","0.1155","0.1226","27833.62",0,"3354.554406",521,"0","0"],[1600804800000,"0.1226","0.1294","0.1162","0.1237","54521.77",0,"6788.67176",1038,"0","0"],[1600819200000,"0.1237","0.1293","0.1188","0.124","31307.93",0,"3896.783363",604,"0","0"],[1600833600000,"0.124","0.124","0.124","0.124","0",0,"0",0,"0","0"],[1600848000000,"0.124","0.124","0.1155","0.1155","675.71",0,"78.866007",3,"0","0"],[1600862400000,"0.1155","0.1155","0.1155","0.1155","36.22",0,"4.18341",1,"0","0"],[1600876800000,"0.1155","0.1194","0.0934","0.1098","70011.03",0,"7813.32322",1240,"0","0"],[1600891200000,"0.1098","0.1196","0.1011","0.1072","88950.28",0,"9844.572595",1579,"0","0"],[1600905600000,"0.1072","0.1188","0.1004","0.1019","34957.18",0,"3804.196654",612,"0","0"],[1600920000000,"0.1019","0.1019","0.1019","0.1019","199.6",0,"20.33924",1,"0","0"],[1600934400000,"0.1019","0.1192","0.1019","0.1177","6668.15",0,"760.789485",125,"0","0"],[1600948800000,"0.1177","0.1193","0.1078","0.1186","75247.13",0,"8593.824456",1346,"0","0"],[1600963200000,"0.1186","0.1193","0.1078","0.1121","70638.03",0,"8069.327455",1285,"0","0"],[1600977600000,"0.1121","0.1193","0.1078","0.1145","72337.9",0,"8262.730587",1325,"0","0"],[1600992000000,"0.1145","0.1193","0.1071","0.1132","71109.61",0,"8120.575937",1290,"0","0"],[1601006400000,"0.1132","0.114","0.1075","0.1124","34418.33",0,"3842.151151",623,"0","0"],[1601020800000,"0.1124","0.125","0.1076","0.1158","51980.78",0,"6050.697118",922,"0","0"],[1601035200000,"0.1158","0.1242","0.11","0.1202","58952.89",0,"6951.076279",1057,"0","0"]]

4. 24hr ticker price change statistics

https://api.zg.com/openapi/quote/v1/ticker/24hr?symbol=CRPUSDT

response example:

{"time":1601046725560,"symbol":"CRPUSDT","bestBidPrice":"0.11","bestAskPrice":"0.1232","volume":"379887.14","quoteVolume":"43821.968534","lastPrice":"0.1214","highPrice":"0.125","lowPrice":"0.1071","openPrice":"0.1193"}

5. Symbol price ticker

https://api.zg.com/openapi/quote/v1/ticker/price?symbol=CRPUSDT

response example:

{"symbol":"CRPUSDT","price":"0.111"}

6. Symbol order book ticker

https://api.zg.com/openapi/quote/v1/ticker/bookTicker?symbol=CRPUSDT

response example:

{"symbol":"CRPUSDT","bidPrice":"0.11","bidQty":"5555.67","askPrice":"0.1232","askQty":"93.03","time":1601046894525}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment