안녕하세요,
코인원 API를 사용하고 싶은데 문제가 있어서 고수님들의 도움이 필요합니다ㅠ
예제처럼 파이썬으로 개발하는건 아니고 자바로 코드 변경해서 제작중입니다.
API중 limit_buy 을 사용하고 싶은데 계속 V2 API body is corrupted 에러가 납니다.
https://api.coinone.co.kr/v2/order/limit_buy/
코인원 API에 나와있는데로 encoded_payload를 body로 넘겨주는데 도데체 왜그러는걸까요ㅠㅠ
혹시 비슷한 문제가 있었던 분이 계실까요?ㅠ
----------------
def get_response(action, payload):
url = '{}{}'.format('https://api.coinone.co.kr/', action) encoded_payload = get_encoded_payload(payload) headers = { 'Content-type': 'application/json', 'X-COINONE-PAYLOAD': encoded_payload, 'X-COINONE-SIGNATURE': get_signature(encoded_payload), } http = httplib2.Http() response, content = http.request(url, 'POST', body=encoded_payload, headers=headers) return content
---------------
고수님들 조언 부탁드립니다ㅠㅠ
----------------
public void sendTest(String strHost, String strMemod, HashMap<String, Object> rgParams, HashMap<String, String> httpHeaders){
try {
// Define the server endpoint to send the HTTP request to
Integer nNonce = usecTime();
JSONObject payload = getCoinonePayload(api_key, nNonce, rgParams);
String encodedPayload = getEncodedPayload(payload.toString(), api_secret);
String signature = getSignature(encodedPayload, api_secret.toUpperCase());
URL serverUrl =
new URL(strHost);
HttpURLConnection urlConnection = (HttpURLConnection)serverUrl.openConnection();
// Indicate that we want to write to the HTTP request body
urlConnection.setDoOutput(true);
urlConnection.setRequestMethod("POST");
urlConnection.setRequestProperty("Content-Type", "application/json");
urlConnection.setRequestProperty("X-COINONE-PAYLOAD", encodedPayload);
urlConnection.setRequestProperty("X-COINONE-SIGNATURE", signature);
// Writing the post data to the HTTP request body
BufferedWriter httpRequestBodyWriter =
new BufferedWriter(new OutputStreamWriter(urlConnection.getOutputStream()));
httpRequestBodyWriter.write(encodedPayload);
httpRequestBodyWriter.close();
// Reading from the HTTP response body
Scanner httpResponseScanner = new Scanner(urlConnection.getInputStream());
while(httpResponseScanner.hasNextLine()) {
System.out.println(httpResponseScanner.nextLine());
}
httpResponseScanner.close();
} catch (ProtocolException ex) {
Logger.getLogger(CoinoneApi.class.getName()).log(Level.SEVERE, null, ex);
} catch (MalformedURLException ex) {
Logger.getLogger(CoinoneApi.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
Logger.getLogger(CoinoneApi.class.getName()).log(Level.SEVERE, null, ex);
}
}
public String getEncodedPayload(String payload, String apiSecret){
String encodedPayload = asHex(hmacSha512(payload, apiSecret));
return encodedPayload;
}
public String getSignature(String encodedPayload, String apiSecret){
String signature = asHex(hmacSha512(encodedPayload, apiSecret));
return signature;
}
public JSONObject getCoinonePayload(String accessToken, Integer nonce, HashMap<String, Object> rgData){
JSONObject payload = new JSONObject();
payload.put("access_token", accessToken);
payload.put("nonce", nonce);
for(Map.Entry<String, Object> entry : rgData.entrySet()){
payload.put(entry.getKey(), entry.getValue());
}
return payload;
}
----------
payload는 아래와 같습니다.
{"access_token":"my access_token","price":1902,"qty":1.3287,"currency":"XTZ","nonce":1557935577}
-------------------------------------
꼬리말
* 게시글 내용 삭제시 레벨 강등
* 질문은 각 주제별 게시판에 적어주세요.
비트코인 암호화화폐 커뮤니티 땡글~ 땡글~
-------------------------------------