Advertisement
Guest User

Untitled

a guest
Dec 5th, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.89 KB | None | 0 0
  1. Function MarketMake(time, starttime, stoptime)
  2.  
  3. 'Our code still submits orders constantly, but realistically,
  4. 'we only want it to submit orders when we have no open orders in the book.
  5. 'Our pending orders are displayed with comma’s separating the fields,
  6. 'and semicolons separating each order: [Order1;Order2;Order3].
  7. 'We can use the semicolon to count the number of orders in the book:
  8. '1)if there’s nothing in this box, we know there’s no orders;
  9. '2)if there’s more than 1 semicolon in this box, we know there’s more than 2 orders.
  10. 'Once again we alter our trading code,
  11. 'so that orders are only submitted when no orders are in the book,
  12. 'and we also add code to cancel our existing orders whenever there’s only 1 order remaining.
  13. 'Our resulting program
  14. '1)submits two orders when we have no orders;
  15. '2)it cancels all orders if we only have 1 order;
  16. '3)it does nothing, otherwise.
  17. 'This means we always have 2 orders in the book (a bid and an ask).
  18.  
  19. 'Initialize the API
  20. Dim API As RIT2.API
  21. Set API = New RIT2.API
  22.  
  23. Dim Status As Boolean
  24.  
  25.  
  26.  
  27. 'Run the algorithm during certain case time
  28. If time < starttime And time > stoptime Then
  29. 'Check if any orders in the book. If you have no orders, put in a bracket.
  30.  
  31. If Range("J6") > 4999 Then
  32. Dim n As Integer
  33. n = Range("J6") \ 5000
  34. Dim index As Integer
  35. index = 1
  36. Do While index <= n
  37. Status = API.AddOrder(Range("STK_1"), Range("defaultsize"), Range("midmarket") - Range("defaultspread"), API.SELL, API.MKT)
  38. index = index + 1
  39. Loop
  40. End If
  41.  
  42. If Range("J6") < -4999 Then
  43. Dim n1 As Integer
  44. n1 = Range("J6") \ 5000
  45. Dim index1 As Integer
  46. index1 = 1
  47. Do While index1 <= n1
  48. Status = API.AddOrder(Range("STK_1"), Range("defaultsize"), Range("midmarket") - Range("defaultspread"), API.BUY, API.MKT)
  49. index1 = index1 + 1
  50. Loop
  51. End If
  52.  
  53. If Range("openorders") = "" Then
  54. 'The following loop submits the Buy section of bracket
  55. Status = False
  56. Do While Status = False
  57. Status = API.AddOrder(Range("STK_1"), Range("defaultsize"), Range("midmarket") - Range("defaultspread"), API.BUY, API.LMT)
  58. Status = API.AddOrder(Range("STK_1"), Range("defaultsize"), Range("midmarket") - Range("defaultspread"), API.BUY, API.LMT)
  59. Loop
  60. 'The following loop submits the Sell section of bracket
  61. Status = False
  62. Do While Status = False
  63. Status = API.AddOrder(Range("STK_1"), Range("defaultsize"), Range("midmarket") + Range("defaultspread"), API.SELL, API.LMT)
  64. Status = API.AddOrder(Range("STK_1"), Range("defaultsize"), Range("midmarket") + Range("defaultspread"), API.SELL, API.LMT)
  65. Loop
  66. '1 second pause
  67. Sleep (1500)
  68. Else
  69. 'Cancel all orders
  70. API.CancelOrderExpr ("price>0")
  71. API.CancelQueuedOrder ("price>0")
  72. API.ClearQueuedOrders
  73.  
  74. 'ElseIf Range("J6") > 4999 And Range("H24") < 5000 Then
  75. 'Status = API.AddOrder(Range("STK_1"), 5000, Range("H8") + Range("D15"), API.SELL, API.LMT)
  76. 'ElseIf Range("J6") < -4999 And Range("H24") < 5000 Then
  77. 'Status = API.AddOrder(Range("STK_1"), 5000, Range("H8") - Range("D15"), API.BUY, API.LMT)
  78. 'Sleep (50)
  79. 'Checks the openorders to see if there's more than one order in the book
  80. '(semicolon indicates multiple orders, no semicolon indicates only 1 order)
  81.  
  82. End If
  83.  
  84. End If
  85.  
  86. MarketMake = Range("PL")
  87.  
  88.  
  89. End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement