Esempio n. 1
0
        public Client(Config cfg)
        {
            Condition.Requires(cfg.Endpoint, "cfg.Endpoint").IsNotNull();
            Condition.Requires(cfg.Products, "cfg.Products").IsNotNull();
            Condition.Requires(cfg.Scheduler, "cfg.Scheduler").IsNotNull();
            if (cfg.Keys != null)
            {
                Condition.Requires(cfg.Keys.ApiKey, "cfg.Keys.ApiKey").IsNotNullOrWhiteSpace();
                Condition.Requires(cfg.Keys.SecretKey, "cfg.Keys.SecretKey").IsNotNullOrWhiteSpace();
            }
            if (cfg.EnableTrading)
            {
                Condition.Requires(cfg.Keys, "cfg.Keys").IsNotNull();
            }
            _cfg      = cfg.Clone();
            _cfg.Keys = _cfg.Keys ?? new Keys()
            {
                ApiKey = "NONE", SecretKey = "NONE"
            };
            var connector = new CodingConnector <IMessageIn, IMessageOut>(
                new ExchangeApi.WebSocket.Connector(_cfg.Endpoint.WebSocket), new WebSocket.Codec(_cfg.Keys));

            _connection = new DurableConnection <IMessageIn, IMessageOut>(connector, _cfg.Scheduler);
            _gateway    = new WebSocket.Gateway(_connection);
            _connection.OnConnection += OnConnection;
            _connection.OnMessage    += OnMessage;
            _restClient           = new REST.RestClient(_cfg.Endpoint.REST, _cfg.Keys);
            _pinger               = new PeriodicAction(_cfg.Scheduler, PingPeriod, PingPeriod, Ping);
            _futurePositionPoller = new FuturePositionPoller(
                _restClient, _cfg.Scheduler,
                _cfg.EnableTrading ? _cfg.Products : new List <Product>());
            _futurePositionPoller.OnFuturePositions += msg => OnFuturePositionsUpdate?.Invoke(msg);
            _spotPositionPoller = new PeriodicAction(_cfg.Scheduler, SpotPositionPollPeriod, SpotPositionPollPeriod, PollSpotPositions);
        }
Esempio n. 2
0
        public Client(Config cfg)
        {
            Condition.Requires(cfg.Endpoint, "cfg.Endpoint").IsNotNull();
            Condition.Requires(cfg.Products, "cfg.Products").IsNotNull();
            Condition.Requires(cfg.Scheduler, "cfg.Scheduler").IsNotNull();
            _cfg = cfg.Clone();
            var connector = new CodingConnector <WebSocket.IMessageIn, WebSocket.IMessageOut>(
                new ExchangeApi.WebSocket.Connector(_cfg.Endpoint.WebSocket), new WebSocket.Codec());

            _connection = new DurableConnection <WebSocket.IMessageIn, WebSocket.IMessageOut>(connector, _cfg.Scheduler);
            _connection.OnConnection += OnConnection;
            _connection.OnMessage    += OnMessage;
            _restClient   = new REST.RestClient(_cfg.Endpoint.REST, _cfg.Keys);
            _orderManager = new OrderManager(_cfg.Scheduler);
            foreach (string product in _cfg.Products)
            {
                _products.Add(product, new OrderBookBuilder());
            }
        }