摘要:完整的步驟如下檢查比特幣或的余額,錢包地址。比特幣的到帳時(shí)間是個(gè)區(qū)塊的高度,約分鐘。
方案一: 通過(guò)ExinCore API進(jìn)行幣幣交易
Exincore 提供了基于Mixin Network的幣幣交易API.
你可以支付USDT給ExinCore, ExinCore會(huì)以最低的價(jià)格,最優(yōu)惠的交易費(fèi)將你購(gòu)買的比特幣轉(zhuǎn)給你, 每一幣交易都是匿名的,并且可以在區(qū)塊鏈上進(jìn)行驗(yàn)證,交易的細(xì)節(jié)只有你與ExinCore知道!
ExinCore 也不知道你是誰(shuí),它只知道你的UUID.
預(yù)備知識(shí):你先需要?jiǎng)?chuàng)建一個(gè)機(jī)器人, 方法在 教程一.
安裝依賴包正如教程一里我們介紹過(guò)的, 我們需要依賴 mixin-csharp-sdk, 你應(yīng)該先安裝過(guò)它了, 這兒我們?cè)侔惭b MsgPack.Cli 軟件包.
dotnet add package MixinCSharpSdk dotnet add package MsgPack.Cli --version 1.0.1充幣到 Mixin Network, 并讀出它的余額.
通過(guò)ExinCore API, 可以進(jìn)行BTC, USDT, EOS, ETH 等等交易, 此處演示用 USDT購(gòu)買BTC 或者 用BTC購(gòu)買USDT。交易前,先檢查一下錢包地址。
完整的步驟如下:
檢查比特幣或USDT的余額,錢包地址。并記下錢包地址。
從第三方交易所或者你的冷錢包中,將幣充到上述錢包地址。
再檢查一下幣的余額,看到帳與否。(比特幣的到帳時(shí)間是5個(gè)區(qū)塊的高度,約100分鐘)。
比特幣與USDT的充值地址是一樣的。
MixinApi mixinApiNewUser = new MixinApi(); mixinApiNewUser.Init(UserIDNewUser, "", SessionIDNewUser, PinTokenNewUser, PrivateKeyNewUser); Asset AssetBTC = mixinApiNewUser.ReadAsset(USRCONFIG.ASSET_ID_BTC); Console.WriteLine("New User " + UserIDNewUser + " "s BTC balance is " + AssetBTC.balance); Console.WriteLine("New User " + UserIDNewUser + " "s BTC address is " + AssetBTC.public_key);查詢ExinCore市場(chǎng)的價(jià)格信息
如何來(lái)查詢ExinCore市場(chǎng)的價(jià)格信息呢?你要先了解你交易的基礎(chǔ)幣是什么,如果你想買比特幣,賣出USDT,那么基礎(chǔ)貨幣就是USDT;如果你想買USDT,賣出比特幣,那么基礎(chǔ)貨幣就是比特幣.
string jsonData = FetchMarketPrice("815b0b1a-2764-3736-8faa-42d694fa620a"); var marketObj = JsonConvert.DeserializeObject交易前,創(chuàng)建一個(gè)Memo!(jsonData); foreach (AssetInfo value in marketObj.data) { Console.WriteLine(value); } public class MarketInfo { public string code { get; set; } public string message { get; set; } public List data { get; set; } public override string ToString() { return JsonConvert.SerializeObject(this); } } public class AssetInfo { public string base_asset { get; set; } public string base_asset_symbol { get; set; } public string exchange_asset_symbol { get; set; } public string price { get; set; } public string minimum_amount { get; set; } public string maximum_amount { get; set; } public List exchanges { get; set; } public override string ToString() { return JsonConvert.SerializeObject(this); } } public static string FetchMarketPrice(string asset_id) { return FetchMarketPriceAsync(asset_id).Result; } public static async Task FetchMarketPriceAsync(string asset_id) { HttpClient client = new HttpClient(); // Call asynchronous network methods in a try/catch block to handle exceptions try { HttpResponseMessage response = await client.GetAsync("https://exinone.com/exincore/markets?base_asset=" + asset_id); response.EnsureSuccessStatusCode(); string responseBody = await response.Content.ReadAsStringAsync(); // Above three lines can be replaced with new helper method below // string responseBody = await client.GetStringAsync(uri); Console.WriteLine(responseBody); return responseBody; } catch(HttpRequestException e) { Console.WriteLine(" Exception Caught!"); Console.WriteLine("Message :{0} ",e.Message); } return null; }
在第二章里,基于Mixin Network的 C# 比特幣開發(fā)教程: 機(jī)器人接受比特幣并立即退還用戶, 我們學(xué)習(xí)過(guò)退還用戶比特幣,在這里,我們除了給ExinCore支付幣外,還要告訴他我們想購(gòu)買的幣是什么,即將想購(gòu)買的幣存到memo里。
private static string TargetAssetID(string asset_id) { Guid guid = new Guid(asset_id); var gbytes = guid.ToByteArray(); Array.Reverse(gbytes,0,4); Array.Reverse(gbytes,4,2); Array.Reverse(gbytes,6,2); var serializer = MessagePackSerializer.Get(gbytes.GetType()); var stream = new MemoryStream(); serializer.Pack(stream, gbytes); return Convert.ToBase64String(stream.ToArray()); }幣幣交易的完整流程
轉(zhuǎn)幣給ExinCore時(shí),將memo寫入你希望購(gòu)買的幣,否則,ExinCore會(huì)直接退幣給你!
如果你想賣出比特幣買入U(xiǎn)SDT,調(diào)用方式如下:
//config.cs public static string EXIN_BOT = "61103d28-3ac2-44a2-ae34-bd956070dab1"; // public static string EXIN_BOT = "0b1a2027-4fd6-3aa0-b3a3-814778bb7a2e"; public static string MASTER_UUID = "0b4f49dc-8fb4-4539-9a89-fb3afc613747"; public static string ASSET_ID_BTC = "c6d0c728-2624-429b-8e0d-d9d19b6592fa"; public static string ASSET_ID_EOS = "6cfe566e-4aad-470b-8c9a-2fd35b49c68d"; public static string ASSET_ID_USDT= "815b0b1a-2764-3736-8faa-42d694fa620a"; //Program.cs if (cmd == "5" ) { var memo = TargetAssetID(USRCONFIG.ASSET_ID_USDT); Console.WriteLine(memo); using (TextReader fileReader = File.OpenText(@"mybitcoin_wallet.csv")) { var csv = new CsvReader(fileReader); csv.Configuration.HasHeaderRecord = false; while (csv.Read()) { string PrivateKeyNewUser; csv.TryGetField(0, out PrivateKeyNewUser); string PinTokenNewUser; csv.TryGetField (1, out PinTokenNewUser); string SessionIDNewUser; csv.TryGetField (2, out SessionIDNewUser); string UserIDNewUser; csv.TryGetField (3, out UserIDNewUser); string PinNewUser; csv.TryGetField (4, out PinNewUser); MixinApi mixinApiNewUser = new MixinApi(); mixinApiNewUser.Init(UserIDNewUser, "", SessionIDNewUser, PinTokenNewUser, PrivateKeyNewUser); // Console.WriteLine(mixinApiNewUser.CreatePIN("", "123456").ToString()); Transfer reqInfo = mixinApiNewUser.Transfer(USRCONFIG.ASSET_ID_BTC, USRCONFIG.EXIN_BOT, "0.0001", PinNewUser.ToString(), System.Guid.NewGuid().ToString(), memo); Console.WriteLine(reqInfo); } } }
如果你想賣出USDT買入比特幣,調(diào)用方式如下:
if (cmd == "6" ) { var memo = TargetAssetID(USRCONFIG.ASSET_ID_BTC); Console.WriteLine(memo); using (TextReader fileReader = File.OpenText(@"mybitcoin_wallet.csv")) { var csv = new CsvReader(fileReader); csv.Configuration.HasHeaderRecord = false; while (csv.Read()) { string PrivateKeyNewUser; csv.TryGetField(0, out PrivateKeyNewUser); string PinTokenNewUser; csv.TryGetField (1, out PinTokenNewUser); string SessionIDNewUser; csv.TryGetField (2, out SessionIDNewUser); string UserIDNewUser; csv.TryGetField (3, out UserIDNewUser); string PinNewUser; csv.TryGetField (4, out PinNewUser); MixinApi mixinApiNewUser = new MixinApi(); mixinApiNewUser.Init(UserIDNewUser, "", SessionIDNewUser, PinTokenNewUser, PrivateKeyNewUser); // Console.WriteLine(mixinApiNewUser.CreatePIN("", "123456").ToString()); Transfer reqInfo = mixinApiNewUser.Transfer(USRCONFIG.ASSET_ID_USDT, USRCONFIG.EXIN_BOT, "1", PinNewUser.ToString(), System.Guid.NewGuid().ToString(), memo); Console.WriteLine(reqInfo); } } }
交易完成后,Exincore會(huì)將你需要的幣轉(zhuǎn)到你的帳上,同樣,會(huì)在memo里,記錄成交價(jià)格,交易費(fèi)用等信息!你只需要按下面的方式解開即可!
NetworkSnapshots 讀取錢包的交易記錄。
using (TextReader fileReader = File.OpenText(@"mybitcoin_wallet.csv")) { var csv = new CsvReader(fileReader); csv.Configuration.HasHeaderRecord = false; while (csv.Read()) { string PrivateKeyNewUser; csv.TryGetField(0, out PrivateKeyNewUser); string PinTokenNewUser; csv.TryGetField (1, out PinTokenNewUser); string SessionIDNewUser; csv.TryGetField (2, out SessionIDNewUser); string UserIDNewUser; csv.TryGetField (3, out UserIDNewUser); string PinNewUser; csv.TryGetField (4, out PinNewUser); MixinApi mixinApiNewUser = new MixinApi(); mixinApiNewUser.Init(UserIDNewUser, "", SessionIDNewUser, PinTokenNewUser, PrivateKeyNewUser); // Console.WriteLine(mixinApiNewUser.CreatePIN("", "123456").ToString()); var snaps = mixinApiNewUser.NetworkSnapshots(10,"2019-03-26T01:49:52.462741863Z", "815b0b1a-2764-3736-8faa-42d694fa620a", "ASC",true); // Console.WriteLine(snaps); foreach (var sn in snaps) { if ( Convert.ToDouble(sn.amount) > 0 ) { if ( sn.data != null ) { var memoBytes = Convert.FromBase64String(sn.data); var memoObj = MessagePackSerializer.UnpackMessagePackObject(memoBytes); Console.WriteLine(memoObj.ToString()); var xR = JsonConvert.DeserializeObject (memoObj.ToString()); Console.WriteLine(xR.C); if (xR.C == "1000") { Console.WriteLine("-----------Successfully--Exchange-------------"); Console.WriteLine("You got " + sn.amount.ToString() + " back!"); Console.WriteLine("Price is " + xR.P + " Fee is " + xR.F + " Percent of fee: " + Convert.ToDouble(xR.F)/Convert.ToDouble(sn.amount)*100 + " %"); Console.WriteLine("Fee Asset uuid: " + HexStringToUUID(xR.FA)); Console.WriteLine("trace uuid: " + HexStringToUUID(xR.O)); Console.WriteLine("----------end of snapshots query--------------"); } } } } } }
一次成功的交易如下:
-----------Successfully--Exchange------------- You got 0.3923244 back! Price is 3938.62 Fee is 0.0007878 Percent of fee: 0.200803212851406 % Fee Asset uuid: 815b0b1a-2764-3736-8faa-42d694fa620a trace uuid: 1a3d8561-26e7-49bb-8ae3-ed85ce2bb957 ----------end of snapshots query--------------讀取幣的余額
通過(guò)讀取幣的余額,來(lái)確認(rèn)交易情況!
MixinApi mixinApiNewUser = new MixinApi(); mixinApiNewUser.Init(UserIDNewUser, "", SessionIDNewUser, PinTokenNewUser, PrivateKeyNewUser); Asset AssetBTC = mixinApiNewUser.ReadAsset(USRCONFIG.ASSET_ID_BTC); Console.WriteLine("New User " + UserIDNewUser + " "s BTC balance is " + AssetBTC.balance); Console.WriteLine("New User " + UserIDNewUser + " "s BTC address is " + AssetBTC.public_key);源代碼執(zhí)行
編譯執(zhí)行,即可開始交易了.
[x] dotnet build 編譯項(xiàng)目.
[x] dotnet bin/Debug/netcoreapp2.2/bitcoin_wallet.dll 運(yùn)行它.
本代碼執(zhí)行時(shí)的命令列表:
1: Create Bitcoin Wallet and update PIN
2: Read Bitcoin balance & address
3: Read USDT balance & address
4: Read EOS balance & address
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
q: Exit
Make your choose:
完整代碼
Solution Two: List your order on Ocean.One exchange文章版權(quán)歸作者所有,未經(jīng)允許請(qǐng)勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。
轉(zhuǎn)載請(qǐng)注明本文地址:http://specialneedsforspecialkids.com/yun/24641.html
摘要:方案二在去中心化交易所上掛單買賣是基于的去中心化交易所,它性能一流。完整的步驟如下檢查比特幣或的余額,錢包地址。比特幣的到帳時(shí)間是個(gè)區(qū)塊的高度,約分鐘。 showImg(https://github.com/wenewzhang/mixin_labs-csharp-bot/raw/master/BItcoin_C%23.jpg); 上一章介紹了Exincore,你可以1秒完成資產(chǎn)的市價(jià)...
摘要:課程簡(jiǎn)介創(chuàng)建一個(gè)機(jī)器人機(jī)器人接受比特幣并立即退還用戶創(chuàng)建比特幣錢包買賣實(shí)時(shí)兌換買賣在自由市場(chǎng)掛單買賣買賣任意在自由市場(chǎng)掛單買賣其他編程語(yǔ)言比特幣開發(fā)教程如下比特幣開發(fā)教程比特幣開發(fā)教程比特幣開發(fā)教程比特幣開發(fā)教程比特幣開發(fā)教程比特幣開發(fā)教程 showImg(https://segmentfault.com/img/bVboFQ6?w=1200&h=659); 課程簡(jiǎn)介 PHP 創(chuàng)建一...
摘要:是一個(gè)免費(fèi)的極速的端對(duì)端加密數(shù)字貨幣交易系統(tǒng)官方資源匯總課程簡(jiǎn)介創(chuàng)建一個(gè)機(jī)器人比特幣開發(fā)教程機(jī)器人接受比特幣并立即退還用戶比特幣開發(fā)教程創(chuàng)建比特幣錢包買賣實(shí)時(shí)兌換買賣在自由市場(chǎng)掛單買賣買賣任意在自由市場(chǎng)掛單買賣其他編程語(yǔ)言匯總比特幣開發(fā)教程 showImg(https://segmentfault.com/img/remote/1460000019234638?w=1200&h=659...
摘要:課程簡(jiǎn)介創(chuàng)建一個(gè)機(jī)器人機(jī)器人接受比特幣并立即退還用戶創(chuàng)建比特幣錢包買賣實(shí)時(shí)兌換買賣在自由市場(chǎng)掛單買賣買賣任意在自由市場(chǎng)掛單買賣其他編程語(yǔ)言比特幣開發(fā)教程如下比特幣開發(fā)教程比特幣開發(fā)教程比特幣開發(fā)教程比特幣開發(fā)教程比特幣開發(fā)教程比特幣開發(fā)教程 showImg(https://segmentfault.com/img/bVboFQ6?w=1200&h=659); 課程簡(jiǎn)介 PHP 創(chuàng)建一...
摘要:比特幣的到帳時(shí)間是個(gè)區(qū)塊的高度,約分鐘。請(qǐng)注意,比特幣與的地址是一樣的。 showImg(https://segmentfault.com/img/remote/1460000018419614?w=1200&h=659); 方案一: 通過(guò)ExinCore API進(jìn)行幣幣交易 Exincore 提供了基于Mixin Network的幣幣交易API. 你可以支付USDT給ExinCore...
閱讀 1642·2021-09-22 15:21
閱讀 2861·2021-09-09 09:32
閱讀 2681·2021-09-02 09:52
閱讀 3299·2019-08-30 14:02
閱讀 2218·2019-08-26 13:25
閱讀 1446·2019-08-26 13:24
閱讀 1599·2019-08-26 10:31
閱讀 1552·2019-08-26 10:16