Esempio n. 1
0
        public void TestHiHat()
        {
            string closedFile = DataManagement.PathForDataFile("Test", "ClosedHiHat.wav");

            Assert.IsTrue(WaveEncoding.SaveStream(
                              filepath: closedFile,
                              stream: InstrumentLookup.GetPercussion(PercussionMap.ClosedHiHat, 0xF7)
                              .SafeCache()
                              .SlowRangeFitter(),
                              overwrite: true));

            string pedalFile = DataManagement.PathForDataFile("Test", "PedalHiHat.wav");

            Assert.IsTrue(WaveEncoding.SaveStream(
                              filepath: pedalFile,
                              stream: InstrumentLookup.GetPercussion(PercussionMap.PedalHiHat, 0xF7)
                              .SafeCache()
                              .SlowRangeFitter(),
                              overwrite: true));

            string openFile = DataManagement.PathForDataFile("Test", "OpenHiHat.wav");

            Assert.IsTrue(WaveEncoding.SaveStream(
                              filepath: openFile,
                              stream: InstrumentLookup.GetPercussion(PercussionMap.OpenHiHat, 0xF7)
                              .SafeCache()
                              .SlowRangeFitter(),
                              overwrite: true));
        }
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>   Event notification for status of authentication. </summary>
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        public void m_api_TTAPIStatusUpdate(object sender, TTAPIStatusUpdateEventArgs e)
        {
            Console.WriteLine("TTAPIStatusUpdate: {0}", e);
            if (e.IsReady == false)
            {
                // TODO: Do any connection lost processing here
                return;
            }
            // TODO: Do any connection up processing here
            //       note: can happen multiple times with your application life cycle

            // can get status multiple times - do not create subscription if it exists
            //
            if (object.ReferenceEquals(m_instrLookupRequest, null) == false)
            {
                return;
            }

            // Status is up and we have not started a subscription yet

            // connection to TT is established
            Console.WriteLine("TTAPI Authenticated");

            MarketId    marketKey   = Market.GetMarketIdFromName(m_market);
            ProductType productType = Product.GetProductTypeFromName(m_prodType);

            // lookup an instrument
            m_instrLookupRequest = new InstrumentLookup(tt_net_sdk.Dispatcher.Current,
                                                        marketKey, productType, m_product, m_alias);

            m_instrLookupRequest.OnData += m_instrLookupRequest_OnData;
            m_instrLookupRequest.GetAsync();
        }
        public async Task <List <BankPortfolioData> > GetPositionData()
        {
            List <BankPortfolioData> output = new List <BankPortfolioData>();
            RobinhoodApi             api    = new RobinhoodApi()
            {
                BearerToken = ApplicationSettings.Default.RobinKey
            };
            OutRobinData <RhPosition> datas = await api.GetPositions();

            foreach (RhPosition data in datas.Data)
            {
                RhInstrument inst = await InstrumentLookup.GetRhInstrument(data.instrument);

                ShowMessage($"{inst.Symbol}- {inst.SimpleName}");
                decimal           shareCount = UtilityHandler.GetDecimalNumber(data.quantity);
                decimal           costBasis  = UtilityHandler.GetDecimalNumber(data.average_buy_price);
                BankPortfolioData d          = new BankPortfolioData()
                {
                    BankAccount_ID = UtilityHandler.GetString(data.account_number),
                    Trade_CODE     = UtilityHandler.GetString(inst.Symbol),
                    Trade_NAME     = UtilityHandler.GetString(inst.SimpleName),
                    Shares_CNT     = shareCount,
                    CostBasis_AMNT = costBasis,
                    Value_AMNT     = shareCount * costBasis,
                    Export_DATE    = DateTime.Today,
                    Instrument_ID  = inst.Id
                };
                output.Add(d);
            }
            return(output);
        }
Esempio n. 4
0
        public void TestSnare()
        {
            string saveFile = DataManagement.PathForDataFile("Test", "SnareTest.wav");

            Assert.IsTrue(WaveEncoding.SaveStream(
                              filepath: saveFile,
                              stream: InstrumentLookup.GetPercussion(PercussionMap.AcousticSnare, 0xF7)
                              .Normalize(80f)
                              .Window(1f)
                              .Center(1.5f),
                              overwrite: true));
        }
Esempio n. 5
0
        Instrument FindInstrument(string product, string alias)
        {
            InstrumentLookup instLookup = new InstrumentLookup(tt_net_sdk.Dispatcher.Current, m_marketId, ProductType.Future, product, alias);
            ProductDataEvent einst      = instLookup.Get();

            if (einst != ProductDataEvent.Found)
            {
                Console.WriteLine("ERROR: can't fetch leg instrument");
                return(null);
            }
            return(instLookup.Instrument);
        }
Esempio n. 6
0
        public void Dispose()
        {
            lock (m_Lock)
            {
                if (!m_isDisposed)
                {
                    // Unattached callbacks and dispose of all subscriptions
                    if (m_instrLookupRequest != null)
                    {
                        m_instrLookupRequest.OnData -= m_instrLookupRequest_OnData;
                        m_instrLookupRequest.Dispose();
                        m_instrLookupRequest = null;
                    }

                    if (m_algoLookupSubscription != null)
                    {
                        m_algoLookupSubscription.OnData -= AlgoLookupSubscription_OnData;
                        m_algoLookupSubscription.Dispose();
                        m_algoLookupSubscription = null;
                    }

                    if (m_priceSubscription != null)
                    {
                        m_priceSubscription.FieldsUpdated -= m_priceSubscription_FieldsUpdated;
                        m_priceSubscription.Dispose();
                        m_priceSubscription = null;
                    }

                    if (m_algoTradeSubscription != null)
                    {
                        m_algoTradeSubscription.OrderUpdated        -= m_algoTradeSubscription_OrderUpdated;
                        m_algoTradeSubscription.OrderAdded          -= m_algoTradeSubscription_OrderAdded;
                        m_algoTradeSubscription.OrderDeleted        -= m_algoTradeSubscription_OrderDeleted;
                        m_algoTradeSubscription.OrderFilled         -= m_algoTradeSubscription_OrderFilled;
                        m_algoTradeSubscription.OrderRejected       -= m_algoTradeSubscription_OrderRejected;
                        m_algoTradeSubscription.ExportValuesUpdated -= m_algoTradeSubscription_ExportValuesUpdated;
                        m_algoTradeSubscription.AlertsFired         -= m_algoTradeSubscription_AlertsUpdated;
                        m_algoTradeSubscription.Dispose();
                        m_algoTradeSubscription = null;
                    }

                    m_isDisposed = true;
                }

                TTAPI.Shutdown();
            }
        }
Esempio n. 7
0
        public void TestGuitar()
        {
            Calibration.Initialize();

            for (int octave = 2; octave <= 4; octave++)
            {
                string guitarFile = DataManagement.PathForDataFile("Test", $"guitarE{octave}.wav");

                Assert.IsTrue(WaveEncoding.SaveStream(
                                  filepath: guitarFile,
                                  stream: InstrumentLookup.GetNote(
                                      set: ReservedSoundSet.ElectricGuitar_Jazz,
                                      note: (byte)(12 * octave + 4),
                                      velocity: 0xF7)
                                  .SafeCache()
                                  .SlowRangeFitter(),
                                  overwrite: true));
            }
        }
