首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Satang api私有http请求

Satang api私有http请求
EN

Stack Overflow用户
提问于 2019-09-11 17:07:24
回答 2查看 139关注 0票数 1

我将在java中使用satang api。这是一本参考书。https://docs.satang.pro/authentication

我已经用java完成了公共请求代码。

代码语言:javascript
运行
复制
private String publicOperation(String operation) throws IOException, BadResponseException {

    StringBuilder result = new StringBuilder();
    URL url = new URL(baseUrl+operation);
    //URL url_ = new URL("https://api.tdax.com/api/orders/?pair=btc_thb");
    HttpURLConnection con = (HttpURLConnection) url.openConnection();
    con.setRequestProperty("User-Agent", "java client");
    con.setRequestMethod("GET");

    //https://api.tdax.com/api/orders/?pair=btc_thb
    int responseCode=con.getResponseCode();

    if(responseCode!=HttpURLConnection.HTTP_OK){
        throw new BadResponseException(responseCode);
    }
    BufferedReader rd = new BufferedReader(new InputStreamReader(con.getInputStream()));

    String line;
    while ((line = rd.readLine()) != null) {
        result.append(line);
    }
    rd.close();
    return result.toString();
}

谁可以用任何编程语言发出私有的http请求?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2019-11-06 22:38:25

代码语言:javascript
运行
复制
public String placeLimitOrder(String amount,String pair,String price,String side) throws IOException, BadResponseException
{
    Long lnonce=new Date().getTime();
    String nonce=lnonce.toString();
    String req="amount="+amount+"&nonce="+nonce+"&pair="+pair+"&price="+price+"&side="+side+"&type=limit";
    String operation="orders/";
    String signature=getSignature(req);
    URL url = new URL(baseUrl+operation);
    HttpURLConnection con = (HttpURLConnection) url.openConnection();
    con.setRequestMethod("POST");
    con.setDoOutput( true );
    con.setInstanceFollowRedirects( false );

    con.setRequestProperty("Authorization", "TDAX-API "+this.key);
    con.setRequestProperty("Signature",signature);
    con.setRequestProperty("Content-Type", "application/json"); 
    con.setRequestProperty("charset", "utf-8");
    con.setRequestProperty("User-Agent", "java client");
    con.setUseCaches( false );

    JsonObject obj=new JsonObject();
    obj.addProperty("amount", amount);
    obj.addProperty("nonce", nonce);
    obj.addProperty("pair", pair);
    obj.addProperty("price", price);
    obj.addProperty("side", side);
    obj.addProperty("type", "limit");
    String json=obj.toString();

    DataOutputStream wr = new DataOutputStream(con.getOutputStream());
    wr.writeBytes(json);
    wr.flush();
    wr.close();

    int responseCode=con.getResponseCode();

    if(responseCode!=HttpURLConnection.HTTP_OK){
        throw new BadResponseException(responseCode);
    }
    BufferedReader rd = new BufferedReader(new InputStreamReader(con.getInputStream()));

    StringBuilder result = new StringBuilder();
    String line;
    while ((line = rd.readLine()) != null) {
        result.append(line);
    }
    rd.close();
    return result.toString();
}
票数 0
EN

Stack Overflow用户

发布于 2019-09-24 11:05:53

我也有同样的问题,但我使用google sheet导入

代码语言:javascript
运行
复制
function satang(){
  var rows=[],obj_array=null;
  try {obj_array=JSON.parse(UrlFetchApp.fetch("https://api.tdax.com/api/orders/?pair=btc_thb").getContentText());} catch (e) {obj_array=null;}
  if (obj_array!=null){
    for (r in obj_array) {rows.push([parseFloat(obj_array[r].bid),parseFloat(obj_array[r].price),parseFloat(obj_array[r].amount),parseFloat(obj_array[r].ask)]);}
    var ss=SpreadsheetApp.getActiveSpreadsheet(),sheet=ss.getSheetByName('Satang');ss.getRange("Satang!A1").setValue(new Date());
    try {var range=sheet.getRange(2,1,sheet.getLastRow(),6).clearContent();} catch(e) {Logger.log("error");}
    if (rows==null||rows=="") {Browser.msgBox("Oops, no data from satang. Please try again"); return false;}
    range=sheet.getRange(2,1,rows.length,4); range.setValues(rows); 
  }
}
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57885715

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档