示例#1
0
        // load from 'pending.dat' file which saves pending data
        public int loadFile()
        {
            string tradePath = System.IO.Directory.GetCurrentDirectory() + "/pending.dat";

            try
            {
                if (System.IO.File.Exists(tradePath))
                {
                    string[] reader = System.IO.File.ReadAllLines(tradePath);
                    if (reader.Length > 0)
                    {
                        for (int i = 0; i < reader.Length; i++)
                        {
                            string[]  tempLine = reader[i].Split('\t');
                            TradeData tempData = new TradeData();
                            tempData.uuid     = tempLine[0];
                            tempData.date     = DateTime.ParseExact(tempLine[1], "u", provider);
                            tempData.coinName = tempLine[2];
                            tempData.isBid    = bool.Parse(tempLine[3]);
                            tempData.unit     = double.Parse(tempLine[4]);
                            tempData.price    = double.Parse(tempLine[5]);
                            tempData.fee      = tempLine[6] == "" ? 0 : double.Parse(tempLine[6]);
                            addNewPending(tempData);
                        }
                    }
                }
                else
                {
                    System.IO.File.Create(tradePath);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Fail to load pending data : " + ex.Message);
                return(-1);
            }

            return(0);
        }
示例#2
0
        // check macro execution was successfully done
        public int executeCheckResult(int index)
        {
            JObject retData = apiData.checkOrder(order.Rows[index]["uuid"].ToString());

            if (retData == null)
            {
                return(-1);
            }
            if (retData["state"].ToString() != "done" && retData["state"].ToString() != "cancel")
            {
                return(0);
            }

            string[] coinName = retData["market"].ToString().Split('-');
            double   price    = 0d;
            double   volume   = 0d;
            double   fee      = (double)retData["paid_fee"];

            JArray trades = (JArray)retData["trades"];

            for (int i = 0; i < trades.Count; i++)
            {
                price  += (double)trades[i]["price"];
                volume += (double)trades[i]["volume"];
            }
            price  /= trades.Count;
            volume /= trades.Count;

            TradeData tradeData = new TradeData();

            tradeData.uuid     = retData["uuid"].ToString();
            tradeData.date     = Convert.ToDateTime(retData["created_at"]);
            tradeData.coinName = coinName[1];
            tradeData.isBid    = retData["side"].ToString() == "bid" ? true : false;
            tradeData.unit     = volume;
            tradeData.price    = price;
            tradeData.fee      = fee;

            if (tradeData.isBid)
            {
                DataRow row = state.Tables[tradeData.coinName].NewRow();
                row["uuid"]  = tradeData.uuid;
                row["date"]  = tradeData.date;
                row["unit"]  = tradeData.unit;
                row["price"] = tradeData.price;
                row["krw"]   = tradeData.unit * tradeData.price;
                state.Tables[tradeData.coinName].Rows.Add(row);

                executionStr.Add(new output(1,
                                            "Macro execution : Buy " + tradeData.unit.ToString("0.####") + " "
                                            + tradeData.coinName + " for " + (tradeData.price * tradeData.unit).ToString("0.##") + " KRW"));
            }
            else
            {
                for (int i = 0; i < state.Tables[tradeData.coinName].Rows.Count; i++)
                {
                    if (tradeData.uuid == state.Tables[tradeData.coinName].Rows[i]["uuid"].ToString())
                    {
                        double temp_price = (double)state.Tables[tradeData.coinName].Rows[i]["price"];

                        executionStr.Add(new output(1,
                                                    "Macro execution : Sold " + tradeData.unit.ToString("0.########") + " "
                                                    + tradeData.coinName + " for " + (tradeData.price * tradeData.unit).ToString("0.##")
                                                    + " KRW (yield : " + ((tradeData.price - temp_price) * tradeData.unit - (tradeData.fee * 2f)).ToString("0.##") + " KRW)"));
                        state.Tables[tradeData.coinName].Rows.RemoveAt(i);
                        break;
                    }
                }
            }

            order.Rows.RemoveAt(index);
            saveFile();
            return(1);
        }