示例#1
0
        void PositionCache_CacheEvent(int action, int row)
        {
            int err = 0;
            object cv = new object();
            decimal dv = 0;
            String symbol = string.Empty;
            decimal pl = 0.00M;
            decimal value = 0.00M;
            int size = 0;
            string acct = string.Empty;
            if (action == 1)
            {
                try
                {
                    v("for position submit row: " + row.ToString());
                    int i = row != 0 ? row - 1 : row;
                    _positionCache.VBGetCell(i, "SYMBOL", ref cv, ref err);
                    v("getcellerr: " + err.ToString());
                    if (!(cv == null))
                    {
                        symbol = cv.ToString();
                    }
                    _positionCache.VBGetCell(i, "PANDL", ref cv, ref err);
                    if (!(cv == null))
                    {
                        if (decimal.TryParse(cv.ToString(), out dv))
                            pl = dv;
                    }
                    _positionCache.VBGetCell(i, "ACCOUNT", ref cv, ref err);
                    v("getcellerr: " + err.ToString());
                    if (!(cv == null))
                    {
                        acct = cv.ToString();
                    }
                    _positionCache.VBGetCell(i, "SYMBOLPOSITION", ref cv, ref err);
                    v("getcellerr: " + err.ToString());
                    if (!(cv == null))
                    {
                        int val;
                        if (int.TryParse(cv.ToString(), out val))
                            size = val;
                    }
                    _positionCache.VBGetCell(i, "ACCOUNTSYMBOLVALUE", ref cv, ref err);
                    v("getcellerr: " + err.ToString());
                    if (!(cv == null))
                    {
                        if (decimal.TryParse(cv.ToString(), out dv))
                            value = dv;
                    }
                    Position p = new PositionImpl(symbol, value, size, pl, acct);
                    pt.NewPosition(p);
                    v("new position: " + p.ToString());
                    // track account
                    if (!accts.Contains(acct))
                        accts.Add(acct);

                }
                catch (Exception exc)
                {
                    debug(exc.Message);
                }
            }
            else
            {
                try
                {
                    v("for position submit row: " + row.ToString());
                    int i = row;
                    _positionCache.VBGetCell(i, "SYMBOL", ref cv, ref err);
                    v("getcellerr: " + err.ToString());
                    if (!(cv == null))
                    {
                        symbol = cv.ToString();
                    }
                    _positionCache.VBGetCell(i, "PANDL", ref cv, ref err);
                    if (!(cv == null))
                    {
                        if (decimal.TryParse(cv.ToString(), out dv))
                            pl = dv;
                    }
                    _positionCache.VBGetCell(i, "ACCOUNT", ref cv, ref err);
                    v("getcellerr: " + err.ToString());
                    if (!(cv == null))
                    {
                        acct = cv.ToString();
                    }
                    _positionCache.VBGetCell(i, "SYMBOLPOSITION", ref cv, ref err);
                    v("getcellerr: " + err.ToString());
                    if (!(cv == null))
                    {
                        int val;
                        if (int.TryParse(cv.ToString(), out val))
                            size = val;
                    }
                    _positionCache.VBGetCell(i, "ACCOUNTSYMBOLVALUE", ref cv, ref err);
                    v("getcellerr: " + err.ToString());
                    if (!(cv == null))
                    {
                        if (decimal.TryParse(cv.ToString(), out dv))
                            value = dv;
                    }
                    Position p = new PositionImpl(symbol, value, size, pl, acct);
                    pt.NewPosition(p);
                    v(p.ToString());
                    // track account
                    if (!accts.Contains(acct))
                        accts.Add(acct);
                }
                catch (Exception exc)
                {
                    debug(exc.Message);
                }
            }
        }
示例#2
0
 void dopositionupdate(ref structSTIPositionUpdate structPositionUpdate)
 {
     // symbol
     string sym = structPositionUpdate.bstrSym;
     // size
     int size = (structPositionUpdate.nSharesBot - structPositionUpdate.nSharesSld) + structPositionUpdate.nOpeningPosition;
     // price
     decimal price = size == 0 ? 0 :Math.Abs((decimal)structPositionUpdate.fPositionCost / size);
     // closed pl
     decimal cpl = (decimal)structPositionUpdate.fReal;
     // account
     string ac = structPositionUpdate.bstrAcct;
     // build position
     Position p = new PositionImpl(sym, price, size, cpl, ac);
     // track it
     pt.NewPosition(p);
     // track account
     if (!accts.Contains(ac))
         accts.Add(ac);
     if (VerboseDebugging)
         debug("new position recv: " + p.ToString());
 }
