示例#1
0
        // average_priceを返す 失敗すれば0.0
        public static async Task <GetParentOrderResponse> getParentOrderOCO
        (
            AuthBitflyer auth,
            string product_code,
            string acceptance_id
        )
        {
            GetParentOrderResponse result = null;

            try
            {
                JObject retObj = await getParentOrderAcceptance(auth, product_code, acceptance_id);

                if (retObj == null)
                {
                    result = null;
                    return(result);
                }

                int    page_id         = (int)retObj["id"];
                string parent_order_id = (string)retObj["parent_order_id"];
                if (parent_order_id == null || parent_order_id.Length <= 0)
                {
                    result = null;
                    return(result);
                }

                JArray retArray = await getChildOrdersParent(auth, product_code, parent_order_id);

                if (retArray == null || retArray.Count <= 0)
                {
                    result = new GetParentOrderResponse();
                    if (result == null)
                    {
                        return(result);
                    }
                    result.page_id            = page_id;
                    result.parent_order_id    = parent_order_id;
                    result.side               = "";
                    result.average_price      = 0.0;
                    result.parent_order_state = "NONE";

                    return(result);
                }

                JObject compObj = null;

                int cntReject  = 0;
                int cntExpired = 0;
                int cntCanceld = 0;
                int cntActive  = 0;

                List <GetChildOrderResponse> children = new List <GetChildOrderResponse>();
                if (children == null)
                {
                    result = null;
                    return(result);
                }

                foreach (JObject jobj in retArray)
                {
                    if (jobj == null)
                    {
                        continue;
                    }

                    GetChildOrderResponse child = new GetChildOrderResponse();
                    if (child == null)
                    {
                        continue;
                    }

                    child.child_order_state         = (string)jobj["child_order_state"];
                    child.average_price             = (double)jobj["average_price"];
                    child.price                     = (double)jobj["price"];
                    child.child_order_id            = (string)jobj["child_order_id"];
                    child.child_order_acceptance_id = (string)jobj["child_order_acceptance_id"];
                    child.side = (string)jobj["side"];

                    children.Add(child);


                    if (child.child_order_state == "COMPLETED")
                    {
                        compObj = jobj;
                    }
                    else if (child.child_order_state == "REJECTED")
                    {
                        cntReject++;
                    }
                    else if (child.child_order_state == "EXPIRED")
                    {
                        cntExpired++;
                    }
                    else if (child.child_order_state == "CANCELED")
                    {
                        cntCanceld++;
                    }
                    else if (child.child_order_state == "ACTIVE")
                    {
                        cntActive++;
                    }
                }

                if (compObj != null)
                {
                    result = new GetParentOrderResponse();
                    if (result == null)
                    {
                        return(result);
                    }
                    result.page_id            = page_id;
                    result.parent_order_id    = parent_order_id;
                    result.side               = (string)compObj["side"];;
                    result.average_price      = (double)compObj["average_price"];
                    result.parent_order_state = (string)compObj["child_order_state"];
                    result.children           = children;
                    Console.WriteLine("COMPLETED. side={0} state={1} accept_id={2} parent_id={3}", result.side, result.parent_order_state, acceptance_id, parent_order_id);
                }
                else if (cntActive == retArray.Count)
                {
                    result = new GetParentOrderResponse();
                    if (result == null)
                    {
                        return(result);
                    }
                    result.page_id            = page_id;
                    result.parent_order_id    = parent_order_id;
                    result.side               = "";
                    result.average_price      = 0.0;
                    result.parent_order_state = "ACTIVE";
                    result.children           = children;
                    //Console.WriteLine("ACTIVE. side={0} state={1} accept_id={2} parent_id={3}", result.side, result.parent_order_state, acceptance_id, parent_order_id);
                }
                else if (cntCanceld == retArray.Count)
                {
                    result = new GetParentOrderResponse();
                    if (result == null)
                    {
                        return(result);
                    }
                    result.page_id            = page_id;
                    result.parent_order_id    = parent_order_id;
                    result.side               = "";
                    result.average_price      = 0.0;
                    result.parent_order_state = "CANCELED";
                    result.children           = children;
                    Console.WriteLine("CANCELED. side={0} state={1} accept_id={2} parent_id={3}", result.side, result.parent_order_state, acceptance_id, parent_order_id);
                }
                else if ((cntReject + cntExpired) == retArray.Count)
                {
                    result = new GetParentOrderResponse();
                    if (result == null)
                    {
                        return(result);
                    }
                    result.page_id            = page_id;
                    result.parent_order_id    = parent_order_id;
                    result.side               = "";
                    result.average_price      = 0.0;
                    result.parent_order_state = "REJECTED";
                    result.children           = children;
                    Console.WriteLine("REJECTED. side={0} state={1} accept_id={2} parent_id={3}", result.side, result.parent_order_state, acceptance_id, parent_order_id);
                }
                else
                {
                    //Console.WriteLine("Entry Order is NULL. accept_id={0} parent_id={1}", acceptance_id, parent_order_id);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                result = null;
            }
            finally
            {
            }
            return(result);
        }
示例#2
0
        // average_priceを返す 失敗すれば0.0
        public static async Task <GetChildOrderResponse> getChildOrderAveragePrice
        (
            AuthBitflyer auth,
            string product_code,
            string acceptance_id
        )
        {
            GetChildOrderResponse result = null;

            try
            {
                JArray retArray = await getChildOrdersAcceptance(auth, product_code, acceptance_id);

                if (retArray != null && retArray.Count > 0)
                {
                    bool   isReject   = false;
                    bool   isFullComp = true;
                    double price      = 0.0;
                    string state      = "";
                    bool   isFirst    = true;
                    foreach (JObject jobj in retArray)
                    {
                        JValue average_price     = (JValue)jobj["average_price"];
                        JValue child_order_state = (JValue)jobj["child_order_state"];
                        if ((string)child_order_state != "COMPLETED")
                        {
                            isFullComp = false;
                        }
                        if ((string)child_order_state == "REJECTED")
                        {
                            isReject = true;
                        }
                        if (isFirst)
                        {
                            price   = (double)average_price;
                            state   = (string)child_order_state;
                            isFirst = false;
                        }
                    }

                    if (isFullComp)
                    {
                        result = new GetChildOrderResponse();
                        if (result == null)
                        {
                            return(result);
                        }
                        result.average_price     = price;
                        result.child_order_state = state;
                    }
                    else if (isReject)
                    {
                        result = new GetChildOrderResponse();
                        if (result == null)
                        {
                            return(result);
                        }
                        result.average_price     = 0.0;
                        result.child_order_state = "REJECTED";
                    }
                }
                else
                {
                    //Console.WriteLine("failed to getChildOrderAveragePrice.");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                result = null;
            }
            finally
            {
            }
            return(result);
        }