Skip to content

Adding New Instruments

annenkov edited this page May 25, 2016 · 4 revisions

Welcome to the prototype wiki!

It is a lot of fun and a great experience to add up a new instrument. Below is a quick guide on how to get it done :)

  1. The instrument folder is found under src/Web/Instrument/ from the Prototype folder.

You can see a couple of examples in this file on how instruments are set up. Ranging from a very simple VanillaOption.hs to a more complicated contract such as DoubleOptionBond.hs

First stage create your own file in the folder and change it appropriately to your new instrument. Change the following line with your own instrument in mind module Instrument.MyNewInstrument (MyNewInstrument, myNewInstrument, makeContract) where

Keep the same code until the line {-@CODE@-}

Thereafter make the following changes

data myNewInstrument = MyNewInst {
{-# As an example we left the data field from the Vanilla Option
 instrument but here you should put the fields that are relevant 
 as an input from the user  #-}
      underlying :: Underlying
    , strike     :: Double
    , endDate    :: Day
    , putOption  :: Bool
} deriving (Show, Generic, Typeable)
myNewInstrument = 
    GUIRepr { guiLabel   = "My New Instrument Name on the Web page"
            , formFields = gtoForm (Proxy :: Proxy (Rep MyNewInstrument))
            , url        = "urlOnTheWebpageOneWord" }

makeContract startDate optData = 
    
{-# Here you should put out the code for your new instrument #-}

So now you have already made most of the work! We are just left with letting the web interface be aware of the fact that you have added a new Instrument so it would be available.

To do so move one folder up to the Web subfolder and look into the file Main.hs

In this file there are 3 lines you need to change First import your New Instrument

import qualified Instrument.MyNewInstrument as MNI

Second create an instance

instance FromJSON MNI.MyNewInstrument
api (url MNI.MyNewInstrument) (jsonContract :: ActionM MNI.MyNewInstrument) MNI.makeContract

Third add it to the list of available contracts

allContracts = [VO.vanillaOption, RO.rainbowOption, BO.basket2Option, MNI.myNewInstrument]

Now you are ready to go just go to the prototype folder press

make run_web

Your new code is available and the web server should run and you can see your results locally at

http://localhost:3000/

username is hiperfit password is 123

Have fun :)

Clone this wiki locally