Esempio n. 1
0
        private Report GenerateTradesHistoryReport(ReportRequestParameters reportRequestParameters)
        {
            var report = new Report();

            report.AddColumn("Date", ComparingType.DateTime);
            report.AddColumn("Market", ComparingType.String);
            report.AddColumn("Trade id", ComparingType.Long);
            report.AddColumn("Order id", ComparingType.Long);
            report.AddColumn("Client order id", ComparingType.String);
            report.AddColumn("Side", ComparingType.String);
            report.AddColumn("Amount", ComparingType.Double);
            report.AddColumn("Price", ComparingType.Double);
            report.AddColumn("Total", ComparingType.String);
            report.AddColumn("Fee", ComparingType.String);
            report.AddColumn("Rebate", ComparingType.String);

            string symbolName = null;

            var settingItem = reportRequestParameters.ReportType.Settings.GetItemByName(REPORT_TYPE_PARAMETER_SYMBOL);

            if (settingItem?.Value is Symbol symbol)
            {
                symbolName = symbol.Id;
            }

            if (string.IsNullOrEmpty(symbolName) || !this.symbolsCache.TryGetValue(symbolName, out var hitSymbol))
            {
                return(report);
            }

            if (!this.TryGetReportFromTo(reportRequestParameters.ReportType.Settings, out var from, out var to))
            {
                return(report);
            }

            var tradesHistory = new List <HitUserTrade>();

            while (from < to)
            {
                var trades = this.CheckHitResponse(this.restApi.GetUserTradesHistoryByTimestampAsync(symbolName, from: from, till: to, limit: ORDERS_HISTORY_LIMIT, cancellationToken: reportRequestParameters.CancellationToken).Result, out var error);

                if (trades == null || error != null || trades.Length == 0)
                {
                    break;
                }

                tradesHistory.AddRange(trades);

                to = trades.Last().Timestamp.AddTicks(-1);

                if (trades.Length < TRADES_HISTORY_LIMIT)
                {
                    break;
                }
            }

            foreach (var trade in tradesHistory)
            {
                double fee    = (double)(trade.Fee > 0 ? trade.Fee * -1m : 0m);
                double rebate = (double)(trade.Fee > 0 ? 0m : trade.Fee * -1m);
                double total  = (double)(trade.Price * trade.Quantity);

                var row = new ReportRow();

                row.AddCell(trade.Timestamp, new DateTimeFormatterDescription(trade.Timestamp));
                row.AddCell(trade.Symbol);
                row.AddCell(trade.Id);
                row.AddCell(trade.OrderId);
                row.AddCell(trade.ClientOrderId);
                row.AddCell(trade.Side.ToString());
                row.AddCell((double)trade.Quantity, new VolumeFormattingDescription((double)trade.Quantity, trade.Symbol));
                row.AddCell((double)trade.Price, new PriceFormattingDescription((double)trade.Price, trade.Symbol));
                row.AddCell(total, new AssetFormattingDescription(hitSymbol.FeeCurrency, total));
                row.AddCell(fee, new AssetFormattingDescription(hitSymbol.FeeCurrency, fee));
                row.AddCell(rebate, new AssetFormattingDescription(hitSymbol.FeeCurrency, rebate));

                report.Rows.Add(row);
            }

            return(report);
        }
Esempio n. 2
0
        private Report GenerateTransactionsReport(ReportRequestParameters reportRequestParameters)
        {
            var report = new Report();

            report.AddColumn("Date", ComparingType.DateTime);
            report.AddColumn("Created at", ComparingType.DateTime);
            report.AddColumn("Id", ComparingType.String);
            report.AddColumn("Type", ComparingType.String);
            report.AddColumn("Currency", ComparingType.String);
            report.AddColumn("Amount", ComparingType.Double);
            report.AddColumn("Fee", ComparingType.Double);
            report.AddColumn("Hash", ComparingType.String);
            report.AddColumn("Address", ComparingType.String);
            report.AddColumn("Index", ComparingType.Long);
            report.AddColumn("Status", ComparingType.String);

            if (!this.TryGetReportFromTo(reportRequestParameters.ReportType.Settings, out var from, out var to))
            {
                return(report);
            }

            var transactionsHistory = new List <HitTransaction>();

            while (from < to)
            {
                var transactions = this.CheckHitResponse(this.restApi.GetTransactionsHistoryByTimestampAsync(from: from, till: to, limit: ORDERS_HISTORY_LIMIT, cancellationToken: reportRequestParameters.CancellationToken).Result, out var error);

                if (transactions == null || error != null || transactions.Length == 0)
                {
                    break;
                }

                transactionsHistory.AddRange(transactions);

                to = transactions.Last().CreatedAt.AddTicks(-1);

                if (transactions.Length < TRANSACTIONS_HISTORY_LIMIT)
                {
                    break;
                }
            }

            foreach (var transaction in transactionsHistory)
            {
                string type = "";

                switch (transaction.Type)
                {
                case HitTransactionType.BankToExchange:
                    type = "Transfer to trading account";
                    break;

                case HitTransactionType.ExchangeToBank:
                    type = "Transfer to main accout";
                    break;

                default:
                    type = transaction.Type.ToString();
                    break;
                }

                var row = new ReportRow();

                row.AddCell(transaction.UpdatedAt, new DateTimeFormatterDescription(transaction.UpdatedAt));
                row.AddCell(transaction.CreatedAt, new DateTimeFormatterDescription(transaction.CreatedAt));
                row.AddCell(transaction.Id);
                row.AddCell(type);
                row.AddCell(transaction.Currency);
                row.AddCell((double)transaction.Amount);
                row.AddCell((double)transaction.Fee);
                row.AddCell(transaction.Hash);
                row.AddCell(transaction.Address);
                row.AddCell(transaction.Index);
                row.AddCell(transaction.Status.ToString());

                report.Rows.Add(row);
            }

            return(report);
        }
