Пример #1
0
 public void PushToken(TransactionToken token)
 {
     if (SymbolState == "ok")
     {
         _tokenQueue.Enqueue(token);
     }
 }
Пример #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;
            }
        }
Пример #3
0
        public void GetTokenHandler(TransactionToken token)
        {
            var watcher = GetOrCreateWatcher(token.Symbol);

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

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

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

            return(new TransactionToken(token)
            {
                Volume = volume,
            });
        }
Пример #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));
        }
Пример #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);
        }
Пример #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);
            }
        }
Пример #9
0
 protected virtual OpenOrderRequest.Template BuildBaseOpenTemplate(TransactionToken token)
 {
     return(_openRequestTemplate.WithSide(token.Side).WithVolume(token.Volume));
 }
Пример #10
0
 protected abstract bool TryBuildOpenRequest(TransactionToken token, out OpenOrderRequest.Template template);
Пример #11
0
        protected override bool TryBuildOpenRequest(TransactionToken token, out OpenOrderRequest.Template template)
        {
            template = BuildBaseOpenTemplate(token).WithType(OrderType.Market);

            return(true);
        }
Пример #12
0
 private TransactionToken(TransactionToken token) : this(token.Symbol, token.Volume, token.Side)
 {
 }