摘要:方案二在去中心化交易所上掛單買賣是基于的去中心化交易所,它性能一流。完整的步驟如下檢查比特幣或的余額,錢包地址。比特幣的到帳時間是個區塊的高度,約分鐘。
上一章介紹了Exincore,你可以1秒完成資產的市價買賣。如果你想限定價格買賣,或者買賣一些exincore不支持的資產,你需要OceanOne。
方案二: 在去中心化交易所OceanOne上掛單買賣BitcoinOcean.one是基于Mixin Network的去中心化交易所,它性能一流。
你可以在OceanOne上交易任何資產,只需要將你的幣轉給OceanOne, 將交易信息寫在交易的memo里,OceanOne會在市場里列出你的交易需求,
交易成功后,會將目標幣轉入到你的MixinNetwork帳上,它有三大特點與優勢:
不需要在OceanOne注冊
不需要存幣到交易所
支持所有Mixin Network上能夠轉賬的資產,所有的ERC20 EOS代幣。
預備知識:你先需要創建一個機器人, 方法在 教程一.
安裝依賴包我們需要依賴 MsgPack.Cli and mixin-csharp-sdk ,第四章 已經做過介紹, 你應該先安裝過它了.
充幣到 Mixin Network, 并讀出它的余額.此處演示用 USDT購買BTC 或者 用BTC購買USDT。交易前,先檢查一下錢包地址。
完整的步驟如下:
檢查比特幣或USDT的余額,錢包地址。并記下錢包地址。
從第三方交易所或者你的冷錢包中,將幣充到上述錢包地址。
再檢查一下幣的余額,看到帳與否。(比特幣的到帳時間是5個區塊的高度,約100分鐘)。
比特幣與USDT的充值地址是一樣的。
if (cmd == "aw" ) { // Console.WriteLine(mixinApi.VerifyPIN(USRCONFIG.PinCode.ToString()).ToString()); MixinApi mixinApiNewUser = GetWalletSDK(); var assets = mixinApiNewUser.ReadAssets(); string wuuid = GetWalletUUID(); Console.WriteLine("Current wallet uuid is " + wuuid); foreach (Asset asset in assets) { if (asset.symbol == "EOS") { Console.WriteLine(asset.symbol + " Public Address is: " + asset.account_name + " " + asset.account_tag + " Balance is: " + asset.balance); } else Console.WriteLine(asset.symbol + " Public Address is: " + asset.public_key + " Balance is: " + asset.balance); Console.WriteLine(); } }取得Ocean.one的市場價格信息
如何來查詢Ocean.one市場的價格信息呢?你要先了解你交易的基礎幣是什么,如果你想買比特幣,賣出USDT,那么基礎貨幣就是USDT;如果你想買USDT,賣出比特幣,那么基礎貨幣就是比特幣.
public class MarketInfoOcean { public Omarket data { get; set; } } public class Omarket { public string market { get; set; } public string timestamp { get; set; } public Side data { get; set; } } public class Side { public List交易前,創建一個Memo!asks { get; set; } public List bids { get; set; } } public class order { public string amount { get; set; } public string funds { get; set; } public string price { get; set; } public string side { get; set; } } if (cmdo == "1") { string jsonData = FetchOceanMarketPrice(USRCONFIG.XIN_ASSET_ID,USRCONFIG.ASSET_ID_USDT); // string jsonData = FetchMarketPrice("c6d0c728-2624-429b-8e0d-d9d19b6592fa"); var marketObj = JsonConvert.DeserializeObject (jsonData); Console.WriteLine("--Price--Amount---Funds---Side----"); foreach (order value in marketObj.data.data.asks) { Console.WriteLine(value.price + " " + value.amount + " " + value.funds + " " + value.side); } foreach (order value in marketObj.data.data.bids) { Console.WriteLine(value.price + " " + value.amount + " " + value.funds + " " + value.side); } } public static string FetchOceanMarketPrice(string asset_id, string base_asset) { return FetchOceanMarketPriceAsync(asset_id,base_asset).Result; } public static async Task FetchOceanMarketPriceAsync(string asset_id, string base_asset) { HttpClient client = new HttpClient(); string baseUrl = "https://events.ocean.one/markets/" + asset_id + "-" + base_asset + "/book"; try { HttpResponseMessage response = await client.GetAsync(baseUrl); 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# 比特幣開發教程: 機器人接受比特幣并立即退還用戶, 我們學習過轉帳,這兒我們介紹如何告訴Ocean.one,我們給它轉帳的目的是什么,信息全部放在memo里.
Side 方向,"B" 或者 "A", "B"是購買, "A"是出售.
AssetUuid 目標虛擬資產的UUID.
Price 價格,如果操作方向是"B", 價格就是AssetUUID的價格; 如果操作方向是"B", 價格就是轉給Ocean.one幣的價格.
private static string GenerateOrderMemo(string Side, string AssetUuid, string Price) { Hashtable temp = new Hashtable(); temp.Add("S","A"); temp.Add("A",StringGuid2Bytes(AssetUuid)); temp.Add("P",Price); temp.Add("T","L"); var serializer3 = MessagePackSerializer.Get(); var stream3 = new MemoryStream(); serializer3.Pack(stream3, temp); string memo = Convert.ToBase64String(stream3.ToArray()); return memo; }
買入XIN的代碼如下:
public static string OCEANONE_BOT = "aaff5bef-42fb-4c9f-90e0-29f69176b7d4"; 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"; public static string XIN_ASSET_ID = "c94ac88f-4671-3976-b60a-09064f1811e8"; if ( cmdo == "b1") { Console.WriteLine("Please input the price of XIN/USDT: "); var pinput = Console.ReadLine(); Console.WriteLine("Please input the amount of USDT: "); var ainput = Console.ReadLine(); string memo = GenerateOrderMemo("A",USRCONFIG.ASSET_ID_USDT,pinput); Console.WriteLine(memo); MixinApi mixinApiNewUser = GetWalletSDK(); var assets = mixinApiNewUser.ReadAsset(USRCONFIG.ASSET_ID_USDT); Console.WriteLine(assets.balance); float balance = float.Parse(assets.balance); float amount = float.Parse(ainput); if ( ( balance >= 1.0 ) && ( balance >= amount ) ) { Transfer reqInfo = mixinApiNewUser.Transfer(USRCONFIG.ASSET_ID_USDT, USRCONFIG.OCEANONE_BOT, ainput, GetWalletPinCode(), System.Guid.NewGuid().ToString(), memo); Console.WriteLine(reqInfo); Console.WriteLine("Order id is " + reqInfo.trace_id); } else Console.WriteLine("Not enough USDT!"); }出售XIN的例子
轉打算出售的XIN給Ocean.one(OCEANONE_BOT),將你打算換回來的目標虛擬資產的UUID放入memo.
if ( cmdo == "s1") { Console.WriteLine("Please input the price of XIN/USDT: "); var pinput = Console.ReadLine(); Console.WriteLine("Please input the amount of XIN: "); var ainput = Console.ReadLine(); string memo = GenerateOrderMemo("B",USRCONFIG.XIN_ASSET_ID,pinput); Console.WriteLine(memo); // Console.WriteLine(Convert.ToBase64String(stream3.ToArray())); MixinApi mixinApiNewUser = GetWalletSDK(); var assets = mixinApiNewUser.ReadAsset(USRCONFIG.XIN_ASSET_ID); float balance = float.Parse(assets.balance); float amount = float.Parse(ainput); if ( ( balance >= 0 ) && ( balance >= amount ) ) { Transfer reqInfo = mixinApiNewUser.Transfer(USRCONFIG.XIN_ASSET_ID, USRCONFIG.OCEANONE_BOT, ainput, GetWalletPinCode(), System.Guid.NewGuid().ToString(), memo); Console.WriteLine(reqInfo); Console.WriteLine("Order id is " + reqInfo.trace_id); } else Console.WriteLine("Not enough XIN!"); }
一個成功的掛單如下:
Please input the price of XIN/USDT: 110 Please input the amount of USDT: 1 hKFBxBDJSsiPRnE5drYKCQZPGBHooVShTKFToUKhUKMxMTA= 1 {"type":"transfer","snapshot_id":"fe04c667-3ad9-4f2b-b205-ba2cef3733ea", "opponent_id":"aaff5bef-42fb-4c9f-90e0-29f69176b7d4", "asset_id":"815b0b1a-2764-3736-8faa-42d694fa620a","amount":"-1", "trace_id":"12cd76aa-e953-4897-bef0-18123a5e69dc", "memo":"hKFBxBDJSsiPRnE5drYKCQZPGBHooVShTKFToUKhUKMxMTA=", "created_at":"2019-05-06T06:43:13.488971627Z"} Order id is 12cd76aa-e953-4897-bef0-18123a5e69dc取消掛單
Ocean.one將trace_id當做訂單,比如上面的例子, 12cd76aa-e953-4897-bef0-18123a5e69dc 就是訂單號,我們用他來取消訂單。
if ( cmdo == "c") { Console.WriteLine("Please input the Order id: "); var oinput = Console.ReadLine(); Hashtable temp = new Hashtable(); temp.Add("O",StringGuid2Bytes(oinput)); var serializer3 = MessagePackSerializer.Get通過讀取資產余額,來確認到帳情況(); var stream3 = new MemoryStream(); serializer3.Pack(stream3, temp); string memo = Convert.ToBase64String(stream3.ToArray()); MixinApi mixinApiNewUser = GetWalletSDK(); var assets = mixinApiNewUser.ReadAsset(USRCONFIG.CNB_ASSET_ID); Console.WriteLine(assets.balance); float balance = float.Parse(assets.balance); if ( balance >= 0 ) { Transfer reqInfo = mixinApiNewUser.Transfer(USRCONFIG.CNB_ASSET_ID, USRCONFIG.OCEANONE_BOT, "0.0000001", GetWalletPinCode(), System.Guid.NewGuid().ToString(), memo); Console.WriteLine(reqInfo); } else Console.WriteLine("Not enough CNB!"); }
MixinApi mixinApiNewUser = GetWalletSDK(); var assets = mixinApiNewUser.ReadAssets();源代碼執行
編譯執行,即可開始交易了.
源代碼執行編譯執行,即可開始交易了.
[x] dotnet build 編譯項目.
[x] dotnet bin/Debug/netcoreapp2.2/bitcoin_wallet.dll 運行它.
本代碼執行時的命令列表:
Commands list of this source code:
1: Create Bitcoin Wallet and update PIN
2: Read Bitcoin balance & address
3: Read USDT balance & address
4: Read EOS balance & address
tub: Transfer USDT from Bot to Wallet
tum: Transfer USDT from Wallet to Master
tcb: Transfer CNB from Bot to Wallet
tcm: Transfer CNB from Wallet to Master
txb: Transfer XIN from Bot to Wallet
txm: Transfer XIN 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
ab: Read Bot Assets
aw: Read Wallet Assets
o: OceanOne Trading
q: Exit
Make your choose:
Make your choose(eg: q for Exit!):
Make your choose:
o
1: Fetch XIN/USDT orders
s1: Sell XIN/USDT
b1: Buy XIN/USDT
2: Fetch ERC20(Benz)/USDT orders
s2: Sell Benz/USDT
b2: Buy Benz/USDT
c: Cancel Order
q: Exit
完整代碼
文章版權歸作者所有,未經允許請勿轉載,若此文章存在違規行為,您可以聯系管理員刪除。
轉載請注明本文地址:http://specialneedsforspecialkids.com/yun/24658.html
摘要:完整的步驟如下檢查比特幣或的余額,錢包地址。比特幣的到帳時間是個區塊的高度,約分鐘。 showImg(https://segmentfault.com/img/remote/1460000018719458?w=1200&h=659); 方案一: 通過ExinCore API進行幣幣交易 Exincore 提供了基于Mixin Network的幣幣交易API. 你可以支付USDT給Ex...
摘要:課程簡介創建一個機器人機器人接受比特幣并立即退還用戶創建比特幣錢包買賣實時兌換買賣在自由市場掛單買賣買賣任意在自由市場掛單買賣其他編程語言比特幣開發教程如下比特幣開發教程比特幣開發教程比特幣開發教程比特幣開發教程比特幣開發教程比特幣開發教程 showImg(https://segmentfault.com/img/bVboFQ6?w=1200&h=659); 課程簡介 PHP 創建一...
摘要:是一個免費的極速的端對端加密數字貨幣交易系統官方資源匯總課程簡介創建一個機器人比特幣開發教程機器人接受比特幣并立即退還用戶比特幣開發教程創建比特幣錢包買賣實時兌換買賣在自由市場掛單買賣買賣任意在自由市場掛單買賣其他編程語言匯總比特幣開發教程 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/remote/1460000018419614?w=1200&h=659); 方案一: 通過ExinCore API進行幣幣交易 Exincore 提供了基于Mixin Network的幣幣交易API. 你可以支付USDT給ExinCore...
閱讀 1589·2023-04-26 01:54
閱讀 1620·2021-09-30 09:55
閱讀 2644·2021-09-22 16:05
閱讀 1855·2021-07-25 21:37
閱讀 2619·2019-08-29 18:45
閱讀 1885·2019-08-29 16:44
閱讀 1881·2019-08-29 12:34
閱讀 1345·2019-08-23 14:02