Esempio n. 1
0
        public async Task OpenAsync()
        {
            await InitializeMarketsAsync();

            await RealtimeSource.TryOpenAsync();

            if (!Client.IsAuthenticated)
            {
                return;
            }

            Positions.Update((await Client.GetPositionsAsync(BfProductCode.FXBTCJPY, CancellationToken.None)).GetContent());
            RealtimeSource.GetChildOrderEventsSource().Subscribe(coe =>
            {
                var productCode = _marketSymbols[coe.ProductCode];
                _markets[productCode].ForwardChildOrderEvents(coe);
                if (productCode == BfProductCode.FXBTCJPY && coe.EventType == BfOrderEventType.Execution)
                {
                    Positions.Update(coe).ForEach(e => PositionChanged?.Invoke(this, new BfxPositionEventArgs(coe.EventDate, e)));
                }
            });

            RealtimeSource.GetParentOrderEventsSource().Subscribe(poe =>
            {
                _markets[_marketSymbols[poe.ProductCode]].ForwardParentOrderEvents(poe);
            });
        }
Esempio n. 2
0
 public BfxAccount(string apiKey, string apiSecret)
 {
     if (string.IsNullOrEmpty(apiKey) || string.IsNullOrEmpty(apiKey))
     {
         Client         = new BitFlyerClient().AddTo(_disposables);
         RealtimeSource = RealtimeSourceFactory.Singleton;
     }
     else
     {
         Client         = new BitFlyerClient(apiKey, apiSecret).AddTo(_disposables);
         RealtimeSource = RealtimeSourceFactory.Singleton;
         RealtimeSource.Authenticate(apiKey, apiSecret);
     }
     RealtimeSource.ConnectionResumed += OnRealtimeConnectionResumed;
 }