Ejemplo n.º 1
0
        internal static IList <ITrade> GetOpenTradesByAssetClass(AssetClass ac)
        {
            var trades = new List <ITrade>();

            try
            {
                using var connection = new SqlConnection(Builder.ConnectionString);
                connection.Open();

                const string sql = "SELECT * From Trade INNER JOIN Market ON Trade.MarketId=Market.Id" +
                                   " INNER JOIN Strategy ON Trade.StrategyId=Strategy.Id WHERE CloseLevel IS NULL AND Market.AssetClass = @assetClass;";

                using (var cmd = new SqlCommand(sql, connection))
                {
                    cmd.Parameters.AddWithValue("@assetClass", ac.ToString());
                    var results = cmd.ExecuteReader();

                    if (results.HasRows)
                    {
                        while (results.Read())
                        {
                            trades.Add(ReadTradeIn(results));
                        }
                    }
                }

                connection.Close();
            }
            catch (SqlException e)
            {
                Debug.WriteLine(e.ToString());
            }

            return(trades);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Returns the class UClass if it is loaded. It is not possible to load the class if it is unloaded since we only have the short name.
 /// </summary>
 /// <returns></returns>
 public UClass GetClass()
 {
     if (!IsValid)
     {
         return(null);
     }
     return(UClass.GetClass(AssetClass.ToString()));
 }
Ejemplo n.º 3
0
        public AssetBase CreateAsset(AssetClass assetClass, string ticker, OptionClass?optionClass = null, string underlyingTicker = null, DateTime?expiration = null, double?strike = null)
        {
            switch (assetClass)
            {
            case AssetClass.Stock:
                Stock stock = new Stock(ticker);
                SaveAsset(stock);
                return(stock);

            case AssetClass.ETF:
                ETF etf = new ETF(ticker);
                SaveAsset(etf);
                return(etf);

            case AssetClass.Bond:
                Bond bond = new Bond(ticker);
                SaveAsset(bond);
                return(bond);

            case AssetClass.Option:
                if (optionClass.HasValue)
                {
                    Option option          = new Option(optionClass.Value, ticker);
                    Stock  unserlyingAsset = (Stock)GetAssetyBy(AssetClass.Stock, underlyingTicker);
                    if (unserlyingAsset == null)
                    {
                        unserlyingAsset = new Stock(underlyingTicker);
                        SaveAsset(unserlyingAsset);
                    }
                    option.UnderlyingAsset = unserlyingAsset;
                    option.ExpirationDate  = expiration.Value;
                    option.Strike          = strike.Value;
                    SaveAsset(option);
                    return(option);
                }
                else
                {
                    throw new ArgumentException("Must provide option class (call other put), underlying asset, strike and expiration when asset is an option");
                }

            case AssetClass.Cash:
                Cash cash = new Cash(ticker);
                SaveAsset(cash);
                return(cash);

            default:
                throw new NotImplementedException($"There is no DBSet AssetClass={assetClass.ToString()}");
            }
        }
Ejemplo n.º 4
0
        private IEnumerable <AssetBase> GetDBSetFor(AssetClass assetClass)
        {
            switch (assetClass)
            {
            case AssetClass.Stock:
                return(Stocks);

            case AssetClass.ETF:
                return(ETFs);

            case AssetClass.Bond:
                return(Bonds);

            case AssetClass.Option:
                return(Options);

            case AssetClass.Cash:
                return(Cash);

            default:
                throw new NotImplementedException($"There is no DBSet AssetClass={assetClass.ToString()}");
            }
        }
Ejemplo n.º 5
0
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            JObject    jo         = JObject.Load(reader);
            AssetClass assetClass = (AssetClass)jo["assetClass"].Value <int>();

            switch (assetClass)
            {
            case AssetClass.Stock:
                return(jo.ToObject <Stock>(serializer));

            case AssetClass.ETF:
                return(jo.ToObject <ETF>(serializer));

            case AssetClass.Option:
                return(jo.ToObject <Option>(serializer));

            case AssetClass.Cash:
                return(jo.ToObject <Cash>(serializer));

            case AssetClass.Bond:
                return(jo.ToObject <Bond>(serializer));

            default:
                throw new NotImplementedException($"There is no convertion for asset class='{assetClass.ToString()}'");
            }
        }
Ejemplo n.º 6
0
 public AssetType(AssetClass assetClass) : base(assetClass.ToString())
 {
 }