OpenClient

StockSharp.cTrader.Native

Inherits: Disposable

Constructors

OpenClient
public OpenClient(string host, uint port)
openClient = OpenClient(host, port)

Creates an instance of OpenClient which is not connected yet

host
The host name of API endpoint
port
The host port number

Properties

Host
public string Host { get; }
value = openClient.Host

The API endpoint host that the current client is connected to

IsCompleted
public bool IsCompleted { get; private set; }
value = openClient.IsCompleted
openClient.IsCompleted = value

If client stream is completed without any error then it will return True, otherwise False

IsTerminated
public bool IsTerminated { get; private set; }
value = openClient.IsTerminated
openClient.IsTerminated = value

If there was any error (exception) on client stream then this will return True, otherwise False

Port
public uint Port { get; }
value = openClient.Port

The API host port that current client is connected to

Methods

Connect
public Task Connect(CancellationToken cancellationToken)
result = openClient.Connect(cancellationToken)

Connects to the API based on you specified method

Returns: Task

ConnectTcp
private Task ConnectTcp(CancellationToken cancellationToken)
result = openClient.ConnectTcp(cancellationToken)

Connects to API by using a TCP client

Returns: Task

DisposeManaged
protected override void DisposeManaged()
openClient.DisposeManaged()

Disposes the client, releases all used resources, and stops all running operations

GetLength
private static int GetLength(byte[] lengthBytes)
result = OpenClient.GetLength(lengthBytes)

Returns the length of a received message without causing extra allocation

lengthBytes
The byte array of received length data

Returns: int

OnCompleted
private void OnCompleted()
openClient.OnCompleted()

Completes each observer by calling their OnCompleted method

OnError
private void OnError(Exception exception)
openClient.OnError(exception)

Disposes the client and then calls each observer OnError after an exception thrown

exception
Exception
ReadTcp
private Task ReadTcp(CancellationToken cancellationToken)
result = openClient.ReadTcp(cancellationToken)

This method will read the TCP stream for incoming messages

cancellationToken
The cancellation token that will be used on ReadAsync calls

Returns: Task

SendMessage
public Task SendMessage(ProtoMessage message, CancellationToken cancellationToken)
result = openClient.SendMessage(message, cancellationToken)

This method will insert your message on messages queue, it will not send the message instantly

message
Message
cancellationToken

Returns: Task

SendMessage``1
public Task SendMessage<T>(T message, ProtoOAPayloadType payloadType, string clientMsgId, CancellationToken cancellationToken)
result = openClient.SendMessage(message, payloadType, clientMsgId, cancellationToken)

This method will insert your message on messages queue, it will not send the message instantly

message
Message
payloadType
Message Payload Type (ProtoOAPayloadType)
clientMsgId
The client message ID (optional)
cancellationToken

Returns: Task

SendMessage``1
public Task SendMessage<T>(T message, string clientMsgId, CancellationToken cancellationToken)
result = openClient.SendMessage(message, clientMsgId, cancellationToken)

This method will insert your message on messages queue, it will not send the message instantly By using this overload of SendMessage method you avoid passing the message payload type and it gets the payload from message itself

message
Message
clientMsgId
The client message ID (optional)
cancellationToken

Returns: Task

SendMessage``1
public Task SendMessage<T>(T message, ProtoPayloadType payloadType, string clientMsgId, CancellationToken cancellationToken)
result = openClient.SendMessage(message, payloadType, clientMsgId, cancellationToken)

This method will insert your message on messages queue, it will not send the message instantly

message
Message
payloadType
Message Payload Type (ProtoPayloadType)
clientMsgId
The client message ID (optional)
cancellationToken

Returns: Task

ThrowObjectDisposedExceptionIfDisposed
private void ThrowObjectDisposedExceptionIfDisposed()
openClient.ThrowObjectDisposedExceptionIfDisposed()

Throws ObjectDisposedException if the client was disposed

WriteTcp
private Task WriteTcp(byte[] messageByte, CancellationToken cancellationToken)
result = openClient.WriteTcp(messageByte, cancellationToken)

Writes the message bytes to TCP stream

messageByte
cancellationToken
The cancellation token that will be used on calling stream methods

Returns: Task

Events

MessageReceived
public event Action<ProtoMessage> MessageReceived
openClient.MessageReceived += handler

This event will be triggered when a message is received from the API