예제 #1
0
        private async Task RefreshUserOrders()
        {
            while (MainActivity.isOnCurrencyFragment == true)
            {
                try
                {
                    //Refresh users orders
                    usersOrders = APIMethods.GetOpenOrders(currencyString);
                    usersOrderAdapter.Update(usersOrders, Activity);
                }
                catch (Exception except)
                {
                    Toast.MakeText(Activity, "Unable to update users orders: " + except.Message.ToString(), ToastLength.Short).Show();
                }

                //Wait for 1 second
                await Task.Delay(1000);
            }
        }
        public async Task CancelOrder(OpenOrder order)
        {
            try
            {
                //Cancel Order
                APIMethods.CancelOrder(order.OrderUuid);

                //Get new order
                var newOpenOrderList = APIMethods.GetOpenOrders(order.Exchange);

                //update list
                CurrencyFragment.usersOrderAdapter.Update(newOpenOrderList, CurrencyFragment.activity);
            }
            catch
            {
                Toast.MakeText(_context, "Unable to update orders", ToastLength.Short).Show();
            }

            await Task.Delay(1);
        }
예제 #3
0
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            // Use this to return your custom view for this Fragment
            var view = inflater.Inflate(Resource.Layout.CurrencyLayout, container, false);

            var viewMain = inflater.Inflate(Resource.Layout.Main, null, false);

            var topToolbar = viewMain.FindViewById <Toolbar>(Resource.Id.toolbar);

            //Hooks into the refresh button listerner
            ToolbarOnClickListener listener = new ToolbarOnClickListener(Activity, buyTextView, sellTextView, lastTextView, currencyString);

            topToolbar.SetOnMenuItemClickListener(listener);

            //Gets the bottom toolbar
            var bottomToolbar = (Toolbar)view.FindViewById(Resource.Id.currencyToolbar);

            bottomToolbar.InflateMenu(Resource.Menu.bot_currency_menu);
            bottomToolbar.MenuItemClick += BottomToolbar_MenuItemClick;

            //Get the orders for the market
            orderBook = APIMethods.GetOrderBook(currencyString, Order.Type.both);

            //Finds the listview for buy orders
            buyOrderListView = (ListView)view.FindViewById(Resource.Id.buyOrders_listView);

            //Create the new adapter
            buyAdapter = new CurrencyOrderBookAdapter(Activity, orderBook.Buys.ToList(), true);
            buyOrderListView.Adapter = buyAdapter;

            //Set the buy orders to the last item
            buyOrderListView.SetSelection(buyOrderListView.Adapter.Count - 1);

            //Finds the listview for sell orders
            sellOrderListView = (ListView)view.FindViewById(Resource.Id.sellOrders_listView);

            //Create the new adapter
            sellAdapter = new CurrencyOrderBookAdapter(Activity, orderBook.Sells.ToList(), false);
            sellOrderListView.Adapter = sellAdapter;

            //Used to handle OnClick events on users Orders cancel button
            activity = Activity;

            //Get the current open orders for the specified currency
            try
            {
                usersOrders = APIMethods.GetOpenOrders(currencyString);
            }
            catch (Exception exc)
            {
                usersOrders = new List <OpenOrder>();

                Toast.MakeText(Activity, exc.Message.ToString(), ToastLength.Short).Show();
            }

            //Find the listview for users orders
            usersOrderListView = (ListView)view.FindViewById(Resource.Id.yourOrder_listView);

            //Create a new adapter for users order listview
            usersOrderAdapter          = new YourOrdersListViewAdapter(this.Context, usersOrders);
            usersOrderListView.Adapter = usersOrderAdapter;

            //Set the on item click event for the listviews
            sellOrderListView.ItemClick += OrderListView_ItemClick;
            buyOrderListView.ItemClick  += OrderListView_ItemClick;

            //Set the trading pair text
            var tradingPairText = (TextView)view.FindViewById(Resource.Id.tradingPairText);

            tradingPairText.Text = currencyString;

            currencySelectedText      = (TextView)view.FindViewById(Resource.Id.selectedCurrencyBalanceAvailableText);
            currencySelectedText.Text = Currency.Substring(4, Currency.Length - 4);

            //Set the amount of available BTC to the user
            btcBalance = (TextView)view.FindViewById(Resource.Id.btcBalance);

            string btcBalanceAmount = "0.000000000";

            try
            {
                Balance b = APIMethods.GetBalance("BTC");
                btcBalanceAmount = b.balance.ToString("0.#########");
            }
            catch
            {
                Toast.MakeText(Activity, "Unable to get BTC Balance, ensure API keys are correct", ToastLength.Short).Show();
            }

            btcBalance.Text = btcBalanceAmount;

            //Set the amount of available currency for the currency selected
            selectedCurrencyBalance = (TextView)view.FindViewById(Resource.Id.selectedCurrencyBalance);

            string selectedCurrencyBalanceAmount = "0.000000000";

            try
            {
                Balance b = APIMethods.GetBalance(Currency.Substring(4, Currency.Length - 4));
                selectedCurrencyBalanceAmount = b.Available.ToString("0.#########");
            }
            catch
            {
                Toast.MakeText(Activity, "Unable to get " + currencyString + " Balance, ensure API keys are correct", ToastLength.Short).Show();
            }

            selectedCurrencyBalance.Text = selectedCurrencyBalanceAmount;

            //Subscribe to text changed events for order section
            totalPriceBtc = (TextView)view.FindViewById(Resource.Id.totalBtcPrice);
            orderAmount   = (EditText)view.FindViewById(Resource.Id.amountToPurchase);
            orderPrice    = (EditText)view.FindViewById(Resource.Id.priceToPurchase);

            orderAmount.TextChanged += OrderData_TextChanged;
            orderPrice.TextChanged  += OrderData_TextChanged;

            //Subscribe the order buttons to on click event
            var buyButton  = (Button)view.FindViewById(Resource.Id.buyOrderbutton);
            var sellButton = (Button)view.FindViewById(Resource.Id.sellOrderbutton);

            buyButton.Click  += BuyButton_Click;
            sellButton.Click += SellButton_Click;

            //Testing awaiting method
            var rereshOrderBook = Task.Run(async() => {
                await RefreshOrderBook();
            });

            //Testing awaiting method
            var refreshUsersOrders = Task.Run(async() => {
                await RefreshUserOrders();
            });

            //Testing awaiting method
            var refreshAvailableBalances = Task.Run(async() => {
                await RefreshAvailableBalances();
            });

            //invoke loop method but DO NOT await it
            //RefreshOrderBook();
            return(view);
        }