Thursday, October 18, 2018

AZure data sync using power shell

https://docs.microsoft.com/en-us/azure/sql-database/scripts/sql-database-sync-data-between-sql-databases

https://blogs.msdn.microsoft.com/datamigration/2018/02/08/automating-the-end-to-end-migration-of-sql-server-to-azure-sql-database-using-the-azure-database-migration-powershell-module/


alter table with primary key


drop index CIX_DT on dbo.[AAPL];

ALTER TABLE dbo.[AAPL] ADD CONSTRAINT [PK_dt] PRIMARY KEY CLUSTERED
(
    dt DESC
)

create table with primary key

The issue with this you have to make sure PK_KEY that KEY has to be unique

USE [market_data]
GO

/****** Object:  Table [dbo].[FLKS]    Script Date: 10/18/2018 6:57:24 PM ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[FLKS](
 [Volume] [numeric](9, 0) NULL,
 [Open] [decimal](18, 4) NULL,
 [High] [decimal](18, 4) NULL,
 [Low] [decimal](18, 4) NULL,
 [Close] [decimal](18, 4) NULL,
 [WAP] [decimal](18, 4) NULL,
 [Count] [numeric](9, 0) NULL,
 [dt] [datetime] NOT NULL,
 [EMA9] [decimal](18, 4) NULL,
 [EMA10] [decimal](18, 4) NULL,
 [EMA20] [decimal](18, 4) NULL,
 [EMA21] [decimal](18, 4) NULL,
 [EMA50] [decimal](18, 4) NULL,
 [EMA100] [decimal](18, 4) NULL,
 [EMA200] [decimal](18, 4) NULL
) ON [PRIMARY]
GO

ALTER TABLE dbo.[FLKS] ADD CONSTRAINT [PK_FLKS] PRIMARY KEY CLUSTERED
(
    dt DESC
)

Tuesday, October 16, 2018

replicate local SQL to Azure SQL

You can to change log on the install SQLDataSyncAgent-2.0-x86-ENU.msi
And I know how to do it in local GPO
When installing a service to run under a domain user account, the account must have the right to logon as a service on the local machine. This logon right strictly applies only to the local computer and must be granted in the Local Security Policy.
Perform the following to edit the Local Security Policy of the computer you want to define the ‘logon as a service’ permission:
1.Logon to the computer with administrative privileges.
2.Open the ‘Administrative Tools’ and open the ‘Local Security Policy’
3.Expand ‘Local Policy’ and click on ‘User Rights Assignment’
4.In the right pane, right-click ‘Log on as a service’ and select properties.
5.Click on the ‘Add User or Group…’ button to add the new user.
6.In the ‘Select Users or Groups’ dialogue, find the user you wish to enter and click ‘OK’
7.Click ‘OK’ in the ‘Log on as a service Properties’ to save changes.
Notes:
•Ensure that the user which you have added above is not listed in the ‘Deny log on as a service’ policy in the Local Security Policy.

https://docs.microsoft.com/en-us/azure/sql-database/sql-database-get-started-sql-data-sync

C# multiple thread updating winform listbox items parallel processing

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace IndicatorUpdator
{
    public partial class Form1 : Form
    {
        SqlConnection cnn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["connection"].ConnectionString);

        public Form1()
        {
            InitializeComponent();
            GetSymbols();
        }

        public void GetSymbols()
        {
            if (cnn.State == ConnectionState.Closed)
            {
                listBox1.Items.Insert(0, " try to open, connection stat:" + cnn.State.ToString());
                cnn.Open();
            }
            else
            {
                listBox1.Items.Insert(0, " already open, connection stat:" + cnn.State.ToString());

            }
            if (cnn.State == ConnectionState.Broken)
            {
                listBox1.Items.Insert(0, "***** broken connection stat:" + cnn.State.ToString());

            }

            listBox1.Items.Insert(0, " connection stat:" + cnn.State.ToString());
            String q1 = "select table_name from information_schema.tables";
            SqlCommand c1 = new SqlCommand(q1, cnn);

            using (var reader = c1.ExecuteReader())
            {
                while (reader.Read())
                {
                    //exist insert record
                    lbSymbol.Items.Insert(0,reader.GetString(0));
                }
            }


        }

        private void btnStart_Click(object sender, EventArgs e)
        {
            System.Threading.Tasks.Parallel.For(0, lbSymbol.Items.Count, i =>
            {
                //Thread.Sleep(1000);
                //int j = i;
                //listBox1.Invoke(() => listBox1.Items.Insert(0, j));

              // below can access winform listbox control from different thread
                this.Invoke((MethodInvoker)delegate
               {
                   this.listBox1.Items.Insert(0, i);
               });
                //So stuff with i

                //Console.WriteLine("i: " + i);
            });
        }
    }
}

C# Parallel Programming

https://www.codeproject.com/Articles/71285/Introducing-NET-4-0-Parallel-Programming

C# more than one backgroundworker

https://stackoverflow.com/questions/10694271/c-sharp-multiple-backgroundworkers

private BackgroundWorker assignmentWorker;

    private void InitializeBackgoundWorkers() {
        assignmentWorker = new BackgroundWorker();
        assignmentWorker.DoWork += AssignmentWorkerOnDoWork;
        // ...
    }

    private void AssignmentWorkerOnDoWork( object sender, DoWorkEventArgs doWorkEventArgs ) {
        for( var f = 0; f < FilesToProcess; f++ ) {
            var fileProcessed = false;
            while( !fileProcessed ) {
                for( var threadNum = 0; threadNum < MaxThreads; threadNum++ ) {
                    if( !threadArray[threadNum].IsBusy ) {
                        Console.WriteLine( "Starting Thread: {0}", threadNum );

                        threadArray[threadNum].RunWorkerAsync( f );
                        fileProcessed = true;
                        break;
                    }
                }
                if( !fileProcessed ) {
                    Thread.Sleep( 50 );
                    break;
                }
            }
        }
    }

    private void button1_Click( object sender, EventArgs e ) {
        assignmentWorker.RunWorkerAsync();
    }

c# backgroundworker-

http://csharp-video-tutorials.blogspot.com/2014/03/backgroundworker-class-example-in.html

Monday, October 15, 2018

EMA calculation

https://stockcharts.com/school/doku.php?id=chart_school:technical_indicators:moving_averages

http://investexcel.net/how-to-calculate-ema-in-excel/

SQL create index

CREATE CLUSTERED INDEX [IX_DT]
ON [Historical] ( [dt] DESC )

Saturday, October 13, 2018

C# sql connection string

            string connetionString = null;
            SqlConnection cnn;
            cnn = new SqlConnection(ConfigurationManager.ConnectionStrings["connection"].ConnectionString);
            try
            {
                cnn.Open();
                MessageBox.Show("Connection Open ! ");
                cnn.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Can not open connection ! ");
            }



<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <configSections>
    </configSections>
    <connectionStrings>
        <add name="connection" connectionString="Data Source='OFFICE\SQLEXPRESS';Initial Catalog=market_data;Persist Security Info=True;User ID=sa;Password=xxxxx" providerName="System.Data.SqlClient" />
    </connectionStrings>
    <startup>
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
    </startup>
</configuration>

market data sql

https://www.mssqltips.com/sqlservertip/4467/using-sql-server-data-analysis-for-stock-trading-strategies/

Saturday, October 6, 2018

C# candlestick

https://stackoverflow.com/questions/1110105/financial-charts-in-net-best-library-to-display-a-live-streaming-1-min-stock-c

Thursday, October 4, 2018

C# app talk to app

https://blogs.windows.com/buildingapps/2015/09/22/using-cross-app-communication-to-make-apps-work-together-10-by-10/