Пример #1
0
        void calcBuySellRemains(int marketID, double[] buysell)
        {
            double buy   = 0;
            double sell  = 0;
            int    total = mContext.mShareManager.getTotalShareIDCount();

            int[] mid = { 0 };
            for (int i = 0; i < total; i++)
            {
                mid[0] = -1;
                int shareID = mContext.mShareManager.getShareIDAt(i, mid);
                if (shareID == 257)
                {
                    shareID = 257;
                }
                if (/*mid[0] == marketID && */ shareID != 0)
                {
                    stPriceboardState ps = mContext.mPriceboard.getPriceboard(shareID);
                    if (ps.getMarketID() == marketID)
                    {
                        buy += ps.getRemainBuyVolume0();
                        buy += ps.getRemainBuyVolume1();
                        buy += ps.getRemainBuyVolume2();

                        sell += ps.getRemainSellVolume0();
                        sell += ps.getRemainSellVolume1();
                        sell += ps.getRemainSellVolume2();
                    }
                }
            }
            buysell[0] = buy;
            buysell[1] = sell;
        }
Пример #2
0
        public void update()
        {
            if (mShare.isIndex())
            {
                if (mShare.mMarketID == 1)
                {
                    setImageIndex(0);
                }
                else if (mShare.mMarketID == 2)
                {
                    setImageIndex(1);
                }
                //  truncate the code
                StringBuilder sb = Utils.sb;
                sb.Length = 0;
                for (int i = 0; i < mShare.mCode.Length; i++)
                {
                    if (mShare.mCode[i] == '^')
                    {
                        continue;
                    }
                    sb.Append(mShare.mCode[i]);
                    //if (sb.Length > 5)
                    //break;
                }
                setTextFont(P_CODE, mContext.getFontSmall());
                setTextForCell(P_CODE, sb.ToString(), C.COLOR_WHITE);

                stPriceboardStateIndex pi = mContext.mPriceboard.getPriceboardIndexOfMarket(mShare.mMarketID);
                //  khop
                uint color = C.COLOR_YELLOW;
                if (pi.changed_point > 0)
                {
                    color = C.COLOR_GREEN;
                }
                else
                {
                    color = C.COLOR_RED;
                }

                setTextForCell(P_PRICE, String.Format("{0:F2}", pi.current_point), color);

                Utils.sb.Length = 0;
                if (pi.changed_point > 0)
                {
                    Utils.sb.AppendFormat("+{0:F2}", (float)(pi.changed_point / 100));
                }
                else
                {
                    Utils.sb.AppendFormat("{0:F2}", ((float)pi.changed_point / 100));
                }
                //  change
                setTextForCell(P_COMPARE, Utils.sb.ToString(), color);
            }
            else
            {
                stPriceboardState ps = mContext.mPriceboard.getPriceboard(mShare.mID);
                if (ps != null)
                {
                    if (ps.getMarketID() == 1)
                    {
                        if (mContext.mAlarmManager.isAlarmInstalled(ps.getCode()))
                        {
                            setImageIndex(2);
                        }
                        else
                        {
                            setImageIndex(0);
                        }
                    }
                    else if (ps.getMarketID() == 2)
                    {
                        if (mContext.mAlarmManager.isAlarmInstalled(ps.getCode()))
                        {
                            setImageIndex(3);
                        }
                        else
                        {
                            setImageIndex(1);
                        }
                    }
                    //  code
                    setTextForCell(P_CODE, ps.getCode(), C.COLOR_WHITE);
                    //setID(ps.getID());
                    //  ref
                    float reference = ps.getRef();
                    float ce        = ps.getCe();
                    float floor     = ps.getFloor();
                    float price     = ps.getCurrentPrice();

                    if (price == 0)
                    {
                        price = ps.getRef();
                    }

                    //  khop
                    uint color = mContext.valToColorF(price, ce, reference, floor);
                    Utils.sb.Length = 0;
                    Utils.sb.AppendFormat("{0:F2}", (float)price);
                    setTextForCell(P_PRICE, Utils.sb.ToString(), color);

                    //  extra info
                    if (mShare.mCompareText == null)
                    {
                        Utils.sb.Length = 0;
                        Utils.sb.AppendFormat("{0:F2}", (float)ps.getChange());
                        mShare.mCompareText = Utils.sb.ToString();
                    }

                    if (mShare.mCompareText != null)
                    {
                        setTextForCell(P_COMPARE, mShare.mCompareText, C.COLOR_WHITE);
                    }
                }
            }
        }
