/// <summary> /// Send message to the websocket channel. /// It inserts the message to the queue and actual sending is done on an other thread /// </summary> /// <param name="message">Message to be sent</param> public Task Send(string message) { BmxValidations.ValidateInput(message, nameof(message)); _messagesToSendQueue.Add(message); return(Task.CompletedTask); }
public BitmexWebsocketClient(IBitmexCommunicator communicator) { BmxValidations.ValidateInput(communicator, nameof(communicator)); _communicator = communicator; _messageReceivedSubsciption = _communicator.MessageReceived.Subscribe(HandleMessage); }
/// <summary> /// Subscribe to trades for selected pair ('XBTUSD', etc) /// </summary> public TradeBinSubscribeRequest(string sizeArg, string pair) { BmxValidations.ValidateInput(pair, nameof(pair)); Symbol = pair; Size = sizeArg; Topic = "tradeBin" + Size; }
/// <inheritdoc /> public BitmexWebsocketClient(IBitmexCommunicator communicator) { BmxValidations.ValidateInput(communicator, nameof(communicator)); _communicator = communicator; _messageReceivedSubscription = _communicator.MessageReceived.Subscribe(HandleMessage); JsonSerializer.SetDefaultResolver(StandardResolver.CamelCase); }
public Task Send <T>(T request) where T : RequestBase { BmxValidations.ValidateInput(request, nameof(request)); var serialized = request.IsRaw ? request.OperationString : BitmexJsonSerializer.Serialize(request); return(_communicator.Send(serialized)); }
public BitmexMultiplexClient(IBitmexCommunicator communicator) { BmxValidations.ValidateInput(communicator, nameof(communicator)); _communicator = communicator; _messageReceivedSubscription = _communicator.MessageReceived.Subscribe(HandleMessage); _channels = new ConcurrentDictionary <Guid, BitmexWebsocketChannel>(); Task.Run(this.PingMonitor); }
public BitmexWebsocketCommunicator(Uri url, Func <ClientWebSocket> clientFactory = null) { BmxValidations.ValidateInput(url, nameof(url)); _url = url; _clientFactory = clientFactory ?? (() => new ClientWebSocket() { Options = { KeepAliveInterval = new TimeSpan(0, 0, 5, 0) } }); }
public async Task Send(string message) { BmxValidations.ValidateInput(message, nameof(message)); Log.Verbose(L($"Sending: {message}")); var buffer = Encoding.UTF8.GetBytes(message); var messageSegment = new ArraySegment <byte>(buffer); var client = await GetClient(); await client.SendAsync(messageSegment, WebSocketMessageType.Text, true, _cancelation.Token); }
public AuthenticationRequest(string apiKey, string apiSecret) { BmxValidations.ValidateInput(apiKey, nameof(apiKey)); BmxValidations.ValidateInput(apiSecret, nameof(apiSecret)); _apiKey = apiKey; _authNonce = BitmexAuthentication.CreateAuthNonce(); _authPayload = BitmexAuthentication.CreateAuthPayload(_authNonce); _authSig = BitmexAuthentication.CreateSignature(apiSecret, _authPayload); }
/// <summary> /// Serializes request and sends message via websocket communicator. /// It logs and re-throws every exception. /// </summary> /// <param name="request">Request/message to be sent</param> public async Task Send <T>(T request) where T : RequestBase { try { BmxValidations.ValidateInput(request, nameof(request)); var serialized = request.IsRaw ? request.OperationString : BitmexJsonSerializer.Serialize(request); await _communicator.Send(serialized).ConfigureAwait(false); } catch (Exception e) { Log.Error(e, L($"Exception while sending message '{request}'. Error: {e.Message}")); throw; } }
/// <summary> /// Subscribe to fundings for selected pair, e.g. 'XBTUSD' /// </summary> public FundingsSubscribeRequest(string pair) { BmxValidations.ValidateInput(pair, nameof(pair)); Symbol = pair; }
/// <summary> /// Subscribe toinstrument updates including turnover and bid/ask from selected pair ('XBTUSD', etc) /// </summary> public InstrumentSubscribeRequest(string pair) { BmxValidations.ValidateInput(pair, nameof(pair)); Symbol = pair; }
/// <summary> /// Send message to the websocket channel. /// It doesn't use a sending queue, /// beware of issue while sending two messages in the exact same time /// on the full .NET Framework platform /// </summary> /// <param name="message">Message to be sent</param> public Task SendInstant(string message) { BmxValidations.ValidateInput(message, nameof(message)); return(SendInternal(message)); }