Log in

View Full Version : [SOLVED:] Creating a State Machine using VBA



CPerry
12-14-2017, 03:16 AM
2117121172

Hello VBAExpress community!

I was wondering whether anybody had done something like this before or had any idea how to create such a thing using VBA? I have attached a diagram of the system in question as a word file and the type of worksheet I will be using also.

Basically, I have a coupe of cells acting as 'triggers' for Cell L9 to display either: BACK, LAY or CLOSE_TRADE (this is a trading app in progress). The problem is that control logic changes during development; triggers are ticking at very quick frequencies (milliseconds). CLOSE_TRADE's should only follow BACK/LAY orders and vice versa.

Another problem I've been having is when I try to close a bet, I could get an error back due to that price (Cell G9) disappearing before I can trade it? Once an order has been placed, I am at the back of a queue to get matched so although my system is very fast, it has to play fair and wait an undeterminable amount of time. The market in question is BetFair exchange which I've been told has many characteristics similar to a type 2 trading market.

Again, if anybody has done something similar to this before or could point me in the right direction to get a state machine type code, it would help me loads!

Thank you,
CPerry :)

SamT
12-14-2017, 07:51 AM
For an example of the design and creation of a VBA Finite State Machine, see: http://www.vbaexpress.com/forum/showthread.php?60909-Bet-Angel-and-Excel

offthelip
12-17-2017, 09:13 AM
Here is a workbook that operates as your state machine. I have done this for you to show you how the state machine logic can all be done in a generic way. So the states and the rules to change between them can be programmed as "data" and not actuall program logic.
I have done this to demonstrate the technique and not to produce the sort of code you need for you application.

The worksheet should be obvious the triggers are in column B wit the description in column A, The states are in columnC and the rules governing the permissable changes of state are in columns E to G
Just type true in B3 to turn it on , then try triger a lay by putting true in B5, and carrry on.

CPerry
12-21-2017, 09:45 AM
This is fantastic! Thank you :D