Example #1
0
 public void UpdateKeyData(ApiKeyData keyData)
 {
     _apiKey        = keyData;
     _authenticator = new Authenticator(
         _apiKey.GetRawApiKey(),
         _apiKey.GetRawApiSecret(),
         _apiKey.GetRawApiPassword());
     _gdaxClient  = new GDAXClient.GDAXClient(_authenticator);
     IsConfigured = true;
 }
Example #2
0
        public async Task <IEnumerable <CryptoTransaction> > GetTransactionsAsync(Exchange exchange)
        {
            var authenticator = new Authenticator(exchange.PublicKey, exchange.PrivateKey, exchange.Passphrase);
            var client        = new GDAXClient.GDAXClient(authenticator);
            var transactions  = new List <CryptoTransaction>();
            var fills         = await client.FillsService.GetAllFillsAsync();

            foreach (var fill in fills)
            {
                foreach (var fillResponse in fill)
                {
                    var buyCurrency = fillResponse.Side == "buy"
                        ? fillResponse.Product_id.Split('-')[0]
                        : fillResponse.Product_id.Split('-')[1];
                    var sellCurrency = fillResponse.Side == "buy"
                        ? fillResponse.Product_id.Split('-')[1]
                        : fillResponse.Product_id.Split('-')[0];

                    var buyAmount = fillResponse.Side == "buy"
                        ? fillResponse.Size
                        : fillResponse.Size * fillResponse.Price;

                    var sellAmount = fillResponse.Side == "buy"
                        ? fillResponse.Size * fillResponse.Price
                        : fillResponse.Size;

                    transactions.Add(CryptoTransaction.NewTrade(fillResponse.Trade_id.ToString(), fillResponse.Created_at,
                                                                exchange.Id,
                                                                "",
                                                                buyAmount,
                                                                buyCurrency,
                                                                fillResponse.Fee,
                                                                "EUR",
                                                                sellAmount,
                                                                sellCurrency,
                                                                await _marketData.GetHistoricRate("CHF", buyCurrency, fillResponse.Created_at)

                                                                ));
                }
            }

            await Task.Delay(200);

            var accounts = await client.AccountsService.GetAllAccountsAsync();

            await Task.Delay(200);

            foreach (var account in accounts)
            {
                var histories = await client.AccountsService.GetAccountHistoryAsync(account.Id.ToString());

                await Task.Delay(200);

                foreach (var history in histories)
                {
                    var transfers = history.Where(h => h.Type == "transfer");

                    foreach (var transfer in transfers)
                    {
                        if (transfer.Amount > 0)
                        {
                            transactions.Add(CryptoTransaction.NewIn(
                                                 transfer.Id,
                                                 transfer.Created_at,
                                                 exchange.Id,
                                                 "Transfer from Coinbase",
                                                 transfer.Amount,
                                                 account.Currency,
                                                 "Coinbase",
                                                 "GDAX",
                                                 transfer.Id
                                                 ));
                        }
                        else
                        {
                            transactions.Add(CryptoTransaction.NewOut(
                                                 transfer.Id,
                                                 transfer.Created_at,
                                                 exchange.Id,
                                                 "To Coinbase",
                                                 transfer.Amount * -1,
                                                 account.Currency,
                                                 0,
                                                 account.Currency,
                                                 "GDAX",
                                                 "Coinbase",
                                                 transfer.Id
                                                 ));
                        }
                    }
                }
            }

            return(transactions);
        }
Example #3
0
        private IEnumerable <Account> aaa(GDAXClient.GDAXClient client)
        {
            var result = Task.Run(async() => { return(await client.AccountsService.GetAllAccountsAsync()); }).Result;

            return(result);
        }
Example #4
0
        static void Main(string[] args)
        {
            var apiKey     = ConfigurationManager.AppSettings["ApiKey"];
            var apiSecret  = ConfigurationManager.AppSettings["SecretKey"];
            var passPhrase = ConfigurationManager.AppSettings["PassPhrase"];

            var trendSize     = int.Parse(ConfigurationManager.AppSettings["TrendItemCount"]);
            var windowSize    = int.Parse(ConfigurationManager.AppSettings["TrendWindow"]);
            var pauseInterval = int.Parse(ConfigurationManager.AppSettings["PauseInterval"]);

            var playerQuota = decimal.Parse(ConfigurationManager.AppSettings["PlayerQuota"]);
            var perBidValue = decimal.Parse(ConfigurationManager.AppSettings["PerBidValue"]);

            Authenticator auth = new Authenticator(apiKey, apiSecret, passPhrase);

            GDAXClient.GDAXClient client = new GDAXClient.GDAXClient(auth, false);
            //var result = client.OrdersService.PlaceLimitOrderAsync(OrderSide.Buy, ProductType.LtcUsd, 0.5M, 20).Result;


            var player = new Player(client, playerQuota, perBidValue);
            var trend  = new Trend(trendSize, windowSize);
            var view   = new ConsoleView(player, trend);

            while (true)
            {
                try
                {
                    var trades        = client.ProductsService.GetProductTradesAsync(player.ProductType).Result.ToList();
                    var currentTicker = client.ProductsService.GetProductTickerAsync(player.ProductType).Result;

                    var buyTrades  = trades.FindAll(t => t.Side == "buy");
                    var sellTrades = trades.FindAll(t => t.Side == "sell");

                    var tradeMedian = GetMedian(trades);
                    var buyMedian   = GetMedian(buyTrades);
                    var sellMedian  = GetMedian(sellTrades);
                    var buyVolume   = buyTrades.Sum(t => t.Size);
                    var sellVolume  = sellTrades.Sum(t => t.Size);

                    var trade = new Trade()
                    {
                        DateTime    = currentTicker.Time,
                        Price       = Decimal.Round(currentTicker.Price, 2),
                        BidPrice    = Decimal.Round(currentTicker.Bid, 2),
                        AskPrice    = Decimal.Round(currentTicker.Ask, 2),
                        TradeMedian = Decimal.Round(tradeMedian, 2),
                        BuyMedian   = Decimal.Round(buyMedian, 2),
                        BuyVolume   = Decimal.Round(buyVolume, 2),
                        SellMedian  = Decimal.Round(sellMedian, 2),
                        SellVolume  = Decimal.Round(sellVolume, 2)
                    };
                    trend.Add(trade);
                    view.Show();
                    //Console.WriteLine($"Time: {trade.DateTime}, Price: {trade.Price}, Bid: {trade.BidPrice}, Ask: {trade.AskPrice}, TradeM: {trade.TradeMedian}, BuyM: {trade.BuyMedian}, SellM: {trade.SellMedian}, BV: {trade.BuyVolume}, SV: {trade.SellVolume}, MedianScore: {trade.MedianScore}");

                    player.Play(trend, trade);
                }
                catch (Exception ex)
                {
                    view.ShowError(ex);
                    Helper.WriteError(ex);
                }
                Thread.Sleep(pauseInterval);
            }
        }
Example #5
0
 public GdaxWrapper()
 {
     Exchange    = SupportedExchanges.GDax;
     _gdaxClient = new GDAXClient.GDAXClient(new Authenticator("", "", ""));
 }