lawlu
發表於 18-4-15 20:23
感謝Alex大的提點
報價已經可以顯示在datagridview上了,但是目前遇到無法下單成功的狀況,我是參考群益的excel 範例及C#的範例-StockOrderControl.cs的寫法而去修改的,程式碼如下,可否請Alex大大在幫忙看一下哪裡有錯,再次感謝!!
Private Sub skO_OnAccount(bstrLogInID As String, bstrAccountData As String) Handles skO.OnAccount
Dim strValues As String()
Dim strAccount As String
strValues = bstrAccountData.Split(","c)
strAccount = bstrLogInID & " " & strValues(1) & strValues(3)
If strValues(0) = "TS" Then
boxStockAccount.Items.Add(strAccount)
End If
End Sub
Private Function SendStockOrder(ByVal bAsyncOrder As Boolean)
Dim strInfo As String = boxStockAccount.Text
Dim strValues As String()
strValues = strInfo.Split(" "c)
UserAccount = strValues(1)
lbxR.Items.Add(strValues(1))
Dim strStockNo As String
Dim nPrime As Integer
Dim nBidAsk As Integer
Dim nPeriod As Integer
Dim nFlag As Integer
Dim strPrice As String
Dim nQty As Integer
strStockNo = txtStockNo.Text.Trim()
nBidAsk = boxBidAsk.SelectedIndex
nFlag = boxFlag.SelectedIndex
strPrice = txtPrice.Text.Trim()
nQty = txtQty.Text
nPrime = 0
nPeriod = 0
Dim pOrder As SKCOMLib.STOCKORDER = New SKCOMLib.STOCKORDER()
pOrder.bstrFullAccount = UserAccount
pOrder.bstrStockNo = strStockNo
pOrder.sBuySell = CShort(nBidAsk)
pOrder.sFlag = CShort(nFlag)
pOrder.sPrime = nPrime
pOrder.sPeriod = nPeriod
pOrder.bstrPrice = strPrice
pOrder.nQty = nQty
End Function
Private Sub btnSendStockOrderAsync_Click(sender As Object, e As EventArgs) Handles btnSendStockOrderAsync.Click
SendStockOrder(True)
End Sub
alexliou
發表於 18-4-15 21:27
lawlu 發表於 18-4-15 20:23
感謝Alex大的提點
報價已經可以顯示在datagridview上了,但是目前遇到無法下單成功的狀況,我是參考群益的 ...
Function SendStockOrder 中
只看到把Order的基本資料準備好
並沒有看到真正send 出的動作
lawlu
發表於 18-4-15 22:30
謝謝Alex大的回覆,在Function SendStockOrder 結束,END FUNCTION後面有皆一副程式btnSendStockOrderAsync_Click下單的動作如下圖顯示
alexliou
發表於 18-4-15 23:05
lawlu 發表於 18-4-15 22:30
謝謝Alex大的回覆,在Function SendStockOrder 結束,END FUNCTION後面有皆一副程式btnSendStockOrderAsync ...
按下button 後執行 SendStockOrder
但SendStockOrder中 無實際執行API下單的指令
lawlu
發表於 18-4-18 14:42
謝謝Alex大的回覆與指導
這次遇到的問題是在我的datagridview屬性已經設定資料靠右對齊,但是當執行
DataGridView_CellPainting事件時,整個資料又全部靠左對齊了,想請教Alex大大,這樣該如何修改才好呢?
謝謝您!
alexliou
發表於 18-4-18 18:20
lawlu 發表於 18-4-18 14:42
謝謝Alex大的回覆與指導
這次遇到的問題是在我的datagridview屬性已經設定資料靠右對齊,但是當執行
我猜測是因為cellpainting event 中
e.Graphics.DrawString
描繪文字時, 是用 graphics 的設定,
而不理會 datagridview 中cell 的文字對齊設定
建議擬改用 cellFormatting event 來顯示 datagridview 中儲存格的文字
如果非要用cellpainting 的話
可能要用到有 StringFormat 參數 的 DrawString overload
並設定 StringFormat 的 Alignment property
https://msdn.microsoft.com/en-us/library/system.drawing.stringformat(v=vs.110).aspx
但這方法我也沒試過
lawlu
發表於 18-4-22 13:49
本帖最後由 lawlu 於 18-4-22 13:53 編輯
謝謝Alex大大不吝說明
現在有另一個問題想請教Alex大大如下說明:
我想將開盤後的第一分K棒的高低點(右表listbox上的資料,是取自onNotifyKLineData),更新到資料表上,但是底下的程式碼好像無法做到
Private Sub skQ_OnNotifyQuote(sMarketNo As Short, sStockIdx As Short) Handles skQ.OnNotifyQuote
skQ.SKQuoteLib_GetStockByIndex(sMarketNo, sStockIdx, pSKStock)
OnUpDateDataRow(pSKStock)
End Sub
Private Sub skQ_OnNotifyKLineData(bstrStockNo As String, bstrData As String) Handles skQ.OnNotifyKLineData
Dim strStockNo As String = bstrStockNo
Dim dtFind As DataRow = m_dtStocks.Rows.Find(strStockNo)
Dim strValues As String()
Dim strKLine_H As String
Dim strKLine_L As String
strValues = bstrData.Split(","c)
strKLine_H = strValues(2)
strKLine_L = strValues(3)
If strValues(0) = "2018/04/20" & " " & "09:01" Then
listKLine.Items.Add(strStockNo)
listKLine.Items.Add(strKLine_H)
listKLine.Items.Add(strKLine_L)
If dtFind Is Nothing Then
Try
Dim myDataRow As DataRow = m_dtStocks.NewRow()
myDataRow("m_caStockNo") = pSKStock.bstrStockNo
myDataRow("m_nHigh_1K") = 0
myDataRow("m_nLow_1K") = 0
m_dtStocks.Rows.Add(myDataRow)
Catch ex As Exception
Dim msg As String = ex.Message
End Try
Else
dtFind("m_caStockNo") = pSKStock.bstrStockNo
dtFind("m_nHigh_1K") = 46
dtFind("m_nLow_1K") = 45.2
End If
End If
End Sub
alexliou
發表於 18-4-22 17:59
本帖最後由 alexliou 於 18-4-22 18:03 編輯
lawlu 發表於 18-4-22 13:49
謝謝Alex大大不吝說明
現在有另一個問題想請教Alex大大如下說明:
邏輯看起來OK
但VB語法我不熟
如不能work,我直覺判斷是Update Datagridview row 的那段程式碼有問題
在C#, cell index 是用[] 框起來
網上查詢到的 VB update row 語法為 :
myDataRow.Cells("m_caStockNo").Value =
不曉得 .Value 是否可省略?
另外, 我猜 assign 常數只是為了debug 方便
不然, 設個Break Point,Debug Step by Step 應該可以找出問題出在哪
clif
發表於 18-4-23 13:23
OnNotifyKLineData取得的是歷史資料,盤中不會有資料的,要盤後才更新.....盤中要資料,要從tick裡面自己去取得並計算...
lawlu
發表於 18-5-2 10:44
感謝Alex大大及Clif大的解惑
關於這個第一根1分K棒價格的取得,小弟想破頭後採用了底下的程式碼,但今天開盤後測試發現,價格並非是第一根K棒產生後的固定值,而是隨著最高,及最低價的變動而跳動的,想請問怎麼修改才能正確取得,謝謝大家
alexliou
發表於 18-5-4 11:45
lawlu 發表於 18-5-2 10:44
感謝Alex大大及Clif大的解惑
關於這個第一根1分K棒價格的取得,小弟想破頭後採用了底下的程式碼, ...
應該不需要用到Timer
既然你的PortfolioQuoteTable中的資料會在skQ_OnNotifyQuote 內的 OnUpDateDataRow更新
你可以在 OnUpDateDataRow 內
0. 判斷傳入的資料是哪一支股票的
1. check 時間是否在 9:01 這根Bar 的範圍內
2. 如果成交價格比 nHigh_1K 高, 則更新nHigh_1K價格
3. 如果成交價格比 nLow_1K低, 則取代 nLow_1K價格
要注意如何設定nHigh_1K, 與nLow_1K的初始值
這個方法的問題是, 如果你在9:00 後才啟動程式(或中途斷線), OnNotifyQuote 就收不到9:01的Quote 資料
lawlu
發表於 18-5-4 20:30
感謝Alex大的回覆與建議
看起來要取得第一分K棒高低點的程式可能有點複雜及困難度,小弟要再多努力加強寫程式碼的能力了
再次感謝Alex大不吝指導
lawlu
發表於 18-5-8 22:35
Alex大大您好:
關於取得第一分K棒高低點的程式,小弟暫以底下的程式碼來跑,同樣也是有一個缺點就是,如果早上09:01分之後才啟動程式,則無法取得第一分K棒的高低點
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
lblTime.Text = Now
Dim dnow As String = DateTime.Now.ToString("HH:mm:ss")
Dim Stocks As String() = txtStocks.Text.Trim().Split(New Char() {","c})
Select Case dnow
Case "09:01:00"
For Each s As String In Stocks
Dim StockNo As String = s.Trim()
Dim rowFind As DataRow = portfolioQuoteTable.Rows.Find(StockNo)
rowFind("nHigh_1K") = rowFind("nHigh")
rowFind("nLow_1K") = rowFind("nLow")
Next
Case "09:05:00"
For Each s As String In Stocks
Dim StockNo As String = s.Trim()
Dim rowFind As DataRow = portfolioQuoteTable.Rows.Find(StockNo)
rowFind("nHigh_5K") = rowFind("nHigh")
rowFind("nLow_5K") = rowFind("nLow")
Next
End Select
End Sub
lawlu
發表於 18-5-8 23:08
Alex大大
另外這幾天早上測試時,發現一個問題,就是您程式的單量顏色,有時候會有幾筆單量與嘉實資訊的單量顏色不同,我猜可能是因為您程式的判斷依據是根據報價中的買價,賣價,成交價與即時Tick事件的其他三個資料產生一些差異的關係而造成的;因此我就想說是否可能在報價表中,改用即時Tick事件的成交明細(也就是說show出買進,賣出,成交,單量,由內盤成交判斷單量為綠色,或外盤成交單量判斷為紅色,中間的顯示白色),但是寫出程式後,卻發現每一檔個股的即時Tick資料雖會更新,但有更新的資料又會將還沒更新的其他個股Tick資料覆蓋過去,可否幫忙看一下問題出在哪裡嗎?
謝謝您,感恩!
Dim sPage As Short
Dim intPage As Integer = -1
If Short.TryParse(txtPageNo.Text, sPage) = False Then Return
Dim Stocks As String() = txtStocks.Text.Trim().Split(New Char() {","c})
For Each s As String In Stocks
Dim nCode As Integer = skQ.SKQuoteLib_GetStockByNo(s.Trim(), pSKStock)
Dim mCode As Integer = skQ.SKQuoteLib_RequestTicks(intPage, s.Trim())
If nCode = 0 AndAlso mCode = 0 Then
OnUpDateDataRow(pSKStock, pSKTick)
End If
intPage = intPage + 1
Next
skQ.SKQuoteLib_RequestStocks(sPage, txtStocks.Text.Trim())
skQ.SKQuoteLib_RequestTicks(intPage, txtStocks.Text.Trim())
txtPageNo.Text = sPage.ToString()
End Sub
Private Sub skQ_OnNotifyQuote(sMarketNo As Short, sStockIdx As Short) Handles skQ.OnNotifyQuote
skQ.SKQuoteLib_GetStockByIndex(sMarketNo, sStockIdx, pSKStock)
OnUpDateDataRow(pSKStock, pSKTick)
End Sub
Private Sub skQ_OnNotifyTicks(sMarketNo As Short, sIndex As Short, nPtr As Integer, nTimehms As Integer, nTimemillismicros As Integer, nBid As Integer, nAsk As Integer, nClose As Integer, nQty As Integer, nSimulate As Integer) Handles skQ.OnNotifyTicks
skQ.SKQuoteLib_GetTick(sMarketNo, sIndex, nPtr, pSKTick)
End Sub
Private Sub OnUpDateDataRow(ByVal pStock As SKCOMLib.SKSTOCK, ByVal pTick As SKCOMLib.SKTICK)
Dim strStockNo As String = pStock.bstrStockNo
Dim drFind As DataRow = portfolioQuoteTable.Rows.Find(strStockNo)
If drFind Is Nothing Then
Try
Dim myDataRow As DataRow = portfolioQuoteTable.NewRow()
myDataRow("sStockidx") = pStock.sStockIdx
myDataRow("sDecimal") = pStock.sDecimal
myDataRow("sTypeNo") = pStock.sTypeNo
myDataRow("cMarketNo") = pStock.bstrMarketNo
myDataRow("caStockNo") = pStock.bstrStockNo
myDataRow("caName") = pStock.bstrStockName
myDataRow("nTickQty") = pStock.nTickQty
myDataRow("nCloseOpen") = (pStock.nClose - pSKStock.nOpen) / (Math.Pow(10, pStock.sDecimal))
myDataRow("nUpDown") = (pStock.nClose - pStock.nRef) / (Math.Pow(10, pStock.sDecimal))
myDataRow("nBid") = pStock.nBid / (Math.Pow(10, pStock.sDecimal))
myDataRow("nAsk") = pStock.nAsk / (Math.Pow(10, pStock.sDecimal))
myDataRow("nClose") = pStock.nClose / (Math.Pow(10, pStock.sDecimal))
myDataRow("nOpen") = pStock.nOpen / (Math.Pow(10, pStock.sDecimal))
myDataRow("nHigh") = pStock.nHigh / (Math.Pow(10, pStock.sDecimal))
myDataRow("nLow") = pStock.nLow / (Math.Pow(10, pStock.sDecimal))
myDataRow("nRef") = pStock.nRef / (Math.Pow(10, pStock.sDecimal))
myDataRow("nHigh_1K") = 0
myDataRow("nLow_1K") = 0
myDataRow("Long1") = 0
myDataRow("Short1") = 0
myDataRow("LongShort1") = 0
myDataRow("nHigh_5K") = 0
myDataRow("nLow_5K") = 0
myDataRow("Long5") = 0
myDataRow("Short5") = 0
myDataRow("LongShort5") = 0
myDataRow("nLastClose") = myDataRow("nClose")
myDataRow("nLastBid") = myDataRow("nBid")
myDataRow("nLastAsk") = myDataRow("nAsk")
myDataRow("nPtr") = pTick.nPtr
myDataRow("nTimehms") = pTick.nTimehms
m_nSimulateStock = pStock.nSimulate
portfolioQuoteTable.Rows.Add(myDataRow)
Catch ex As Exception
Dim msg As String = ex.Message
End Try
Else
drFind("nLastClose") = drFind("nClose")
drFind("nLastBid") = drFind("nBid")
drFind("nLastAsk") = drFind("nAsk")
'drFind("sStockidx") = pStock.sStockIdx
'drFind("sDecimal") = pStock.sDecimal
'drFind("sTypeNo") = pStock.sTypeNo
'drFind("cMarketNo") = pStock.bstrMarketNo
'drFind("caStockNo") = pStock.bstrStockNo
'drFind("caName") = pStock.bstrStockName
drFind("nTickQty") = pStock.nTickQty
drFind("nCloseOpen") = (pStock.nClose - pSKStock.nOpen) / (Math.Pow(10, pStock.sDecimal))
drFind("nUpDown") = (pStock.nClose - pStock.nRef) / (Math.Pow(10, pStock.sDecimal))
drFind("nBid") = pStock.nBid / (Math.Pow(10, pStock.sDecimal))
drFind("nAsk") = pStock.nAsk / (Math.Pow(10, pStock.sDecimal))
drFind("nClose") = pStock.nClose / (Math.Pow(10, pStock.sDecimal))
drFind("nOpen") = pStock.nOpen / (Math.Pow(10, pStock.sDecimal))
drFind("nHigh") = pStock.nHigh / (Math.Pow(10, pStock.sDecimal))
drFind("nLow") = pStock.nLow / (Math.Pow(10, pStock.sDecimal))
drFind("nRef") = pStock.nRef / (Math.Pow(10, pStock.sDecimal))
drFind("nPtr") = pTick.nPtr
drFind("nTimehms") = pTick.nTimehms
m_nSimulateStock = pStock.nSimulate
End If
End Sub
lawlu
發表於 18-5-8 23:15
Alex大大您好
出現不同的nPtr位址的資料如下兩圖
頁:
1
2
3
4
5
6
7
8
[9]
10
11
12