摘要:完整的步驟如下檢查比特幣或的余額,錢包地址。比特幣的到帳時間是個塊的高度,約分鐘。
方案一: 通過ExinCore API進行幣幣交易
Exincore 提供了基于Mixin Network的幣幣交易API.
你可以支付USDT給ExinCore, ExinCore會以最低的價格,最優惠的交易費將你購買的比特幣轉給你, 每一幣交易都是匿名的,并且可以在鏈上進行驗證,交易的細節只有你與ExinCore知道!
ExinCore 也不知道你是誰,它只知道你的UUID.
預備知識:你先需要創建一個機器人, 方法在 教程一.
安裝依賴包正如教程一里我們介紹過的, 我們需要依賴 mixin-java-sdk, 你應該先安裝過它了, 這兒我們再安裝其它的軟件包.
下載地址: mvnrepository
build.gradle.kts的dependencies,加入如下依賴的包:
implementation("com.google.guava:guava:27.0.1-jre") implementation("commons-codec:commons-codec:1.11") implementation("com.auth0:java-jwt:3.8.0") compile(files("libs/mixin-java-sdk.jar")) implementation("com.squareup.okhttp3:okhttp:3.12.1") implementation("com.squareup.okio:okio:2.2.2") implementation("com.google.code.gson:gson:2.8.5") implementation("org.bouncycastle:bcprov-jdk16:1.46") implementation("org.apache.commons:commons-csv:1.6") implementation("org.msgpack:msgpack-core:0.8.16") implementation("com.fasterxml.jackson.core:jackson-databind:2.9.8") implementation("com.fasterxml.jackson.core:jackson-core:2.9.8") implementation("org.jetbrains.kotlin:kotlin-stdlib:1.3.30")充幣到 Mixin Network, 并讀出它的余額.
通過ExinCore API, 可以進行BTC, USDT, EOS, ETH 等等交易, 此處演示用 USDT購買BTC 或者 用BTC購買USDT。交易前,先檢查一下錢包地址。
完整的步驟如下:
檢查比特幣或USDT的余額,錢包地址。并記下錢包地址。
從第三方交易所或者你的冷錢包中,將幣充到上述錢包地址。
再檢查一下幣的余額,看到帳與否。(比特幣的到帳時間是5個塊的高度,約100分鐘)。
比特幣與USDT的充值地址是一樣的。
private static final String BTC_ASSET_ID = "c6d0c728-2624-429b-8e0d-d9d19b6592fa"; private static final String EOS_ASSET_ID = "6cfe566e-4aad-470b-8c9a-2fd35b49c68d"; private static final String USDT_ASSET_ID = "815b0b1a-2764-3736-8faa-42d694fa620a"; MixinAPI mixinApiUser = generateAPI_FromCSV(); JsonObject asset = mixinApiUser.getAsset(BTC_ASSET_ID); System.out.println(asset); System.out.println("------------------------BTC------Information---------------------------"); System.out.println("The BTC wallet address is " + asset.get("public_key").getAsString()); System.out.println("The BTC wallet balance is " + asset.get("balance").getAsString()); System.out.println("-----------------------------------------------------------------------");查詢ExinCore市場的價格信息
如何來查詢ExinCore市場的價格信息呢?你要先了解你交易的基礎幣是什么,如果你想買比特幣,賣出USDT,那么基礎貨幣就是USDT;如果你想買USDT,賣出比特幣,那么基礎貨幣就是比特幣.
if ( input.equals("8") ) { JsonArray res = FetchExinOneMarketInfos(USDT_ASSET_ID); System.out.println("--exchange_asset--exchange_asset_symbol/base_asset_symbol--price--minimum--maximum--exchanges--"); // System.out.println(res); res.forEach((element) -> { JsonObject jsonObj = element.getAsJsonObject(); System.out.println(jsonObj.get("exchange_asset").getAsString() + " " + jsonObj.get("exchange_asset_symbol").getAsString() + "/" + jsonObj.get("base_asset_symbol").getAsString() + " " + jsonObj.get("price").getAsString() + " " + jsonObj.get("minimum_amount").getAsString() + " " + jsonObj.get("maximum_amount").getAsString() + " " + jsonObj.get("exchanges").getAsString() ); }); System.out.println("-----------------------------------------------------------------------"); } private static JsonArray FetchExinOneMarketInfos(String url) { OkHttpClient client = new OkHttpClient(); String baseUrl = "https://exinone.com/exincore/markets?base_asset="; String fullUrl = baseUrl + url; Request request = new Request.Builder() .url(fullUrl) .build(); try { Response response = client.newCall(request).execute(); if (!response.isSuccessful()) { throw new IOException("Unexpected code " + response); } return processJsonObjectWithDataOrError(response.body().string()); } catch(Exception e) { e.printStackTrace(); } return null; } public static JsonArray processJsonObjectWithDataOrError(String res) { JsonParser parser = new JsonParser(); JsonElement jsonTree = parser.parse(res); if ( jsonTree.isJsonObject() ) { if ( jsonTree.getAsJsonObject().get("data") != null ) { return jsonTree.getAsJsonObject().get("data").getAsJsonArray(); } } return null; }交易前,創建一個Memo!
在第二章里,基于Mixin Network的 Java 比特幣開發教程: 機器人接受比特幣并立即退還用戶, 我們學習過退還用戶比特幣,在這里,我們除了給ExinCore支付幣外,還要告訴他我們想購買的幣是什么,即將想購買的幣存到memo里。
public static String encodeUUID(UUID uuid) { try { byte[] byteUuid = asBytes(uuid); MessageBufferPacker packer = MessagePack.newDefaultBufferPacker(); packer.writePayload(byteUuid); packer.close(); byte[] packedData = packer.toByteArray(); byte[] prex = { (byte)129, (byte)161, 65, (byte)196, 16 }; ByteArrayOutputStream output = new ByteArrayOutputStream(); output.write(prex); output.write(packedData); byte[] out = output.toByteArray(); return Base64.getEncoder().encodeToString(out); } catch (Exception e) { e.printStackTrace(); } return null; }幣幣交易的完整流程
轉幣給ExinCore時,將memo寫入你希望購買的幣,否則,ExinCore會直接退幣給你!
如果你想賣出比特幣買入USDT,調用方式如下:
private static final String EXIN_BOT = "61103d28-3ac2-44a2-ae34-bd956070dab1"; private static final String BTC_ASSET_ID = "c6d0c728-2624-429b-8e0d-d9d19b6592fa"; private static final String EOS_ASSET_ID = "6cfe566e-4aad-470b-8c9a-2fd35b49c68d"; private static final String USDT_ASSET_ID = "815b0b1a-2764-3736-8faa-42d694fa620a"; private static final String BTC_WALLET_ADDR = "14T129GTbXXPGXXvZzVaNLRFPeHXD1C25C"; private static final String MASTER_UUID = "0b4f49dc-8fb4-4539-9a89-fb3afc613747"; if ( input.equals("5") ) { MixinAPI mixinApiUser = generateAPI_FromCSV(); UUID usdtUUID = UUID.fromString(USDT_ASSET_ID); String memoTarget = encodeUUID(usdtUUID); System.out.println("------------------------USDT-BTC-EXCHANGE----------------------------"); System.out.println(memoTarget); JsonObject asset = mixinApiUser.getAsset(BTC_ASSET_ID); System.out.println(asset); System.out.println(asset.get("balance").getAsFloat()); if ( (asset.get("balance").getAsFloat() * 10000) >= 1 ) { JsonObject transInfo = mixinApiUser.transfer(BTC_ASSET_ID, EXIN_BOT, "0.0001",memoTarget); System.out.println("------------------------BTC Transfer To EXCHANGE Information----------------------"); System.out.println(transInfo); System.out.println("-----------------------------------------------------------------------"); } else System.out.println("-----------------------------------------------------------------------"); }
如果你想賣出USDT買入比特幣,調用方式如下:
if ( input.equals("6") ) { MixinAPI mixinApiUser = generateAPI_FromCSV(); UUID btcUUID = UUID.fromString(BTC_ASSET_ID); String memoTarget = encodeUUID(btcUUID); System.out.println(memoTarget); System.out.println("-------------------------BTC-USDT-EXCHANGE----------------------------"); JsonObject asset = mixinApiUser.getAsset(BTC_ASSET_ID); System.out.println(asset); if ( asset.get("balance").getAsFloat() >= 1 ) { JsonObject transInfo = mixinApiUser.transfer(USDT_ASSET_ID, EXIN_BOT, "1",memoTarget); System.out.println("------------------------USDT-BTC EXCHANGE Information----------------------"); System.out.println(transInfo); System.out.println("-----------------------------------------------------------------------"); } else System.out.println("-----------------------------------------------------------------------"); }
交易完成后,Exincore會將你需要的幣轉到你的帳上,同樣,會在memo里,記錄成交價格,交易費用等信息!你只需要按下面的方式解開即可!
getSnapshots 讀取錢包的交易記錄。
if ( input.equals("7") ) { MixinAPI mixinApiUser = generateAPI_FromCSV(); String transDatetime = ""; String assetUUID = ""; if ( mixinApiUser.getClientID().equals("091651f2-19c3-34f0-b45e-724ff203d921") ) { transDatetime = "2019-04-19T06:53:22.593529Z"; assetUUID = USDT_ASSET_ID; } else { System.out.print("Input the transaction Date time (eg:2019-04-19T06:53:22.593529Z):"); transDatetime = System.console().readLine(); } JsonArray snapshots = mixinApiUser.getSnapshots(assetUUID,3,transDatetime,"ASC"); // System.out.println(snapshots); snapshots.forEach((element) -> { JsonObject jsonObj = element.getAsJsonObject(); if ( jsonObj.get("amount").getAsFloat() > 0 && jsonObj.get("data") != null ) { System.out.println(jsonObj.get("data").getAsString() ); try { byte[] encoded = Base64.getDecoder().decode(jsonObj.get("data").getAsString()); MessageUnpacker unpacker = MessagePack.newDefaultUnpacker(encoded); Value memoVal = unpacker.unpackValue(); if ( memoVal.isMapValue()) { Mapmap = memoVal.asMapValue().map(); System.out.println(map.size()); if ( map.get(ValueFactory.newString("C")).asIntegerValue().asInt() == 1000 ) { System.out.println("Exchange successful" + " Code: " + map.get(ValueFactory.newString("C")).asIntegerValue()); System.out.println("Price is " + map.get(ValueFactory.newString("P")).asStringValue()); System.out.println("Fee is " + map.get(ValueFactory.newString("F")).asStringValue()); System.out.println("Type is " + map.get(ValueFactory.newString("T")).asStringValue()); ByteBuffer AssetBinValue = map.get(ValueFactory.newString("FA")).asRawValue().asByteBuffer(); System.out.println("Fee is asset UUID is " + ByteBufferAsUuid(AssetBinValue)); ByteBuffer TraceBinValue = map.get(ValueFactory.newString("O")).asRawValue().asByteBuffer(); System.out.println("The trace id is " + ByteBufferAsUuid(TraceBinValue)); } } } catch(Exception e) { e.printStackTrace(); } } }); }
一次成功的交易如下:
Make your choose(eg: q for Exit!): 7 7 -------------------------get-Snapshots--------------------------------------------- hqFDzQPooVCnNTIyNi4wM6FGqTAuMDAxMDQ1MqJGQcQQgVsLGidkNzaPqkLWlPpiCqFUoVKhT8QQPAsBVqKtQ5uS67M/ZTNleg== Exchange successful Code: 1000 Price is 5226.03 Fee is 0.0010452 Type is R Fee is asset UUID is 815b0b1a-2764-3736-8faa-42d694fa620a The trace id is 3c0b0156-a2ad-439b-92eb-b33f6533657a ---------------------end-of-get-Snapshots---------------------------------------------讀取幣的余額
通過讀取幣的余額,來確認交易情況!
MixinAPI mixinApiUser = generateAPI_FromCSV(); JsonObject asset = mixinApiUser.getAsset(BTC_ASSET_ID);源代碼執行
編譯執行,即可開始交易了.
gradle build 編譯項目.
java -cp 運行項目.
java -cp .:build/libs/bitcoin_wallet-java.jar:libs/* bitcoin_wallet.java.App
注意:不能使用gradle run來運行,因為我們使用的System.console().readLine()不被Gradle支持,只能使用java -cp
來運行!
本代碼執行時的命令列表:
1: Create Bitcoin Wallet and update PIN
2: Read Bitcoin balance & address
3: Read USDT balance & address
4: Read EOS balance & address
tbb:Transfer BTC from Bot to Wallet
tbm:Transfer BTC from Wallet to Master
teb:Transfer EOS from Bot to Wallet
tem:Transfer EOS from Wallet to Master
tub:Transfer USDT from Bot to Wallet
tum:Transfer USDT from Wallet to Master
5: pay 0.0001 BTC buy USDT
6: pay $1 USDT buy BTC
7: Read Snapshots
8: Fetch market price(USDT)
9: Fetch market price(BTC)
v: Verify Wallet Pin
wb: Withdraw BTC
we: WitchDraw EOS
a: Read All Assets Infos
q: Exit
Make your choose(eg: q for Exit!):
完整代碼
Solution Two: List your order on Ocean.One exchange文章版權歸作者所有,未經允許請勿轉載,若此文章存在違規行為,您可以聯系管理員刪除。
轉載請注明本文地址:http://specialneedsforspecialkids.com/yun/74262.html
摘要:完整的步驟如下檢查比特幣或的余額,錢包地址。比特幣的到帳時間是個塊的高度,約分鐘。 showImg(https://segmentfault.com/img/remote/1460000018952144?w=1200&h=659); 方案一: 通過ExinCore API進行幣幣交易 Exincore 提供了基于Mixin Network的幣幣交易API. 你可以支付USDT給Exi...
摘要:是一個免費的極速的端對端加密數字貨幣交易系統官方資源匯總課程簡介創建一個機器人比特幣開發教程機器人接受比特幣并立即退還用戶比特幣開發教程創建比特幣錢包買賣實時兌換買賣在自由市場掛單買賣買賣任意在自由市場掛單買賣其他編程語言匯總比特幣開發教程 showImg(https://segmentfault.com/img/remote/1460000019234638?w=1200&h=659...
摘要:課程簡介創建一個機器人機器人接受比特幣并立即退還用戶創建比特幣錢包買賣實時兌換買賣在自由市場掛單買賣買賣任意在自由市場掛單買賣其他編程語言比特幣開發教程如下比特幣開發教程比特幣開發教程比特幣開發教程比特幣開發教程比特幣開發教程比特幣開發教程 showImg(https://segmentfault.com/img/bVboFQ6?w=1200&h=659); 課程簡介 PHP 創建一...
摘要:課程簡介創建一個機器人機器人接受比特幣并立即退還用戶創建比特幣錢包買賣實時兌換買賣在自由市場掛單買賣買賣任意在自由市場掛單買賣其他編程語言比特幣開發教程如下比特幣開發教程比特幣開發教程比特幣開發教程比特幣開發教程比特幣開發教程比特幣開發教程 showImg(https://segmentfault.com/img/bVboFQ6?w=1200&h=659); 課程簡介 PHP 創建一...
摘要:如果你想限定價格買賣,或者買賣一些不支持的資產,你需要。完整的步驟如下檢查比特幣或的余額,錢包地址。從第三方交易所或者你的冷錢包中,將幣充到上述錢包地址。比特幣的到帳時間是個區塊的高度,約分鐘。 showImg(https://segmentfault.com/img/remote/1460000018952144?w=1200&h=659);上一章介紹了Exincore,你可以1秒完...
閱讀 1104·2021-09-22 15:37
閱讀 1131·2021-09-13 10:27
閱讀 2466·2021-08-25 09:38
閱讀 2444·2019-08-26 11:42
閱讀 1524·2019-08-26 11:39
閱讀 1554·2019-08-26 10:58
閱讀 2316·2019-08-26 10:56
閱讀 2569·2019-08-23 18:08