DataFlex
DataFlex
Bitfinex v2 REST Public Trades
See more Bitfinex v2 REST Examples
The trades endpoint allows the retrieval of past public trades and includes details such as price, size, and time. Optional parameters can be used to limit the number of results; you can specify a start and end timestamp, a limit, and a sorting method.Chilkat DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Handle hoHttp
Variant vSbResponseBody
Handle hoSbResponseBody
Handle hoJarrResp
Integer iRespStatusCode
Variant vJarr_trade
Handle hoJarr_trade
Integer i
Integer iCount_i
String sTrade_id
String sMts
String sAmount
String sPrice
String sTemp1
Move False To iSuccess
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
Get Create (RefClass(cComChilkatHttp)) To hoHttp
If (Not(IsComObjectCreated(hoHttp))) Begin
Send CreateComObject of hoHttp
End
// Implements the following CURL command:
// curl https://api-pub.bitfinex.com/v2/trades/tBTCUSD/hist?limit=5
// Use the following online tool to generate HTTP code from a CURL command
// Convert a cURL Command to HTTP Source Code
Get Create (RefClass(cComChilkatStringBuilder)) To hoSbResponseBody
If (Not(IsComObjectCreated(hoSbResponseBody))) Begin
Send CreateComObject of hoSbResponseBody
End
Get pvComObject of hoSbResponseBody to vSbResponseBody
Get ComQuickGetSb Of hoHttp "https://api-pub.bitfinex.com/v2/trades/tBTCUSD/hist?limit=5" vSbResponseBody To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoHttp To sTemp1
Showln sTemp1
Procedure_Return
End
Get Create (RefClass(cComChilkatJsonArray)) To hoJarrResp
If (Not(IsComObjectCreated(hoJarrResp))) Begin
Send CreateComObject of hoJarrResp
End
Get pvComObject of hoSbResponseBody to vSbResponseBody
Get ComLoadSb Of hoJarrResp vSbResponseBody To iSuccess
Set ComEmitCompact Of hoJarrResp To False
Showln "Response Body:"
Get ComEmit Of hoJarrResp To sTemp1
Showln sTemp1
Get ComLastStatus Of hoHttp To iRespStatusCode
Showln "Response Status Code = " iRespStatusCode
If (iRespStatusCode >= 400) Begin
Showln "Response Header:"
Get ComLastHeader Of hoHttp To sTemp1
Showln sTemp1
Showln "Failed."
Procedure_Return
End
// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)
// on trading pairs (ex. tBTCUSD)
// [
// [
// ID,
// MTS,
// AMOUNT,
// PRICE
// ]
// ]
// [
// [
// 472164271,
// 1594077725121,
// -0.15101673,
// 9370
// ],
// [
// 472164270,
// 1594077723860,
// -0.015,
// 9370
// ],
// [
// 472164269,
// 1594077720208,
// -0.015,
// 9370
// ],
// [
// 472164267,
// 1594077718125,
// -0.005,
// 9370
// ],
// [
// 472164251,
// 1594077697587,
// -0.015,
// 9370
// ]
// ]
// Sample code for parsing the JSON response...
// Use the following online tool to generate parsing code from sample JSON:
// Generate Parsing Code from JSON
Get Create (RefClass(cComChilkatJsonArray)) To hoJarr_trade
If (Not(IsComObjectCreated(hoJarr_trade))) Begin
Send CreateComObject of hoJarr_trade
End
Move 0 To i
Get ComSize Of hoJarrResp To iCount_i
While (i < iCount_i)
Get pvComObject of hoJarr_trade to vJarr_trade
Get ComArrayAt2 Of hoJarrResp i vJarr_trade To iSuccess
Get ComStringAt Of hoJarr_trade 0 To sTrade_id
Get ComStringAt Of hoJarr_trade 1 To sMts
Get ComStringAt Of hoJarr_trade 2 To sAmount
Get ComStringAt Of hoJarr_trade 3 To sPrice
Move (i + 1) To i
Loop
End_Procedure