仮想通貨の自動売買プログラムを作る過程を紹介しています。
基本的な実装はできましたが、プログラムは流しっぱなしにする前提なので、今回は情報の出力をしっかりとしていきたいと思います。
今まではなんでもかんでも TextBox1 に出力していましたが、これからは以下 3 箇所に分けて出力します。
- TextBox1 : 最初に作ったテキストボックスは通知目的で使う
- DataGridView: エクセルみたいな表を追加して、取引に関する情報はここにまとめる
- Visual Studio の出力: アプリ単体で動作させたら見れなくなるが、Visual Studio から実行している間はここに Console.WriteLine で出力できるのでデバッグ系の情報はこっちに出力する。
プログラムに表を追加 (DataGridView)
取引に関する情報を後からでも確認できるように DataGridView を追加。とりあえず以下の情報があれば見やすくなるはず。
- child_order_date : 取引の日時
- child_order_acceptance_id: 注文 ID
- child_order_state: 注文の状態
- side: 売りか買いか
- child_order_type: 成行か指値か
- price: 価格
- size: 枚数
Form に DataGridView を追加して、これら値を入れれるように列を作っておく。
後は取引状況に変更があったらここに内容を入れていくだけ。
注文を入れてすぐには ID 以外の情報がわからないので、以下で ID だけは記録しておく。
1 |
dataGridViewTrackDeals.Rows.Add("TBA", ChildOrderAcceptanceID, "TBA", "BUY", "MARKET", "TBA", numericUpDownMarketOrder.Value); |
ID から情報が取得できるようになったら、その内容を更新する。該当する所を更新したいので、child_order_acceptance_id で探して、その行を更新する。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
for (int RowNum = 0; RowNum < dataGridViewTrackDeals.Rows.Count; RowNum++) { if ((dataGridViewTrackDeals.Rows[RowNum].Cells["child_order_acceptance_id"].Value != null) && (dataGridViewTrackDeals.Rows[RowNum].Cells["child_order_acceptance_id"].Value.ToString() == ChildOrderAcceptanceID)) { dataGridViewTrackDeals.Rows[RowNum].Cells["child_order_date"].Value = DesirializedResponse2.child_order_date; dataGridViewTrackDeals.Rows[RowNum].Cells["child_order_acceptance_id"].Value = DesirializedResponse2.child_order_acceptance_id; dataGridViewTrackDeals.Rows[RowNum].Cells["child_order_state"].Value = DesirializedResponse2.child_order_state; dataGridViewTrackDeals.Rows[RowNum].Cells["side"].Value = DesirializedResponse2.side; dataGridViewTrackDeals.Rows[RowNum].Cells["child_order_type"].Value = DesirializedResponse2.child_order_type; dataGridViewTrackDeals.Rows[RowNum].Cells["price"].Value = DesirializedResponse2.average_price; dataGridViewTrackDeals.Rows[RowNum].Cells["size"].Value = DesirializedResponse2.size; } } |
消すことはないので、これを取引状況が変わる要所要所で設定していく。
自動売買プログラムの作成状況
今回取引をリストする DataGrid を追加したので見た目がこんな感じになった。
そしていつも通り、これが今のプログラムの全コード。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 |
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.Net.Http; using System.Net.Http.Headers; using Newtonsoft.Json; using System.Security.Cryptography; namespace BtcFxStep1 { public partial class Form1 : Form { static readonly Uri endpointUri = new Uri("https://api.bitflyer.jp"); static readonly string apiKey = "xxxxxxxxxxxxx"; static readonly string apiSecret = "xxxxxxxxxxxxx"; // //JSON の型を定義:/v1/me/getchildorders // public class JsonGetChildOrders { public double id { get; set; } public string child_order_id { get; set; } public string product_code { get; set; } public string side { get; set; } public string child_order_type { get; set; } public double price { get; set; } public double average_price { get; set; } public double size { get; set; } public string child_order_state { get; set; } public DateTime expire_date { get; set; } public DateTime child_order_date { get; set; } public string child_order_acceptance_id { get; set; } public double outstanding_size { get; set; } public double cancel_size { get; set; } public double executed_size { get; set; } public double total_commission { get; set; } } // //JSON の型を定義: /v1/me/sendchildorder // public class JsonSendChildOrder { public string child_order_acceptance_id; } // //JSON の型を定義: v1/ticker // public class JsonTicker { public string product_code { get; set; } public DateTime timestamp { get; set; } public int tick_id { get; set; } public double best_bid { get; set; } public double best_ask { get; set; } public double best_bid_size { get; set; } public double best_ask_size { get; set; } public double total_bid_depth { get; set; } public double total_ask_depth { get; set; } public double ltp { get; set; } public double volume { get; set; } public double volume_by_product { get; set; } } // //指値注文を入れる // public async Task<string> MakeLimitOrder(string sSide, double iPrice, double iSize) { var method = "POST"; var path = "/v1/me/sendchildorder"; var query = ""; var body = @"{ ""product_code"": ""FX_BTC_JPY"", ""child_order_type"": ""LIMIT"", ""side"": """ + sSide + @""", ""price"":" + iPrice + @", ""size"": " + iSize + @", ""minute_to_expire"": 43200, ""time_in_force"": ""GTC"" }"; using (var client = new HttpClient()) using (var request = new HttpRequestMessage(new HttpMethod(method), path + query)) using (var content = new StringContent(body)) { client.BaseAddress = endpointUri; content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); request.Content = content; var timestamp = DateTimeOffset.UtcNow.ToUnixTimeSeconds().ToString(); var data = timestamp + method + path + query + body; var hash = SignWithHMACSHA256(data, apiSecret); request.Headers.Add("ACCESS-KEY", apiKey); request.Headers.Add("ACCESS-TIMESTAMP", timestamp); request.Headers.Add("ACCESS-SIGN", hash); var message = await client.SendAsync(request); var response = await message.Content.ReadAsStringAsync(); if (response == "[]") { Console.WriteLine("Error: MakeMarketOrder() returning ERROR_NO_RESPONSE"); return "ERROR_NO_RESPONSE"; } return response; } } // //成行注文を入れる // public async Task<string> MakeMarketOrder(string sSide, double iSize) { var method = "POST"; var path = "/v1/me/sendchildorder"; var query = ""; var body = @"{ ""product_code"": ""FX_BTC_JPY"", ""child_order_type"": ""MARKET"", ""side"": """ + sSide + @""", ""price"": 0, ""size"": " + numericUpDownMarketOrder.Value + @", ""minute_to_expire"": 43200, ""time_in_force"": ""GTC"" }"; using (var client = new HttpClient()) using (var request = new HttpRequestMessage(new HttpMethod(method), path + query)) using (var content = new StringContent(body)) { client.BaseAddress = endpointUri; content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); request.Content = content; var timestamp = DateTimeOffset.UtcNow.ToUnixTimeSeconds().ToString(); var data = timestamp + method + path + query + body; var hash = SignWithHMACSHA256(data, apiSecret); request.Headers.Add("ACCESS-KEY", apiKey); request.Headers.Add("ACCESS-TIMESTAMP", timestamp); request.Headers.Add("ACCESS-SIGN", hash); var message = await client.SendAsync(request); var response = await message.Content.ReadAsStringAsync(); if (response == "[]") { Console.WriteLine("Error: MakeMarketOrder() returning ERROR_NO_RESPONSE"); return "ERROR_NO_RESPONSE"; } return response; } } // // child_order_acceptance_id から情報を取得する // public async Task<string> GetOrderInformationWithID(string ChildOrderAcceptanceID) { var method = "GET"; var path = "/v1/me/getchildorders"; var query = "?product_code=FX_BTC_JPY&child_order_acceptance_id=" + ChildOrderAcceptanceID; using (var client = new HttpClient()) using (var request = new HttpRequestMessage(new HttpMethod(method), path + query)) { client.BaseAddress = endpointUri; var timestamp = DateTimeOffset.UtcNow.ToUnixTimeSeconds().ToString(); var data = timestamp + method + path + query; var hash = SignWithHMACSHA256(data, apiSecret); request.Headers.Add("ACCESS-KEY", apiKey); request.Headers.Add("ACCESS-TIMESTAMP", timestamp); request.Headers.Add("ACCESS-SIGN", hash); var message = await client.SendAsync(request); var response = await message.Content.ReadAsStringAsync(); if (response == "[]") { Console.WriteLine("GetOrderInformationWithID():OUT returning ERROR_NO_RESPONSE"); return "ERROR_NO_RESPONSE"; } return response; } } static string SignWithHMACSHA256(string data, string secret) { using (var encoder = new HMACSHA256(Encoding.UTF8.GetBytes(secret))) { var hash = encoder.ComputeHash(Encoding.UTF8.GetBytes(data)); return ToHexString(hash); } } static string ToHexString(byte[] bytes) { var sb = new StringBuilder(bytes.Length * 2); foreach (var b in bytes) { sb.Append(b.ToString("x2")); } return sb.ToString(); } // //最終取引価格を毎秒 TextBoxPrice に出力する // public async Task GetCurrentBtcFxPrice() { while (true) { var method = "GET"; var path = "/v1/ticker"; var query = "?product_code=FX_BTC_JPY"; using (var client = new HttpClient()) using (var request = new HttpRequestMessage(new HttpMethod(method), path + query)) { client.BaseAddress = endpointUri; var message = await client.SendAsync(request); var response = await message.Content.ReadAsStringAsync(); var DesirializedResponse = JsonConvert.DeserializeObject<JsonTicker>(response); var CurrentPrice = String.Format("{0:#,0}", DesirializedResponse.ltp); textBoxPrice.Text = CurrentPrice; } await Task.Delay(1000); } } // //Form // public Form1() { InitializeComponent(); Task JobUpdatePrice = GetCurrentBtcFxPrice(); } // //Button 1 // private void button1_Click(object sender, EventArgs e) { Task JobButton1 = RunThisWhenButton1IsClicked(); } public async Task RunThisWhenButton1IsClicked() { } // //Button MakeMarketOrder // private void buttonMarketOrder_Click(object sender, EventArgs e) { Task JobMakeMarketOrder = RunThisWhenButtonMarketOrderIsClicked(); } public async Task RunThisWhenButtonMarketOrderIsClicked() { string ResponseMakeMarketOrder = await MakeMarketOrder("BUY", (double)numericUpDownMarketOrder.Value); var DesirializedResponse = JsonConvert.DeserializeObject<JsonSendChildOrder>(ResponseMakeMarketOrder); var ChildOrderAcceptanceID = DesirializedResponse.child_order_acceptance_id; textBox1.AppendText("MakeMarketOrder() succeeded: side=BUY, size=" + numericUpDownMarketOrder.Value + " child_order_acceptance_ID=" + ChildOrderAcceptanceID + System.Environment.NewLine); } // //Button SpecialOrderBuyBuy // private void buttonSpecialOrderBuyBuy_Click(object sender, EventArgs e) { Task Job1 = RunThisWhenButtonSpecialOrderBuyBuyIsClicked(); } public async Task RunThisWhenButtonSpecialOrderBuyBuyIsClicked() { bool bContinueBuyBuy=true; while (bContinueBuyBuy) { //1) 成行注文 //成行注文を入れてレスポンス (JsonSendChildOrder) から注文 ID ("JRF20180314-102635-135926") を取り出す string ResponseMakeMarketOrder = await MakeMarketOrder("BUY", (double)numericUpDownMarketOrder.Value); var DesirializedResponse = JsonConvert.DeserializeObject<JsonSendChildOrder>(ResponseMakeMarketOrder); var ChildOrderAcceptanceID = DesirializedResponse.child_order_acceptance_id; textBox1.AppendText("MakeMarketOrder() succeeded: side=BUY, size=" + numericUpDownMarketOrder.Value + " child_order_acceptance_ID=" + ChildOrderAcceptanceID + System.Environment.NewLine); dataGridViewTrackDeals.Rows.Add("TBA", ChildOrderAcceptanceID, "TBA", "BUY", "MARKET", "TBA", numericUpDownMarketOrder.Value); //2) 注文 ID が取れるのを待つ。 string ResponseGetOrderInformationWithID = await GetOrderInformationWithID(ChildOrderAcceptanceID); while (ResponseGetOrderInformationWithID == "ERROR_NO_RESPONSE") { textBox1.AppendText(" Waiting for order to complete. Re-check in 10sec." + System.Environment.NewLine); await Task.Delay(10000); ResponseGetOrderInformationWithID = await GetOrderInformationWithID(ChildOrderAcceptanceID); } //3) レスポンス (JsonGetChildOrders) から確約価格を取得 var DesirializedResponse2 = JsonConvert.DeserializeObject<JsonGetChildOrders>(ResponseGetOrderInformationWithID.Substring(1, ResponseGetOrderInformationWithID.Length - 2)); var AveragePrice = DesirializedResponse2.average_price; textBox1.AppendText(" GetOrderInformationWithID succeeded for ID: " + ChildOrderAcceptanceID + System.Environment.NewLine); textBox1.AppendText(" child_order_date: "+ DesirializedResponse2.child_order_date+ System.Environment.NewLine); textBox1.AppendText(" child_order_acceptance_id: "+ DesirializedResponse2.child_order_acceptance_id+ System.Environment.NewLine); textBox1.AppendText(" child_order_state: "+ DesirializedResponse2.child_order_state+ System.Environment.NewLine); textBox1.AppendText(" side: "+ DesirializedResponse2.side+ System.Environment.NewLine); textBox1.AppendText(" child_order_type: "+ DesirializedResponse2.child_order_type+ System.Environment.NewLine); textBox1.AppendText(" price: "+ DesirializedResponse2.average_price + System.Environment.NewLine); textBox1.AppendText(" size: "+ DesirializedResponse2.size+ System.Environment.NewLine); for (int RowNum = 0; RowNum < dataGridViewTrackDeals.Rows.Count; RowNum++) { if ((dataGridViewTrackDeals.Rows[RowNum].Cells["child_order_acceptance_id"].Value != null) && (dataGridViewTrackDeals.Rows[RowNum].Cells["child_order_acceptance_id"].Value.ToString() == ChildOrderAcceptanceID)) { dataGridViewTrackDeals.Rows[RowNum].Cells["child_order_date"].Value = DesirializedResponse2.child_order_date; dataGridViewTrackDeals.Rows[RowNum].Cells["child_order_acceptance_id"].Value = DesirializedResponse2.child_order_acceptance_id; dataGridViewTrackDeals.Rows[RowNum].Cells["child_order_state"].Value = DesirializedResponse2.child_order_state; dataGridViewTrackDeals.Rows[RowNum].Cells["side"].Value = DesirializedResponse2.side; dataGridViewTrackDeals.Rows[RowNum].Cells["child_order_type"].Value = DesirializedResponse2.child_order_type; dataGridViewTrackDeals.Rows[RowNum].Cells["price"].Value = DesirializedResponse2.average_price; dataGridViewTrackDeals.Rows[RowNum].Cells["size"].Value = DesirializedResponse2.size; } } //4) 確約した成行注文の値段 + x を指値注文を入れる double LimitOrderPrice = AveragePrice + double.Parse(textBoxSpecialOrderBuyBuy.Text); string ResponseMakeLimitOrder = await MakeLimitOrder("SELL", LimitOrderPrice, (double)numericUpDownMarketOrder.Value); var DesirializedResponse3 = JsonConvert.DeserializeObject<JsonSendChildOrder>(ResponseMakeLimitOrder); var ChildOrderAcceptanceID2 = DesirializedResponse3.child_order_acceptance_id; textBox1.AppendText("MakeLimitOrder succeeded with ID= " + ChildOrderAcceptanceID2 + System.Environment.NewLine); dataGridViewTrackDeals.Rows.Add("TBA", ChildOrderAcceptanceID2, "TBA", "BUY", "MARKET", "TBA", numericUpDownMarketOrder.Value); //5) 注文 ID が取れるのを待つ。 string ResponseGetOrderInformationWithID2 = await GetOrderInformationWithID(ChildOrderAcceptanceID2); while (ResponseGetOrderInformationWithID2 == "ERROR_NO_RESPONSE") { textBox1.AppendText(" Waiting for order to complete. Re-check in 10sec." + System.Environment.NewLine); await Task.Delay(10000); ResponseGetOrderInformationWithID2 = await GetOrderInformationWithID(ChildOrderAcceptanceID2); } //6) レスポンス (JsonGetChildOrders) から child_order_state を取得。 var DesirializedResponse4 = JsonConvert.DeserializeObject<JsonGetChildOrders>(ResponseGetOrderInformationWithID2.Substring(1, ResponseGetOrderInformationWithID2.Length - 2)); var ChildOrderState2 = DesirializedResponse4.child_order_state; textBox1.AppendText(" GetOrderInformationWithID succeeded for ID: " + ChildOrderAcceptanceID2 + System.Environment.NewLine); textBox1.AppendText(" child_order_date: " + DesirializedResponse4.child_order_date + System.Environment.NewLine); textBox1.AppendText(" child_order_acceptance_id: " + DesirializedResponse4.child_order_acceptance_id + System.Environment.NewLine); textBox1.AppendText(" child_order_state: " + DesirializedResponse4.child_order_state + System.Environment.NewLine); textBox1.AppendText(" side: " + DesirializedResponse4.side + System.Environment.NewLine); textBox1.AppendText(" child_order_type: " + DesirializedResponse4.child_order_type + System.Environment.NewLine); textBox1.AppendText(" price: " + DesirializedResponse4.average_price + System.Environment.NewLine); textBox1.AppendText(" size: " + DesirializedResponse4.size + System.Environment.NewLine); for (int RowNum = 0; RowNum < dataGridViewTrackDeals.Rows.Count; RowNum++) { if ((dataGridViewTrackDeals.Rows[RowNum].Cells["child_order_acceptance_id"].Value != null) && (dataGridViewTrackDeals.Rows[RowNum].Cells["child_order_acceptance_id"].Value.ToString() == ChildOrderAcceptanceID2)) { dataGridViewTrackDeals.Rows[RowNum].Cells["child_order_date"].Value = DesirializedResponse4.child_order_date; dataGridViewTrackDeals.Rows[RowNum].Cells["child_order_acceptance_id"].Value = DesirializedResponse4.child_order_acceptance_id; dataGridViewTrackDeals.Rows[RowNum].Cells["child_order_state"].Value = DesirializedResponse4.child_order_state; dataGridViewTrackDeals.Rows[RowNum].Cells["side"].Value = DesirializedResponse4.side; dataGridViewTrackDeals.Rows[RowNum].Cells["child_order_type"].Value = DesirializedResponse4.child_order_type; dataGridViewTrackDeals.Rows[RowNum].Cells["price"].Value = DesirializedResponse4.price; dataGridViewTrackDeals.Rows[RowNum].Cells["size"].Value = DesirializedResponse4.size; } } //7) 注文が通るのを待つ (ACTIVE から COMPLETE に代わるのを待つ) for (int i=0; i<100 && ChildOrderState2 == "ACTIVE"; i++) { ChildOrderState2 = "INITIALIZED"; textBox1.AppendText("Limit Order ID " + ChildOrderAcceptanceID2 + " is still ACTIVE. recheck in 60s." + ChildOrderState2 + System.Environment.NewLine); await Task.Delay(60000); ResponseGetOrderInformationWithID2 = await GetOrderInformationWithID(ChildOrderAcceptanceID2); while (ResponseGetOrderInformationWithID2 == "ERROR_NO_RESPONSE") { textBox1.AppendText(" Waiting for order to complete. Re-check in 10sec." + System.Environment.NewLine); await Task.Delay(10000); ResponseGetOrderInformationWithID2 = await GetOrderInformationWithID(ChildOrderAcceptanceID2); } DesirializedResponse4 = JsonConvert.DeserializeObject<JsonGetChildOrders>(ResponseGetOrderInformationWithID2.Substring(1, ResponseGetOrderInformationWithID2.Length - 2)); ChildOrderState2 = DesirializedResponse4.child_order_state; } //8) 注文が COMPLETE になったら状態を更新して、再度 1) からループする for (int RowNum = 0; RowNum < dataGridViewTrackDeals.Rows.Count; RowNum++) { if ((dataGridViewTrackDeals.Rows[RowNum].Cells["child_order_acceptance_id"].Value != null) && (dataGridViewTrackDeals.Rows[RowNum].Cells["child_order_acceptance_id"].Value.ToString() == ChildOrderAcceptanceID2)) { dataGridViewTrackDeals.Rows[RowNum].Cells["child_order_date"].Value = DesirializedResponse4.child_order_date; dataGridViewTrackDeals.Rows[RowNum].Cells["child_order_acceptance_id"].Value = DesirializedResponse4.child_order_acceptance_id; dataGridViewTrackDeals.Rows[RowNum].Cells["child_order_state"].Value = DesirializedResponse4.child_order_state; dataGridViewTrackDeals.Rows[RowNum].Cells["side"].Value = DesirializedResponse4.side; dataGridViewTrackDeals.Rows[RowNum].Cells["child_order_type"].Value = DesirializedResponse4.child_order_type; dataGridViewTrackDeals.Rows[RowNum].Cells["price"].Value = DesirializedResponse4.price; dataGridViewTrackDeals.Rows[RowNum].Cells["size"].Value = DesirializedResponse4.size; } } if (ChildOrderState2 == "COMPLETED") { bContinueBuyBuy = true; //re-run the whole process again textBox1.AppendText("TRANSACTION COMPLETED. RERUNNING THE PROCESS." + System.Environment.NewLine); } else { bContinueBuyBuy = false; //ABORT textBox1.AppendText("SOMETHING WENT WRONG:" + System.Environment.NewLine); textBox1.AppendText(" child_order_state: " + ChildOrderState2 + System.Environment.NewLine); } } } // //Button CheckOrderFromID // private void buttonCheckOrderFromID_Click(object sender, EventArgs e) { Task Job1 = RunThisWhenButtonCheckOrderFromIDIsClicked(); } public async Task RunThisWhenButtonCheckOrderFromIDIsClicked() { //注文 ID の情報を取得。早すぎるとエラーになるのでその場合には再チャレンジ string ResponseGetOrderInformationWithID = await GetOrderInformationWithID(textBoxCheckOrderFromID.Text); for (int i=0; (ResponseGetOrderInformationWithID == "ERROR_NO_RESPONSE") && (i<100); i++) { textBox1.AppendText("Waiting for response. Re-check in 10sec." + System.Environment.NewLine); await Task.Delay(10000); ResponseGetOrderInformationWithID = await GetOrderInformationWithID(textBoxCheckOrderFromID.Text); } //レスポンス (JsonGetChildOrders) を表示。 var DesirializedResponse = JsonConvert.DeserializeObject<JsonGetChildOrders>(ResponseGetOrderInformationWithID.Substring(1, ResponseGetOrderInformationWithID.Length - 2)); textBox1.AppendText("GetOrderInformationWithID succeeded for ID: " + textBoxCheckOrderFromID.Text + System.Environment.NewLine); textBox1.AppendText(" id: " + DesirializedResponse.id + System.Environment.NewLine); textBox1.AppendText(" child_order_id: " + DesirializedResponse .child_order_id+ System.Environment.NewLine); textBox1.AppendText(" product_code: " + DesirializedResponse.product_code + System.Environment.NewLine); textBox1.AppendText(" side: " + DesirializedResponse.side + System.Environment.NewLine); textBox1.AppendText(" child_order_type: " + DesirializedResponse.child_order_type + System.Environment.NewLine); textBox1.AppendText(" price: " + DesirializedResponse.price + System.Environment.NewLine); textBox1.AppendText(" average_price: " + DesirializedResponse.average_price + System.Environment.NewLine); textBox1.AppendText(" size: " + DesirializedResponse.size + System.Environment.NewLine); textBox1.AppendText(" child_order_state: " + DesirializedResponse.child_order_state + System.Environment.NewLine); textBox1.AppendText(" expire_date: " + DesirializedResponse.expire_date + System.Environment.NewLine); textBox1.AppendText(" child_order_date: " + DesirializedResponse.child_order_date + System.Environment.NewLine); textBox1.AppendText(" child_order_acceptance_id: " + DesirializedResponse.child_order_acceptance_id + System.Environment.NewLine); textBox1.AppendText(" outstanding_size: " + DesirializedResponse.outstanding_size + System.Environment.NewLine); textBox1.AppendText(" cancel_size: " + DesirializedResponse.cancel_size + System.Environment.NewLine); textBox1.AppendText(" executed_size: " + DesirializedResponse.executed_size + System.Environment.NewLine); textBox1.AppendText(" total_commission: " + DesirializedResponse.total_commission + System.Environment.NewLine); } } } |
これで自動売買プログラムのできあがり。あとは上昇トレンドになったらこれを流しっぱなしにして様子を見る。