示例#3
0
 Position[] tl_newPosList(string account)
 {
     AmeritradeBrokerAPI.ATradeArgument brokerAcctPosArgs = new AmeritradeBrokerAPI.ATradeArgument();
     brokerAcctPosArgs.oPositions = new List<AmeritradeBrokerAPI.Positions>();
     api.TD_getAcctBalancesAndPositions(_user.Text, _pass.Text, AmeritradeBrokerAPI.SOURCEID, APIVER, ref brokerAcctPosArgs.oCashBalances, ref brokerAcctPosArgs.oPositions);
     List<Position> plist = new List<Position>();
     foreach (AmeritradeBrokerAPI.Positions oPosition in brokerAcctPosArgs.oPositions)
     {
         try
         {
             decimal price = 0;
             string acct = brokerAcctPosArgs.BrokerAcctID;
             decimal.TryParse(oPosition.AveragePric, out price);
             int size = 0;
             int.TryParse(oPosition.Quantity, out size);
             Position p = new PositionImpl(oPosition.StockSymbol, price, size, 0, acct);
             if (p.isValid)
                 plist.Add(p);
             else
                 debug("can't send invalid position: " + p.ToString());
         }
         catch (Exception ex)
         {
             debug("can't send invalid position: " + oPosition.StockSymbol + " " + oPosition.AveragePric + " " + oPosition.Quantity + " " + brokerAcctPosArgs.BrokerAcctID);
         }
     }
     return plist.ToArray();
 }
示例#4
0
 Position[] ServerBlackwood_newPosList(string account)
 {
     foreach (BWStock s in m_Session.GetOpenPositions())
     {
         Position p = new PositionImpl(s.Symbol, (decimal)s.Price, s.Size, (decimal)s.ClosedPNL);
         pt.Adjust(p);
         v(p.Symbol + " found position: " + p.ToString());
     }
     return pt.ToArray();
 }
示例#5
0
 void m_Session_OnPositionMessage(object sender, BWPosition positionMsg)
 {
     string sym = positionMsg.Symbol;
     int size = positionMsg.Size;
     decimal price = (decimal)positionMsg.Price;
     decimal cpl = (decimal)positionMsg.CloseProfit;
     //string ac = positionMsg.UserID.ToString();
     Position p = new PositionImpl(sym, price, size, cpl, _acct);
     pt.NewPosition(p);
     v(p.Symbol + " new position information: " + p.ToString());
 }
示例#6
0
        void dopositionupdate(ref structSTIPositionUpdate structPositionUpdate)
        {
            // symbol
            string ssym = structPositionUpdate.bstrSym;
            string sym = ssym;
            if (UseSubscribedSymbolForNotify)
            {
                sym = getfullsymbolname(ssym);
            }
            if (!UseSubscribedSymbolForNotify || (sym == ssym))
            {
                // only do for non-equities
                if (structPositionUpdate.bstrInstrument == "O")
                    sym = ssym + " "+SecurityType.OPT;
                else if (structPositionUpdate.bstrInstrument == "X")
                    sym = ssym + " " + SecurityType.CASH;
                else if (structPositionUpdate.bstrInstrument == "F")
                    sym = ssym + " " + SecurityType.FUT;
            }

            // size
            int size = (structPositionUpdate.nSharesBot - structPositionUpdate.nSharesSld) + structPositionUpdate.nOpeningPosition;
            // price
            decimal price = size == 0 ? 0 :Math.Abs((decimal)structPositionUpdate.fPositionCost / size);
            // closed pl
            decimal cpl = (decimal)structPositionUpdate.fReal;
            // account
            string ac = structPositionUpdate.bstrAcct;
            // build position
            Position p = new PositionImpl(sym, price, size, cpl, ac);
            // track it
            bool adjust = false;
            if (_posupdatelimit && _receivedorder)
                ;
            else
            {
                pt.NewPosition(p);
                adjust = true;
            }
            if (RegSHOShorts)
                sho.GotPosition(p);
            // track account
            if (!accts.Contains(ac))
                accts.Add(ac);
            if (VerboseDebugging)
                debug("new position recv: " + p.ToString()+" info: "+pt[p.Symbol,ac]+" acct: "+ac);
        }
 Position[] ServerBlackwood_newPosList(string account)
 {
     v(String.Format("Received position list request for account: {0}", account));
     foreach (BWStock s in m_Session.GetOpenPositions())
     {
         Position p = new PositionImpl(s.Symbol, (decimal)s.Price, s.Size, (decimal)s.ClosedPNL);
         pt.Adjust(p);
         v(String.Format("{0} found position: {1}" ,p.symbol, p.ToString()));
     }
     return pt.ToArray();
 }