Exemplo n.º 1
0
        private void button6_Click(object sender, EventArgs e)
        {
            float price, amount, fee, paid, minus_fee, zero_sell;

            if (!float.TryParse(tb_price.Text.Replace('.', ','), out price))
            {
                return;
            }
            if (!float.TryParse(tb_amount.Text.Replace('.', ','), out amount))
            {
                return;
            }
            if (!float.TryParse(tb_fee.Text.Replace('.', ','), out fee))
            {
                return;
            }

            minus_fee = 1 - fee / 100;
            paid      = (1 - fee / 200) * amount * price;

            zero_sell = price / (1 - fee / 100);

            WalletItem item = new WalletItem();

            item.data = new TradeAnalysation(price, amount, 0.8f);
            item.date = DateTime.Now;

            Wallet.that.BuyItem(item);
        }
Exemplo n.º 2
0
        public void Load()
        {
            XmlDocument doc = new XmlDocument();

            try
            {
                doc.Load(URL);

                _content.Clear();

                XmlElement root = doc.DocumentElement;

                foreach (XmlElement xmlItem in root.GetElementsByTagName("item"))
                {
                    WalletItem item = new WalletItem();

                    DateTime.TryParse(xmlItem.GetAttribute("date"), out item.date);
                    item.data = TradeAnalysation.Load(xmlItem);
                    //bool.TryParse(xmlItem.GetAttribute("buy"), out item.buy);
                    float.TryParse(xmlItem.GetAttribute("share_res"), out item.share[(int)VolumeOwner.RESERVE_BTC]);
                    float.TryParse(xmlItem.GetAttribute("share_spec"), out item.share[(int)VolumeOwner.SPECULATION]);

                    _content.Add(item);
                }

                _money.Load(root);
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show("Failed to load wallet!");
                Save();
            }
        }
Exemplo n.º 3
0
        public bool BuyItem(WalletItem item)
        {
            for (int i = 0; i < item.share.Length; i++)
            {
                float price     = item.share[i] * item.data.PaidPrice;
                float remaining = _money.RemainingMoney((VolumeOwner)i);
                if (remaining < price)
                {
                    Logger.Log("Wallet", "Not enough money in reserve '" + ((VolumeOwner)i).ToString() + "' to buy item!");
                    Logger.LogVal("available", remaining, LogType.EUR);
                    Logger.LogVal("item price", item.data.PaidPrice, LogType.EUR);
                    Logger.LogVal("share", item.share[i], LogType.PERC);
                    Logger.LogVal("price share", price, LogType.EUR);
                    return(false);
                }
            }
            for (int i = 0; i < item.share.Length; i++)
            {
                _money.Spend((VolumeOwner)i, item.share[i] * item.data.PaidPrice);
            }

            _content.Add(item);

            Logger.Log("Wallet", "Successfully added item to wallet!");
            Logger.LogLineSub();
            Logger.LogVal("cost", item.data.BuyPrice, LogType.EUR);
            Logger.LogVal("cost (fee)", item.data.GetFeePrice(true), LogType.EUR);
            Logger.LogVal("amount", item.data.Amount, LogType.BTC);
            Logger.LogVal("price", item.data.PaidPrice, LogType.EUR);

            for (int i = 0; i < (int)VolumeOwner.COUNT; i++)
            {
                if (item.share[i] != 0)
                {
                    Logger.LogVal("share (" + ((VolumeOwner)i).ToString() + ")", item.share[i], LogType.PERC);
                }
            }
            Logger.Log("");

            GraphForm.that.AddMarker(item.date, item.data, false);

            Save();

            return(true);
        }
Exemplo n.º 4
0
        //amount before fee
        public void Buy(int id, float amount, float[] share)
        {
            OfferBook.that.Trade(id, amount, true);

            var offer = OfferBook.that.BuyOffers[id];

            WalletItem item = new WalletItem();

            item.date = DateTime.Now;

            item.data = new TradeAnalysation(offer.info.BuyPrice, amount, 0.08f);
            //item.buy = true;

            int i = 0;

            foreach (var s in share)
            {
                item.share[i] = share[i];
                i++;
            }
            Wallet.that.BuyItem(item);

            Form1.that.RefreshWallet();
        }
Exemplo n.º 5
0
        void FindBuyOffers()
        {
            float[] share = new float[(int)VolumeOwner.COUNT];

            float[] money = new float[(int)VolumeOwner.COUNT];

            //---- determine available money

            foreach (var req in _requestListBuy)
            {
                switch (req.owner)
                {
                //all reserve buys (€ and btc) go to reserve_btc
                case RequestOwner.SPEC:
                {
                    money[(int)VolumeOwner.RESERVE_BTC] += Wallet.that._money.RemainingMoney(VolumeOwner.RESERVE_EUR, 0.25f);
                    money[(int)VolumeOwner.SPECULATION] += Wallet.that._money.RemainingMoney(VolumeOwner.SPECULATION);
                    break;
                }

                case RequestOwner.RESERVE:
                {
                    money[(int)VolumeOwner.RESERVE_BTC] += Wallet.that._money.RemainingMoney(VolumeOwner.RESERVE_EUR, 0.25f);
                    money[(int)VolumeOwner.RESERVE_BTC] += Wallet.that._money.RemainingMoney(VolumeOwner.RESERVE_BTC);
                    break;
                }
                }
            }

            float ges = 0;

            foreach (float v in money)
            {
                ges += v;
            }

            int i = 0;

            foreach (float v in money)
            {
                share[i] = money[i] / ges;

                i++;
            }

            //---- find offers
            float        necMoney;
            List <int>   ids    = new List <int>();
            List <float> amount = new List <float>();

            if (OfferBook.that.FindBuyOffer(ges, out necMoney, amount, ids))
            {
                Logger.Log("Buy Offers", "Found " + ids.Count.ToString() + " matching offers!");

                int j = 0;
                foreach (var id in ids)
                {
                    WalletItem item = new WalletItem();
                    item.data = new TradeAnalysation(OfferBook.that.BuyOffers[id].info.BuyPrice,
                                                     amount[j], 0.08f);
                    item.date  = DateTime.Now;
                    item.share = share;

                    OfferBook.that.Trade(id, amount[j], true);

                    Wallet.that.BuyItem(item);

                    j++;
                }
                //priority order: spec, reserve_btc, reserve_eur
                foreach (var r in _requestListBuy)
                {
                    if (r.owner == RequestOwner.SPEC)
                    {
                        Logger.Log("Speculation", "Removed speculation buy request!");
                    }
                }
            }
        }