Esempio n. 8
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>   Event notification for status of authentication. </summary>
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        public void m_api_TTAPIStatusUpdate(object sender, TTAPIStatusUpdateEventArgs e)
        {
            Console.WriteLine("TTAPIStatusUpdate: {0}", e);
            if (e.IsReady == false)
            {
                // TODO: Do any connection lost processing here
                return;
            }
            // TODO: Do any connection up processing here
            //       note: can happen multiple times with your application life cycle

            // can get status multiple times - do not create subscription if it exists
            //
            if (object.ReferenceEquals(m_instrLookupRequest, null) == false)
            {
                return;
            }

            MarketId    marketKey   = Market.GetMarketIdFromName(m_market);
            ProductType productType = Product.GetProductTypeFromName(m_prodType);

            // lookup an instrument
            m_instrLookupRequest = new InstrumentLookup(tt_net_sdk.Dispatcher.Current,
                                                        marketKey, productType, m_product, m_alias);

            m_instrLookupRequest.OnData += m_instrLookupRequest_OnData;
            m_instrLookupRequest.GetAsync();

            // Get the accounts
            m_accounts = m_api.Accounts;

            // Start Algo Trading thread.
            Thread algoThread = new Thread(() => this.StartAlgo());

            algoThread.Name = "Algo Trading Thread";
            algoThread.Start();
        }
        private async Task <List <BankTransactionData> > Convert2BankTransactionData(OutRobinData <RhTransaction> datas)
        {
            List <BankTransactionData> output = new List <BankTransactionData>();

            foreach (RhTransaction data in datas.Data)
            {
                string       accountID = UtilityHandler.GetIdFromUrl(data.account);
                RhInstrument inst      = await InstrumentLookup.GetRhInstrument(data.instrument);

                decimal valueAmt = UtilityHandler.GetDecimalNumber(data?.executed_notional?.amount);
                if (data.state == "cancelled")
                {
                    ShowMessage($"{inst.Symbol} [{data.side.ToUpper()}] - {inst.SimpleName}");
                    BankTransactionData d = new BankTransactionData()
                    {
                        BankAccount_ID   = accountID,
                        TransAction_DATE = UtilityHandler.GetDateValue(data.created_at),
                        TransAction_CODE = UtilityHandler.GetString(data.side).ToUpper(),
                        Settlement_DATE  = UtilityHandler.GetDateValue(data.updated_at),
                        Trade_CODE       = UtilityHandler.GetString(inst.Symbol),
                        Trade_NAME       = UtilityHandler.GetString(inst.SimpleName),
                        Instrument_ID    = UtilityHandler.GetString(inst.Id),
                        Trade_ID         = string.Empty,
                        Shares_CNT       = UtilityHandler.GetDecimalNumber(data.quantity),
                        CostBasis_AMNT   = UtilityHandler.GetDecimalNumber(data.price),
                        Value_AMNT       = valueAmt,
                        Type_CODE        = UtilityHandler.GetString(data.type),
                        GoodUntil_CODE   = UtilityHandler.GetString(data.time_in_force),
                        State_CODE       = UtilityHandler.GetString(data.state),
                        Export_DATE      = DateTime.Today
                    };
                    output.Add(d);
                    continue;
                }
                if (data.executions is null)
                {
                    continue;
                }
                foreach (Execution e in data.executions)
                {
                    ShowMessage($"{inst.Symbol} [{data.side.ToUpper()}] - {inst.SimpleName}");
                    BankTransactionData d = new BankTransactionData()
                    {
                        BankAccount_ID   = accountID,
                        TransAction_DATE = data.executions[0].timestamp,
                        TransAction_CODE = UtilityHandler.GetString(data.side).ToUpper(),
                        Settlement_DATE  = UtilityHandler.GetDateValue(data.executions[0].settlement_date),
                        Trade_CODE       = UtilityHandler.GetString(inst.Symbol),
                        Trade_NAME       = UtilityHandler.GetString(inst.SimpleName),
                        Instrument_ID    = UtilityHandler.GetString(inst.Id),
                        Trade_ID         = UtilityHandler.GetString(e.id),
                        Shares_CNT       = UtilityHandler.GetDecimalNumber(e.quantity),
                        CostBasis_AMNT   = UtilityHandler.GetDecimalNumber(e.price),
                        Value_AMNT       = valueAmt,
                        Type_CODE        = UtilityHandler.GetString(data.type),
                        GoodUntil_CODE   = UtilityHandler.GetString(data.time_in_force),
                        State_CODE       = UtilityHandler.GetString(data.state),
                        Export_DATE      = DateTime.Today
                    };
                    output.Add(d);
                }
            }
            int seqNumb = output.Count;

            foreach (BankTransactionData row in output)
            {
                row.Seq_NUMB = seqNumb; seqNumb--;
            }
            return(output);
        }