This repository has been archived by the owner on Jun 8, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 217
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #329 from henryxwong/bitmex-merge
Bitmex misc merge
- Loading branch information
Showing
28 changed files
with
2,010 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
bitmex.api.key= | ||
bitmex.secret.key= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
xchange-bitmex/src/main/java/info/bitrich/xchangestream/bitmex/BitmexAuthenticator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package info.bitrich.xchangestream.bitmex; | ||
|
||
import javax.crypto.Mac; | ||
import javax.crypto.spec.SecretKeySpec; | ||
import java.nio.charset.Charset; | ||
|
||
/** | ||
* Created by heath on 2018/3/1. | ||
*/ | ||
public class BitmexAuthenticator { | ||
|
||
public static String getSHA256String(String str, String key) { | ||
|
||
try { | ||
Charset asciiCs = Charset.forName("US-ASCII"); | ||
SecretKeySpec signingKey = new SecretKeySpec(asciiCs.encode(key).array(), "HmacSHA256"); | ||
Mac sha256_HMAC = Mac.getInstance("HmacSHA256"); | ||
sha256_HMAC.init(signingKey); | ||
byte[] mac_data = sha256_HMAC.doFinal(asciiCs.encode(str).array()); | ||
StringBuilder result = new StringBuilder(); | ||
for (final byte element : mac_data) { | ||
result.append(Integer.toString((element & 0xff) + 0x100, 16).substring(1)); | ||
} | ||
// System.out.println("SHA256String Result:[" + result + "]"); | ||
return result.toString().toUpperCase(); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
return null; | ||
} | ||
|
||
public static String generateSignature(String secret, String verb, String url, String nonce, String data) { | ||
String message = verb + url + nonce + data; | ||
// System.out.println(message); | ||
return getSHA256String(message, secret); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.