Links

获取兑换汇率

接口汇率更新频率

提供两个币种之间兑换的汇率,汇率更新频率为:4~6s
1. 接口调用:
https://{host}/api/v1/getBaseInfo
2. 请求参数实例
参数
是否必须
说明
depositCoinCode
BTC
receiveCoinCode
ETH
depositCoinAmt
原币数量
3.请求参数示例
{
"depositCoinCode":"ETH",
"receiveCoinCode":"BNB(BSC)",
"depositCoinAmt":"1.5"
}
4.返回结果示例
{
"data": {
"chainFee": "0.001",//兑换完成后发币网络手续费
"depositCoinFeeRate": "0.002",//兑换手续费率,兑换手续费 = 存币数量 * depositCoinFeeRate
"depositMax": "14",//最大存币范围
"depositMin": "0.038603",//最小存币范围
"instantRate": "6.875775974236",//当前汇率
"burnRate": "0"//燃烧率
"isSupportNoGas": true //是否支持免 gas 兑换,
"isSupport": true //该币对是否支持兑换
},
"resCode": "800",
"resMsg": "成功",
"resMsgEn": ""
}
5.返回参数说明
字段名称
字段
数据类型
备注
即时汇率
instantRate
String
"精确到小数点后十位 接收货币/存入货币的汇率"
最低存储额
depositMin
String
精确到小数点后六位
最高存储额
depositMax
String
精确到小数点后六位
兑换手续费
depositCoinFeeRate
String
精确到小数点后六位
发币手续费
chainFee
String
精确到小数点后六位
燃烧率
burnRate
String
燃烧率 默认为0
是否支持免 gas 兑换
isSupportNoGas
Boolean
true/false
是否支持兑换
isSupport
Boolean
true/false

代码示例

java代码示例

OkHttpClient client = new OkHttpClient();
MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, "{\"depositCoinCode\":\"BTC\",\"receiveCoinCode\":\"ETH\"}");
Request request = new Request.Builder()
.url("https://{host}/api/v1/getBaseInfo")
.post(body)
.addHeader("Content-Type", "application/json")
.addHeader("cache-control", "no-cache")
.build();
Response response = client.newCall(request).execute();

C# 代码示例

var client = new RestClient("${host}/api/v1/getBaseInfo");
var request = new RestRequest(Method.POST);
request.AddHeader("cache-control", "no-cache");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("undefined", "{\"depositCoinCode\":\"BTC\",\"receiveCoinCode\":\"ETH\"}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);

Objective-C 代码示例

#import <Foundation/Foundation.h>
NSDictionary *headers = @{ @"Content-Type": @"application/json",
@"cache-control": @"no-cache" };
NSDictionary *parameters = @{ @"depositCoinCode": @"BTC",
@"receiveCoinCode": @"ETH" };
NSData *postData = [NSJSONSerialization dataWithJSONObject:parameters options:0 error:nil];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"https://{host}/api/v1/getBaseInfo"]
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:10.0];
[request setHTTPMethod:@"POST"];
[request setAllHTTPHeaderFields:headers];
[request setHTTPBody:postData];
NSURLSession *session = [NSURLSession sharedSession];
NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request
completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
if (error) {
NSLog(@"%@", error);
} else {
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *) response;
NSLog(@"%@", httpResponse);
}
}];
[dataTask resume];

Nodejs代码示例

//getToken example
import axios from 'axios'
const params = {
depositCoinCode: 'ETH',
receiveCoinCode: 'BNB(BSC)',
}
const res = await axios.post('https://{host}/api/v1/getBaseInfo', params )
console.log(res)

Postman示例

返回结果示例

{
"data": {
"chainFee": "0.001",//兑换完成后发币网络手续费
"depositCoinFeeRate": "0.002",//兑换手续费率,兑换手续费 = 存币数量 * depositCoinFeeRate
"depositMax": "14",//最大存币范围
"depositMin": "0.038603",//最小存币范围
"instantRate": "6.875775974236",//当前汇率
"burnRate": "0",//燃烧率
"isSupportNoGas": true //是否支持免 gas 兑换
},
"resCode": "800",
"resMsg": "成功",
"resMsgEn": ""
}

特殊字段说明

字段
说明
minerFee
该值用于中心化兑换,存入币种使用SWFTC作为手续费时的汇率值,SWFTC手续费 = 存币数量 * minerFee
depositCoinFeeRate
该值为兑换手续费率,SWFT兑换手续费 = 存币数量 * depositCoinFeeRate
chainFee
该值用于去中心化兑换,同receiveCoinFee,兑换成功后发币时扣取的网络手续费,单位为接收币币种,可用于提前计算用户大致接收到的币的数量,或用于显示用户即将扣除发币网络手续费的数量

注意事项

因为去中心化兑换,用户的手续费方式为原币,非SWFTC,因此可以忽略minerFee字段,手续费固定收取存入原币的千分之二(即:存入0.1btc,实际会扣取0.0002btc作为兑换的手续费,实际兑换时,只拿0.0998btc去做兑换)

计算用户兑换实际到账数量

实际到账数量 = (用户存币数量 - 兑换手续费数量)* 汇率 - 链上发币网络手续费
= (depositCoinAmt - depositCoinAmt * depositCoinFeeRate) * instantRate - chainFee

响应数据

参数参见API接口文档 获取汇率接口

业务参考图