Beispiel #1
0
        public static async Task <SendChildOrderResponse> SellMarket
        (
            AuthBitflyer auth,
            string product_code,
            double size
        )
        {
            SendChildOrderResponse retObj = null;

            try
            {
                retObj = await PostSendChildOrder(
                    auth,
                    product_code,
                    "MARKET",
                    "SELL",
                    0.0,
                    size,
                    10000,
                    "GTC"
                    );
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                retObj = null;
            }
            finally
            {
            }
            return(retObj);
        }
Beispiel #2
0
        public static async Task <SendChildOrderResponse> PostSendChildOrder
        (
            AuthBitflyer auth,
            SendChildOrderBody bodyObj
        )
        {
            SendChildOrderResponse retObj = null;

            try
            {
                if (bodyObj == null)
                {
                    Console.WriteLine("SendChildOrderBody is null.");
                    return(null);
                }

                string method = "POST";
                string path   = "/v1/me/sendchildorder";

                string body = JsonConvert.SerializeObject(bodyObj, Formatting.None);
                if (body == null || body.Length <= 0)
                {
                    Console.WriteLine("failed to Serialize bodyObj.");
                    return(null);
                }

                string resJson = await RequestBitflyer.Request(auth, method, path, body);

                if (resJson == null)
                {
                    //Console.WriteLine("failed to RequestBitflyer.");
                    return(null);
                }

                retObj = JsonConvert.DeserializeObject <SendChildOrderResponse>(resJson);
                if (retObj == null)
                {
                    Console.WriteLine("SendChildOrder's DeserializeObject is null.");
                    return(null);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                retObj = null;
            }
            finally
            {
            }
            return(retObj);
        }
Beispiel #3
0
        public static async Task <SendChildOrderResponse> PostSendChildOrder
        (
            AuthBitflyer auth,
            string product_code,
            string child_order_type,
            string side,
            double price,
            double size,
            int minute_to_expire,
            string time_in_force
        )
        {
            SendChildOrderResponse retObj = null;

            try
            {
                SendChildOrderBody bodyObj = new SendChildOrderBody();
                if (bodyObj == null)
                {
                    Console.WriteLine("failed to create SendChildOrderBody.");
                    return(null);
                }
                bodyObj.product_code     = product_code;
                bodyObj.child_order_type = child_order_type;
                bodyObj.side             = side;
                bodyObj.price            = price;
                bodyObj.size             = size;
                bodyObj.minute_to_expire = minute_to_expire;
                bodyObj.time_in_force    = time_in_force;

                retObj = await PostSendChildOrder(auth, bodyObj);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                retObj = null;
            }
            finally
            {
            }
            return(retObj);
        }
Beispiel #4
0
        // average_priceを返す 失敗すれば0.0
        private static async Task <double> SendMarketAcceptance
        (
            AuthBitflyer auth,
            string side,
            string product_code,
            double size
        )
        {
            double result = 0.0;

            try
            {
                SendChildOrderResponse retObj = await PostSendChildOrder(
                    auth,
                    product_code,
                    "MARKET",
                    side,
                    0.0,
                    size,
                    10000,
                    "GTC"
                    );

                if (retObj == null)
                {
                    Console.WriteLine("faile to SellMarketAcceptance.");
                    return(result);
                }

                Console.WriteLine("child_order_acceptance_id={0}", retObj.child_order_acceptance_id);

                int retry_cnt = 0;
                while (true)
                {
                    System.Threading.Thread.Sleep(1000);

                    JArray retArray = await getChildOrdersAcceptance(auth, product_code, retObj.child_order_acceptance_id);

                    if (retArray != null && retArray.Count > 0)
                    {
                        JObject jobj   = (JObject)retArray[0];
                        JValue  jvalue = (JValue)jobj["average_price"];
                        result = (double)jvalue.Value;
                        break;
                    }
                    else
                    {
                        Console.WriteLine("retry={0}. faile to getChildOrdersAcceptance.", retry_cnt);
                    }


                    retry_cnt++;
                    if (retry_cnt > 180)
                    {
                        Console.WriteLine("timeout. faile to getChildOrdersAcceptance.");
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                result = 0.0;
            }
            finally
            {
            }
            return(result);
        }