public static ProtoMessage Deal_List_Req(long ctidTraderAccountId, long fromTimestamp, long toTimestamp, int maxRows = 0) { ProtoOADealListReq message = new ProtoOADealListReq { payloadType = ProtoOAPayloadType.ProtoOaDealListReq, ctidTraderAccountId = ctidTraderAccountId, fromTimestamp = fromTimestamp, toTimestamp = toTimestamp }; if (maxRows > 0) { message.maxRows = maxRows; } Log.Info("ProtoOADealListReq:: " + $"ctidTraderAccountId: {ctidTraderAccountId}; " + $"fromTimestamp: {fromTimestamp} ({EpochToString(fromTimestamp)}; " + $"toTimestamp: {toTimestamp} ({EpochToString(toTimestamp)}; " + $"maxRows: {maxRows}"); InnerMemoryStream.SetLength(0); Serializer.Serialize(InnerMemoryStream, message); return(Encode((uint)message.payloadType, InnerMemoryStream.ToArray())); }
public ProtoMessage CreateDealsListRequest(long accountId, long from, long to, string clientMsgId = null) { var _msg = ProtoOADealListReq.CreateBuilder(); _msg.SetCtidTraderAccountId(accountId); _msg.SetFromTimestamp(from); _msg.SetToTimestamp(to); return(CreateMessage((uint)_msg.PayloadType, _msg.Build().ToByteString(), clientMsgId)); }
public async Task <HistoricalTradeModel[]> GetHistoricalTrades(long accountId, bool isLive, DateTimeOffset from, DateTimeOffset to) { VerifyConnection(); var client = GetClient(isLive); List <HistoricalTradeModel> result = new(); CancellationTokenSource cancelationTokenSource = null; using var disposable = client.OfType <ProtoOADealListRes>().Where(response => response.CtidTraderAccountId == accountId).Subscribe(response => { var trades = response.Deal.Select(deal => { var trade = new HistoricalTradeModel { Id = deal.DealId, SymbolId = deal.SymbolId, OrderId = deal.OrderId, PositionId = deal.PositionId, Volume = deal.Volume, FilledVolume = deal.FilledVolume, TradeSide = deal.TradeSide, Status = deal.DealStatus, Commission = deal.Commission, ExecutionPrice = deal.ExecutionPrice, MarginRate = deal.MarginRate, BaseToUsdConversionRate = deal.BaseToUsdConversionRate, CreationTime = DateTimeOffset.FromUnixTimeMilliseconds(deal.CreateTimestamp), ExecutionTime = DateTimeOffset.FromUnixTimeMilliseconds(deal.ExecutionTimestamp), LastUpdateTime = DateTimeOffset.FromUnixTimeMilliseconds(deal.UtcLastUpdateTimestamp) }; if (deal.ClosePositionDetail != null) { trade.IsClosing = true; trade.ClosedVolume = deal.ClosePositionDetail.ClosedVolume; trade.GrossProfit = deal.ClosePositionDetail.GrossProfit; trade.Swap = deal.ClosePositionDetail.Swap; trade.ClosedBalance = deal.ClosePositionDetail.Balance; trade.QuoteToDepositConversionRate = deal.ClosePositionDetail.QuoteToDepositConversionRate; } else { trade.IsClosing = false; } return(trade); }); result.AddRange(trades); if (cancelationTokenSource is not null) { cancelationTokenSource.Cancel(); } }); var timeAmountToAdd = TimeSpan.FromMilliseconds(604800000); var time = from; do { var toTime = time.Add(timeAmountToAdd); var requestMessage = new ProtoOADealListReq { FromTimestamp = time.ToUnixTimeMilliseconds(), ToTimestamp = toTime.ToUnixTimeMilliseconds(), CtidTraderAccountId = accountId }; cancelationTokenSource = new CancellationTokenSource(); await SendMessage(requestMessage, ProtoOAPayloadType.ProtoOaDealListReq, client, cancelationTokenSource, () => cancelationTokenSource.IsCancellationRequested); await Task.Delay(TimeSpan.FromSeconds(1)); time = toTime; } while (time < to); return(result.ToArray()); }