Esempio n. 3
0
        private Report GenerateOrdersHistoryReport(ReportRequestParameters reportRequestParameters)
        {
            var report = new Report();

            report.AddColumn("Date", ComparingType.DateTime);
            report.AddColumn("Created", ComparingType.DateTime);
            report.AddColumn("Market", ComparingType.String);
            report.AddColumn("Order id", ComparingType.Long);
            report.AddColumn("Client order id", ComparingType.String);
            report.AddColumn("Side", ComparingType.String);
            report.AddColumn("Order type", ComparingType.String);
            report.AddColumn("Price", ComparingType.Double);
            report.AddColumn("Stop price", ComparingType.Double);
            report.AddColumn("Amount", ComparingType.Double);
            report.AddColumn("Executed", ComparingType.Double);
            report.AddColumn("Time in force", ComparingType.String);
            report.AddColumn("Status", ComparingType.String);

            string symbolName = null;

            var settingItem = reportRequestParameters.ReportType.Settings.GetItemByName(REPORT_TYPE_PARAMETER_SYMBOL);

            if (settingItem?.Value is Symbol symbol)
            {
                symbolName = symbol.Id;
            }

            if (!this.TryGetReportFromTo(reportRequestParameters.ReportType.Settings, out var from, out var to))
            {
                return(report);
            }

            var ordersHistory = new List <HitOrder>();

            while (from < to)
            {
                var orders = this.CheckHitResponse(this.restApi.GetOrdersHistoryAsync(symbolName, from: from, till: to, limit: ORDERS_HISTORY_LIMIT, cancellationToken: reportRequestParameters.CancellationToken).Result, out var error);

                if (orders == null || error != null || orders.Length == 0)
                {
                    break;
                }

                ordersHistory.AddRange(orders);

                to = orders.Last().CreatedAt.AddTicks(-1);

                if (orders.Length < ORDERS_HISTORY_LIMIT)
                {
                    break;
                }
            }

            foreach (var order in ordersHistory)
            {
                double price     = 0d;
                double stopPrice = 0d;

                if (order.OrderType == HitOrderType.Limit || order.OrderType == HitOrderType.StopLimit)
                {
                    price = (double)order.Price;
                }

                if (order.OrderType == HitOrderType.StopMarket || order.OrderType == HitOrderType.StopLimit)
                {
                    stopPrice = (double)order.StopPrice;
                }

                var row = new ReportRow();

                row.AddCell(order.UpdatedAt, new DateTimeFormatterDescription(order.UpdatedAt));
                row.AddCell(order.CreatedAt, new DateTimeFormatterDescription(order.CreatedAt));
                row.AddCell(order.Symbol);
                row.AddCell(order.Id);
                row.AddCell(order.ClientOrderId);
                row.AddCell(order.Side.ToString());
                row.AddCell(this.ConvertOrderType(order.OrderType));
                row.AddCell(price, new PriceFormattingDescription(price, order.Symbol));
                row.AddCell(stopPrice, new PriceFormattingDescription(stopPrice, order.Symbol));
                row.AddCell(order.Quantity, new VolumeFormattingDescription((double)order.Quantity, order.Symbol));
                row.AddCell(order.CumulativeQuantity, new VolumeFormattingDescription((double)order.CumulativeQuantity, order.Symbol));
                row.AddCell(this.ConvertTimeInForce(order.TimeInForce).ToString());
                row.AddCell(this.ConvertOrderStatus(order.Status).ToString());

                report.Rows.Add(row);
            }

            return(report);
        }