示例#1
0
 public KeyBinding(Key key, bool onKeyDown,
                   TradeOp operation, BaseQuote quote, double value, int quantity)
 {
     this.Key       = key;
     this.OnKeyDown = onKeyDown;
     this.Action    = new OwnAction(operation, quote, value, quantity);
 }
示例#2
0
 public OwnAction(TradeOp operation, BaseQuote quote, double value, int quantity)
 {
     this.Operation = operation;
     this.Quote     = quote;
     this.Value     = value;
     this.Quantity  = quantity;
 }
        //private readonly IHttpClientFactory _clientFactory;
        //private readonly ServiceProvider services = new ServiceCollection().AddHttpClient().BuildServiceProvider();

        //public OshcApiHandler()
        //{
        //    _clientFactory = services.GetRequiredService<IHttpClientFactory>();
        //}

        public async Task <decimal?> NibApiHandler(BaseQuote bq)
        {
            var startDate = DateTime.Now.ToString("dd-MMM-yyyy");
            var endDate   = DateTime.Now.AddMonths(bq.duration).AddDays(-1).ToString("dd-MMM-yyyy");

            var request = new HttpRequestMessage
            {
                Method     = HttpMethod.Get,
                RequestUri =
                    new Uri(
                        $"https://www.nib.com.au/overseas-students/join/api/price?startDate={startDate}&endDate={endDate}&scale={bq.NibCoverType}"),
                Headers =
                {
                    { HttpRequestHeader.Referer.ToString(),        "https://www.nib.com.au/overseas-students" },
                    { "Origin",                                    "https://www.nib.com.au"                   },
                    { HttpRequestHeader.AcceptEncoding.ToString(), "gzip, deflate, br"                        },
                    { HttpRequestHeader.AcceptLanguage.ToString(), "en-US,en;q=0.5"                           },
                    { HttpRequestHeader.ContentType.ToString(),    "application/json, text/plain, */*"        },
                    { "DNT",                                       "1"                                        },
                    {
                        HttpRequestHeader.UserAgent.ToString(),
                        "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:65.0) Gecko/20100101 Firefox/65.0"
                    }
                }
            };
            //  var client = _clientFactory.CreateClient();
            var t = await client.SendAsync(request).Result.Content.ReadAsStringAsync();

            return(Decimal.Parse(t));
        }
        /// <summary>
        /// Quote is fetched from db because of the response time limitation.
        /// Check cronjob folder for the cronjob that fetches and save prices automatically
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public string OshcGetQuote(DflowWebhookRequest request)
        {
            var stopwatch = new Stopwatch();

            stopwatch.Start();
            var bq    = new BaseQuote();
            var cover = "";

            bq.duration = (int)(request.QueryResult.Parameters.Duration.Value ?? 0);
            if (request.QueryResult.Parameters.Duration.DurationDuration == "year")
            {
                bq.duration = bq.duration * 12;
            }
            var child = request.QueryResult.Parameters.Child.ToLower();
            var adult = request.QueryResult.Parameters.Partner.ToLower();

            if (child == "no" && adult == "no")
            {
                cover = "Single";
            }
            else if (child == "no" && adult == "yes")
            {
                cover = "Couple";
            }
            else if (child == "yes" && adult == "yes")
            {
                cover = "Family";
            }
            else if (child == "yes" && adult == "no")
            {
                cover = "Single Parent";
            }

            string model = "";

            Console.WriteLine($"Sending to Handler: {stopwatch.Elapsed.ToString()} has elapsed");
            mbsContext mbs = new mbsContext();

            try
            {
                OshcQuote quote = mbs.OshcQuote.Where(e => (e.Covertype == cover) && (e.Duration == bq.duration)).OrderByDescending(a => a.Date)
                                  .Select(p => p).FirstOrDefault();;
                Console.WriteLine($"OP class: {stopwatch.Elapsed.ToString()} has elapsed");
                model = $"You will need a {cover} cover.\n" +
                        $"For {bq.duration} months, this is the quote I have fetched:\n" +
                        $"1. Allianz OSHC: ${quote.Allianz}AUD \n" +
                        $"2. Medibank OSHC: ${quote.Medibank}AUD \n" +
                        $"3. Nib OSHC: ${quote.Nib}AUD \n" +
                        $"4. AHM OSHC: ${quote.Ahm}AUD \n" +
                        $"**This quote was fetched on {quote.Date.ToString("g", new CultureInfo("en-AU"))} AEST. It will be updated on {quote.Date.AddDays(1).ToString("d", new CultureInfo("en-AU"))} at 6:00 AM AEST";
                stopwatch.Stop();
            }
            catch (Exception e)
            {
                model = "Sorry, but something went wrong. Please try later";
            }

            return(model);
        }
 private void SetUserName(BaseQuote theObject)
 {
     if (this.Context.CurrentUser == null)
     {
         theObject.UserName = String.Empty;
     }
     else
     {
         theObject.UserName = this.Context.CurrentUser.UserName;
     }
 }
