Ejemplo n.º 1
0
        private void RegisterTrade(SymbolFeed feed, Trade trade, bool isTaker)
        {
            lock (LockObject)
            {
                var qBal = _Balances[feed.Symbol.QuoteAsset];
                var aBal = _Balances[feed.Symbol.Asset];

                if (trade.Direction == TradeDirection.Buy)
                {
                    aBal.Free   += trade.Amount;
                    qBal.Locked -= (trade.Amount * trade.Price);
                    Debug.Assert(qBal.Locked >= 0, "incoerent trade");
                }
                else if (trade.Direction == TradeDirection.Sell)
                {
                    qBal.Free   += trade.Amount * trade.Price;
                    aBal.Locked -= trade.Amount;
                    Debug.Assert(_Balances[feed.Symbol.Asset].Locked >= -0.0000000001m, "incoerent trade");
                }
                //always pay commissions on quote asset
                var feeRatio = isTaker ? TakerFee : MakerFee;
                trade.Commission      = trade.Amount * feeRatio * trade.Price;
                trade.CommissionAsset = feed.Symbol.QuoteAsset;
                qBal.Free            -= trade.Commission;

                //set order status
                trade.Order.Status = OrderStatus.Filled;
                trade.Order.Filled = trade.Amount;
                this._Trades.Add(trade);
                TradesToSignal.Add(trade);
            }
        }
Ejemplo n.º 2
0
 private void InitializeDataSourceCallBack(Market market, SymbolFeed feed)
 {
     if (!IncrementalHistoryLoading)
     {
         if (feed.DataSource == null)
         {
             var histInfo = new SymbolHistoryId(market.MarketName, feed.Symbol.Key, TimeSpan.FromSeconds(60));
             feed.DataSource = this.HistoryDb.GetSymbolHistory(histInfo, StartTime, EndTime);
             //this.HistoryDb.CloseFile(histInfo);
         }
     }
 }
Ejemplo n.º 3
0
        public Task <ISymbolFeed> GetSymbolFeedAsync(string symbol)
        {
            var feedFound = SymbolsFeeds.TryGetValue(symbol, out SymbolFeed feed);

            if (!feedFound)
            {
                var sInfo = SymbolsTable[symbol];
                feed = new SymbolFeed(this.MarketName, sInfo);
                initializeDataSourceCallBack(this, feed);
                lock (LockObject)
                    SymbolsFeeds.Add(symbol, feed);
            }
            if (!_Balances.ContainsKey(feed.Symbol.Asset))
            {
                _Balances.Add(feed.Symbol.Asset, new AssetBalance());
            }
            if (!_Balances.ContainsKey(feed.Symbol.QuoteAsset))
            {
                _Balances.Add(feed.Symbol.QuoteAsset, new AssetBalance());
            }

            return(Task.FromResult <ISymbolFeed>(feed));
        }
Ejemplo n.º 4
0
 public void AddNewCandle(SymbolFeed feed, Candlestick tick)
 {
     Logger.Trace("New candle  {0} - {1}", feed.Symbol, tick);
     feed.Spread = tick.Close * Spread;
     feed.AddNewData(tick);
 }