Exemplo n.º 1
0
        /// <summary>
        /// Converts a string to a FlexQueryResponse.
        /// </summary>
        /// <param name="xmlFile"></param>
        /// <param name="options"></param>
        /// <returns>An object with account activities</returns>
        public Contracts.FlexQueryResponse GetByString(string xmlFile, Options options = null)
        {
            if (options != null)
            {
                if (options.UseXmlReader)
                {
                    XmlReaderSettings settings = new XmlReaderSettings
                    {
                        Async = true
                    };

                    using (XmlReader reader = XmlReader.Create(xmlFile, settings))
                    {
                        var result = Deserializer.Deserialize <Xml.Contracts.QueryResponse.FlexQueryResponse, Contracts.FlexQueryResponse>(reader, out var errorObjects, out string mappingError);
                        result               = result ?? new Contracts.FlexQueryResponse();
                        result.Errors        = errorObjects;
                        result.MappingErrors = mappingError;
                        foreach (FlexStatement statement in result.FlexStatements.FlexStatement)
                        {
                            Logic.ProcessStatement(statement, options);
                        }

                        return(result);
                    }
                }
            }

            using (var stream = sb.GenerateStream(xmlFile))
            {
                var result = Deserializer.Deserialize <Xml.Contracts.QueryResponse.FlexQueryResponse, Contracts.FlexQueryResponse>(stream, out var errorObjects, out string mappingError);
                result               = result ?? new Contracts.FlexQueryResponse();
                result.Errors        = errorObjects;
                result.MappingErrors = mappingError;
                foreach (FlexStatement statement in result.FlexStatements.FlexStatement)
                {
                    Logic.ProcessStatement(statement, options);
                }

                return(result);
            }
        }
Exemplo n.º 2
0
        public void BrokerInterestReceived()
        {
            var str = StringFactory.XmlStart + @"<CashTransactions>
            <CashTransaction type='Broker Interest Received' />
            </CashTransactions>" + StringFactory.XmlEnd;
            var obj = Deserializer.Deserialize <FlexQueryResponse, Contracts.FlexQueryResponse>(streamBuilder.GenerateStream(str), out var msg);
            var cashTransactions = obj.FlexStatements.FlexStatement[0].CashTransactions.CashTransaction;

            cashTransactions.Count.Should().Be(1);
            cashTransactions[0].Type.Should().Be(Contracts.Enums.CashTransactionType.BrokerInterestReceived);
        }
Exemplo n.º 3
0
        public void TestTrades_AccountId()
        {
            var str    = StringFactory.XmlStart + @"<Trades>
            <Trade accountId='abcdefg' />
            </Trades>" + StringFactory.XmlEnd;
            var obj    = Deserializer.Deserialize <FlexQueryResponse, Contracts.FlexQueryResponse>(streamBuilder.GenerateStream(str), out var msg);
            var trades = obj.FlexStatements.FlexStatement[0].Trades.Trade;

            trades.Count.Should().Be(1);
            trades[0].AccountId.Should().Be("abcdefg");
        }
Exemplo n.º 4
0
        public void TestFlexStatementResponse()
        {
            var str = @"<FlexStatementResponse timestamp=""17 October, 2018 02:32 PM EDT"">
<Status>Success</Status>
<ReferenceCode>1735268776</ReferenceCode>
<Url>
https://gdcdyn.interactivebrokers.com/Universal/servlet/FlexStatementService.GetStatement
</Url>
</FlexStatementResponse>
";

            var obj = Deserializer.Deserialize <XmlFlexStatementResponse, FlexStatementResponse>(sb.GenerateStream(str), out var msg, out string mappingError);

            obj.Status.Should().Be("Success");
            obj.ReferenceCode.Should().Be(1735268776);
        }