示例#1
0
        public async Task SubscribeToSpots(long accountId, bool isLive, params long[] symbolIds)
        {
            var client = GetClient(isLive);

            using var cancelationTokenSource = new CancellationTokenSource();

            ProtoOASubscribeSpotsRes receivedResponse = null;

            using var disposable = client.OfType <ProtoOASubscribeSpotsRes>().Where(response => response.CtidTraderAccountId == accountId)
                                   .Subscribe(response =>
            {
                receivedResponse = response;

                cancelationTokenSource.Cancel();
            });

            var requestMessage = new ProtoOASubscribeSpotsReq
            {
                CtidTraderAccountId = accountId,
            };

            requestMessage.SymbolId.AddRange(symbolIds);

            await SendMessage(requestMessage, ProtoOAPayloadType.ProtoOaSubscribeSpotsReq, client, cancelationTokenSource, () => receivedResponse is not null);
        }
        public ProtoMessage CreateSubscribeForSpotsRequest(long accountId, int symbolId, string clientMsgId = null)
        {
            var _msg = ProtoOASubscribeSpotsReq.CreateBuilder();

            _msg.SetCtidTraderAccountId(accountId);
            _msg.AddSymbolId(symbolId);
            return(CreateMessage((uint)_msg.PayloadType, _msg.Build().ToByteString(), clientMsgId));
        }
示例#3
0
        private async static void SubscribeToSymbolSpot(string[] commandSplit)
        {
            Console.WriteLine("Subscribing to symbol spot event...");

            var subscribeSpotsReq = new ProtoOASubscribeSpotsReq()
            {
                CtidTraderAccountId = long.Parse(commandSplit[2]),
            };

            subscribeSpotsReq.SymbolId.AddRange(commandSplit.Skip(3).Select(iSymbolId => long.Parse(iSymbolId)));

            await _client.SendMessage(subscribeSpotsReq, ProtoOAPayloadType.ProtoOaSubscribeSpotsReq);
        }
示例#4
0
        private void Transmit()
        {
            while (!isShutdown)
            {
                if (_trasmitQueue.Count() > 0)
                {
                    //get the next message to submit
                    ProtoMessage msg = _trasmitQueue.Dequeue();

                    //Sends the Proto message
                    var    msgByteArray = msg.ToByteArray();
                    byte[] length       = BitConverter.GetBytes(msgByteArray.Length).Reverse().ToArray();
                    _apiSocket.Write(length);
                    _apiSocket.Write(msgByteArray);


                    switch ((ProtoOAPayloadType)msg.PayloadType)
                    {
                    case ProtoOAPayloadType.PROTO_OA_APPLICATION_AUTH_REQ:
                        MessageHandler?.Invoke("Authorising App.");
                        break;

                    case ProtoOAPayloadType.PROTO_OA_ACCOUNT_AUTH_REQ:
                        var accAuth = ProtoOAAccountAuthReq.CreateBuilder().MergeFrom(msg.Payload).Build();
                        MessageHandler?.Invoke("Authorising account " + Users[accAuth.AccessToken].AccountId);
                        break;

                    case ProtoOAPayloadType.PROTO_OA_SUBSCRIBE_SPOTS_REQ:
                        var spotReq = ProtoOASubscribeSpotsReq.CreateBuilder().MergeFrom(msg.Payload).Build();
                        //get the associated user
                        UserConfig config = Users.Where(x => x.Value.AccountId == spotReq.CtidTraderAccountId).Select(x => x.Value).FirstOrDefault();
                        //get the associated symbol
                        Symbol symbol = config.Symbols.Where(x => x.Id == spotReq.GetSymbolId(0)).FirstOrDefault();
                        //Notify the spot request has been sent
                        SymbolTickRequestHandler?.Invoke(symbol);
                        break;
                    }
                }
                else if (!_heartbeatTimer.Enabled)
                {
                    //start the heartbeat timer
                    _heartbeatTimer.Enabled = true;
                    _heartbeatTimer.Start();
                }

                //Wait 2.01 seconds between each message as to not exceed the 30 messages per minute restriction
                Thread.Sleep(2010);
            }
        }
示例#5
0
        private void btnSubscribeForSpots_Click(object sender, EventArgs e)
        {
            var spotRequest = new ProtoOASubscribeSpotsReq
            {
                CtidTraderAccountId = _accountID,
            };

            spotRequest.SymbolId.Add(1);

            var message = new ProtoMessage
            {
                Payload     = spotRequest.ToByteString(),
                PayloadType = (int)ProtoOAPayloadType.ProtoOaSubscribeSpotsReq,
            };

            Transmit(message);
        }
示例#6
0
        public static ProtoMessage Subscribe_Spots_Req(long ctidTraderAccountId, long[] symbolIDs)
        {
            ProtoOASubscribeSpotsReq message = new ProtoOASubscribeSpotsReq
            {
                payloadType         = ProtoOAPayloadType.ProtoOaSubscribeSpotsReq,
                ctidTraderAccountId = ctidTraderAccountId,
                symbolIds           = symbolIDs
            };

            Log.Info("ProtoOASubscribeSpotsReq:: " +
                     $"ctidTraderAccountId: {ctidTraderAccountId}; " +
                     $"symbolIds: [{string.Join("; ", symbolIDs)}]");

            InnerMemoryStream.SetLength(0);
            Serializer.Serialize(InnerMemoryStream, message);

            return(Encode((uint)message.payloadType, InnerMemoryStream.ToArray()));
        }
 public ProtoOASubscribeSpotsReq GetSubscribeForSpotsRequest(byte[] msg = null)
 {
     return(ProtoOASubscribeSpotsReq.CreateBuilder().MergeFrom(GetPayload(msg)).Build());
 }