1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
|
Option Explicit
Dim lastId As Long
Dim offset As Long
Public runWhen As Double
Public Const RUN_INTERVAL_SECONDS = 1
Public Const CapitalAmount = 10000
Public Const ProfitBarrier = 20
Public Const RUN_WHAT = "Example1.ArbSearch"
Public Const OppLim = 0.05
Sub ArbSearch()
Dim symbol As String
Dim SecType As String
Dim Exchange As String
Dim BidPrice As Double
Dim AskPrice As Double
Dim BidPrice2 As Double
Dim AskPrice2 As Double
Dim logSuccess As Boolean
Dim TickerRow As Integer
Dim NumShares As Double
For TickerRow = 8 To 87
symbol = UCase(Worksheets("Tickers").Cells(TickerRow, 1).value)
SecType = UCase(Worksheets("Tickers").Cells(TickerRow, 2).value)
Exchange = UCase(Worksheets("Tickers").Cells(TickerRow, 7).value)
BidPrice = CDbl(Worksheets("Tickers").Cells(TickerRow, 15).value)
AskPrice = CDbl(Worksheets("Tickers").Cells(TickerRow, 16).value)
BidPrice2 = CDbl(Worksheets("Tickers").Cells(TickerRow + 1, 15).value)
AskPrice2 = CDbl(Worksheets("Tickers").Cells(TickerRow + 1, 16).value)
NumShares = CapitalAmount / AskPrice2
If symbol = UCase(Worksheets("Tickers").Cells(TickerRow + 1, 1).value) And Exchange <> UCase(Worksheets("Tickers").Cells(TickerRow + 1, 7).value) Then
If (BidPrice2 - AskPrice) * NumShares > ProfitBarrier Or (BidPrice - AskPrice2) * NumShares > ProfitBarrier Then
MsgBox symbol
MsgBox BidPrice
MsgBox AskPrice
MsgBox BidPrice2
MsgBox AskPrice2
End If
End If
Next TickerRow
startTimer ' schedule next run
End Sub
Sub startTimer()
runWhen = Now + TimeSerial(0, 0, RUN_INTERVAL_SECONDS)
Worksheets("Auto Orders").Range("X3").value = Format(runWhen, "yyyy-mm-dd hh:mm")
Application.OnTime earliesttime:=runWhen, procedure:=RUN_WHAT, schedule:=True
End Sub
Sub stopTimer()
On Error Resume Next
Application.OnTime earliesttime:=runWhen, procedure:=RUN_WHAT, schedule:=False
Worksheets("Auto Orders").Range("X3").value = "Stopped"
End Sub |
Partager