AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Stock Market Day Trading Program, price changes.

 
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
Frankie



Joined: 02 Nov 2008
Posts: 2850

PostPosted: Wed Jun 24, 2009 1:18 pm    Post subject: Stock Market Day Trading Program, price changes. Reply with quote

Heres the code (very unfinished):
Code:
Gui, Add, Edit, vCash ReadOnly
Gui, Add, ListView, r20 w300 vSelected, Stock|Shares|Price
Gui, Add, Text, ym, Ticker:
Gui, Add, Edit, vBuy
Gui, Add, Button, Default, Buy
Gui, Add, Edit, vStock ym
Gui, Add, Edit, vSell
Gui, Add, Button, Default, Sell

#s::
Inputbox, User, User, Enter your username:
If !User
  ExitApp
UpdateLV()
Gui, Show, Center, Paper Trade (User: %User%)
Return

^!q:: ExitApp


ButtonBuy:
Gui, Submit, NoHide
ControlGet, Selected, List, Count Focused, SysListView321, A
MsgBox % "Buying " . Buy . " shares of " . Stock%Selected% . " for $" . Buy * Price%Selected% . ".  You already have "
. Shares%Selected% . " shares.  Price%Selected% = " . Price%Selected%
If(Cash - (Buy * Price%Selected%) >= 0)
{
  Cash -= Buy * Price%Selected%
  Shares%Selected% := Shares%Selected% + Buy
  Msgbox % "Shares%Selected% = " . Shares%Selected% . "`nCash = " . Cash
  WriteFile()
  UpdateLV()
}
Else
  MsgBox, Not enough money to make that transaction.
Return
 
UpdateLV() {
  global
  GetShares()
  GetPrice()
  LV_Delete()
  GuiControl,, Cash, %Cash%
  Loop %Line%
     LV_Add("", Stock%A_Index%, Shares%A_Index%, Price%A_Index%)
}

GetShares() {
  global
  Loop, Read, %user% Stocks.csv
  {
    Line := A_Index - 1
    If A_Index = 1
      Cash := A_LoopReadLine
    Else
      Loop, Parse, A_LoopReadLine, CSV
        If A_Index = 1
          Stock%Line% := A_LoopField
        Else If A_Index = 2
          If A_LoopField
            Shares%Line% := A_LoopField
          Else
            Shares%Line% := 0
  }
  If StrLen(Stock1) >= 6
    StringTrimLeft, Stock1, Stock1, 3
}

GetPrice(Stock="") {
  global
  If !Stock
  {
    Loop
    {
      If !Stock%A_Index%
      {
        StringTrimRight, Stock_List, Stock_List, 1
        Break
      }
      Stock_List .= Stock%A_Index% . "+"
    }
    URLDownloadToFile, http://quote.yahoo.com/d/quotes.csv?s=%Stock_List%&f=l1,Stocks.txt
    Loop, Read, Stocks.txt
      Price%A_Index% := A_LoopReadLine
  }
  Else
  {
    URLDownloadToFile, http://quote.yahoo.com/d/quotes.csv?s=%Stock%&f=l1,Stocks.txt
    Loop, Read, Stocks.txt
      Price%A_Index% := A_LoopReadLine
  }
   
}

WriteFile() {
  global
  FileDelete, %User% Stocks.csv
  FileAppend, %Cash%`n, %User% Stocks.csv
  Loop %Line%
    FileAppend, % Stock%A_Index% . ", " . Shares%A_Index% + 0 . "`n", %User% Stocks.csv
}

Heres an example of the CSV file (Frankie Stocks.CSV):
Code:
9817.400000
RSH, 0
MSFT, 8295
GOOG, 0

The CSV file is in the format of the first line is the cash, then all other lines are Symbol, Shares.

When you run it press #s then type Frankie (assuming you named the file Frankie Stocks.CSV). Then buy some shares of any of the stocks and the last price will go to 0.00. I can't figure out why.

Thanks for any help.
_________________
aboutscriptappsscripts
Any code ⇈ above ⇈ requires AutoHotkey_L to run
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group