Saturday, April 16, 2016

Basics of Cmd/Batch file

@echo off color 0F  2E start http://www.cnn.com start 99.txt

set /p input=
if %input%==1 (  REM must be if (    ) else (
goto L1
) else  (
goto L99
)
:L1 LEnd set /p input=enter somthing || set input=nothing REM prompt
echo. > %filename%.%extension%  REM =touch in bash but 1 empty line with dot
ping www.cnn.com -n 5 >nul or 2>nul :: n=count nul not null 2=error

for %%i in (1 2 3) do (
REM % escape % to show 1% 2% 3% vs %%i loop var
echo %%i%%  
)

setlocal enabledelayedexpansion  REM ! =% but delayed
set v=test
REM =test when parse =90 when exec so show 90 test
set v=90 & echo !v! %v% ^^!  REM escape ! by ^^

for /r %%i in ( * ) do ( for /d REM rooted =file d=dir for /f %%i in ('dir /b') do (
:main setlocal   endlocal  dir /b /a:D /o-D REM bare folder /a:-D not folder sort D=datetime -D=desc

%CD% %~dp0 %~dp1 REM currDir param 0=1.cmd 1,2 dir only so c:\%~fs0 REM full path filename
echo %CD% pushD c:\1 echo %CD% PopD REM chg dir chg back %~n0 %~x0 REM filename ext
for /f %%i in ('dir /b') do (
echo %%~di  %%~pi %%i  REM show drive letter working dir and filename
)

for /f "Tokens=1,3" %%g in ('dir') do (echo %%h) REM %%g %%H %%i with tokens=
for /f "tokens=* delimis=," in (1.txt) .. REM similar to bash cut

:: function is label and pass in var and modify var byref %~1= param
:function1
echo f1 %~1 set %~1=9
call :function1 ro_val set v=-1 call :function1 v :: show 9

Array
set a[0]=A
set a[1]=B
set a[2]=C

set i=0
:loop
if %i% equ 3 goto :eof
:: usebackq=alternate quote, back quote ` =command processing
for /f "usebackq delims== tokens=2" %%j in (`set a[%i%]`) do (
 echo %%j 
)
set /a i=%i%+1


Sunday, April 10, 2016

MS Build project with Assembly version update

(1) evt.trading.build .\1\1.sln are the solution/build file structure
(2) msbuild .\Evt.Trading.Build /property:Configuration=Release /p:BUILD_NUMBER="1.0.17.239" 
(3) msbuild path C:\Program Files (x86)\MSBuild\14.0\Bin
(4) 1.sln can have C++/CLI project, may consider Nuget file repo for non-nugget lib.
(5) on Team City, BUILD_NUMBER need to be defined.
(6) TAP_WPF is the shell Title = Assembly.GetExecutingAssembly().GetName().Version.ToString();



<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"
         ToolsVersion="14.0" DefaultTargets="Compile">
  <ItemGroup>
    <BuildArtifacts  Include=".\__buildartifacts" />
    <SolutionFile Include=".\1\1.sln" />
  </ItemGroup>
  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)'=='' ">Debug</Configuration> <!-- msbuild /property:Configuration=Release-->
    <SolutionRoot>$(MSBuildProjectDirectory)</SolutionRoot>
  </PropertyGroup>
  
  <Target Name="Clean" >
    <RemoveDir Directories ="@(BuildArtifacts)" />
  </Target>
  
  <Target Name="Init" DependsOnTargets="Clean" >
   <MakeDir Directories="@(BuildArtifacts)" />
  </Target>
  
  <Target Name="Compile" DependsOnTargets="Init;UpdateAssemblyVersion;">
    <MSBuild  Projects="@(SolutionFile)" Targets="Rebuild"  Properties="OutDir=%(BuildArtifacts.FullPath);Configuration=$(Configuration)"/>
  </Target>


<UsingTask TaskName="RegexTransform" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll">
        <ParameterGroup>
            <Items ParameterType="Microsoft.Build.Framework.ITaskItem[]" />
        </ParameterGroup>
        <Task>
            <Using Namespace="System.IO" />
            <Using Namespace="System.Text.RegularExpressions" />
            <Using Namespace="Microsoft.Build.Framework" />
            <Code Type="Fragment" Language="cs">
                <![CDATA[
            foreach(ITaskItem item in Items) {
              string fileName = item.GetMetadata("FullPath");
              string find = item.GetMetadata("Find");
              string replaceWith = item.GetMetadata("ReplaceWith");
              
              if(!File.Exists(fileName)) {
                Log.LogError(null, null, null, null, 0, 0, 0, 0, String.Format("Could not find version file: {0}", fileName), new object[0]);
              }
              string content = File.ReadAllText(fileName);
              File.WriteAllText(
                fileName,
                Regex.Replace(
                  content,
                  find,
                  replaceWith
                )
              );
            }
          ]]>
            </Code>
        </Task>
    </UsingTask>

    <ItemGroup>
        <RegexTransform Include="$(SolutionRoot)\TAP_WPF\Properties\AssemblyInfo.cs">
            <Find>(?<major>\d+)\.(?<minor>\d+)\.\d+\.(?<revision>\d+)</Find>
            <ReplaceWith>$(BUILD_NUMBER)</ReplaceWith>
        </RegexTransform>
    </ItemGroup>
  
    <Target Name="UpdateAssemblyVersion" Condition="'$(BUILD_NUMBER)' != ''">   <!--  msbuild .\Evt.Trading.Build /property:Configuration=Release /p:BUILD_NUMBER="1.0.17.235"-->
        <RegexTransform Items="@(RegexTransform)" />
    </Target>


</Project>


Linux Admin braindump --Rasbian, Unbuntu


SD Formatter (SD card Association), RasberryPi.org download NOOBS 1G boot menu+Rasbian
[Putty SSH shutdown RasPi] halt -h //wait all LED off, cmd poweroff not work
passwd pi useradd  -p xxxxxx -G adm jimmy groups //list all groups cut -d: -f1 /etc/group
raspi-config //enable SSH change password reboot pm-hibernate 
ifconfig -a iwlist scan hostname -I iwlist wlan0  essid Cap15 //try to get wifi dhclient wlan0 ifconfig wlan0 up/down service ssh start
cd=cd / cal cal-3 cal 7 14 1995 date date --date "30 days ago" "30 days"  free -m top shit-f s %MEM [esc] // sort by mem
lsb-release -a uname -r //system, kernel info distrowatch.com
tty w=who chvt apt-get update/dist-upgrade ssn localhost exit lsscsi lsub lspci lshw //hardware info uptime uname -a which lsscsi //file path
/dev /sys /proc /proc/interrupts //pseudo file system IRQ 0=system timer 75=nic //use cat/ls on pfile watch -n1 head -n 10 interrupts // 1sec realtime interrupts upd hwclock --systohc // copy system time to hardware clock see rtc0 upd gnome-system-monitor //=taskmgr cat /sys/block/sda/size cd /dev/sda cd /proc/14 cat stack  /sys vs /dev meta data

sofware management
/var/lib/rpm /apt  rpm -qa apt list rpm -i/-e 
rpm -vhU https://nmap.org/dist/nmap-7.12-1.x86_64.rpm
rpm -qf $(which nmap)
apt-get install yum

RH/CentOS -- rpm -qpi //query pkg info -qpl //list /etc/repo.d loca.repo [local] baseurl=file:///repo mkdir /repo yum install createrepo createrepo /repo yum install nmap //w/o repo this will not work

debian/ubuntu --- dpkg -i -r -s -L -l dpkg-reconfig apt repository apt-get update ls /var/cache/apt apt-cache search postfix
cat /etc/apt/sources.list //rabian or ubuntu repo url  apt-cache pkgnames postfix //search a pkg to install

shared lib--user module
ldd /bin/ls DLL=.so .ko //shared kernel cat /etc/ld.so.conf //PATH less /etc/ld.so.conf.d/libc.conf ldd $(which useradd) ldconfig ldconfig -p mkdir /testlib cp librt.so.0 export LD_LIBRARY_PATH=/testlib/ ldd /bin/ls  // dependency shows testlib unset LD_...

shared lib--kernel module
lsmod | grep psmouse = grep psmouse /proc/modules // show size dependcy modinfo psmouse modprobe -r psmouse modprobe psmouse //remove add
ls /etc/modprobe.d less blacklist.conf //not loading outdated modules

file management
lsblk ls -l /dev/sda //show brw-rw.. b=block lsblk /dev/sda fdisk -l /dev/sda  gdisk parted /dev/sda print mkfs. XFS ext4 apt-cache pkgnames xfs mkdir -p /data/{d1,d2} // can mount to dir  blkid /dev/sdb1  mount mount -t ext4 -o acl,noexec /dev/sdb1 /mnt unmount /mnt /etc/fstab

Swap file
mkswap swapon --show = free -m /var/swap on RasPi /dev/sda6 gdisk

partprobe /dev/sda6 //avoid reboot to sync new parti cat/proc/partitions ls /dev/sda* mkswap /dev/sda3 swapon /dev/sda3 gdisk /dev/sda6 select p=print parti table n=new parti 3=sda3 8200=linux swap file others like Microsoft reserved
swapoff /dev/sda3 swap on -p 10 /dev/sda3 //priority 10 vi /etc/fstab sw, pri=10 //mount by editing
add a new line /dev/sda3 none swap, pri=10 0 0 //no mount point, 0 dump 0 check on restart
mount -a //read, refresh mount map swapon -a //read swap file swapon -s =show 
dd if=/dev/zero of=/root/swapfile1 count=1000 bs=1024 //init NULL dd=disk imaging copy mkswap /rro/swapfile1 // not mkfs
swap -p 10 /root/swapfile1 swapon -s grep swap /etc/fstab  //now swapfile1 is virtual mem swapfile
du df dd //file and disk usage imaging tune2fs e2fsck dumpfs debugfs //tunable ext2,3,4 check tune2fs -L 'label1' /dev/sda5
df -lhT //local human type du -hs /etc //human size dumpe2fs /dev/sda5 mount
dd if=/dev/sda of=/data/backup/file1 count=1 bs=512 //back up 1st boot rec fdisk -l //show boot rec
tar -cvf /data/backup/etc.tar /etc //backup etc create verbose file
debugfs /dev/sda5 ls ls -d <14>=deleted file stat <14> apt-get install extundelete extundelete --inode 89 /dev/sdb1 //inode=fs data structure extundelete --restore-file dir1/1.confi /dev/sdb1 ~RECOVERED_FILES mount -a cp //need manually copy files

permission
id sudo -i //switch to root user cannot change root passwd su - ask password  exit //logout super user
ugo=usr group other rwx symbolic/octal 7=111=rwx 6=110=rw 4=100=r chmod chown chgrp stat umask
stat f1.txt =ls -l //verbose show octal and sym mkdir -p /data/dir{1,2,3} umask //show defautl 2=0002 umask 0 //now 0000 =>true default for files touch f1.txt =>rw-rw-rw //666 not 664 by umask umask 007=>touch f3.txt show rw-rw-r-- x not set even allowed
umask 007 // 7=rwx, 6=rw 4=r 1=x not allow 0=any can be set
ls -ld . //drwx-rw- current dir perm chmod 777 chmod u=rwx g=rw o=r chmod +rw -rw
chgrp users /dir1 //perm now for users not root 
sticky bit on dir --- /dir1 -rwx /dir1/f1.txt -r-- // readonly still can delete if parent dir rw chmod o+t /dir1 can no longer delete f1.txt ls -ld /dir1 drwxrwxrwxT //t=sticky bit prevent readlonly file deletion for others
hard/soft link --- . is a link current dir ls -a //at least two links . ..   filename inode[meta data] are two links stat->stat file->stat f1.txt ls -ld doc find /usr/share/doc -maxdepth 1 -type d |wc -l // count subdir | head -n 3 
ln f1.txt hl1 //hard link ln -s f1.txt sl1 //soft link  stat f1.txt //show same inode for hard diff for soft ls -li f.txt //show inode
dd if=/dev/zero of=/data/big.txt count=1 bs=1024M //create 1G file for testing

Linux Boot up and Service Control
find . -name "menu.lst" /etc/init grep -i default_run * //case insensitive runlevel 0=halt 1=single user 2=multi no gui/no netw 3=no gui 5=full gui 6=reboot //no 4  init 0 init 2 ubuntu/debia 2=3=5 /etc/init upstart rc-sysinit.conf env DEFAULT_RUN_LEVEL=2
runlevel = who -r //show N 2 N5  telinit 6 telinit 3 halt =into BIOS
boot procedure: pwr self-test =>locate MBR (master boot rec) =>boot loader (kernel/Ram disk) =>kernel/Ram disk =>init Daemon (RunLevel 5 for desktop 3 for server)
grub grub2 menu.lst Grand Unified boot loader shutdown poweroff reboot shutdown -r now shutdown -h 18:27 "donw at 6pm" -h +5"in 5min" shhutdown -c //cancel or Ctrl+c

service status start stop restart netstat -anl ls /etc/init.d /etc/inittab chkconfig --list sshd update-rc.d -f sshd remove update-rc.d sshd defaults



Wednesday, April 6, 2016

Prism bits


CompositeCommand
namespace   Infrastructure {
public static class GlobalCommands
{
         static GlobalCommands()
         {
             SaveAll = new CompositeCommand(); // better than field init ??
         }


  public CompositeCommand SaveAllCommand {get; set;}
}

}

//Register child command
Infrastructure.GlobalCommands.SaveAll.RegisterCommand(Save_Local_Command)

// not binding but static ref
<Button Content="Save All" Command="{x:static inf:GlobalCommands.SaveAllCommands}"


Event aggregator---CompositePresentationEvent Publish/Subscribe

View Injection --- using Region Manager or MEF ServiceLocator.GetInstance+Region Manager

Shared Service
using module to host a singleton servivice so that module does not hard-reference another module

infrastructure:IPersonRepository
ServiceModule::PersonRepository : IPersonRepository
Init() { _container.Ressolve<IPersonRepository>(new ContainerControlledLifetimeManager()); //singleton

usage _repository.Save();  //DI IRepository to _repository

RegionContext
DataContext Master/Detail vs Region Master/Detail (Parent/Child)
<ListBox Name="lb" /> <ContentControl prism:RegionManager.RegionContext={Binding SelectedItem ElementName=lb />
DetailView::ctor() { RegionContext.GetObservableContext(this).PropertyChanged +=(s,e)=> { var ctx=(ObservableObject<object>) s; (ViewModel as IPersonDetailViewModel).SelectedPerson=ctx.value as Person;} // note Model Person now in  View, should be inside VM select a person by ID

State based Navigation
Not really move but to update layout, same data/task but different look and feel

Busy Indicator in Async loading 
<toolkit:BusyIndicator IsBuzy={Binding IsBusy}><LisBox/>

Replace Layout by DataTrigger <DataTrigger Binding={Binding IsChecked, ElementName=ToggleBtn1} Value=T>
<Setter Property =ItemTemplate  ItemPanel />

User Interaction through Command -- popup vs in-place editing
DelegateCommand EditCommand
prop SelectedPerson {set {EditCommand.RaiseCanExecuteChanged(); }
<toolkit:ChildWindow WindowState={Binding WindowState}><Grid  DataContext=SelectedPerson >
prop WindowState WindowState

View Based Nav
infrastructure::AppCmds {static CompositeCommand Nav;}
<Button Command={x:static inf:AppCmds.Nav} CommandParam={x:type views:ViewA} . // use type as URI no databinding here.
DelegateCommand<object> Nav_local= new ((obj)=>{RegionManager.RegisterNavigation(ContentRegion,obj);}
Nav.RegisterCommand(Nav_local) // local command has URL set and connect to button by global cmd
Module A/B regtype must use full name of view tyoe as URI
Container.RegisterType(typeof(ViewA)); // very specific syntax here

Monday, April 4, 2016

Git Braindump

View 
tree .git cat .git/HEAD cat .git/refs/heads/master git reflog git checkout -b topic git reset --head git reset --head [SHA] //point to ci git checkout master grh [SHA] gl master topic gbrt //all branch in time order  git log ..[branchname] //msg, not including head git status --short git add --update // staging grep -r'<<<<' // conflicts gl HEAD@{1} alias gm="git merge --no--ff" gmf="merge --ff--only" //no fast forward
Merge == new commit, no chg hist, Rebase = recommit a set of ci on top of new point, new hist
git rebase --abort gp origin local:remote git push :[branchname] //delete remote branch git log --patch filename git log -S'key word' // search entire commit  git log --patch -S"" //patch format git log --all --simplify-by-decoration //only tagged, branched git l --simplify-by-decoration git clean -n // untracked ignored -n= safe dry run rvm use default@global gem install git-smart git smart-pull 

Between Remote and Local
msysgit windows install, tortoisegit --mimic svn gitextensioin instead.(window explorer integration)
git init //create repo c:\prog x86\Git\etc\gitconfig  c:\Users\w3333\.gitconfig git config
git remote rm origin git remote -v git remote add origin git@github.com:jqd/myproj.git
git clone http://.../proj.git git log --oneline --graph |wc -l git shortlog -sne git show HEAD~10 git remote -v //verbose show fetch/push url  protocols http/git/ssh/file cat .git/config

git branch [-r] //remote gita tag git remote -v git remote add origin http://../jqd/proj1.git=>git fetch //pull down git fetch origin //where  git log origin/master //chg in remote but not in head git log //not integrated into local yet git merge origin/master //now local will have  remote chg and git log will show ff
git pull=git fetch;git merge origin/mster
git branch --set-upstream orgin/master // remote tracking branch git pull git clone set upstream automatically
git status git commit -am 'msg' git push  //ask uid/pwd for http
git remote add origin git@github.com.jqd.proj1.git //use SSH version url no more uid/pwd ssh key git tag v1.0 git tag git tag -a "msg" v1.0 git push --tags //tag must be pushed

Working locally
git init git status git add f2.txt
git commit // brings up vim/notepad, git commit -a "msg" //avoid editor  git add -u // stage not add file not the same as git add -A //truly add, no more untracked
git add f1.txt //stage not add,  rm f2.txt=> git add -u =>git commit //del=>stage=>ci del
git diff dd6819..a15ec6 //only need 6 in SHA git diff HEAD~1..HEAD = git diff HEAD~1 //back 1

git checkout f1.txt //override changes git reset --hard HEAD //back to HEAD throw away local git reset --hard HEAD~1 //set head back git reset --soft HEAD~1 //move changes back to working/loc copy, head no changes
git clean -n //dry run clean up working dir git clean -f //force

vim .gitignore /logs /logs/*.txt git add .gitignore git commit -a "add ig" .gitignore.

Branch/Merge/Rebase
git log --oneline --graph --all --decorate //show head,tag,branch,master git config
git config --global alias.gla "log --graph --oneline --all --decorate" git lga //git log all cat ~/.gitconfig
git branch feature1 git checkout feature1 = git checkout -b feature1 //branch and switch locally.

git lga=> make changes=>gig commit -am "msg" =>git lga=>4577ae [HEAD,feature1 //head feature both point to changes

git checkout master=>2332dc6 [HEAD naster] //head point away

git branch fix1 974b5a=>git checkout fix1=>changes=>git commit -am""=>git lga [HEAD fix1] // shows a new [5a78cb7 HEAD] above everyone including master
git branch -m fix bug123 // move=rename git branch -d bug123 //cannot del since change not merged to master
git branch -D bug123 // force del=D
git reflot =>git branch bug123 5a78cb => git checkout bug123 //un-delete if<30days

git checkout f3 =>make changes=>git stash=>git stash list=>(switch away fix bug123)=> git check f3=>git stash apply // come back to f3 work
git reset --hard HEAD => git stash apply //still restore from stash git stash pop =apply but loss on hard-reset git stash drop git stash branch f3_addl
git checkout masgter=>git merge f1  //ff master to f1 [f1,master,HEAD] git branch -d f1 [master,HEAD]
git mergetool //beyoundcompare kdiff3 git diff --cached //repo vs. staging git commit -m "merg into master"
git branch f3 v1.0 // branch from [tag,master]=>[HEAD,f3] git show f3
git checkout f3=> changes=> git commit -am => git rebase master=>git lga //f3 not longer from [tag,master] rather it is on top of master 
git checkout master => git merge f3 //ff merf just move [master HEAD,f3]
git rebase master=>conflict tools=>rm *.orig =>git diff --cahsed=>git rebase --continue Rebase = replay commit on top of mast but rebase is dangerous 

Cherry Picking
git checkout master //have two commits but only want 1 in master, cannot rebase or merge 
git cherry-pick 6fa4327 => git lga 19ae38f7 [HEAD,master] "fix from 6fa4327"



git fetch origin master  git push = git push origin master // ff [master origin/master HEAD]
git push origin v1.0_fix  //new remote branch created git branch -r  // show orign/master origin/v1.0__fix 
git push origina v1.0_fix:v10_remote_name // give it a name
(strange way to delete remote branch by local name=null) git push origin :v10_remote_anme
git rebase -i HEAD~3 //modify last 3 commit message may need git rebase --continue/abort. git log --graph --oneline to check git reset --hard 7e458f9 // delete commit from local
git log --cc --since="6am" --author="joe" | git diff-tree -v

start git repo
(1) There are no git command to create Repo.
(2) General structure  Project/Repos  e.g. eTrading/ET-Options, ET-RFQ, ET-Equity
    for personal git, there are no project ( or default just one for your own repo)
      https://stash-prod1.us.myFirm.net:8443/projects/eTrading
      https://stash-prod1.us.myFirm.net:8443/users/w123
(3) git clone empty repo would get local repo established but no origin
   git clone https://stash-prod1.us.myFirm.net:8443/projects/eTrading/ET-Options.git
   git clone https://W123@stash-prod1.us.myFirm.net:8443/scm/~w123/e-trading.git
(4) init-commit local-add origin-push master--connecting to git
    (There are no develop yet)
cd existing-project
git init
git add --all
git commit -m "Initial Commit"
git remote add origin https://W123@stash-prod1.us.myFirm.net:8443/scm/~w123/e-trading.git
git push origin master

(5) switch code tracking on git
cd existing-project
git remote set-url origin https://W123@stash-prod1.us.myFirm.net:8443/scm/~w123/e-trading.git
git push origin master

submodule --- point to a specific commit of other repo, not tracking
git clone url_superProj => subm_dir empty git submodule update --init // bring down a subm commit
cat .gitmodules shows url dir of subm inside superproject
git submodule add url path_subm git status git log git push origin master:master brnch:brnch // all for separate commit of subm. must fork if no perm for subm.
git add subm_name // upd to new commit in the subm, not automatically bring down
cd subm_dir git push origin master:master // must push separately and 1st
git reset HEAD subm_name // remove changes or branching git push origin b1:b1 // new remote branching.
git submodule update 

A successful git branching model in Git command

http://nvie.com/posts/a-successful-git-branching-model/

(1) Develop a feature
// only branch from develop for features

git checkout -b myfeature develop

// merge back to develop no fast forward
// no ff=> merge has ci obj clear hist

git checkout develop
git merge --no-ff myfeature

// clean up

git branch -d myfeature
git push origin develop

(2) Release --always from develop, stay for a while
git checkout -b release-1.2 develop
./bump-version.sh 1.2
git commit -a -m "Bumped version number to 1.2"

(3) Release -- close up by merge

git checkout master
git merge --no-ff release-1.2
git tag -a 1.2

git checkout develop
git merge --no-ff release-1.2

git branch -d release-1.2

(4) Hotfix --always from master

git checkout -b hotfix-1.2.1 master
./bump-version.sh 1.2.1
git commit -a -m "Bumped version number to 1.2.1"
git commit -m "Fixed severe production problem"

git checkout master
git merge --no-ff hotfix-1.2.1
git tag -a 1.2.1

git checkout develop
git merge --no-ff hotfix-1.2.1

git branch -d hotfix-1.2.1

HTML5/Web Socket Realtime trading App feasible ?


1. WebSocket is bi-directional, full-duplex, single tcp conn, lean
2. Keypad support --- how web gui knows keypad, vendor javascript?
3. javascript development framework? DI, MVVM, Formatter (Augular2)
4. Browser vs store app on Win8/10  --- if wait a few years, no need for OpenFin
5. Testing and Perf/diag tools.  (Karma, Protractor)
6. Java WS-Server =Model/Service WS-Duplex =DataProvider Augular=VM/Xaml/DataBinding
7. Performance:  WS-Dup > Rx ? Angular >Xaml ? javascript databinding > C# databinding ?


Possible issues
(1) Floating window out of range in multi-monitor
(2) how do you resize windows from OpenFin? infinitely small ?
(3) How could two network traffics not reduce performance? (WS and Streambase)
    in WPF WS is replaced by Rx in memory.
(4) WebSocket Play!Framework vs. raw Tcp comparison 10x slower
     http://eng.kifi.com/websockets-vs-regular-sockets/

intranet: use Tcp Socket
internet WebSocket init using Http then negotiate WS protocol to be Tcp like



Sunday, April 3, 2016

Strategy, Swap and Algo


delta cross
(1) a future hedge, both maturity and currency of
   mismatch underlying
(2) P+C, negative move of C=>positive move of P

Collars -- put-call after stock gain-hedge wrapper
booster -- 1x2 call ratio spread c-2c
straddle --p+c
strangle --p+c different strike, wider.
butterfly- c-2c+c= short one call spread +long a call spread
Risk Reversal -- c-p

dividend swap -- fixed vs total div paid by underlying
             x Notional shares, single stock or basket
variance swap-- one lege pay var of Px move, one pay fix strike.
     (var strike, realized var, vega notional)
     Exchange Rate, interest rate, stock index vol.

Correlation swap--

which swap are delta 1-- divd, all swap are delta 1???

algo:
reserve -- block options, post small slice,rest in reserve
       replenish on exec, stop loss cxl, auto-hedge each slice
price movement -- walk from mid to stop, sweep/re-sweep by short-lived
       limit order. stop walk if underlying cross threshold, auto-hedge
       on execution.
vol post---reserve+limit price=continous re-calc(spot,vol limit)
         each exec => stock order, keep delta exposure thresthold
vol stealth --limit=continous re-calc(spot,vol limit), 
     monitor NBBO Sweep by IOC,exec=>stock order for delta
NBBO =national best bid/offer.

Practical SVN


svn checkout https://ch9:8443/svn/demo/trunk . (trunk per app)
branches, tag are not for main dev
tortoise svn command line --C:\Program Files\TortoiseSVN\bin
svn add 1.txt svn commit 1.txt -m "RTEC-1234: Comment"
svn ci -m "ci current dir implicitly"

Three types of SCM
Locking ---
Merging  --SVN
Distributed ---Git

SVN-- update as often as you can to minimize merge issue
ignore-- parent folder tsvn->property-> svn:ignore bin \n *.exe
commit changes to properties such as ignore
branch for feature/release/cutomized version

switch branch/trunk vs separate local dir for branch/trunk
checkout branch to its own loc dir vs. same loc dir as trunk with switch.
either way not affecting server.  switch+ci -- careful where committed. n
Suggested Server structure:  
branches 
tags swi
trunk

Merge--- switch loc dir to trunk --> merge branch to local working copy
-->Edit Conflict -->commit --> mark some file as "Resolvled"

Merge require switch to destination first
most common merge--re-integrate branch=> branch to trunk.

tagging-- switch to tags server directory during branching.
not really read-only but make sure do not commit
https://ch9:8443/svn/demo/tags/release-1.0.17.241

Show log-- 
search commit messages RTEC-9730 -- include Jira # better search
"stop on copy and rename"--- merged branch will only show changes on
the branch after created from trunk, much shorter
"include merged revision" --- on trunk see all branch chg from merges

Commit Monitor---
http://stefanstools.sourceforge.net/CommitMonitor.html

Branching Strategy --
per feature -- too many, merge issues.overhead
per release --- off to work on a release,better as post release 
per developer/team --CI not well supported.
Branch as needed --- best strategy
 (1) everyone work on trunk, see merge issue sooner
 (2) when release needed,branch and never merge back 
 (3) branch bug fix/hot fix stay in branch and merge back if fit
     ( trunk could have a re-write without hot fix)
 (4) CI easier and effective on trunk
 (5) never need to deal with merging unless Hot Fix.
 (6) Exception: experiemental feature branch may merge back

Merge in/Merg out ---Merge trunk to branch->resolve conflict--> test
  --> merge branch to trunk(trivial no conflicts)

"Merge a range of Revision":
(1) Cherry Picking--switch to trunk local ->merge branch to trunk->Show Log
  --> pick time or pick individual chg in the log->merge->edit conflicts
  --> commit
(2) Rollback merge --switch to trunk -->Merge trunk to trunk -->
    -->show log find the entry of the merge -->pick "reverse merge"
    --> commit => merge rollback


Saturday, April 2, 2016

Fix Log Tag Printer in Python


#!/usr/bin/env python3
""" show fix log tag per line,e.g flt.py log.txt 52 49 55  """

import os
import sys
""" mod """
def get_tag_values(line,tags):
    tag_values=[]   
    for t in tags:
        if t+"=" in line:
            tag_values.append(line.split(t+"=")[1].split("=")[0])
    return tag_values

def show_tags_per_line(file,tags):
    os.chdir(".")
    with open(file) as lines:
        for line in lines:
            v=get_tag_values(line,tags)
            if len(v) >0:
                print(v)
                
def ask_help(argv):
    if len(argv)<2:
        pass
    v=argv[1]
    if v=="/h" or v=="/help" or v=="-h" or v=="-help":
        print(__doc__)
        sys.exit(0)
    
if __name__=='__main__':
    ask_help(sys.argv)
        
    tags=sys.argv[2:]
    file=sys.argv[1]
    show_tags_per_line(file,tags);

Fix Protocol Braindump


Spec PDF
http://cdn.batstrading.com/resources/membership/BATS_US_EQUITIES_FIX_SPECIFICATION.pdf

http://www.fixtradingcommunity.org/FIXimate/FIXimate3.0/
http://fixparser.com/
ef311b37

Commonly used Tags
58 -- Free form text, error message
44- limit price
8 --begin
35 msgtype (0=heartbeat 1=test 5/A=logout/logon 2=resent/request D=new order single
   9=ordcxlrequest 8=execrpt(F,PF,ZF) 4=seg# resend 3=reject)

Example of Tag 35
35-3+ tag45 =>reject with tag 45 Seq #
35-2+tag7(20) and Tag16(30) =>Resend with begin 20, end 30
35-2, only see 12,14 missing 13
35-4 => user did not logout, next day see high Seq#

49/5-- sender/tgt compId=Routing Tag
34 --Seq #, connection troubleshooting
50/59 --Sender/Tgt subid, which trader on both side
43/97--PossDup/Resend--possible resend, new seq #
52/122-- sending/original timestamp
372/373 ---refmsgtype/reason for 35/3 reject
123 --GapFillFlag ----Do not resend expired order 35/4 Y=> req-sequencing

Order Entry Message
1-Acct 11-CientOrderID 60--Transaction Timestamp (Latency Complaints
55--Symbol 65--sufix FB.TO .PK (Toronto, pinksheet) .SS China 54-side
38-Tot Qty 111-Max Floor, Display Qty, on exch floor
40--ordertype 2=limit p=Pegged 59 --Time In Force 0-day 6=GTC good tc 
IOC=Imm or cxl, FOK fill or kill
126--Expire time
32=100 38=100 => 39=4  LastShr/OrdQty=> filled=2
110=110 38=210 32=10 minQty=> wrong data
38=100 110=200 wrong setup 
18 --execinst --- R=primary Peg P=mkt peg M=Mid Pt Peg
Peg=Limit order matching bets=Mkt ord
110--MinQty 31/32=Last Px/Share
39-- Order Status(New=0,PF,ZF 2=Filled, Done for day, Expired)

filter using bash
$ cat log.txt | grep '52=' |grep -v 'Note' | awk '{gsub(/52=/,"____SendTime____");print}' | awk '{gsub(/54=2/,"____SELL____");print}'
must have tag 52 but does not have 'Note' replace 52 as SendTS 54=2 as SELL order
cat *.log | grep | awk combined log