示例#1
0
文件: Account.cs 项目: qadmium/ibapi
        public Account(string name, IConnection connection, IApiObjectsFactory factory, IExecutionStorageInternal executionStorage,
            IPositionsStorageInternal positionsesStorageInternal, IOrdersStorageInternal ordersStorageInternal,
            IIdsDispenser idsDispenser, CancellationTokenSource internalCancelationTokenSource,
            AccountCurrenciesFields accountCurrenciesFields)
        {
            CodeContract.Requires(!string.IsNullOrEmpty(name));
            CodeContract.Requires(connection != null);
            CodeContract.Requires(factory != null);
            CodeContract.Requires(executionStorage != null);
            CodeContract.Requires(positionsesStorageInternal != null);
            CodeContract.Requires(ordersStorageInternal != null);
            CodeContract.Requires(accountCurrenciesFields != null);
            CodeContract.Requires(idsDispenser != null);

            this.AccountName = name;
            this.AccountId = name;

            this.factory = factory;
            this.executionStorage = executionStorage;
            this.positionsesStorage = positionsesStorageInternal;
            this.ordersStorage = ordersStorageInternal;
            this.accountCurrenciesFields = accountCurrenciesFields;
            this.idsDispenser = idsDispenser;
            this.internalCancelationTokenSource = internalCancelationTokenSource;

            this.subscription =
                connection.Subscribe((AccountValueMessage message) => message.AccountName == this.AccountName,
                    this.OnAccountValueMessage);
        }
示例#2
0
 public PositionsStorage(IConnection connection, IApiObjectsFactory objectsFactory, string accountName)
 {
     System.Diagnostics.Contracts.Contract.Requires(connection != null);
     System.Diagnostics.Contracts.Contract.Requires(objectsFactory != null);
     System.Diagnostics.Contracts.Contract.Requires(!string.IsNullOrEmpty(accountName));
     this.objectsFactory = objectsFactory;
     this.accountName = accountName;
     this.Subscribe(connection);
 }
示例#3
0
        public OrdersStorage(IConnection connection, IApiObjectsFactory objectsFactory, string accountName)
        {
            Contract.Requires(connection != null);
            Contract.Requires(objectsFactory != null);

            this.objectsFactory = objectsFactory;
            this.accountName = accountName;

            this.Subscribe(connection);
        }
示例#4
0
文件: Order.cs 项目: qadmium/ibapi
        public Order(int id, string account, IConnection connection, IApiObjectsFactory factory, CancellationTokenSource internaCancellationTokenSource)
        {
            CodeContract.Requires(connection != null);
            CodeContract.Requires(factory != null);

            this.factory = factory;
            this.internaCancellationTokenSource = internaCancellationTokenSource;
            this.Id = id;
            this.Subscribe(connection);
            this.Account = account;
        }
        public CreateAccountStorageOperation(CancellationToken cancellationToken, IApiObjectsFactory factory,
            IConnection connection,
            string[] managedAccountsList)
        {
            Contract.Requires(factory != null);
            Contract.Requires(connection != null);
            Contract.Requires(managedAccountsList != null && managedAccountsList.Length > 0);

            SendAutoOpenOrdersRequest(connection);
            this.CreateAndWaitAccounts(managedAccountsList, factory, connection, cancellationToken);
        }
示例#6
0
文件: Client.cs 项目: qadmium/ibapi
        public Client(IApiObjectsFactory objectsFactory, IAccountsStorage accountsStorage, Dispatcher dispatcher,
            IConnection connection,
            CancellationTokenSource internalCancelationTokenSource)
        {
            CodeContract.Requires(objectsFactory != null);
            CodeContract.Requires(accountsStorage != null);
            CodeContract.Requires(dispatcher != null);
            CodeContract.Requires(connection != null);
            CodeContract.Requires(accountsStorage.Accounts.Count() != 0);

            this.objectsFactory = objectsFactory;
            this.accountsStorage = accountsStorage;
            this.dispatcher = dispatcher;
            this.internalCancelationTokenSource = internalCancelationTokenSource;
            this.accountChangedEvent = dispatcher.RegisterEvent();
            connection.OnDisconnect += this.ConnectionOnOnDisconnect;
        }
示例#7
0
        public CreateAccountOperation(IConnection connection, IApiObjectsFactory factory, string account,
            CancellationToken cancellationToken)
        {
            Contract.Requires(connection != null);
            Contract.Requires(factory != null);
            Contract.Requires(!string.IsNullOrEmpty(account));

            this.factory = factory;
            this.account = account;
            this.cancellationToken = cancellationToken;
            this.cancellationToken.Register(() => this.taskCompletionSource.TrySetCanceled());
            this.positionStorage = this.factory.CreatePositionStorage(account);
            this.ordersStorage = this.factory.CreateOrdersStorage(account);
            this.createExecutionsStorage = factory.CreateExecutionStorageOperation(account, cancellationToken);
            this.Subscribe(connection);
            this.SendRequest(connection);
        }
        private async void CreateAndWaitAccounts(string[] managedAccountsList, IApiObjectsFactory factory,
            IConnection connection, CancellationToken cancellationToken)
        {
            var tasks =
                managedAccountsList.Select(account => factory.CreateAccountOperation(account, cancellationToken))
                    .ToList();

            SendAutoOpenOrdersRequest(connection);

            var accounts = new List<IAccountInternal>();
            foreach (var task in tasks)
            {
                accounts.Add(await task);
            }

            this.taskCompletionSource.SetResult(factory.CreateAccountStorage(accounts));
        }
        public CreateExecutionsStorageOperation(IConnection connection, IIdsDispenser dispenser, CancellationToken cancellationToken,
            IApiObjectsFactory factory,
            string account)
        {
            Contract.Requires(connection != null);
            Contract.Requires(factory != null);
            Contract.Requires(account != null);

            this.connection = connection;
            this.cancellationToken = cancellationToken;
            this.factory = factory;
            this.cancellationToken.Register(() =>
            {
                this.subscriptions.Unsubscribe();
                this.taskCompletionSource.TrySetCanceled();
            });
            this.account = account;
            this.Subscribe(dispenser);
        }