Esempio n. 1
0
        public async Task <TransactionModel[]> GetTransactions(long accountId, bool isLive, DateTimeOffset from, DateTimeOffset to)
        {
            VerifyConnection();

            var client = GetClient(isLive);

            List <TransactionModel> result = new();

            CancellationTokenSource cancelationTokenSource = null;

            using var disposable = client.OfType <ProtoOACashFlowHistoryListRes>().Where(response => response.CtidTraderAccountId == accountId).Subscribe(response =>
            {
                var transactions = response.DepositWithdraw.Select(depositWithdraw => new TransactionModel
                {
                    Id             = depositWithdraw.BalanceHistoryId,
                    Type           = depositWithdraw.OperationType,
                    Balance        = depositWithdraw.Balance,
                    BalanceVersion = depositWithdraw.BalanceVersion,
                    Delta          = depositWithdraw.Delta,
                    Equity         = depositWithdraw.Equity,
                    Time           = DateTimeOffset.FromUnixTimeMilliseconds(depositWithdraw.ChangeBalanceTimestamp),
                    Note           = string.IsNullOrEmpty(depositWithdraw.ExternalNote) ? string.Empty : depositWithdraw.ExternalNote
                });

                result.AddRange(transactions);

                if (cancelationTokenSource is not null)
                {
                    cancelationTokenSource.Cancel();
                }
            });

            var timeAmountToAdd = TimeSpan.FromMilliseconds(604800000);

            var time = from;

            do
            {
                var toTime = time.Add(timeAmountToAdd);

                var requestMessage = new ProtoOACashFlowHistoryListReq
                {
                    FromTimestamp       = time.ToUnixTimeMilliseconds(),
                    ToTimestamp         = toTime.ToUnixTimeMilliseconds(),
                    CtidTraderAccountId = accountId
                };

                cancelationTokenSource = new CancellationTokenSource();

                await SendMessage(requestMessage, ProtoOAPayloadType.ProtoOaCashFlowHistoryListReq, client, cancelationTokenSource, () => cancelationTokenSource.IsCancellationRequested);

                await Task.Delay(TimeSpan.FromSeconds(1));

                time = toTime;
            } while (time < to);

            return(result.ToArray());
        }
        public ProtoMessage CreateCashflowHistoryRequest(long accountId, long from, long to, string clientMsgId = null)
        {
            var _msg = ProtoOACashFlowHistoryListReq.CreateBuilder();

            _msg.SetCtidTraderAccountId(accountId);
            _msg.SetFromTimestamp(from);
            _msg.SetToTimestamp(to);
            return(CreateMessage((uint)_msg.PayloadType, _msg.Build().ToByteString(), clientMsgId));
        }
Esempio n. 3
0
        public static ProtoMessage Cash_Flow_History_List_Req(long ctidTraderAccountId,
                                                              long fromTimestamp,
                                                              long toTimestamp)
        {
            ProtoOACashFlowHistoryListReq message = new ProtoOACashFlowHistoryListReq
            {
                payloadType         = ProtoOAPayloadType.ProtoOaCashFlowHistoryListReq,
                ctidTraderAccountId = ctidTraderAccountId,
                fromTimestamp       = fromTimestamp,
                toTimestamp         = toTimestamp
            };

            Log.Info("ProtoOACashFlowHistoryListReq:: " +
                     $"ctidTraderAccountId: {ctidTraderAccountId}; " +
                     $"fromTimestamp: {fromTimestamp} ({EpochToString(fromTimestamp)}; " +
                     $"toTimestamp: {toTimestamp} ({EpochToString(toTimestamp)}");

            InnerMemoryStream.SetLength(0);
            Serializer.Serialize(InnerMemoryStream, message);

            return(Encode((uint)message.payloadType, InnerMemoryStream.ToArray()));
        }