Пример #3
0
        protected void renderCandle(xGraphics g, stCell c)
        {
            int x, y;

            x = c.x;
            y = 0;

            uint color;

            object o = getUserData();
            String code;

            if (o is String)
            {
                code = (String)o;
            }
            else
            {
                stGainloss gainloss = (stGainloss)o;
                code = gainloss.code;
            }

            if (code == null)
            {
                return;
            }
            stPriceboardState ps = Context.getInstance().mPriceboard.getPriceboard(code);

            if (ps == null)
            {
                return;
            }

            Context ctx = Context.getInstance();

            float price = ps.getCurrentPrice();
            float open  = ctx.mPriceboard.getOpen(ps.getID());

            if (open == 0)
            {
                open = price;
            }

            float hi = ps.getMax();
            float lo = ps.getMin();

            //  check hi/lo valid

            if ((hi == 0 || lo == 0))
            {
                TradeHistory trade = Context.getInstance().getTradeHistory(ps.getID());
                float[]      hl    = new float[2];
                if (trade != null && trade.getHiLo(hl))
                {
                    if (hi == 0)
                    {
                        hi = hl[0];
                    }
                    if (lo == 0)
                    {
                        lo = hl[1];
                    }
                }
            }

            if (hi == lo)
            {
                hi = price;
            }

            if (hi == 0)
            {
                hi = open > price ? open : price;
            }
            if (lo == 0)
            {
                lo = open < price ? open : price;
            }
            if (lo == 0)
            {
                lo = hi;
            }
            //---------------------------------------------

            float priceLen = (float)(hi - lo);

            int y0 = 0;

            float min = ps.getRef() - (ps.getRef() / 13);       //	+-7% (7*13==100)
            float max = ps.getRef() + (ps.getRef() / 13);

            if (ps.getMarketID() == 1)
            {
                min = ps.getRef() - (ps.getRef() / 19); //	+-5%
                max = ps.getRef() + (ps.getRef() / 19);
            }

            if (min > lo && lo > 0)
            {
                min = (float)lo;
            }
            if (max < hi)
            {
                max = (float)hi;
            }

            float totalPrice = (max - min);  //(10%);

            if (totalPrice < priceLen)
            {
                totalPrice = priceLen;
            }

            if (totalPrice == 0)
            {
                return;
            }

            float ry = (float)(getH() - 2 * y0) / totalPrice;

            int totalH = (int)(ry * totalPrice);
            int bodyW  = c.w / 2;

            //================frame=============================
            //  line _ref
            g.setColor(0x70ffff00);
            y = (int)(y0 + totalH - (ps.getRef() - min) * ry);
            g.drawLineDotHorizontal(c.x + 1, y, c.w - 2);
            //===================================================
            if (price == 0)
            {
                return; //	khong co giao dich
            }
            color = price < open ? C.COLOR_RED : C.COLOR_GREEN;
            if (price == open)
            {
                color = C.COLOR_WHITE;
            }

            //  draw shadow
            g.setColor(C.COLOR_WHITE);
            x = c.x + c.w / 2;

            if (lo > 0 && hi > 0)
            {
                int minY = (int)(y0 + totalH - (lo - min) * ry);
                int maxY = (int)(y0 + totalH - (hi - min) * ry);

                g.drawLine(x, maxY, x, minY);
            }
            int centerX = x + bodyW / 2;
            //  candle's body
            int oY = (int)(y0 + totalH - (open - min) * ry);
            int cY = (int)(y0 + totalH - (price - min) * ry);

            y = oY < cY ? oY : cY;
            int bodyH = Utils.ABS_INT(cY - oY);

            if (bodyH < 2)
            {
                bodyH = 2;
            }
            g.setColor(color);
            g.fillRect(x - bodyW / 2, y, bodyW, bodyH);
        }
