获取兑换汇率

接口汇率更新频率

提供两个币种之间兑换的汇率,汇率更新频率为:4~6s

1. 接口调用:

https://{host}/api/v1/getBaseInfo

2. 请求参数实例

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.返回参数说明

代码示例

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字段,手续费固定收取存入原币的千分之二(即:存入0.1btc,实际会扣取0.0002btc作为兑换的手续费,实际兑换时,只拿0.0998btc去做兑换)

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

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

= (depositCoinAmt - depositCoinAmt * depositCoinFeeRate) * instantRate - chainFee

响应数据

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

业务参考图

Last updated