Exemple #1
0
 public void PushToken(TransactionToken token)
 {
     if (SymbolState == "ok")
     {
         _tokenQueue.Enqueue(token);
     }
 }
Exemple #2
0
        private async Task OpenOrderByToken(TransactionToken token)
        {
            while (token.Volume.Gte(_symbol.MinTradeVolume))
            {
                var openToken = TransactionToken.Min(_symbol.MaxTradeVolume, token);

                if (TryBuildOpenRequest(openToken, out var template))
                {
                    var result = await _bot.OpenOrderAsync(template.MakeRequest());

                    if (result.IsCompleted)
                    {
                        var resultingToken = new TransactionToken(result.ResultingOrder);
                        var remainingToken = openToken - resultingToken; // if TTS opened partial order

                        token -= openToken;

                        if (remainingToken.Volume.Gte(_symbol.MinTradeVolume))
                        {
                            _tokenQueue.Enqueue(remainingToken);
                        }

                        continue;
                    }
                }

                _tokenQueue.Enqueue(token);
                break;
            }
        }
        public void GetTokenHandler(TransactionToken token)
        {
            var watcher = GetOrCreateWatcher(token.Symbol);

            _bot.PrintDebug($"Received {token}");

            watcher.PushToken(token);
        }
Exemple #4
0
        public PositionState(DateTime time, string symbol, OrderSide side, double volume)
        {
            Time   = time;
            Volume = volume;
            Symbol = symbol;
            Side   = side;

            Token = new TransactionToken(this);
        }
Exemple #5
0
        public static TransactionToken Min(double volume, TransactionToken token)
        {
            if (token.Volume.Lte(volume))
            {
                return(token);
            }

            return(new TransactionToken(token)
            {
                Volume = volume,
            });
        }
Exemple #6
0
        protected override bool TryBuildOpenRequest(TransactionToken token, out OpenOrderRequest.Template template)
        {
            var traling = CalculateTraling();

            _bot.PrintDebug($"{_symbol.Name} traling = {traling}");

            template = BuildBaseOpenTemplate(token).WithPrice(PriceWithPips(token.Side, traling))
                       .WithComment($"{traling:F10}")
                       .WithType(OrderType.Limit);

            return(traling.Gte(0.0));
        }
Exemple #7
0
        private TransactionToken GetOptimazeAccountToken()
        {
            var baseToken = new TransactionToken(_symbol.Name);

            foreach (var order in Orders)
            {
                if (!order.IsNull)
                {
                    baseToken += new TransactionToken(order);
                }
            }

            return(baseToken);
        }
Exemple #8
0
        private async Task UpdateAccountStateByToken(TransactionToken token)
        {
            await CancelOrdersBySide(token.IsEmpty?null : (OrderSide?)token.Side.Inverse());

            var accountToken = GetOptimazeAccountToken();

            _bot.PrintDebug($"Queue token = {token}, acc token = {accountToken} in update");

            if (!accountToken.IsEmpty && accountToken.Volume.Lte(token.Volume))
            {
                await OpenOrderByToken(token - accountToken);
            }
            else
            {
                await CancelOrdersBySide(accountToken.Side);
                await OpenOrderByToken(token);
            }
        }
Exemple #9
0
 protected virtual OpenOrderRequest.Template BuildBaseOpenTemplate(TransactionToken token)
 {
     return(_openRequestTemplate.WithSide(token.Side).WithVolume(token.Volume));
 }
Exemple #10
0
 protected abstract bool TryBuildOpenRequest(TransactionToken token, out OpenOrderRequest.Template template);
Exemple #11
0
        protected override bool TryBuildOpenRequest(TransactionToken token, out OpenOrderRequest.Template template)
        {
            template = BuildBaseOpenTemplate(token).WithType(OrderType.Market);

            return(true);
        }
Exemple #12
0
 private TransactionToken(TransactionToken token) : this(token.Symbol, token.Volume, token.Side)
 {
 }