Official SDK
Last updated
Last updated
You can find the official SDK and usage examples here: 🌐
javaCopyEdit/**
* Generate request signature
*/
private String toSign(String timestamp, String method, String requestPath,
String queryString, String body, String secretKey) throws Exception {
String preHash = preHash(timestamp, method, requestPath, queryString, body);
SecretKeySpec secretKeySpec = new SecretKeySpec(secretKey.getBytes("UTF-8"), "HmacSHA256");
Mac mac = Mac.getInstance("HmacSHA256");
mac.init(secretKeySpec);
return Hex.encodeHexString(mac.doFinal(preHash.getBytes("UTF-8")));
}
/**
* Construct the string to be signed
*/
private String preHash(String timestamp, String method, String requestPath,
String queryString, String body) {
StringBuilder preHash = new StringBuilder()
.append(timestamp)
.append(method.toUpperCase())
.append(requestPath);
if (StringUtils.isNotEmpty(queryString)) {
preHash.append("?").append(queryString);
}
if (StringUtils.isNotEmpty(body)) {
preHash.append(body);
}
return preHash.toString();
}
/**
* Extract query string from request URL
*/
private String queryString(ServerHttpRequest request) {
String url = request.getURI().toString();
return url.contains("?") ? url.substring(url.lastIndexOf("?") + 1) : "";
}
javaCopyEditOkHttpClient client = new OkHttpClient();
MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, "{\"symbol\":\"BTCUSDT\",\"volume\":1,\"side\":\"BUY\",\"type\":\"LIMIT\",\"price\":10000}");
Request request = new Request.Builder()
.url("https://openapi.coinlocally.com/sapi/v2/order")
.post(body)
.addHeader("X-CH-APIKEY", "Your API key")
.addHeader("X-CH-TS", "1596543296058")
.addHeader("X-CH-SIGN", "encrypted-signature")
.addHeader("Content-Type", "application/json")
.build();
Response response = client.newCall(request).execute();
pythonCopyEditimport requests
url = "https://openapi.coinlocally.com/sapi/v2/order"
headers = {
"X-CH-APIKEY": "Your API key",
"X-CH-TS": "1596543881257",
"X-CH-SIGN": "encrypted-signature",
"Content-Type": "application/json"
}
payload = {
"symbol": "BTCUSDT",
"volume": 1,
"side": "BUY",
"type": "LIMIT",
"price": 10000
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)
goCopyEditpackage main
import (
"net/http"
"strings"
"fmt"
"io/ioutil"
)
func main() {
payload := strings.NewReader(`{"symbol":"BTCUSDT","volume":1,"side":"BUY","type":"LIMIT","price":10000}`)
req, _ := http.NewRequest("POST", "https://openapi.coinlocally.com/sapi/v2/order", payload)
req.Header.Add("X-CH-APIKEY", "Your API key")
req.Header.Add("X-CH-TS", "1596543881257")
req.Header.Add("X-CH-SIGN", "encrypted-signature")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := ioutil.ReadAll(res.Body)
fmt.Println(string(body))
}
phpCopyEdit<?php
require_once 'HTTP/Request2.php';
$request = new HTTP_Request2();
$request->setUrl('https://openapi.coinlocally.com/sapi/v2/order');
$request->setMethod(HTTP_Request2::METHOD_POST);
$request->setHeader([
'X-CH-APIKEY' => 'Your API key',
'X-CH-TS' => '1596543881257',
'X-CH-SIGN' => 'encrypted-signature',
'Content-Type' => 'application/json'
]);
$request->setBody('{"symbol":"BTCUSDT","volume":1,"side":"BUY","type":"LIMIT","price":10000}');
try {
$response = $request->send();
echo $response->getBody();
} catch (HTTP_Request2_Exception $e) {
echo 'Error: ' . $e->getMessage();
}
?>
jsCopyEditconst request = require('request');
const options = {
method: 'POST',
url: 'https://openapi.coinlocally.com/sapi/v2/order',
headers: {
'X-CH-APIKEY': 'Your API key',
'X-CH-TS': '1596543881257',
'X-CH-SIGN': 'encrypted-signature',
'Content-Type': 'application/json'
},
body: JSON.stringify({
symbol: "BTCUSDT",
volume: 1,
side: "BUY",
type: "LIMIT",
price: 10000
})
};
request(options, (error, response) => {
if (error) throw new Error(error);
console.log(response.body);
});