forked from wzrdsappr/trading-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfsm-agent.lisp
44 lines (35 loc) · 1.51 KB
/
fsm-agent.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
;;;; event.lisp
(in-package #:trading-core)
(defclass fsm-agent (fsm agent)
((states :accessor states :initform nil)
(initialized :initform nil))) ; determines if the agent is ready to begin trading
;;; FSM-Agent methods
(defmethod set-fsm ((a fsm-agent))
(with-slots (states current-state) a
(setf current-state (first states))))
(defmethod update ((a fsm-agent) (e comm))
(set-fsm a)
(logv:format-log "Set FSM completed for ~S~%" a)
(logv:format-log "MAIN method completed for ~S and COMM event ~S~%" a e))
(defmethod operate-fsm ((a fsm-agent) (e event))
(let* ((applicable-transitions
(cdr (assoc (current-state a) (transitions a))))
(effected-transition
(car (remove-if-not (lambda (x) (perform x e))
applicable-transitions))))
(funcall (actuator effected-transition)
(funcall (sensor effected-transition) e))
(setf (current-state a) (final-state effected-transition))
(logv:format-log "~S Transition ~A -> ~A~%"
(name a)
(initial-state effected-transition)
(final-state effected-transition))))
(defmethod update ((a fsm-agent) (e market-update))
(set-fsm a)
(logv:format-log "Set FSM completed for ~S~%" (name a))
(operate-fsm a e)
(logv:format-log "Operate FSM completed for ~S~%" (name a))
(push (current-state a) (states a))
(logv:format-log ":MAIN completed for ~S and new state ~S added ~%"
(name a) (current-state a)))
;;EOF