Esempio n. 1
0
        public override PricingResultEntity ProcessOutputDocument(PricingParameters pricingParameters, IPricingOutputDocumentBase outputDocument, string currency)
        {
            if (outputDocument != null)
            {
                /*
                 * outputDocument.GetType().GetRuntimeProperty("PricingSeverity").SetValue(outputDocument, PricingSeverity.Warning);
                 * Message message = new Message(this.GetType(), "ProcessOutputDocument", SeverityCode.Warning, "My Message");
                 * MethodInfo method = outputDocument.GetType().GetMethod("AddMessage", new [] {message.GetType()});
                 *
                 * this.LogDebug("*** ZPricingManager:Before Invoke " + (method != null) + " " + outputDocument.Messages.Count());
                 * method.Invoke(outputDocument, new object[] { message });
                 * this.LogDebug("*** ZPricingManager:After Invoke " + outputDocument.Messages.Count());
                 */


                if (warningMet)
                {
                    this.LogDebug("*** ZPricingManager:ShowAlert=> " + WarningMessage);
                    Dialog.ShowAlertAsync("Condiciones De Ventas", WarningMessage);
                    //Dialog.ShowErrorAsync("Condiciones De Ventas", WarningMessage);
                }
            }

            return(base.ProcessOutputDocument(pricingParameters, outputDocument, currency));
        }
Esempio n. 2
0
        private PostResponse PricePush(int listingId, DateTime startDate, DateTime endDate, bool isAvailable, double price, string note)
        {
            // Fantastic API takes request body as the same format as query parameters; not a serialized json object
            var requestContent = PricingParameters.Stringify(listingId, startDate, endDate, isAvailable, price, note);
            var endPoint       = RestRequest.GetEndPoint(API_CALENDAR_SERVICE);

            return(RestRequest.Post(endPoint, requestContent));
        }
Esempio n. 3
0
        public static decimal GetInstrumentPrice(Instrument instrument)
        {
            SetApiCredentials();
            var param = new PricingParameters()
            {
                instruments = new List <string>()
                {
                    instrument.name
                }
            };

            return(GetPricingAsync(AccountID, param).Result.First().asks.First().price);
        }
Esempio n. 4
0
        /// <summary>
        /// Get pricing information for a specified list of instrumentes within an Account
        /// http://developer.oanda.com/rest-live-v20/pricing-ep/#collapse_endpoint_2
        /// </summary>
        /// <param name="accountID">Account Identifier</param>
        /// <param name="parameters">The parameters for the request</param>
        /// <returns></returns>
        public static async Task <List <Price> > GetPricingAsync(string accountID, PricingParameters parameters)
        {
            string uri = ServerUri(EServer.Account) + "accounts/" + accountID + "/pricing";

            if (!(parameters?.instruments?.Count > 0))
            {
                throw new ArgumentException("List of instruments cannot be null or empty.");
            }

            var requestParams = ConvertToDictionary(parameters);

            string instrumentsCSV = GetCommaSeparatedString(parameters.instruments);

            requestParams.Add("instruments", instrumentsCSV);

            //requestParams.Add("instruments", Uri.EscapeDataString(instrumentsCSV));

            var response = await MakeRequestAsync <PricingResponse>(uri, "GET", requestParams);

            return(response.prices ?? new List <Price>());
        }
Esempio n. 5
0
        /// <summary>
        /// Determines if trading is halted for the provided instrument.
        /// </summary>
        /// <param name="instrument">Instrument to check if halted. Default is EUR_USD.</param>
        /// <returns>True if trading is halted, false if trading is not halted.</returns>
        public static async Task <bool> IsMarketHalted(string instrument = InstrumentName.Currency.EURUSD)
        {
            var accountID  = Credentials.GetDefaultCredentials().DefaultAccountId;
            var parameters = new PricingParameters()
            {
                instruments = new List <string>()
                {
                    instrument
                }
            };

            var prices = await Rest20.GetPricingAsync(accountID, parameters);

            bool isTradeable = false, hasBids = false, hasAsks = false;

            if (prices[0] != null)
            {
                isTradeable = prices[0].tradeable;
                hasBids     = prices[0].bids.Count > 0;
                hasAsks     = prices[0].asks.Count > 0;
            }

            return(!(isTradeable && hasBids && hasAsks));
        }
