Server now returns the results of the Monte Carlo Price
This commit is contained in:
39
serve.go
39
serve.go
@@ -6,28 +6,37 @@ import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// index is a function that handles all requests to the main page
|
||||
// Note that there are two separate returns
|
||||
func index(w http.ResponseWriter, r *http.Request) {
|
||||
formatRequest(r)
|
||||
fmt.Fprintf(w, "Hello go!\n")
|
||||
}
|
||||
if r.Method == "POST" {
|
||||
|
||||
func formatRequest(r *http.Request) {
|
||||
mcOpt := &Option{}
|
||||
bsOpt := &Option{}
|
||||
|
||||
var opt Option
|
||||
err := json.NewDecoder(r.Body).Decode(&opt)
|
||||
if err != nil {
|
||||
fmt.Printf("Error: %s\n", err)
|
||||
err := json.NewDecoder(r.Body).Decode(&mcOpt)
|
||||
if err != nil {
|
||||
fmt.Printf("Error: %s\n", err)
|
||||
}
|
||||
|
||||
mcOpt.PriceMonteCarlo()
|
||||
|
||||
options := make(map[string]Option)
|
||||
options["MonteCarlo"] = *mcOpt
|
||||
options["BlackScholes"] = *bsOpt
|
||||
|
||||
json.NewEncoder(w).Encode(options)
|
||||
if err != nil {
|
||||
fmt.Printf("Error: %v\n", err)
|
||||
}
|
||||
|
||||
} else if r.Method == "GET" {
|
||||
fmt.Fprintf(w, "Hello go!") // To be updated
|
||||
}
|
||||
|
||||
fmt.Println("Option type:", opt.OptType)
|
||||
fmt.Println("Strike:", opt.Strike)
|
||||
fmt.Println("Expiry date:", opt.ExpiryDate.Format("2006-01-02"))
|
||||
|
||||
for k, v := range r.Header {
|
||||
fmt.Printf("%v: %v\n", k, v)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func main() {
|
||||
http.HandleFunc("/", index)
|
||||
http.ListenAndServe(":8080", nil)
|
||||
|
||||
Reference in New Issue
Block a user