コード例 #1
0
        private CryptoPosition Convert(Position position)
        {
            var key      = GetPositionKey(position);
            var existing = _positions.ContainsKey(key) ? _positions[key] : null;

            var currency = position.Currency ?? "XBt";

            var current = new CryptoPosition()
            {
                Pair             = position.Symbol ?? existing?.Pair,
                CurrentTimestamp = position.CurrentTimestamp ?? existing?.CurrentTimestamp,
                OpeningTimestamp = position.OpeningTimestamp ?? existing?.OpeningTimestamp,

                EntryPrice       = position.AvgEntryPrice ?? existing?.EntryPrice ?? 0,
                LastPrice        = position.LastPrice ?? existing?.LastPrice ?? 0,
                MarkPrice        = position.MarkPrice ?? existing?.MarkPrice ?? 0,
                LiquidationPrice = position.LiquidationPrice ?? existing?.LiquidationPrice ?? 0,

                Amount      = position.HomeNotional ?? existing?.Amount ?? 0,
                AmountQuote = position.CurrentQty ?? existing?.AmountQuote ?? 0,

                Side = ConvertSide(position.CurrentQty ?? existing?.AmountQuote),

                Leverage      = position.Leverage ?? existing?.Leverage,
                RealizedPnl   = ConvertToBtc(currency, position.RealisedPnl) ?? existing?.RealizedPnl,
                UnrealizedPnl = ConvertToBtc(currency, position.UnrealisedPnl) ?? existing?.UnrealizedPnl,
            };

            _positions[key] = current;
            return(current);
        }
コード例 #2
0
 private static void HandlePositionChanged(CryptoPosition pos)
 {
     Log.Information($"Position '{pos.Pair}' [{pos.Side}], " +
                     $"price: {pos.LastPrice:0.00######}, amount: {pos.Amount}/{pos.AmountQuote}, " +
                     $"leverage: {pos.Leverage}x, " +
                     $"pnl realized: {pos.RealizedPnl:0.00######}, unrealized: {pos.UnrealizedPnl:0.00######}, " +
                     $"liquidation: {pos.LiquidationPrice:0.00######}");
 }