Esempio n. 6
0
        //////////////////////////////////////////////////////////
        /// <summary>
        /// OandaAPIによる現在値取得スレッド
        /// </summary>
        private async void StartOandaAPIThread(IConfiguration config)
        {
            var source = "OandaAPI";

            OandaAPI_AccountID   = config["OandaAPI:AccountID"];
            OandaAPI_Token       = config["OandaAPI:Token"];
            OandaAPI_Environment = config["OandaAPI:Environment"];

            ////////////////////////////////////////////
            //      OandaAPI初期化
            ////////////////////////////////////////////
            EEnvironment env = EEnvironment.Practice;

            if (OandaAPI_Environment == "Trade")
            {
                env = EEnvironment.Trade;
            }
            Credentials.SetCredentials(env, OandaAPI_Token, OandaAPI_AccountID);

            ////////////////////////////////////////////
            //      取得通貨を設定する
            ////////////////////////////////////////////
            var param = new PricingParameters();

            param.instruments = new List <string>
            {
                "USD_JPY",
                "GBP_JPY",
                "GBP_USD",
                "EUR_JPY",
                "EUR_USD"
            };

            ////////////////////////////////////////////
            //      辞書の初期化
            ////////////////////////////////////////////
            OandaPrice.TryAdd(USDJPY, new Price(source, TradeEngine.USDJPY));
            OandaPrice.TryAdd(GBPJPY, new Price(source, TradeEngine.GBPJPY));
            OandaPrice.TryAdd(GBPUSD, new Price(source, TradeEngine.GBPUSD));
            OandaPrice.TryAdd(EURJPY, new Price(source, TradeEngine.EURJPY));
            OandaPrice.TryAdd(EURUSD, new Price(source, TradeEngine.EURUSD));

            Log("[Oanda] Server Started");

            ////////////////////////////////////////////
            //      現在値取得ループ
            ////////////////////////////////////////////
            for (; ;)
            {
                try
                {
                    var list = await GetPricingAsync(OandaAPI_AccountID, param);

                    if (list == null)
                    {
                        Log("[Oanda] Communication error");
                        continue;
                    }

                    foreach (var p in list)
                    {
                        if (p.instrument == "USD_JPY")
                        {
                            var price = OandaPrice[TradeEngine.USDJPY];
                            price.Ask  = (double)p.closeoutAsk;
                            price.Bid  = (double)p.closeoutBid;
                            price.Time = DateTime.Now;
                            if (price.IsPriceChanged())
                            {
                                OnPriceChanged(price);
                            }
                        }
                        if (p.instrument == "GBP_JPY")
                        {
                            var price = OandaPrice[TradeEngine.GBPJPY];
                            price.Ask  = (double)p.closeoutAsk;
                            price.Bid  = (double)p.closeoutBid;
                            price.Time = DateTime.Now;
                            if (price.IsPriceChanged())
                            {
                                OnPriceChanged(price);
                            }
                        }
                        if (p.instrument == "GBP_USD")
                        {
                            var price = OandaPrice[TradeEngine.GBPUSD];
                            price.Ask  = (double)p.closeoutAsk;
                            price.Bid  = (double)p.closeoutBid;
                            price.Time = DateTime.Now;
                            if (price.IsPriceChanged())
                            {
                                OnPriceChanged(price);
                            }
                        }
                        if (p.instrument == "EUR_JPY")
                        {
                            var price = OandaPrice[TradeEngine.EURJPY];
                            price.Ask  = (double)p.closeoutAsk;
                            price.Bid  = (double)p.closeoutBid;
                            price.Time = DateTime.Now;
                            if (price.IsPriceChanged())
                            {
                                OnPriceChanged(price);
                            }
                        }
                        if (p.instrument == "EUR_USD")
                        {
                            var price = OandaPrice[TradeEngine.EURUSD];
                            price.Ask  = (double)p.closeoutAsk;
                            price.Bid  = (double)p.closeoutBid;
                            price.Time = DateTime.Now;
                            if (price.IsPriceChanged())
                            {
                                OnPriceChanged(price);
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    Log($"[Oanda] {e.Message}");
                    continue;
                }
            }
        }