示例#6
0
        public static string ToString(BaseQuote value, bool detailed)
        {
            switch (value)
            {
            case BaseQuote.Counter:
                return(detailed ? "относительно лучшей встречной котировки" : "Встречная");

            case BaseQuote.Similar:
                return(detailed ? "относительно лучшей попутной котировки" : "Попутная");

            case BaseQuote.Absolute:
                return(detailed ? "указанная мышью в стакане" : "Указанная");

            case BaseQuote.Position:
                return(detailed ? "относительно цены позиции" : "Цена поз.");
            }

            return(value.ToString());
        }
示例#7
0
        /// <summary>
        ///     FundID =17
        ///     single = S; Single Parent =P
        ///     Family = F; Couple=D
        /// </summary>
        /// <returns></returns>
        public async Task <string> MedibankQuoteHandler(BaseQuote bq)
        {
            Console.WriteLine("Medibank Start");
            var stopwatch = new Stopwatch();

            stopwatch.Start();
            var startdate = DateTime.Now.ToString("d", new CultureInfo("en-AU"));
            var enddate   = DateTime.Now.AddMonths(bq.duration).AddDays(-1).ToString("d", new CultureInfo("en-AU"));
            var request   = new HttpRequestMessage
            {
                Method     = HttpMethod.Get,
                RequestUri =
                    new Uri(
                        $"https://www.members.medibankoshc.com.au/api/quotes/new?startDate={startdate}&visaEndDate={enddate}&fundId=17&scope={bq.medibankCoverType}&courseCompletionDate={enddate}"),
                Headers =
                {
                    { HttpRequestHeader.Referer.ToString(),        "https://www.medibankoshc.com.au/get-a-quote/" },
                    { "Origin",                                    "https://www.medibankoshc.com.au"              },
                    {
                        HttpRequestHeader.CacheControl.ToString(),
                        "no-store, no-cache, must-revalidate, proxy-revalidate"
                    },
                    { HttpRequestHeader.AcceptEncoding.ToString(), "gzip, deflate, br"                            },
                    { HttpRequestHeader.AcceptLanguage.ToString(), "en-US,en;q=0.5"                               },
                    { "pragma",                                    "no-cache"                                     },
                    { HttpRequestHeader.ContentType.ToString(),    "application/json"                             },
                    { "x-api-key",                                 "WeDmY4YdhyhLxvVrKEiO6OvLod7kiin5HaOBTjxe"     },
                    { "DNT",                                       "1"                                            },
                    {
                        HttpRequestHeader.UserAgent.ToString(),
                        "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.131 Safari/537.36"
                    }
                }
            };
            var client   = _clientFactory.CreateClient();
            var response = await client.SendAsync(request).Result.Content.ReadAsStringAsync();

            var t = JObject.Parse(response)["amount"].ToString();

            Console.WriteLine($"Medibank: {stopwatch.Elapsed.ToString()} has elapsed");
            stopwatch.Stop();
            return(t);
        }
示例#8
0
        public async Task <string> AllianzQuoteHandler(BaseQuote bq)
        {
            Console.WriteLine("Allianz Start");
            var stopwatch = new Stopwatch();

            stopwatch.Start();
            var startDate = DateTime.Now.ToString("yyyy-MM-dd");
            var endDate   = DateTime.Now.AddMonths(bq.duration).AddDays(-1).ToString("yyyy-MM-dd");
            var request   = new HttpRequestMessage
            {
                Method     = HttpMethod.Get,
                RequestUri =
                    new Uri(
                        $"https://ihealthapi.agaassistance.com.au/v1/quote?Adults={bq.Allianzadult}&Dependants={bq.Allianzchild}&StartDate={startDate}&EndDate={endDate}"),
                Headers =
                {
                    {
                        HttpRequestHeader.Referer.ToString(),
                        "https://allianzassistancehealth.com.au/oneweb/angular/iHealth/index.html?appKey=troy-1176533814&&"
                    },
                    { "Origin",                                    "https://allianzassistancehealth.com.au" },
                    { HttpRequestHeader.AcceptEncoding.ToString(), "gzip, deflate, br"                      },
                    { HttpRequestHeader.AcceptLanguage.ToString(), "en-US,en;q=0.5"                         },
                    { "timestamp",                                 DateTime.Now.Ticks.ToString()            },
                    { HttpRequestHeader.ContentType.ToString(),    "application/json"                       },
                    { "X-Requested-With",                          "XMLHttpRequest"                         },
                    { "DNT",                                       "1"                                      },
                    { "Accept",                                    "application/json, text/plain, */*"      },
                    {
                        HttpRequestHeader.UserAgent.ToString(),
                        "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:65.0) Gecko/20100101 Firefox/65.0"
                    }
                }
            };
            var client   = _clientFactory.CreateClient();
            var response = await client.SendAsync(request).Result.Content.ReadAsStringAsync();

            var tt = JObject.Parse(response)["premium"]["amount"].ToString();

            Console.WriteLine($"Allianz: {stopwatch.Elapsed.ToString()} has elapsed");
            stopwatch.Stop();
            return(tt);
        }
示例#9
0
 public OwnAction(TradeOp operation,
                  BaseQuote quote = BaseQuote.None,
                  int value       = 0,
                  QtyType qtyType = QtyType.None,
                  int quantity    = 0,
                  bool isStop     = false,
                  int slippage    = 0,
                  int trailStart  = 0,
                  int trailOffset = 0)
 {
     this.Operation   = operation;
     this.Quote       = quote;
     this.Value       = value;
     this.QtyType     = qtyType;
     this.Quantity    = quantity;
     this.IsStop      = isStop;
     this.Slippage    = slippage;
     this.TrailStart  = trailStart;
     this.TrailOffset = trailOffset;
 }
示例#10
0
        // --------------------------------------------------------------

        public void ReadXml(XmlReader reader)
        {
            List <OwnAction> actions = new List <OwnAction>();

            if (!reader.IsEmptyElement)
            {
                while (reader.Read() && reader.NodeType != XmlNodeType.EndElement)
                {
                    if (reader.NodeType == XmlNodeType.Element && reader.Name == cnBinding)
                    {
                        Key key = (Key)Enum.Parse(typeof(Key), reader.GetAttribute(cnKey));

                        actions.Clear();

                        if (!reader.IsEmptyElement)
                        {
                            while (reader.Read() && reader.NodeType != XmlNodeType.EndElement)
                            {
                                if (reader.IsEmptyElement)
                                {
                                    TradeOp op = (TradeOp)Enum.Parse(typeof(TradeOp), reader.Name);

                                    BaseQuote quote       = BaseQuote.None;
                                    int       value       = 0;
                                    QtyType   qtyType     = QtyType.None;
                                    int       quantity    = 0;
                                    bool      isStop      = false;
                                    int       slippage    = 0;
                                    int       trailStart  = 0;
                                    int       trailOffset = 0;

                                    if (reader.MoveToAttribute(cnQuote))
                                    {
                                        quote = (BaseQuote)Enum.Parse(typeof(BaseQuote),
                                                                      reader.ReadContentAsString());
                                    }

                                    if (reader.MoveToAttribute(cnValue))
                                    {
                                        value = reader.ReadContentAsInt();
                                    }

                                    if (reader.MoveToAttribute(cnQtyType))
                                    {
                                        qtyType = (QtyType)Enum.Parse(typeof(QtyType),
                                                                      reader.ReadContentAsString());
                                    }

                                    if (reader.MoveToAttribute(cnQuantity))
                                    {
                                        quantity = reader.ReadContentAsInt();
                                    }

                                    if (reader.MoveToAttribute(cnSlippage))
                                    {
                                        isStop   = true;
                                        slippage = reader.ReadContentAsInt();

                                        if (reader.MoveToAttribute(cnTrailStart))
                                        {
                                            trailStart = reader.ReadContentAsInt();
                                        }

                                        if (reader.MoveToAttribute(cnTrailOffset))
                                        {
                                            trailOffset = reader.ReadContentAsInt();
                                        }
                                    }

                                    // ========== конвертация с версии 3.5 ==========
                                    if (qtyType == QtyType.None)
                                    {
                                        switch (op)
                                        {
                                        case TradeOp.Close:
                                            qtyType  = QtyType.Position;
                                            quantity = 100;
                                            break;

                                        case TradeOp.Downsize:
                                            op = TradeOp.Close;
                                            break;

                                        case TradeOp.Reverse:
                                            op       = TradeOp.Close;
                                            qtyType  = QtyType.Position;
                                            quantity = 200;
                                            break;
                                        }

                                        if (quantity < 0)
                                        {
                                            qtyType  = QtyType.WorkSize;
                                            quantity = -quantity;
                                        }
                                    }
                                    // ==============================================

                                    actions.Add(new OwnAction(op, quote, value, qtyType,
                                                              quantity, isStop, slippage, trailStart, trailOffset));
                                }
                                else
                                {
                                    throw new FormatException();
                                }
                            }
                        }

                        this.Add(key, actions.ToArray());
                    }
                    else
                    {
                        throw new FormatException();
                    }
                }
            }

            reader.Read();
        }
示例#11
0
 public static string ToString(BaseQuote value)
 {
     return(ToString(value, false));
 }
示例#12
0
 public BaseQuoteItem(BaseQuote value)
 {
     this.Value = value;
 }
示例#13
0
        public async Task <OshcQuote> OshcGetQuote(BotQuoteRequest quoteRequest)
        {
            string Covertype = quoteRequest.CoverType;
            int    duration  = quoteRequest.Duration;
            var    bq        = new BaseQuote
            {
                duration = duration
            };

            var op = new OshcQuote
            {
                Date = DateTime.UtcNow.AddHours(10).ToString("f",
                                                             CultureInfo.CreateSpecificCulture("en-AU")) + " AEST",
                Duration = duration
            };

            // Generating ID using covertype, duration and datetime
            op.Id = Covertype + "-" + duration + "-" + op.Date;
            if (Covertype == "Single")
            {
                bq.Allianzadult      = "1";
                bq.Allianzchild      = "0";
                bq.NibCoverType      = "Single";
                bq.medibankCoverType = "S";
                op.Covertype         = "Single";
            }
            else if (Covertype == "Couple")
            {
                bq.Allianzadult      = "2";
                bq.Allianzchild      = "0";
                bq.NibCoverType      = "Couple";
                bq.medibankCoverType = "D";
                op.Covertype         = "Couple";
            }
            else if (Covertype == "Family")
            {
                bq.Allianzadult      = "2";
                bq.Allianzchild      = "1";
                bq.NibCoverType      = "Family";
                bq.medibankCoverType = "F";
                op.Covertype         = "Family";
            }
            else if (Covertype == "Parent")
            {
                bq.Allianzadult      = "1";
                bq.Allianzchild      = "1";
                bq.NibCoverType      = "Family";
                bq.medibankCoverType = "P";
                op.Covertype         = "Single Parent";
            }

            //  Console.WriteLine($"Sending to Handler: {stopwatch.Elapsed.ToString()} has elapsed");

            var oshcApiHandler = new OshcApiHandler();

            //Parallel request to reduce processing time
            //Might not work in linux based installations. Check before deploying
            //Doesn't work in 5 dollar DigitalOcean droplet

            op.Allianz = await oshcApiHandler.AllianzQuoteHandler(bq);

            op.Nib = await oshcApiHandler.AllianzQuoteHandler(bq);

            op.Ahm = await oshcApiHandler.AhmQuoteHandler(bq);

            op.Medibank = await oshcApiHandler.MedibankQuoteHandler(bq);



            //stopwatch.Stop();
            return(op);
        }