-
-
Save sonumehrotra/402b206f1e2ec68d52a43bac6a135ec0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.template | |
import scala.util.Random | |
object Trading extends App { | |
val Sell = "sell" | |
val Buy = "buy" | |
trait Id { | |
def id: Int | |
} | |
trait Order { | |
def quantity: Int | |
} | |
case class BuyOrder(id: Int, quantity: Int) extends Order with Id | |
case class SellOrder(id: Int, quantity: Int) extends Order with Id | |
def mkOrder(side: String, qty: Int) = | |
if (side.equals(Sell)) SellOrder(mkId, qty) else BuyOrder(mkId, qty) | |
def mkId: Int = Random.nextInt() | |
println(mkOrder("buy", 100)) | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment