Last active
October 18, 2016 23:29
-
-
Save frgomes/b792acaa5f0595de057d to your computer and use it in GitHub Desktop.
Scala - Extractor using match and regex
This file contains hidden or 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
| object RichText { | |
| val GTDmatch = """GTD[(][0-9A-Za-z\-]+[)]""".r | |
| val NORMAL = """NORMAL[(][0-9]+[)]""".r | |
| val SYNTHETIC_STOP_LIMIT = """SYNTHETIC_STOP_LIMIT[(][0-9]+,[0-9]+[)]""".r | |
| val SYNTHETIC_STOP = """SYNTHETIC_STOP[(][0-9]+[)]""".r | |
| val SYNTHETIC_MARKET_IF_TOUCHED = """SYNTHETIC_MARKET_IF_TOUCHED[(][0-9]+[)]""".r | |
| val NATIVE_STOP_WITH_PROTECTION = """NATIVE_STOP_WITH_PROTECTION[(][0-9]+[)]""".r | |
| val NATIVE_STOP_LIMIT = """NATIVE_STOP_LIMIT[(][0-9]+,[0-9]+[)]""".r | |
| } | |
| implicit class RichText(text: String) { | |
| implicit def toOrderType: Option[ticket.OrderType] = { | |
| import ticket.Market | |
| import ticket.MarketLimit | |
| import ticket.NativeStopLimit | |
| import ticket.NativeStopWithProtection | |
| import ticket.Normal | |
| import ticket.SyntheticMarketIfTouched | |
| import ticket.SyntheticStop | |
| import ticket.SyntheticStopLimit | |
| import RichText.NORMAL | |
| import RichText.SYNTHETIC_STOP_LIMIT | |
| import RichText.SYNTHETIC_STOP | |
| import RichText.SYNTHETIC_MARKET_IF_TOUCHED | |
| import RichText.NATIVE_STOP_WITH_PROTECTION | |
| import RichText.NATIVE_STOP_LIMIT | |
| text.toUpperCase match { | |
| case NORMAL(price) => Some(Normal(price.toInt)) | |
| case "MARKET_LIMIT" => Some(MarketLimit) | |
| case "MARKET" => Some(Market) | |
| case SYNTHETIC_STOP_LIMIT(trigger, price) => Some(SyntheticStopLimit(trigger.toInt, price.toInt)) | |
| case SYNTHETIC_STOP(trigger) => Some(SyntheticStop(trigger.toInt)) | |
| case SYNTHETIC_MARKET_IF_TOUCHED(trigger) => Some(SyntheticMarketIfTouched(trigger.toInt)) | |
| case NATIVE_STOP_WITH_PROTECTION(trigger) => Some(NativeStopWithProtection(trigger.toInt)) | |
| case NATIVE_STOP_LIMIT(trigger, price) => Some(NativeStopLimit(trigger.toInt, price.toInt)) | |
| case _ => None | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment