public bool openPosition(double amount, long timestamp, OrderType type, string info = null)
        {
            OpenPosition p = new OpenPosition(amount, timestamp, (type == OrderType.Long ? ask : bid), type, info);

            if (type == OrderType.Long)
            {
                if (openPositionsLong == null)
                {
                    openPositionsLong = p;
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                if (openPositionShort == null)
                {
                    openPositionShort = p;
                }
                else
                {
                    return(false);
                }
            }

            return(true);
        }
        public bool closePosition(OrderType type, long timestamp)
        {
            OpenPosition p = null;

            if (type == OrderType.Long)
            {
                p = openPositionsLong;
            }
            else
            {
                p = openPositionShort;
            }

            if (p != null)
            {
                closedPositions.Add(new ClosedPosition(p, timestamp, (type == OrderType.Long ? bid : ask)));

                if (type == OrderType.Long)
                {
                    openPositionsLong = null;
                }
                else
                {
                    openPositionShort = null;
                }

                return(true);
            }
            else
            {
                return(false);
            }
        }
Beispiel #3
0
        public ClosedPosition(OpenPosition openPosition, long timestampClose, double priceClose)
        {
            this.priceOpen     = openPosition.priceOpen;
            this.timestampOpen = openPosition.timestampOpen;
            this.amount        = openPosition.amount;

            this.priceClose     = priceClose;
            this.timestampClose = timestampClose;
            this.info           = openPosition.info;
        }