private async void sellMarket_Click(object sender, EventArgs e) { try { label6.Text = "Sell Market " + amount.ToString() + " BTC Requesting"; await client.Sell(amount); label6.Text = "Sell Market " + amount.ToString() + " BTC Accepted"; } catch (Exception ex) { label6.Text = "Sell Market " + amount.ToString() + " BTC Failed."; label6.Text += "\n" + ex.ToString(); Console.WriteLine(ex); await Task.Delay(5000); } await Task.Delay(3000); }
// 天気によって売買を判断するボット static async Task BotLogic() { // 東京の今日の天気 string url = "http://weather.livedoor.com/forecast/webservice/json/v1?city=130010"; HttpClient httpClient = new HttpClient(); string json = await httpClient.GetStringAsync(url); var data = JsonConvert.DeserializeObject <dynamic>(json); string telop = data.forecasts[0].telop; // ログ Console.WriteLine("東京の今日の天気: " + telop); // 晴れっぽい天気なら買う if (telop.IndexOf("晴") >= 0) { Console.WriteLine("buy"); await client.Buy(0.001); } // それ以外なら建玉を手じまいする else { Console.WriteLine("leave all positions"); var positions = await client.GetMyPositions(); foreach (var p in positions) { if (p.Side == OrderSide.BUY) { await client.Sell(p.Size); } else if (p.Side == OrderSide.SELL) { await client.Buy(p.Size); } } } }
/// <summary> /// Bitflyerの建玉の手じまいをする /// </summary> /// <param name="client"></param> /// <returns></returns> public static async Task Tejimai(BitflyerClient client) { await client.CancelAllOrders(); double buy = 0; double sell = 0; try { Console.WriteLine("leave all positions"); var positions = await client.GetMyPositions(); foreach (var p in positions) { if (p.Side == OrderSide.BUY) { sell += p.Size; } else if (p.Side == OrderSide.SELL) { buy += p.Size; } } if (sell >= 0.001) { //sell = ToRoundDown(sell, 3); await client.Sell(sell); } if (buy >= 0.001) { //buy = ToRoundDown(buy, 3); await client.Buy(buy); } } catch (Exception ex) { Console.WriteLine("Error: " + ex.Message + "," + sell + "," + buy); } }