Exemplo n.º 1
0
        public async Task ExcecuteMarketTrade(NewOrderRequest orderRequest, AlpacaEnviornment type)
        {
            var tasks  = new List <Task>();
            var trades = new List <TradeTemplate>();
            var users  = await BR.GetAppUsers();

            users = users.Where(e => e.EnableLiveTrading == "Y").ToList();

            users.Where(asdfadf => asdfadf.EnablePaperTrading == "Y").ToList();
            foreach (var user in users)
            {
                var keys = new AlpacaKeys()
                {
                    LiveApiKey     = user.ApiKey,
                    LiveSecretKey  = user.SecretKey,
                    PaperApiKey    = user.PaperApiKey,
                    PaperSecretKey = user.PaperSecretKey
                };
                var template = new TradeTemplate(type, keys, orderRequest, user.UserId, user);
                trades.Add(template);
            }


            trades.ForEach(e => tasks.Add(e.ExecuteOrder()));
            await Task.WhenAll(tasks);

            Logger.Info("Trades");
        }
Exemplo n.º 2
0
 public TradeTemplate(AlpacaEnviornment type, AlpacaKeys keys, NewOrderRequest orderRequest, int userId, AppUsers user = null)
 {
     Logger = NLogBuilder.ConfigureNLog("nlog.config").GetCurrentClassLogger();
     if (type == AlpacaEnviornment.Live)
     {
         AlpacaTradingClient = Environments.Live.GetAlpacaTradingClient(new SecretKey(keys.LiveApiKey, keys.LiveSecretKey));
     }
     else if (type == AlpacaEnviornment.Paper)
     {
         AlpacaTradingClient = Environments.Paper.GetAlpacaTradingClient(new SecretKey(keys.PaperApiKey, keys.PaperSecretKey));
     }
     else
     {
     }
     AppUser      = user;
     OrderRequest = orderRequest;
     UserId       = userId;
     SuccessFlag  = false;
     HasRan       = false;
 }