Пример #4
0
        static public void _exportGroupToCSV(xVector v, String sortedColumn, String filepath)
        {
            String cols = "Market, Symbol, Close, Open, Hi, Lo, Volume, Gia tri GD(vnd), EPS(K), PE, RSI, MFI, KL Niem yet(mil), Von Hoa(bil), Company\n";

            //if (sortedColumn != null)
            //{
            //cols = String.Format("Market, Symbol, Close, Open, Hi, Lo, Volume, Gia tri GD, EPS, PE, RSI, MFI, KL Niem yet, Von Hoa, Company", sortedColumn);
            //}

            //xFileManager.removeFile(filepath);

            try{
                Encoding               encoding = Encoding.GetEncoding("UTF-8");
                System.IO.FileStream   fs       = new System.IO.FileStream(filepath, System.IO.FileMode.Create);
                System.IO.StreamWriter writer   = new System.IO.StreamWriter(fs, encoding);
                writer.Write(cols);

                for (int i = 0; i < v.size(); i++)
                {
                    Share share = (Share)v.elementAt(i);

                    if (share != null)
                    {
                        stPriceboardState ps = Context.getInstance().mPriceboard.getPriceboard(share.getCode());

                        if (ps != null & share != null)
                        {
                            share.loadShareFromCommonData(true);
                            if (share.getCandleCnt() < 3)
                            {
                                continue;
                            }

                            if (share.mCode.CompareTo("HPG") == 0)
                            {
                                int t = 0;
                            }

                            String market = "-";

                            if (ps.getMarketID() == 1)
                            {
                                market = "HSX";
                            }
                            else if (ps.getMarketID() == 2)
                            {
                                market = "HNX";
                            }
                            else if (ps.getMarketID() == 3)
                            {
                                market = "UPC";
                            }

                            share.selectCandle(share.getCandleCnt() - 1);
                            String price = String.Format("{0:F2}", share.getClose());
                            String open  = String.Format("{0:F2}", share.getOpen());
                            String hi    = String.Format("{0:F2}", share.getHighest());
                            String lo    = String.Format("{0:F2}", share.getLowest());

                            stCompanyInfo inf     = Context.getInstance().mShareManager.getCompanyInfo(ps.id);
                            String        company = "";
                            String        vonhoa  = "0";
                            if (inf != null)
                            {
                                company = inf.company_name;
                                vonhoa  = "" + inf.vontt;
                            }

                            share.calcRSI(0);
                            share.calcMFI(0);

                            double giatriGD = ps.current_price_1 * ps.total_volume;
                            giatriGD *= 1000; //  to vnd

                            double vontt = 0; // inf.vontt;
                            if (vontt == 0)
                            {
                                vontt = inf.volume * ps.current_price_1;
                            }
                            vontt /= 1000;  //  to ti vnd

                            String line = "";
                            if (false)//sortedColumn != null)
                            {
                                line = String.Format("{0}, {1}, {2}, {3}, {4}, {5}, {6:D},{7},{8}\n",
                                                     market, ps.code,     //  0, 1
                                                     price, open, hi, lo, //  2, 3, 4, 5
                                                     share.getVolume(),
                                                     share.mCompareText,
                                                     company
                                                     );
                            }
                            else
                            {
                                //  0       1       2      3    4   5   6           7       8    9  10   11     12          13          14
                                //Market, Symbol, Close, Open, Hi, Lo, Volume, Gia tri GD, EPS, PE, RSI, MFI, KL Niem yet, Von Hoa, Company
                                line = String.Format("{0}, {1}, {2}, {3}, {4}, {5}, {6:D},{7},{8:F2},{9:F2},{10:F1},{11:F1},{12:F1},{13:F1},{14}\n",
                                                     market, ps.code,                      //  0, 1
                                                     price, open, hi, lo,                  //  2, 3, 4, 5
                                                     share.getVolume(),                    //  6
                                                     giatriGD,                             //  7   gia tri GD
                                                     inf.EPS / 1000.0f,                    //  8:   EPS
                                                     inf.PE / 1000.0f,                     //  9: PE
                                                     share.pRSI[share.getCandleCnt() - 1], //  10: RSI
                                                     share.pMFI[share.getCandleCnt() - 1], //  11: MFI
                                                     ((double)inf.volume / 1000),          //  12: KL niem yet
                                                     vontt,                                //  13: von thi truong

                                                     company
                                                     );
                            }


                            writer.Write(line);
                        }
                    }
                }
                writer.Close();
            }
            catch (Exception e) {
            }
        }