DRRK/docs/vba/Module1.bas

102 lines
3.3 KiB
QBasic

Attribute VB_Name = "Module1"
Sub upd_quotes()
Dim tmpSheet As Worksheet
Dim infoSheet As Worksheet
Dim k_date_from As Date, k_date_to As Date
Dim k_isin As String, j_mkt As String
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Set cwb = ActiveWorkbook
Set tmpSheet = cwb.Worksheets("moex_tmp")
Set secinfoSheet = cwb.Worksheets("SECURITIES INFO")
Set summarySheet = cwb.Worksheets("SUMMARY")
rep_date = summarySheet.Range("REP_DT")
rep_dt = Format(rep_date, "YYYY-MM-DD")
last_row = secinfoSheet.Cells(secinfoSheet.Rows.Count, 1).End(xlUp).Row
'clearing tmp sheet
tmpSheet.Cells.ClearContents
'clearing connections
For Each xConnect In cwb.Connections
xConnect.Delete
Next xConnect
'clearing XML maps
For Each xMap In cwb.XmlMaps
xMap.Delete
Next xMap
'clear data sheet
secinfoSheet.Range("D3:F" & last_row).ClearContents
secinfoSheet.Range("H3:H" & last_row).ClearContents
For k = 3 To last_row
k_isin = secinfoSheet.Cells(k, 1)
plc_date = secinfoSheet.Cells(k, 12)
If k_isin <> "" And rep_date > plc_date Then
pct_completion = Round((k - 2) / (last_row - 2) * 100, 0)
Application.StatusBar = "Importing Data from MOEX server... " & pct_completion & "% Completed"
link = "https://iss.moex.com/iss/history/engines/stock/markets/bonds/securities/" & k_isin & "/?from=" & rep_dt & "&limit=1"
cwb.XmlImport URL:=link, ImportMap:=Nothing, Overwrite:=True, Destination:=tmpSheet.Range("$A$1")
'obtaining
wa_price = Application.WorksheetFunction.Index(tmpSheet.ListObjects(1).ListColumns("WAPRICE").Range, 2)
mk3_price = Application.WorksheetFunction.Index(tmpSheet.ListObjects(1).ListColumns("MARKETPRICE3").Range, 2)
acc_int = Application.WorksheetFunction.Index(tmpSheet.ListObjects(1).ListColumns("ACCINT").Range, 2)
yield = Application.WorksheetFunction.Index(tmpSheet.ListObjects(1).ListColumns("YIELDATWAP").Range, 2)
yield_close = Application.WorksheetFunction.Index(tmpSheet.ListObjects(1).ListColumns("YIELDCLOSE").Range, 2)
dur = Application.WorksheetFunction.Index(tmpSheet.ListObjects(1).ListColumns("DURATION").Range, 2)
'clearing tmp sheet
tmpSheet.Cells.ClearContents
'clearing connections
For Each xConnect In cwb.Connections
xConnect.Delete
Next xConnect
'clearing XML maps
For Each xMap In cwb.XmlMaps
xMap.Delete
Next xMap
'writing output values
secinfoSheet.Cells(k, 4) = dur / 365
If yield = "" Then secinfoSheet.Cells(k, 5) = yield_close Else secinfoSheet.Cells(k, 5) = yield
If wa_price = "" Then secinfoSheet.Cells(k, 6) = mk3_price Else secinfoSheet.Cells(k, 6) = wa_price
secinfoSheet.Cells(k, 8) = acc_int
dur = 0
yield = 0
wa_price = 0
acc_int = 0
Else
' writing if isin is blank or issue is not placed
secinfoSheet.Cells(k, 4) = (secinfoSheet.Cells(k, 12) - CDate(Now())) / 365
secinfoSheet.Cells(k, 5) = secinfoSheet.Cells(k, 15)
secinfoSheet.Cells(k, 6) = 100
secinfoSheet.Cells(k, 8) = 0
End If
Next
Call Refresh_list
Call UpdFxRates
Application.ScreenUpdating = True
Application.StatusBar = False
Application.Calculation = xlCalculationAutomatic
End Sub
Sub Macro2()
Attribute Macro2.VB_ProcData.VB_Invoke_Func = " \n14"
End Sub