Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require "vcl"
- transId = 100
- secClass = "SPBFUT"
- secCode = "RIU5"
- account = "zzz"
- mainForm = VCL.Form("mainForm")
- mainForm.Caption = "My Trade"
- mainForm._= { position="podesktopcenter", height=150, width=300}
- mainMenu = VCL.MainMenu(mainForm,"mainMenu")
- mainMenu:LoadFromTable({
- {name="mmfile", caption="&File",
- submenu={
- {caption="Exit", onclick="onMenuExitClick", shortcut="Ctrl+F4"},
- }
- }
- })
- label = VCL.Label(mainForm,"Label")
- label.Top = 30
- label.Left = 50
- label.Caption = "MyTrade"
- label.Font.Size = 20
- buttonBuy = VCL.Button(mainForm,"buttonBuy")
- buttonBuy._ = { Top=70, Left=20, width=80, height=25, caption="B", onclick = "onButtonBuyClick" }
- buttonSell = VCL.Button(mainForm,"buttonSell")
- buttonSell._ = { Top=70, Left=120, width=80, height=25, caption="S", onclick = "onButtonSellClick" }
- buttonCancelOrders = VCL.Button(mainForm,"buttonCancelOrders")
- buttonCancelOrders._ = { Top=70, Left=210, width=80, height=25, caption="CancelOrders", onclick = "onButtonCancelOrdersClick" }
- function onMenuExitClick()
- OnStop()
- end
- mainForm:Show()
- is_run = true
- function main()
- while is_run do
- sleep(50)
- end
- end
- function OnStop()
- is_run = false
- mainForm:Free()
- end
- function GetTransId()
- if transId == 999 then
- transId = 100;
- end
- datetime = os.date("!*t",os.time())
- res = tostring(datetime.hour) .. tostring(datetime.min) .. tostring(datetime.sec) .. tostring(transId);
- transId = transId + 1;
- return res
- end
- function onButtonBuyClick(sender)
- qt = getQuoteLevel2(secClass, secCode)
- bid = qt.bid[qt.bid_count+0].price;
- transaction={
- ["CLASSCODE"]=secClass,
- ["ACTION"]="NEW_ORDER",
- ["ACCOUNT"]=account,
- ["OPERATION"] = "B",
- ["SECCODE"] = secCode,
- ["PRICE"] = tostring(bid+0),
- ["QUANTITY"] = tostring(1)
- }
- transaction.TRANS_ID = GetTransId();
- res = sendTransaction(transaction);
- end
- function onButtonSellClick(sender)
- qt = getQuoteLevel2(secClass, secCode)
- ask = qt.offer[1].price;
- transaction={
- ["CLASSCODE"]=secClass,
- ["ACTION"]="NEW_ORDER",
- ["ACCOUNT"]=account,
- ["OPERATION"] = "S",
- ["SECCODE"] = secCode,
- ["PRICE"] = tostring(ask+0),
- ["QUANTITY"] = tostring(1)
- }
- transaction.TRANS_ID = GetTransId();
- res = sendTransaction(transaction);
- end
- function onButtonCancelOrdersClick(sender)
- n = getNumberOf("orders")
- order={}
- for i=0,n-1 do
- order = getItem("orders", i)
- status = "not active"
- if bit.band(order.flags, 1) == 1 then
- status = "active"
- kill_order_trans = {
- ["CLASSCODE"]=secClass,
- ["SECCODE"] = secCode,
- ["ACTION"] = "KILL_ORDER"}
- kill_order_trans.TRANS_ID = GetTransId()
- kill_order_trans.order_key = tostring(order.order_num)
- sendTransaction(kill_order_trans)
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement