Advertisement
Guest User

Untitled

a guest
Sep 1st, 2015
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.84 KB | None | 0 0
  1. require "vcl"
  2.  
  3. transId = 100
  4. secClass = "SPBFUT"
  5. secCode = "RIU5"
  6. account = "zzz"
  7.  
  8. mainForm = VCL.Form("mainForm")
  9. mainForm.Caption = "My Trade"
  10. mainForm._= { position="podesktopcenter", height=150, width=300}
  11. mainMenu = VCL.MainMenu(mainForm,"mainMenu")
  12. mainMenu:LoadFromTable({
  13.     {name="mmfile", caption="&File",
  14.         submenu={
  15.             {caption="Exit", onclick="onMenuExitClick", shortcut="Ctrl+F4"},
  16.         }
  17.     }
  18. })
  19.  
  20. label = VCL.Label(mainForm,"Label")
  21. label.Top = 30
  22. label.Left = 50
  23. label.Caption = "MyTrade"
  24. label.Font.Size = 20
  25.  
  26. buttonBuy = VCL.Button(mainForm,"buttonBuy")
  27. buttonBuy._ = { Top=70, Left=20, width=80, height=25, caption="B", onclick = "onButtonBuyClick" }
  28.  
  29. buttonSell = VCL.Button(mainForm,"buttonSell")
  30. buttonSell._ = { Top=70, Left=120, width=80, height=25, caption="S", onclick = "onButtonSellClick" }
  31.  
  32. buttonCancelOrders = VCL.Button(mainForm,"buttonCancelOrders")
  33. buttonCancelOrders._ = { Top=70, Left=210, width=80, height=25, caption="CancelOrders", onclick = "onButtonCancelOrdersClick" }
  34.  
  35. function onMenuExitClick()
  36.     OnStop()
  37. end
  38.  
  39. mainForm:Show()
  40.  
  41. is_run = true    
  42.  
  43. function main()
  44.     while is_run do
  45.         sleep(50)
  46.     end
  47. end
  48.  
  49. function OnStop()
  50.     is_run = false
  51.     mainForm:Free()
  52. end
  53.  
  54. function GetTransId()
  55.     if transId == 999 then
  56.         transId = 100;
  57.     end
  58.     datetime = os.date("!*t",os.time())
  59.     res = tostring(datetime.hour) .. tostring(datetime.min) .. tostring(datetime.sec) .. tostring(transId);
  60.     transId = transId + 1;
  61.     return res
  62. end
  63.  
  64. function onButtonBuyClick(sender)
  65.     qt = getQuoteLevel2(secClass, secCode)
  66.     bid = qt.bid[qt.bid_count+0].price;
  67.     transaction={
  68.                     ["CLASSCODE"]=secClass,
  69.                     ["ACTION"]="NEW_ORDER",
  70.                     ["ACCOUNT"]=account,
  71.                     ["OPERATION"] = "B",
  72.                     ["SECCODE"] = secCode,
  73.                     ["PRICE"] = tostring(bid+0),
  74.                     ["QUANTITY"] = tostring(1)
  75.                 }
  76.     transaction.TRANS_ID = GetTransId();
  77.     res = sendTransaction(transaction);
  78. end
  79.  
  80. function onButtonSellClick(sender)
  81.     qt = getQuoteLevel2(secClass, secCode)
  82.     ask = qt.offer[1].price;
  83.     transaction={
  84.                     ["CLASSCODE"]=secClass,
  85.                     ["ACTION"]="NEW_ORDER",
  86.                     ["ACCOUNT"]=account,
  87.                     ["OPERATION"] = "S",
  88.                     ["SECCODE"] = secCode,
  89.                     ["PRICE"] = tostring(ask+0),
  90.                     ["QUANTITY"] = tostring(1)
  91.                 }
  92.     transaction.TRANS_ID = GetTransId();
  93.     res = sendTransaction(transaction);
  94. end
  95.  
  96. function onButtonCancelOrdersClick(sender)
  97.     n = getNumberOf("orders")
  98.     order={}   
  99.     for i=0,n-1 do
  100.         order = getItem("orders", i)
  101.         status = "not active"
  102.         if bit.band(order.flags, 1) == 1 then
  103.             status = "active"
  104.             kill_order_trans = {
  105.                         ["CLASSCODE"]=secClass,
  106.                         ["SECCODE"] = secCode,
  107.                         ["ACTION"] = "KILL_ORDER"}
  108.             kill_order_trans.TRANS_ID = GetTransId()
  109.             kill_order_trans.order_key = tostring(order.order_num)
  110.             sendTransaction(kill_order_trans)
  111.         end
  112.     end
  113. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement