(ns propeller.push.instructions.signal
  "SIGNAL instructions. Instructions pertaining only to trading signals
   are located here."
  (:require [propeller.tools.math :as math]
           [propeller.push.instructions :refer [def-instruction
                                                generate-instructions
                                                make-instruction]]))

;; Changes the top signal from :buy to :sell if applicable
(def-instruction
  :signal_swap_buy_sell
  ^{:stacks #{:signal}}
  (fn [state]
    (make-instruction state #(if (= :buy %) :sell :buy) [:signal] :signal)))

;; Changes the top signal from :buy to :hold if applicable
(def-instruction
  :signal_swap_buy_hold
  ^{:stacks #{:signal}}
  (fn [state]
    (make-instruction state #(if (= :buy %) :hold :buy) [:signal] :signal)))

;; Changes the top signal from :sell to :buy if applicable
(def-instruction
  :signal_swap_sell_buy
  ^{:stacks #{:signal}}
  (fn [state]
    (make-instruction state #(if (= :sell %) :buy :sell) [:signal] :signal)))

;; Changes the top signal from :sell to :hold if applicable
(def-instruction
  :signal_swap_sell_hold
  ^{:stacks #{:signal}}
  (fn [state]
    (make-instruction state #(if (= :sell %) :hold :sell) [:signal] :signal)))

;; Changes the top signal from :hold to :buy if applicable
(def-instruction
  :signal_swap_hold_buy
  ^{:stacks #{:signal}}
  (fn [state]
    (make-instruction state #(if (= :hold %) :buy :hold) [:signal] :signal)))

;; Changes the top signal from :hold to :sell if applicable
(def-instruction
  :signal_swap_hold_sell
  ^{:stacks #{:signal}}
  (fn [state]
    (make-instruction state #(if (= :hold %) :sell :hold) [:signal] :signal)))