public static ProtoMessage Get_Trendbars_Req(long ctidTraderAccountId, long fromTimestamp, long toTimestamp, ProtoOATrendbarPeriod period, long symbolId = 0) { ProtoOAGetTrendbarsReq message = new ProtoOAGetTrendbarsReq { payloadType = ProtoOAPayloadType.ProtoOaGetTrendbarsReq, ctidTraderAccountId = ctidTraderAccountId, fromTimestamp = fromTimestamp, toTimestamp = toTimestamp, Period = period }; if (symbolId > 0) { message.symbolId = symbolId; } Log.Info("ProtoOAGetTrendbarsReq:: " + $"ctidTraderAccountId: {ctidTraderAccountId}; " + $"fromTimestamp: {fromTimestamp} ({EpochToString(fromTimestamp)}; " + $"toTimestamp: {toTimestamp} ({EpochToString(toTimestamp)}; " + $"period: {period}"); InnerMemoryStream.SetLength(0); Serializer.Serialize(InnerMemoryStream, message); return(Encode((uint)message.payloadType, InnerMemoryStream.ToArray())); }
public ProtoMessage CreateTrendbarsRequest(long accountId, int symbolId, long from, long to, ProtoOATrendbarPeriod period, string clientMsgId = null) { var _msg = ProtoOAGetTrendbarsReq.CreateBuilder(); _msg.SetCtidTraderAccountId(accountId); _msg.SetSymbolId(symbolId); _msg.SetFromTimestamp(from); _msg.SetToTimestamp(to); _msg.SetPeriod(period); return(CreateMessage((uint)_msg.PayloadType, _msg.Build().ToByteString(), clientMsgId)); }
public async Task <ProtoOATrendbar[]> GetTrendbars(long accountId, bool isLive, DateTimeOffset from, DateTimeOffset to, ProtoOATrendbarPeriod period, long symbolId) { VerifyConnection(); var periodMaximum = GetMaximumTrendBarTime(period); if (from == default) { from = to.Add(-periodMaximum); } if (to - from > periodMaximum) { throw new ArgumentOutOfRangeException(nameof(to), "The time range is not valid"); } var client = GetClient(isLive); List <ProtoOATrendbar> result = new(); CancellationTokenSource cancelationTokenSource = new(); using var disposable = client.OfType <ProtoOAGetTrendbarsRes>().Where(response => response.CtidTraderAccountId == accountId).Subscribe(response => { result.AddRange(response.Trendbar); cancelationTokenSource.Cancel(); }); var requestMessage = new ProtoOAGetTrendbarsReq { FromTimestamp = from.ToUnixTimeMilliseconds(), ToTimestamp = to.ToUnixTimeMilliseconds(), CtidTraderAccountId = accountId, Period = period, SymbolId = symbolId }; await SendMessage(requestMessage, ProtoOAPayloadType.ProtoOaGetTrendbarsReq, client, cancelationTokenSource, () => cancelationTokenSource.IsCancellationRequested); return(result.ToArray()); }