Ejemplo n.º 1
0
		private void Form1_Load(object sender, EventArgs e)
		{
			LoadSettings();
			_firstRun = true;
			//_cexApiKey = "o3qCw0mySJkWNisqP6di8t9Dk";
			//_cexApiSecret = "SMtI8IFsb2TbPfz9yTJlHNPhK2s";
			//_cexUserName = "******";
			_apiCallCount = 0;
			_cexApiCredentials = new ApiCredentials(_cexUserName, _cexApiKey, _cexApiSecret);
			_cexClient = new CexApi(_cexApiCredentials);

			richTextBox1.Text = @"Started @ " + DateTime.Now + Environment.NewLine;
			_stopwatch = new Stopwatch();
			_stopwatch.Start();
			_balance = new Balance();

			

			button1_Click(null, null);
		}
Ejemplo n.º 2
0
		private async void button1_Click(object sender, EventArgs e)
		{
			try
			{

				_balance = await _cexClient.AccountBalance();

				_apiCallCount = ++_apiCallCount;


				if (Convert.ToDecimal(lblBtcValue.Text) == _previousBtcValue)
					lblBtcValue.ForeColor = System.Drawing.Color.Black;

				if (Convert.ToDecimal(lblNmcValue.Text) == _previousNmcValue)
					lblNmcValue.ForeColor = System.Drawing.Color.Black;

				if (Convert.ToDecimal(lblIXCValue.Text) == _previousIxcValue)
					lblIXCValue.ForeColor = System.Drawing.Color.Black;

				if (Convert.ToDecimal(lblGhsValue.Text) == _previousGhsValue)
					lblGhsValue.ForeColor = System.Drawing.Color.Black;


			}
			catch (CexNonceException)
			{
				Console.WriteLine(@"nonce exception");
			}
			catch (Exception ex)
			{

				richTextBox1.Text += ex.ToString();
			}
			richTextBox1.SelectionStart = richTextBox1.Text.Length;
			richTextBox1.ScrollToCaret();
			UpdateUi();
		}
Ejemplo n.º 3
0
		private async void PlaceOrder(SymbolPair pair, Balance balance, OrderType orderType)
		{
			Order order = new Order();
			OrderBook orderBook = await _cexClient.OrderBook(pair);
			_apiCallCount = ++_apiCallCount;
			
			
			IEnumerable<OrderBookOrder> bids = orderBook.Bids;
			order.Price = ((OrderBookOrder[]) (bids))[0].Price;

			decimal amount = 0;
			decimal availableBalance;
			if (orderType == OrderType.Buy)
			{
				if (pair.To == Symbol.NMC)
				{
					availableBalance = balance.NMC.Available;
					amount = PurchaseAmount(order.Price, availableBalance);
				}


				if (pair.To == Symbol.BTC)
				{
					availableBalance = balance.BTC.Available - udMaintanMinBtcBalance.Value;
					amount = PurchaseAmount(order.Price, availableBalance);
				}

				if (amount <= (decimal) 0.00000001)
					return;
			}

			if (orderType == OrderType.Sell)
			{
				if (pair.From == Symbol.IXC)
				{
					availableBalance = balance.IXC.Available;

					if (availableBalance < (decimal) .00000001)
						return;
					decimal saleValue = order.Price*availableBalance;
					if (saleValue < (decimal) .00000001)
						return;
				}
			}

			order.Type = orderType;
			order.Amount = amount;

			try
			{
				OpenOrder orderDetails = await _cexClient.PlaceOrder(pair, order);
				_apiCallCount = ++_apiCallCount;

				decimal totalOrder = order.Price*order.Amount;
				decimal totalOrderCostRounded = Math.Round(totalOrder, 8);

				richTextBox1.AppendText(string.Format(@"Sold:{8} {1} @ {2} for {0} {7}: Total: {3} @ {4} -- Order #{5}{6}",
				                                      order.Amount,
				                                      pair.To,
				                                      order.Price,
				                                      totalOrderCostRounded,
				                                      DateTime.Now,
				                                      orderDetails.Id,
				                                      Environment.NewLine, pair.From,
				                                      Math.Round(orderDetails.Price*order.Amount, 8)));
				_ghsPurchased = _ghsPurchased + order.Amount;
				_orderCount = ++_orderCount;
				UpdateUi();
			}
			catch
			{
				Console.WriteLine(@"oops");

			}

		}
Ejemplo n.º 4
0
        internal static Balance FromDynamic(dynamic data)
        {
            var balance = new Balance();
            var json = data as JsonObject;
            if (json == null) return balance;

            foreach (var sym in Enum.GetValues(typeof (Symbol)).Cast<Symbol>())
            {
                if (json.ContainsKey(sym.Name()))
                {
                    var symJson = json[sym.Name()] as JsonObject;
                    if (symJson != null)
                    {
                        balance[sym] = SymbolBalance.FromDynamic(symJson);
                    }
                }
            }

            balance.Timestamp = data["timestamp"];

            return balance;
        }