Esempio n. 1
0
        private static decimal FindTWMarginRequirement(string account, Positions positions)
        {
            Position pos = positions.ElementAt(0).Value;

            // this loop could be eliminated if the long symbol name gets persisted in database
            foreach (KeyValuePair <string, TWMargin> p in twMarginReq[account])
            {
                TWMargin mar = p.Value;
                if (pos.Symbol == mar.Symbol)
                {
                    return(mar.CapitalRequirement);
                }
            }

            return(0M);
        }
Esempio n. 2
0
        // used for determining capital requirement during initial load
        public static TWMargins MarginData(string accountNumber)
        {
            SetHeaders(Token);
            string reply = Web.DownloadString("https://api.tastyworks.com/margin/accounts/" + accountNumber);

            JObject package = JObject.Parse(reply);

            List <JToken> list = package["data"]["underlyings"].Children().ToList();

            TWMargins retval = new TWMargins();

            foreach (JToken item in list)
            {
                TWMargin mar = new TWMargin();
                mar.Symbol             = item["underlying-symbol"].ToString();
                mar.CapitalRequirement = Convert.ToDecimal(item["maintenance-requirement"]);
                retval.Add(mar.Symbol, mar);
            }

            return(retval);
        }