Beispiel #1
0
        static async Task ShowAssetInfo()
        {
            Console.WriteLine("");
            Console.WriteLine("========================================");
            Console.WriteLine("asset");
            Console.WriteLine("========================================");

            // 資産情報を取得・表示
            var assetList = await client.GetMyAssetList();

            Console.WriteLine(assetList);
            Console.WriteLine("JPY = " + assetList.Jpy.Amount);
            Console.WriteLine("JPY(Available) = " + assetList.Jpy.Available);
            Console.WriteLine("BTC = " + assetList.Btc.Amount);

            // 証拠金情報
            var collateral = await client.GetMyCollateral();

            Console.WriteLine(collateral);

            // 建玉情報
            Console.WriteLine("----positions----");
            var positions = await client.GetMyPositions();

            foreach (var p in positions)
            {
                Console.WriteLine(p);
            }
            Console.WriteLine("----/positions----");


            Console.WriteLine("");
        }
Beispiel #2
0
        /// <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);
            }
        }
Beispiel #3
0
        // 天気によって売買を判断するボット
        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);
                    }
                }
            }
        }
Beispiel #4
0
        async Task getPosition()
        {
            Collateral col = null;

            try
            {
                col = await client.GetMyCollateral();
            }
            catch (Exception ex)
            {
                label2.Text = "Failed to get collateral info.";
                label3.Text = "";
                label6.Text = ex.ToString();

                return;
            }

            label2.Text = "Equity: " + Math.Round(col.CollateralAmount, 1).ToString() + " JPY,  Margin: " + Math.Round(col.KeepRate * 100, 2).ToString() + " %";

            List <Position> pos = null;

            try
            {
                pos = await client.GetMyPositions();
            }
            catch (Exception ex)
            {
                label3.Text = "Failed to get position info.";
                label6.Text = ex.ToString();

                return;
            }

            double average = 0;

            positions = 0;

            foreach (Position ps in pos)
            {
                average   += (ps.Size * ps.Price);
                positions += ps.Size;
            }

            if (pos.Count == 0)
            {
                label8.Text      = "Ave: ";
                label3.Text      = "No Open Position.";
                label3.ForeColor = Color.Black;
            }
            else
            {
                label8.Text = "Ave: " + Math.Round(average / positions, 1).ToString();
                label3.Text = pos[0].Side + ss[1] + positions.ToString() + " BTC,  PL: " + (0 < col.OpenPositionProfitAndLoss ? "+" : "") + Math.Round(col.OpenPositionProfitAndLoss, 1).ToString() + " JPY";

                if (0 <= col.OpenPositionProfitAndLoss)
                {
                    label3.ForeColor = Color.Blue;
                }
                else
                {
                    label3.ForeColor = Color.Red;
                }
            }
        }