Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Initial spring data Jpa commi for historical

  • Loading branch information...
commit f25a8cd68de8e8009b993262fd9daf69af70e55b 1 parent daa3d0f
@mchapala authored
View
35 app/src/main/scala/com/ats/api/model/AtsContract.scala
@@ -6,19 +6,52 @@ import javax.persistence._
// Analogous to Contract object of tws
@Entity
@Table(name = "Contract")
-class AtsContract() extends AbstractEntity {
+class AtsContract() {
+
+ @Id
+ @GeneratedValue(strategy = GenerationType.AUTO)
+ var contract_id:Long=_;
+
+
+ @Column(name = "mSymbol")
var mSymbol: String = _;
+
+ @Column(name = "mSecType")
var mSecType: String = _;
+
+ @Column(name = "mExpiry")
var mExpiry: String = _;
+
+
+ @Column(name = "mStrike")
var mStrike: java.lang.Double = _;
+
+ @Column(name = "mRight")
var mRight: String = _;
+
+ @Column(name = "mMultiplier")
var mMultiplier: String = _;
+
+ @Column(name = "mExchange")
var mExchange: String = _;
+
+ @Column(name = "mCurrency")
var mCurrency: String = _;
+
+
+ @Column(name = "mLocalSymbol")
var mLocalSymbol: String = _;
+
+ @Column(name = "mPrimaryExch")
var mPrimaryExch: String = _;
+
+ @Column(name = "mIncludeExpired")
var mIncludeExpired: Boolean = _;
+
+ @Column(name = "mComboLegsDescrip")
var mComboLegsDescrip: String = _;
+
+ @Column(name = "mComboLegs")
var mComboLegs: String = _;
}
View
12 app/src/main/scala/com/ats/api/model/RequestHistoricalData.scala
@@ -1,8 +1,8 @@
package com.ats.api.model
-import reflect.BeanProperty
-import javax.persistence.{Column, OneToMany, Table, Entity}
-import org.springframework.data.jpa.repository.JpaRepository
+
+import javax.persistence._
+import scala.beans.BeanProperty
/**
@@ -23,6 +23,8 @@ import org.springframework.data.jpa.repository.JpaRepository
class RequestHistoricalData extends AbstractEntity{
@BeanProperty
+ @OneToOne(cascade = Array(CascadeType.PERSIST))
+ @JoinColumn(name = "contract_id")
var contract:AtsContract=_;
@BeanProperty
@@ -66,7 +68,5 @@ object RequestHistoricalDataUtil {
}
-trait RequestHistoricalDataRepository extends JpaRepository[RequestHistoricalData,java.lang.Long] {
- def findByContractMSymbol(symbol:String);
-}
+
View
8 app/src/main/scala/com/ats/api/model/RequestMarketData.scala
@@ -7,9 +7,11 @@ import scala.beans.BeanProperty
@Table(name = "REQUEST_MARKET_DATA")
class RequestMarketData() extends AbstractEntity {
- @OneToMany
@BeanProperty
- var contract: java.util.Set[AtsContract] = _;
+ @OneToOne(cascade = Array(CascadeType.PERSIST))
+ @JoinColumn(name = "contract_id")
+ var contract:AtsContract=_;
+
@Column(name = "tickTypeList")
@BeanProperty
@@ -21,7 +23,7 @@ class RequestMarketData() extends AbstractEntity {
}
object RequestMarketDataUtil {
- def makeRequest(contract: java.util.Set[AtsContract], tickTypeList: String, snapShot: Boolean): RequestMarketData = {
+ def makeRequest(contract: AtsContract, tickTypeList: String, snapShot: Boolean): RequestMarketData = {
val request: RequestMarketData = new RequestMarketData()
request.contract = contract
request.tickTypeList = tickTypeList
View
16 app/src/main/scala/com/ats/persistence/impl/RequestHistoricalDataRepository.scala
@@ -0,0 +1,16 @@
+package com.ats.persistence.impl
+
+import org.springframework.data.jpa.repository.JpaRepository
+import com.ats.api.model.RequestHistoricalData
+
+/**
+ * Created with IntelliJ IDEA.
+ * User: mchapala
+ * Date: 24/5/13
+ * Time: 11:03 PM
+ * To change this template use File | Settings | File Templates.
+ */
+ trait RequestHistoricalDataRepository extends JpaRepository[RequestHistoricalData,java.lang.Long] {
+ def findByContractMSymbol(symbol:String);
+ }
+
View
5 app/src/main/scala/com/ats/persistence/impl/RequestMarketDataRepository.scala
@@ -6,13 +6,8 @@ import org.springframework.data.jpa.repository.JpaRepository
import org.springframework.stereotype.Component
import org.springframework.transaction.annotation.Transactional
-
-
trait RequestMarketDataRepository extends JpaRepository[RequestMarketData,java.lang.Long] {
-
def findByContractMSymbol(symbol:String);
-
-
}
View
37 app/src/main/scala/com/ats/script/DBScript.scala
@@ -1,8 +1,10 @@
package com.ats.script
import org.springframework.stereotype.Component
-import com.ats.persistence.impl.RequestMarketDataRepository
+import com.ats.persistence.impl.{RequestHistoricalDataRepository, AtsContractRepository, RequestMarketDataRepository}
import org.springframework.beans.factory.annotation.Autowired
+import com.ats.api.model.{RequestHistoricalData,RequestHistoricalDataUtil ,RequestMarketDataUtil, RequestMarketData, AtsContractUtil}
+import scala.beans.BeanProperty
/**
* Created with IntelliJ IDEA.
@@ -16,24 +18,39 @@ import org.springframework.beans.factory.annotation.Autowired
class DBScript {
@Autowired
- var requestMarketData:RequestMarketDataRepository=_;
+ @BeanProperty
+ var requestMarketDataRepository: RequestMarketDataRepository = _;
+ @Autowired
+ var contractRepository: AtsContractRepository = _;
+
+ @Autowired
+ @BeanProperty
+ var requestHistoricalDataRepository: RequestHistoricalDataRepository = _;
def loadData(){
- loadRequestMarketData();
- loadHistoricalData();
+ loadRequestMarketData("BAC");
+ loadRequestMarketData("IBN");
+ loadRequestMarketData("GOOG");
+ loadHistoricalData("BAC");
}
- def loadRequestMarketData(){
- // load bac
- // load ibn
- // load google
+ def loadRequestMarketData(stk:String){
+ val contract = AtsContractUtil.makeContract(stk, "STK", null, null, null, null, "SMART", "USD", null, null, false, null, null)
+ contractRepository.saveAndFlush(contract);
+ val data: RequestMarketData = RequestMarketDataUtil.makeRequest(contract, "100", false);
+ requestMarketDataRepository.saveAndFlush(data)
+ }
+ def loadHistoricalData(stk:String){
+ val contract = AtsContractUtil.makeContract(stk, "STK", null, null, null, null, "SMART", "USD", null, null, false, null, null)
+ contractRepository.saveAndFlush(contract);
+ val data= RequestHistoricalDataUtil.makeRequestHistoricalData(contract,"ENDTIME","DURATION","BARSIZE","whattoshow",1,1);
+ requestHistoricalDataRepository.saveAndFlush(data)
}
- def loadHistoricalData(){
- }
+
}
View
3  app/src/main/scala/com/ats/start/AtsApp.scala
@@ -29,16 +29,13 @@ object AtsApp {
lazy val camelContext:AtsCamelContext = springContext.getBean(classOf[AtsCamelContext])
def onStart() {
-
logger.debug("Tws Starting..Start")
val twsStarter:TwsStarter = springContext.getBean(classOf[TwsStarter])
-
logger.debug("Global.Tws Started..End")
camelContext.addRoute(new GatewayRouteBuilder)
camelContext.addRoute(new TwsConfigRouteBuilder)
camelContext.onStartUp();
twsStarter.init();
-
}
def onStop() {
View
35 app/src/test/scala/AtsContractsRepositoryTest.scala → app/src/test/scala/AtsRepositoryTest.scala
@@ -1,7 +1,7 @@
import com.ats.api.model._
import com.ats.app.config.spring.AtsSpringDataConfig
-import com.ats.persistence.impl.{RequestMarketDataRepository, AtsContractRepository}
+import com.ats.persistence.impl.{RequestHistoricalDataRepository, RequestMarketDataRepository, AtsContractRepository}
import com.thoughtworks.xstream.XStream
import org.scalatest.testng.TestNGSuite
@@ -22,29 +22,44 @@ class AtsRepositoryTest extends AbstractTestNGSpringContextTests with TestNGSuit
var requestMarketDataRepository: RequestMarketDataRepository = _;
@Autowired
-// @BeanProperty
+ @BeanProperty
var contractRepository: AtsContractRepository = _;
+ @Autowired
+ @BeanProperty
+ var requestHistoricalDataRepository: RequestHistoricalDataRepository = _;
+
var marketData:RequestMarketData=_;
- @Test(dependsOnGroups = Array("addContract"))
+ @Test(dependsOnGroups = Array("addContract"),groups=Array("addRequestMarketData"))
def testAddRequestMarketData() {
val contract = AtsContractUtil.makeContract("BAC", "STK", null, null, null, null, "SMART", "USD", null, null, false, null, null)
- contractRepository.save(contract);
- val set: java.util.Set[AtsContract] = new java.util.HashSet[AtsContract]();
- set.add(contract);
- val data: RequestMarketData = RequestMarketDataUtil.makeRequest(set, "100", false);
- marketData = requestMarketDataRepository.save(data)
+ contractRepository.saveAndFlush(contract);
+ val data: RequestMarketData = RequestMarketDataUtil.makeRequest(contract, "100", false);
+ marketData = requestMarketDataRepository.saveAndFlush(data)
assert(true)
}
+ @Test(dependsOnGroups = Array("addContract"),groups=Array("addRequestMarketData"))
+ def testAddRequestHistoricalData() {
+ val contract = AtsContractUtil.makeContract("BAC", "STK", null, null, null, null, "SMART", "USD", null, null, false, null, null)
+ contractRepository.saveAndFlush(contract);
+ val data: RequestHistoricalData = RequestHistoricalDataUtil.makeRequestHistoricalData(contract,"ENDDATE","DURATION","BARSIZE","whattoshow",1,1);
+ val histData = requestHistoricalDataRepository.saveAndFlush(data)
+ assert(true)
+
+ }
+
+
+
@Test(groups = Array("addContract"))
def testAddContract() {
val contract = AtsContractUtil.makeContract("BAC", "STK", null, null, null, null, "SMART", "USD", null, null, false, null, null)
- contractRepository.save(contract);
+ contractRepository.saveAndFlush(contract);
+
assert(true)
}
@@ -56,7 +71,7 @@ class AtsRepositoryTest extends AbstractTestNGSpringContextTests with TestNGSuit
assert(true)
}
- @Test(groups = Array("deleteSingleContract"),dependsOnGroups = Array("addContract"))
+ @Test(groups = Array("deleteSingleContract"),dependsOnGroups = Array("addContract","addRequestMarketData"))
def testDeleteOneRequestMarketData() {
this.requestMarketDataRepository.delete(marketData.getId);
assert(true)
Please sign in to comment.
Something went wrong with that request. Please try again.