Exemplo n.º 1
0
        private PriceData ParseSingleLine(string line, DateTime?lastKnownDate, Symbol symbol)
        {
            try
            {
                string[] data = line.Split(',');

                PriceData day = new PriceData();
                day.Date = DateTime.Parse(data[0].Replace("\"", ""));

                if (lastKnownDate.HasValue && lastKnownDate.Value >= day.Date)
                {
                    return(null);
                }

                day.OpenPrice    = ParseSegment(data[1]);
                day.MaxPrice     = ParseSegment(data[2]);
                day.MinPrice     = ParseSegment(data[3]);
                day.ClosingPrice = ParseSegment(data[4]);
                day.Volume       = int.Parse(data[5].Replace("\"", ""));
                day.Symbol       = symbol;

                if (day.OpenPrice == 0 || day.ClosingPrice == 0)
                {
                    return(null);
                }

                return(day);
            }
            catch
            {
                return(null);
            }
        }
        public async Task StreamPrices(IEnumerable <Stock> stocks)
        {
            try
            {
                StringBuilder queryBuilder = new StringBuilder();
                string        query        = string.Join(",", stocks.Select(s => s.name));
                var           accountId    = await localStorage.GetItemAsync <string>("api-account-id");

                PriceData priceData = await httpClient.GetFromJsonAsync <PriceData>($"v3/accounts/{accountId}/pricing?instruments={query}");

                foreach (var price in priceData.prices)
                {
                    Stock thisStock = stocks.Where(s => s.name.Equals(price.instrument)).FirstOrDefault();
                    if (null != thisStock)
                    {
                        thisStock.bid = Double.Parse(price.bids[0].price);
                        thisStock.ask = Double.Parse(price.asks[0].price);
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.WriteLine(ex.StackTrace);
            }
        }
Exemplo n.º 3
0
    private void SetOfferId(MyEvent obj)
    {
        IOSEvent e = obj as IOSEvent;

        MsgFromIOS.InfoFromIOS info = e.data as MsgFromIOS.InfoFromIOS;

        //根据临时tempId找到数据 PriceData priceData = GetPriceData(info.tempId);
        PriceData priceData = uiData.GetPriceData(info.tempId.ToString());

        if (priceData == null)
        {
            return;
        }

        //删除本地临时缓存-未上传服务器的数据
        jsonCacheManager.RemoveOfferCache(priceData.tempId);
        //移除字典中按本地临时id存储的数据--为后面用新正式的id重新存入
        uiData.RemovePriceData(priceData.targetId, priceData.stringId);
        //移除当前数据的报价列表中的临时info.tempId
        schemeManifest.prices.Remove(info.tempId.ToString());

        // 给数据赋值服务器给的新id priceData.serverId = info.priceId;
        priceData.serverId = info.priceId;

        //存入服务器报价缓存
        jsonCacheManager.AddOfferCache(priceData);
        //重新存入字典 报价不会变动 下一次也可以直接使用 防止下次使用再去加载
        uiData.AddPriceData(priceData);
        //添加当前数据的报价列表info.priceId
        schemeManifest.prices.Add(info.priceId);

        //抛报价本地变服务器的事件 此处用处不大  SetOfferId(MyEvent obj)本身就是监听的UnityIOSMsg的事件
        this.dispatchEvent(new MainPageUIDataEvent(MainPageUIDataEvent.OfferIdChanged, e.data));
    }
Exemplo n.º 4
0
    public void OpenFastEditorOffer(PriceData pricedata)
    {
        Debug.Log("打开指定报价快速编辑");
        UITool.SetActionFalse(scheme.tab1);
        UITool.SetActionTrue(scheme.tab2);
        UITool.SetActionFalse(scheme.offerGenerate.gameObject);
        UITool.SetActionTrue(scheme.deletePrice.gameObject);
        //editorOfferScroll.selectDeleteList.Clear();
        UITool.SetActionFalse(scheme.mask.gameObject);
        UITool.SetActionFalse(scheme.generaterExit.gameObject);
        isPress = false;
        scheme.offerAllCancel.text   = "全选";
        editorOfferScroll.isLeftMove = false;
        for (int i = 0; i < pricedata.priceList.Count; i++)
        {
            ItemPrice item = pricedata.priceList[i] as ItemPrice;
            item.isSelect = false;
        }
        //GeneraterOfferScroll.ToggleGroup(false);

        //设为当前报价
        currentEditorablePricedata = pricedata;
        //打开界面
        CommonChangeChildActive(scheme.generateOffer);
        //显示数据 可编辑
        editorOfferScroll.Display(currentEditorablePricedata.priceList);


        //itemGeneraterOffer = itemCreateOffer;
    }
Exemplo n.º 5
0
        private void deployFirebase(PriceData payload)
        {
            string jsonDataset = new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(payload);
            var    myFirebase  = "https://mtdash01.firebaseio.com/.json";
            var    request     = WebRequest.CreateHttp(myFirebase);

            request.Method = "POST";                            // PUT writes over + POST - Pushing Data
            byte[] byteArray = Encoding.UTF8.GetBytes(jsonDataset);
            request.ContentType   = "application/json";
            request.ContentLength = byteArray.Length;
            Stream dataStream = request.GetRequestStream();

            dataStream.Write(byteArray, 0, byteArray.Length);
            dataStream.Close();
            WebResponse response = request.GetResponse();

            dataStream = response.GetResponseStream();
            StreamReader reader             = new StreamReader(dataStream);
            string       responseFromServer = reader.ReadToEnd();

            reader.Close();
            dataStream.Close();
            response.Close();
            request.Abort();
        }
Exemplo n.º 6
0
        /// <summary>
        ///     Generate the different type of price information for the product
        /// </summary>
        /// <param name="price">
        ///     User specific price information based on the chosen option for the product on the product detail
        ///     page
        /// </param>
        public ProductPrices(UserSpecificPrice price)
        {
            if (price.ListPriceGreaterThanCurrentPrice)
            {
                ListPrice = new PriceData
                {
                    Label    = GlobalLocalization.GetString("ListPrice"),
                    Text     = price.ListPrice.ToString("C"),
                    RawValue = price.ListPrice.ToString("F")
                };
            }

            SitePrice = new PriceData
            {
                Label    = GlobalLocalization.GetString("SitePrice"),
                Text     = price.DisplayPrice(true, false),
                RawValue = price.DisplayPrice(true, false)
            };

            if (price.BasePrice < price.ListPrice && price.OverrideText.Trim().Length < 1)
            {
                YouSave = new PriceData
                {
                    Label = GlobalLocalization.GetString("YouSave"),
                    Text  =
                        string.Format("{0} - {1}{2}", price.Savings.ToString("c"), price.SavingsPercent,
                                      Thread.CurrentThread.CurrentUICulture.NumberFormat.PercentSymbol),
                    RawValue = price.SavingsPercent.ToString("N")
                };
            }
        }
Exemplo n.º 7
0
 /// <summary>
 /// 编辑报价
 /// </summary>
 /// <param name="pricedata"></param>
 public void OpenEditorOffer(PriceData pricedata)
 {
     Debug.Log("打开指定报价");
     UITool.SetActionFalse(scheme.tab2);
     UITool.SetActionTrue(scheme.tab1);
     UITool.SetActionTrue(scheme.offerGenerate.gameObject);
     UITool.SetActionFalse(scheme.deletePrice.gameObject);
     UITool.SetActionTrue(scheme.mask.gameObject);
     UITool.SetActionTrue(scheme.generaterExit.gameObject);
     editorOfferScroll.isLeftMove = true;
     for (int i = 0; i < pricedata.priceList.Count; i++)
     {
         ItemPrice item = pricedata.priceList[i] as ItemPrice;
         item.isSelect = true;
     }
     if (pricedata.priceList.Count == 0)
     {
         scheme.offerGenerate.interactable = false;
     }
     else
     {
         scheme.offerGenerate.interactable = true;
     }
     //设为当前报价
     currentEditorablePricedata = pricedata;
     //打开界面
     CommonChangeChildActive(scheme.generateOffer);
     //显示数据 可编辑
     editorOfferScroll.Display(currentEditorablePricedata.priceList);
     //itemGeneraterOffer = itemCreateOffer;
 }
Exemplo n.º 8
0
 private void MinsMaxs(AnalyticData data, PriceData round)
 {
     if (round.MaxPrice >= data.MaxPrice)
     {
         data.MaxPrice     = round.MaxPrice;
         data.MaxPriceDate = round.Date;
     }
     if (round.MinPrice <= data.MinPrice)
     {
         data.MinPrice     = round.MinPrice;
         data.MinPriceDate = round.Date;
     }
     if (round.MinPrice <= data.MinPrice)
     {
         data.MinPrice     = round.MinPrice;
         data.MinPriceDate = round.Date;
     }
     if (round.Volume >= data.MaxVolume)
     {
         data.MaxVolume     = round.Volume;
         data.MaxVolumeDate = round.Date;
     }
     if (round.Volume <= data.MinVolume)
     {
         data.MinVolume     = round.Volume;
         data.MinVolumeDate = round.Date;
     }
 }
Exemplo n.º 9
0
        /// <summary>Step the simulation by one 'StepSize'</summary>
        public void Step()
        {
            var time0 = UtcNow;
            var time1 = UtcNow + StepSize;

            // Collect the candle data to send from each transmitter over the step period
            var data = Transmitters.SelectMany(x => x.Value.EnumCandleData(time0, time1)).OrderBy(x => x.Candle.Timestamp);

            // "Post" the candle data to tradee
            foreach (var d in data)
            {
                var candle = d.Candle as Candle;

                // Fake the price data using the candle data
                var trans = Transmitters[d.SymbolCode];
                foreach (var price in new[] { candle.Open, candle.High, candle.Low, candle.Median, candle.Close })
                {
                    var pd = new PriceData(trans.PriceData)
                    {
                        AskPrice = price,
                        BidPrice = price + trans.PriceData.AvrSpread,
                    };
                    Model.DispatchMsg(new InMsg.SymbolData(trans.SymbolCode, pd));
                }

                // Send the candle
                Model.DispatchMsg(d);
            }

            UtcNow = time1;
        }
Exemplo n.º 10
0
        public async Task <AnalyticData> GetAnalytics(string symbol, string currency = "PESOS")
        {
            var priceSeries = new List <PriceData>();

            var symbolId = this.Symbol.Where(x => x.Name == symbol).FirstOrDefault().ID;

            if (currency.Equals("PESOS"))
            {
                priceSeries = await PriceData.Where(x => x.Symbol_ID == symbolId).OrderBy(x => x.Date).ToListAsync();
            }
            else
            {
                priceSeries = await this.PriceData.Where(ps => ps.Symbol.ID == symbolId)
                              .Join(this.DollarData.Where(ds => ds.DollarType == currency), ps => ps.Date, ds => ds.ExchangeDate,
                                    (ps, ds) => new PriceData
                {
                    ClosingPrice = (ps.ClosingPrice / ds.Price),
                    Date         = ps.Date,
                    MaxPrice     = (ps.MaxPrice / ds.Price),
                    MinPrice     = (ps.MinPrice / ds.Price),
                    OpenPrice    = (ps.OpenPrice / ds.Price),
                    Volume       = ps.Volume
                }).OrderBy(x => x.Date).ToListAsync();
            }

            return(new AnalyticProcessor(symbol, priceSeries).ProcessData());
        }
Exemplo n.º 11
0
        public JsonResult saveData(string price_data, int count, string coin)
        {
            dynamic stuff = JsonConvert.DeserializeObject(price_data);


            string[] Users = stuff[0].ToObject <string[]>();

            // int ac = 0;
            do
            {
                // string subArray = stuff[1];
                string[] SubArrayData = stuff[count].ToObject <string[]>();
                string   price        = SubArrayData[1];
                decimal  price2       = Convert.ToDecimal(price);
                string   date1        = SubArrayData[0];
                double   epoch        = Convert.ToDouble(date1);
                DateTime datex        = new DateTime(1970, 1, 1).AddSeconds(epoch / 1000);
                //DateTime date4 = ConvertUnixTimeStamp(date1);


                // string date2 = Regex.Replace(date1, @"[^\d\s\.:]", string.Empty);
                // DateTime date3 = DateTime.ParseExact(date1, "MM.dd.yyyy HH:mm:ss", CultureInfo.InvariantCulture);
                //DateTime time = DateTime.ParseExact(SubArrayData[0], "dd/MM/yyyy", null);

                // string data1 = subArray[0];
                //Decimal price = stuff[ac].price;
                //DateTime time = stuff[ac].price_timestamp;
                //decimal? rank = stuff[ac].rank;
                //decimal? rankdelta = stuff[ac].rank_delta;
                //decimal marketcap = stuff[ac].market_cap;
                //string symbol = stuff[ac].symbol;
                //textBox1.AppendText(coinname + Environment.NewLine);
                //textBox1.AppendText(price + Environment.NewLine);
                //textBox1.AppendText(time + Environment.NewLine);
                using (var context = new db61a6afb29dc84f4597e3a2b500ebed20Entities())
                {
                    var t = new PriceData
                    {
                        Coin  = coin,
                        Price = price2,
                        //Rank = rank,
                        //Rankdelta = rankdelta,
                        //Marketcap = marketcap,
                        //Symbol = symbol,
                        Timestamp = datex
                    };

                    context.PriceDatas.Add(t);

                    context.SaveChanges();
                }

                count--;
            } while (count > 0);



            return(Json(new { status = "saved" }, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 12
0
        public static async Task <PricePrediction> Predict(PriceData tt)
        {
            var model = await Train();

            Evaluate(model);

            return(model.Predict(tt));
        }
Exemplo n.º 13
0
        public static void GetAllRiderInfo(ref List <Runner> runners, ref List <RunnerDescription> runnerDescription, ref List <MarketProfitAndLoss> runnerPNL, ref CurrentOrderSummaryReport orders)
        {
            PriceData pricedata1 = PriceData.EX_ALL_OFFERS;
            PriceData pricedata2 = PriceData.EX_TRADED;
            PriceData pricedata3 = PriceData.EX_BEST_OFFERS;

            HashSet <PriceData> prijsdata = new HashSet <PriceData>();

            prijsdata.Add(pricedata1);
            prijsdata.Add(pricedata2);
            prijsdata.Add(pricedata3);

            PriceProjection priceprojection = new PriceProjection();
            OrderProjection orderprojection = new OrderProjection();
            MatchProjection matchprojection = new MatchProjection();

            orderprojection           = OrderProjection.ALL;
            matchprojection           = MatchProjection.ROLLED_UP_BY_AVG_PRICE;
            priceprojection.PriceData = prijsdata;

            MarketFilter marketFilter = new MarketFilter();

            ISet <string> set = new HashSet <string>();

            set.Add(BackEnd.marketID);
            marketFilter.MarketIds = set;

            var marketSort = MarketSort.FIRST_TO_START;

            ISet <MarketProjection> marketProjections = new HashSet <MarketProjection>();

            marketProjections.Add(MarketProjection.RUNNER_DESCRIPTION);

            List <string> marketIds = new List <string>();

            marketIds.Add(BackEnd.marketID);

            try
            {
                runners = apiClient.listMarketBook(marketIds, priceprojection, orderprojection, matchprojection)[0].Runners;
            }
            catch { }
            try
            {
                runnerDescription = apiClient.listMarketCatalogue(marketFilter, marketProjections, marketSort)[0].Runners;
            }
            catch { }
            try
            {
                runnerPNL = apiClient.listMarketProfitAndLoss(marketIds, true, true, true).ToList <MarketProfitAndLoss>();
            }
            catch { }
            try
            {
                orders = apiClient.listCurrentOrders();
            }
            catch { }
        }
Exemplo n.º 14
0
 public void Load(UXMLElement element)
 {
     id       = element.GetString("id");
     itemId   = element.GetString("item_id");
     itemType = element.GetEnum <InventoryItemType>("item_type");
     count    = element.GetInt("count");
     price    = new PriceData();
     price.Load(element);
 }
Exemplo n.º 15
0
        public IActionResult _PriceData()
        {
            var data = new PriceData[] {
                new PriceData
                {
                    Name  = "List",
                    Value = 100
                },
                new PriceData
                {
                    Name  = "List\nDiscount",
                    Value = -5
                },
                new PriceData
                {
                    Name    = "Invoice",
                    Summary = "total"
                },
                new PriceData
                {
                    Name  = "Invoice\nDiscount",
                    Value = -6
                },
                new PriceData
                {
                    Name  = "Rebates",
                    Value = -3
                },
                new PriceData
                {
                    Name  = "Errors",
                    Value = -1.10m
                },
                new PriceData
                {
                    Name    = "Pocket\nPrice",
                    Summary = "total"
                },
                new PriceData
                {
                    Name  = "Cost",
                    Value = -57.10m
                },
                new PriceData
                {
                    Name  = "Handling",
                    Value = -0.50m
                },
                new PriceData
                {
                    Name    = "Pocket\nMargin",
                    Summary = "total"
                }
            };

            return(Json(data));
        }
Exemplo n.º 16
0
    /// <summary>
    /// 已经存在的报价, 打开查看详情
    /// </summary>
    public void OpenOffer(MyEvent myEvent)
    {
        //Debug.LogWarning("22222222222");
        SchemeEvent       myevent         = myEvent as SchemeEvent;
        ManifestOfferItem manifestOffer   = myevent.data as ManifestOfferItem;
        string            openPriceDataId = manifestOffer.priceDataId;
        PriceData         priceData       = uiData.GetPriceData(openPriceDataId);

        OpenOffer(priceData);
    }
Exemplo n.º 17
0
 private void ShowPriceData(PriceData data)
 {
     CurrencyTextBlock.Text = "Currency: " + data.Ticker;
     DateTextBlock.Text     = "Date: " + data.Date;
     TimeTextBlock.Text     = "Time: " + data.Time;
     OpenTextBlock.Text     = "Open: " + data.Open.ToString();
     HighTextBlock.Text     = "High: " + data.High.ToString();
     LowTextBlock.Text      = "Low: " + data.Low.ToString();
     CloseTextBlock.Text    = "Close: " + data.Close.ToString();
 }
Exemplo n.º 18
0
        public void UpdatePrice(PriceData price)
        {
            _price = price;

            Invoke((MethodInvoker) delegate
            {
                ConnectionLabelError.Text  = "Trading is possible";
                LimitTextPriceCurrent.Text = Communication.S(_price.Close);
                EnablePanel(true);
            });
        }
Exemplo n.º 19
0
        public void BuyBTCfromDigitalBTC()
        {
            DC.Providers.DigitalBTC digitalbtc = new DC.Providers.DigitalBTC();
            Decimal btcAmount = 0.046687M;

            PriceData pricedata = digitalbtc.GetSpotPrice2(btcAmount, "USD");

            float     price          = (float)pricedata.Price;
            float     btcorderamount = (float)btcAmount;
            OrderData orderdata      = digitalbtc.Order(price, btcorderamount);
        }
Exemplo n.º 20
0
 /// <summary>
 /// 删除报价-注意PriceData serverId的赋值 顺序
 /// </summary>
 /// <param name="data"></param>
 /// <param name="json"></param>
 public void RemoveOfferCache(PriceData data)
 {
     if (data.isUnUpload == true)
     {
         RemoveOfferCache(data.tempId);
     }
     else
     {
         RemoveOfferCache(data.serverId);
     }
 }
Exemplo n.º 21
0
    private void OnCreateOffer()
    {
        Debug.Log("创建 报价 数据 编辑用 还未保存");

        PriceData pricedata = new PriceData();

        List <ItemData> list = GetInputProductDataList();

        pricedata.priceList = list;
        GeneraterOfferScroll.ToggleGroup(true);
        OpenEditorOffer(pricedata);
    }
Exemplo n.º 22
0
    /// <summary>
    /// 打开指定报价
    /// </summary>
    /// <param name="pricedata"></param>
    public void OpenOffer(PriceData pricedata)
    {
        Debug.Log("打开指定报价");
        //设为当前报价
        currentCannotEditorablePricedata = pricedata;
        //打开界面
        CommonChangeChildActive(scheme.setMainOffer);

        //显示数据
        setMainOfferScroll.Display(currentCannotEditorablePricedata.priceList);
        //itemGeneraterOffer = itemCreateOffer;
    }
Exemplo n.º 23
0
        /// <summary>Thread entry</summary>
        private void Run()
        {
            bool send = false;

            for (; !m_quit.WaitOne(100);)
            {
                m_price += m_rng.NextDouble(-0.01, +0.01);

                if (!m_send.WaitOne(0))
                {
                    send = false;
                    continue;
                }

                // Send historic data on first send
                if (!send)
                {
                    SendHistoricData();
                    send = true;
                }

                // Send per tick
                foreach (var tf in TimeFrames)
                {
                    var one    = Misc.TimeFrameToTicks(1.0, tf);
                    var spread = m_rng.NextDouble(0.001, 0.01);

                    // Fake price data
                    if (++m_candle.Volume == 11)
                    {
                        m_now += one;

                        m_candle.Timestamp = m_now;
                        m_candle.Open      = m_price;
                        m_candle.High      = m_price;
                        m_candle.Low       = m_price;
                        m_candle.Close     = m_price;
                        m_candle.Volume    = 1;
                    }
                    m_candle.High  = Math.Max(m_candle.High, m_price);
                    m_candle.Low   = Math.Min(m_candle.Low, m_price);
                    m_candle.Close = m_price;

                    Model.Post(new InMsg.CandleData(SymbolCode, tf, m_candle));

                    // Fake spread
                    var sym_data = new PriceData(m_price + spread, m_price, spread, 10000, 0.0001, 1.0, 1000, 1000, 100000000);
                    var data     = new InMsg.SymbolData(SymbolCode, sym_data);
                    Model.Post(data);
                }
            }
        }
Exemplo n.º 24
0
    //public DataSave<BaseStat> dataList;
    public void LoadPrice(List <Dictionary <string, string> > dataCSV)
    {
        priceList = new List <PriceData>();
        for (int i = 0; i < dataCSV.Count; i++)
        {
            PriceData _data = new PriceData(dataCSV[i]);
            priceList.Add(_data);
        }
        DataSave <BaseStat> dataList = BacJson.FromJson <BaseStat, ResourceStat, ItemStat>(priceList[0].json);
        string _json = BacJson.ToJson <BaseStat>(dataList);

        Debug.Log(_json);
    }
Exemplo n.º 25
0
        public bool HasCoins(PriceData coins)
        {
            switch (coins.type)
            {
            case MoneyType.gold: {
                return(gold >= coins.price);
            }

            case MoneyType.silver: {
                return(silver >= coins.price);
            }
            }
            return(false);
        }
Exemplo n.º 26
0
 /// <summary>Return the properties of a price data object to match the update command</summary>
 public static object[] UpdatePriceDataParams(PriceData pd)
 {
     return(new object[]
     {
         pd.AskPrice,
         pd.BidPrice,
         pd.AvrSpread,
         pd.LotSize,
         pd.PipSize,
         pd.PipValue,
         pd.VolumeMin,
         pd.VolumeStep,
         pd.VolumeMax,
     });
 }
Exemplo n.º 27
0
        public void RemoveCoins(PriceData coins)
        {
            switch (coins.type)
            {
            case MoneyType.gold: {
                RemoveGold(coins.price);
            }
            break;

            case MoneyType.silver: {
                RemoveSilver(coins.price);
            }
            break;
            }
        }
Exemplo n.º 28
0
        public void AddCoins(PriceData coins)
        {
            switch (coins.type)
            {
            case MoneyType.gold: {
                AddGold(coins.price);
            }
            break;

            case MoneyType.silver: {
                AddSilver(coins.price);
            }
            break;
            }
        }
Exemplo n.º 29
0
    private void OnPriceLoaded(object obj)
    {
        SimpleCacheLoader loader = obj as SimpleCacheLoader;

        if (loader.state == SimpleLoadedState.Failed)
        {
            //Debug.LogError(loader.uri);
            return;
        }
        string    json      = loader.loadedData.ToString();
        object    jsonObj   = MyJsonTool.FromJson(json);
        PriceData priceData = new PriceData();

        priceData.Deserialize(jsonObj as Dictionary <string, object>);
        mainpageData.AddPriceData(priceData);
    }
Exemplo n.º 30
0
        private static PriceData ParsePriceDataInto(string priceDataString)
        {
            //parse string into object
            var rawData = JsonConvert.DeserializeObject <dynamic>(priceDataString);

            //parse object into PriceData object
            PriceData data = new PriceData()
            {
                Ask  = rawData.ask,
                Bid  = rawData.bid,
                Spot = rawData.spot
            };

            //return
            return(data);
        }