static string ProtoMessageToString(ProtoMessage msg) { if (!msg.HasPayload) { return("ERROR in ProtoMessage: Corrupted execution event, no payload found"); } var _str = "ProtoMessage{"; switch ((ProtoPayloadType)msg.PayloadType) { case ProtoPayloadType.PROTO_MESSAGE: var _msg = ProtoMessage.CreateBuilder().MergeFrom(msg.Payload).Build(); _str += ProtoMessageToString(_msg); break; case ProtoPayloadType.HEARTBEAT_EVENT: var _hb = ProtoHeartbeatEvent.CreateBuilder().MergeFrom(msg.Payload).Build(); _str += "Heartbeat"; break; case ProtoPayloadType.ERROR_RES: var _err = ProtoErrorRes.CreateBuilder().MergeFrom(msg.Payload).Build(); _str += "ErrorResponse{errorCode:" + _err.ErrorCode + (_err.HasDescription ? ", description:" + _err.Description : "") + "}"; break; default: _str += OpenApiMessageToString(msg); break; } _str += (msg.HasClientMsgId ? ", clientMsgId:" + msg.ClientMsgId : "") + "}"; return(_str); }
public ProtoMessage GetMessage(byte[] msg) { var _msg = ProtoMessage.CreateBuilder().MergeFrom(msg).Build(); lastMessagePayloadType = _msg.PayloadType; lastMessagePayload = _msg.Payload; return(_msg); }
public ProtoMessage CreateMessage(uint payloadType, ByteString payload = null, string clientMsgId = null) { var protoMsg = ProtoMessage.CreateBuilder(); protoMsg.PayloadType = payloadType; if (payload != null) { protoMsg.SetPayload(payload); } if (clientMsgId != null) { protoMsg.SetClientMsgId(clientMsgId); } return(protoMsg.Build()); }
public void SendTrade(UserConfig config, string symbolName, string direction, long size, string clientMsgId, string orderComment, long stopPoints = 0, long takeProfitPoints = 0) { ProtoOATradeSide tradeSide = ProtoOATradeSide.BUY; if (direction == "SHORT") { tradeSide = ProtoOATradeSide.SELL; } int symbolId = config.Symbols.SymbolId(symbolName); //create the trade request message and queue it var _msg = ProtoOANewOrderReq.CreateBuilder(); _msg.SetCtidTraderAccountId(config.AccountId); _msg.SetSymbolId(symbolId); _msg.SetOrderType(ProtoOAOrderType.MARKET); _msg.SetTradeSide(tradeSide); _msg.SetVolume(size); _msg.SetLabel("LABEL"); if (stopPoints > 0) { _msg.SetRelativeStopLoss(stopPoints); } if (takeProfitPoints > 0) { _msg.SetRelativeTakeProfit(takeProfitPoints); } _msg.SetComment(orderComment); var protoMsg = ProtoMessage.CreateBuilder(); protoMsg.PayloadType = (uint)_msg.PayloadType; protoMsg.SetPayload(_msg.Build().ToByteString()); protoMsg.SetClientMsgId(clientMsgId); _trasmitQueue.Enqueue(protoMsg.Build()); }