Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

jpa

  • Loading branch information...
commit 6bdf329b9f0183704eee7e429988412f9200cb16 1 parent 45e3147
@mchapala authored
View
68 app/src/main/scala/com/ats/api/model/AbstractEntity.java
@@ -23,45 +23,45 @@
@MappedSuperclass
public class AbstractEntity {
- @Id
- @GeneratedValue(strategy = GenerationType.AUTO)
- private Long id;
+ @Id
+ @GeneratedValue(strategy = GenerationType.AUTO)
+ private Long id;
- /**
- * Returns the identifier of the entity.
- *
- * @return the id
- */
- public Long getId() {
- return id;
- }
+ /**
+ * Returns the identifier of the entity.
+ *
+ * @return the id
+ */
+ public Long getId() {
+ return id;
+ }
- /*
- * (non-Javadoc)
- * @see java.lang.Object#equals(java.lang.Object)
- */
- @Override
- public boolean equals(Object obj) {
+ /*
+ * (non-Javadoc)
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
+ if (this == obj) {
+ return true;
+ }
- if (this.id == null || obj == null || !(this.getClass().equals(obj.getClass()))) {
- return false;
- }
+ if (this.id == null || obj == null || !(this.getClass().equals(obj.getClass()))) {
+ return false;
+ }
- AbstractEntity that = (AbstractEntity) obj;
+ AbstractEntity that = (AbstractEntity) obj;
- return this.id.equals(that.getId());
- }
+ return this.id.equals(that.getId());
+ }
- /*
- * (non-Javadoc)
- * @see java.lang.Object#hashCode()
- */
- @Override
- public int hashCode() {
- return id == null ? 0 : id.hashCode();
- }
+ /*
+ * (non-Javadoc)
+ * @see java.lang.Object#hashCode()
+ */
+ @Override
+ public int hashCode() {
+ return id == null ? 0 : id.hashCode();
+ }
}
View
14 app/src/main/scala/com/ats/api/model/Account.scala
@@ -3,7 +3,7 @@ package com.ats.api.model
import beans.BeanProperty
-class Account{
+class Account {
/**
@@ -12,21 +12,21 @@ class Account{
var serialVersionUID: Long = 6669464777716480909L;
@BeanProperty
- var netLiquidation:Double = _;
+ var netLiquidation: Double = _;
@BeanProperty
- var dayTradesRemaining:Int=_
+ var dayTradesRemaining: Int = _
@BeanProperty
- var equityWithLoanValue:Double=_
+ var equityWithLoanValue: Double = _
@BeanProperty
- var initMarginReq:Double=_
+ var initMarginReq: Double = _
@BeanProperty
- var maintMarginReq:Double = _
+ var maintMarginReq: Double = _
@BeanProperty
- var cash:Double = _;
+ var cash: Double = _;
}
View
53 app/src/main/scala/com/ats/api/model/AtsContract.scala
@@ -6,17 +6,42 @@ import javax.persistence._
// Analogous to Contract object of tws
@Entity
@Table(name = "Contract")
-case class AtsContract(
- m_symbol: String,
- m_secType: String,
- m_expiry: Option[String] = None,
- m_strike: Option[Double] = None,
- m_right: Option[String] = None,
- m_multiplier: Option[String] = None,
- m_exchange: Option[String],
- m_currency: String,
- m_localSymbol: Option[String] = None,
- m_primaryExch: Option[String] = None,
- m_includeExpired: Option[Boolean] = None,
- m_comboLegsDescrip: Option[String] = None,
- m_comboLegs: Option[String] = None) extends AbstractEntity
+class AtsContract() extends AbstractEntity {
+ var m_symbol: String = _;
+ var m_secType: String = _;
+ var m_expiry: Option[String] = _;
+ var m_strike: Option[Double] = _;
+ var m_right: Option[String] = _;
+ var m_multiplier: Option[String] = _;
+ var m_exchange: Option[String] = _;
+ var m_currency: String = _;
+ var m_localSymbol: Option[String] = _;
+ var m_primaryExch: Option[String] = _;
+ var m_includeExpired: Option[Boolean] = _;
+ var m_comboLegsDescrip: Option[String] = _;
+ var m_comboLegs: Option[String] = _;
+}
+
+object AtsContractUtil {
+ def makeContract(m_symbol: String, m_secType: String, m_expiry: Option[String], m_strike: Option[Double], m_right: Option[String], m_multiplier: Option[String], m_exchange: Option[String], m_currency: String
+ , m_localSymbol: Option[String], m_primaryExch: Option[String], m_includeExpired: Option[Boolean], m_comboLegsDescrip: Option[String]
+ , m_comboLegs: Option[String]): AtsContract = {
+ val contract: AtsContract = new AtsContract();
+ contract.m_comboLegs = m_comboLegs;
+ contract.m_comboLegsDescrip = m_comboLegsDescrip;
+ contract.m_currency = m_currency;
+ contract.m_exchange = m_exchange;
+ contract.m_expiry = m_expiry;
+ contract.m_includeExpired = m_includeExpired;
+ contract.m_localSymbol = m_localSymbol;
+ contract.m_multiplier = m_multiplier
+ contract.m_primaryExch = m_primaryExch
+ contract.m_right = m_right;
+ contract.m_secType = contract.m_secType;
+ contract.m_strike = contract.m_strike;
+ contract.m_symbol = contract.m_symbol;
+ return contract;
+ }
+
+
+}
View
2  app/src/main/scala/com/ats/api/model/Options.java
@@ -12,7 +12,7 @@
Integer qty;
Date expiry;
-
+
public Options() {
}
View
3  app/src/main/scala/com/ats/api/model/Order.scala
@@ -3,7 +3,6 @@ package com.ats.api.model
import scala.Serializable;
-import org.apache.log4j.pattern.IntegerPatternConverter
;
/**
@@ -13,4 +12,4 @@ import org.apache.log4j.pattern.IntegerPatternConverter
* Time: 11:15 PM
* To change this template use File | Settings | File Templates.
*/
-case class Order(symbol:String,qty:Int, isLimitOrder:Boolean,isMarketOrder:Boolean,price:Double,id:String ) extends Serializable
+case class Order(symbol: String, qty: Int, isLimitOrder: Boolean, isMarketOrder: Boolean, price: Double, id: String) extends Serializable
View
28 app/src/main/scala/com/ats/api/model/RequestMarketData.scala
@@ -3,17 +3,25 @@ package com.ats.api.model
import javax.persistence._
@Entity
-//@Table(name="REQUEST_MARKET_DATA")
-case class RequestMarketData(
- @OneToMany
- contract: AtsContract,
+@Table(name = "REQUEST_MARKET_DATA")
+class RequestMarketData() extends AbstractEntity {
- @Column(name = "tickTypeList")
- tickTypeList: String,
-
- @Column(name = "snapshot")
- snapshot: Boolean)
- extends AbstractEntity
+ @OneToMany
+ var contract: java.util.Set[AtsContract] = _;
+ @Column(name = "tickTypeList")
+ var tickTypeList: String = _;
+ @Column(name = "snapshot")
+ var snapshot: Boolean = _;
+}
+object RequestMarketDataUtil {
+ def makeRequest(contract: java.util.Set[AtsContract], tickTypeList: String, snapShot: Boolean): RequestMarketData = {
+ val request: RequestMarketData = new RequestMarketData()
+ request.contract = contract
+ request.tickTypeList = tickTypeList
+ request.snapshot = snapShot;
+ return request;
+ }
+}
View
2  app/src/main/scala/com/ats/api/model/TickData.scala
@@ -26,7 +26,7 @@ class TickData {
var service: String = null
@BeanProperty
- var date:Date=null
+ var date: Date = null
@BeanProperty
var requestId: Int = 0;
View
45 app/src/main/scala/com/ats/impl/tws/TwsClient.scala
@@ -2,7 +2,7 @@
package com.ats.impl.tws
-import com.ib.client.{EClientSocket, EWrapper}
+import com.ib.client.EClientSocket
import com.ats.common.Constants
import messages._
import messages.TwsConnectionTime
@@ -10,10 +10,9 @@ import messages.TWSNextValidId
import messages.TwsPlaceOrder
import messages.TwsReqOpenOrders
import org.slf4j.LoggerFactory
-import org.apache.camel.Consume
import org.springframework.beans.factory.annotation.{Value, Autowired}
import org.springframework.stereotype.Component
-import com.ats.api.model.{RequestMarketData, AtsContract}
+import com.ats.api.model.RequestMarketData
import com.ats.app.config.spring.AtsCamelContext
@@ -24,11 +23,11 @@ import com.ats.app.config.spring.AtsCamelContext
*/
-@Component(value="twsClient")
+@Component(value = "twsClient")
class TwsClient {
@Autowired
- var camelContext:AtsCamelContext=null
+ var camelContext: AtsCamelContext = null
val logger = LoggerFactory.getLogger(getClass().getName());
@@ -48,7 +47,7 @@ class TwsClient {
lazy val endpointUri = com.ats.common.Constants.SEND_MSG_TO_TWS;
@Autowired
- var clientSocket:EClientSocket=null;
+ var clientSocket: EClientSocket = null;
// consume messages from this end point
@@ -80,14 +79,14 @@ class TwsClient {
}
- def handleError(error:TwsError) {
+ def handleError(error: TwsError) {
- if(error.errorCode==100){
+ if (error.errorCode == 100) {
Thread.sleep(100000);
}
// TODO create tws constants file
- if(error.errorCode== Constants.TWS_DISCONNECT_ERROR){
+ if (error.errorCode == Constants.TWS_DISCONNECT_ERROR) {
logger.debug("Sending reconnect request after 100 secs")
Thread.sleep(100000);
logger.debug("Sending reconnect request ")
@@ -96,9 +95,9 @@ class TwsClient {
}
// TODO chnage this to property when migrate to camel 2.11
- //@Consume(uri = "direct:send_msg_to_tws")
+ //@Consume(uri = "direct:send_msg_to_tws")
def receive(mesg: Any): Unit = mesg match {
- case error: TwsError => {
+ case error: TwsError => {
logger.debug("TwsAdapterActorSubscriber.received message" + this + "object" + error)
handleError(error)
}
@@ -107,37 +106,37 @@ class TwsClient {
logger.debug("Connect mesg rcvd");
connect()
}
- case twsRequestCurrentTime:TWSRequestCurrentTime => {
+ case twsRequestCurrentTime: TWSRequestCurrentTime => {
this.clientSocket.reqCurrentTime()
}
- case twsConnectionTime:TwsConnectionTime => {
+ case twsConnectionTime: TwsConnectionTime => {
this.clientSocket.reqCurrentTime()
}
- case twsRequestMarketData:RequestMarketData => {
- if(!this.clientSocket.isConnected) connect; //tickerId // contract // tickType // Boolean
- val atsContract:AtsContract = twsRequestMarketData.contract;
-
+ case twsRequestMarketData: RequestMarketData => {
+ if (!this.clientSocket.isConnected) connect; //tickerId // contract // tickType // Boolean
+ //val atsContract:AtsContract = twsRequestMarketData.contract;
+
//this.clientSocket.reqMktData(twsRequestMarketData.tickerId.get,,twsRequestMarketData.tickTypeList,twsRequestMarketData.snapshot)
}
- case twsPlaceOrder:TwsPlaceOrder => {
- this.clientSocket.placeOrder(twsPlaceOrder.id,twsPlaceOrder.contract,twsPlaceOrder.order)
+ case twsPlaceOrder: TwsPlaceOrder => {
+ this.clientSocket.placeOrder(twsPlaceOrder.id, twsPlaceOrder.contract, twsPlaceOrder.order)
}
- case oo:TwsReqOpenOrders => {
+ case oo: TwsReqOpenOrders => {
this.clientSocket.reqAllOpenOrders()
}
- case nid:TWSNextValidId => {
+ case nid: TWSNextValidId => {
logger.debug("TwsAdapterActorPublisherReceived" + nid);
this.clientSocket.reqIds(1);
}
- case sid:String =>{
+ case sid: String => {
logger.debug("TwsAdapterActorPublisherReceived" + sid);
}
- case any:AnyRef => {
+ case any: AnyRef => {
logger.debug("TwsAdapter unknown message " + this + any);
}
}
View
25 app/src/test/scala/AtsContractsRepositoryTest.scala
@@ -1,5 +1,5 @@
-import com.ats.api.model.{RequestMarketData, AtsContract}
+import com.ats.api.model.{RequestMarketDataUtil, AtsContractUtil, RequestMarketData, AtsContract}
import com.ats.app.config.spring.AtsSpringDataConfig
import com.ats.persistence.impl.{AtsContractRepository, RequestMarketDataRepository}
@@ -26,17 +26,19 @@ class AtsContractsRepositoryTest extends AbstractTestNGSpringContextTests with T
var contractRepository: AtsContractRepository = _;
@Test(dependsOnGroups = Array("addContract"))
- def testAdd() {
- val contract = new AtsContract("BAC", "STK", None, None, None, None, Some("SMART"), "USD", None, None, Some(false), None, None)
+ def testAddRequestMarketData() {
+ val contract = AtsContractUtil.makeContract("BAC", "STK", None, None, None, None, Some("SMART"), "USD", None, None, Some(false), None, None)
contractRepository.save(contract);
- val data: RequestMarketData = new RequestMarketData(contract, "100", false);
+ val set: java.util.Set[AtsContract] = new java.util.HashSet[AtsContract]();
+ set.add(contract);
+ val data: RequestMarketData = RequestMarketDataUtil.makeRequest(set, "100", false);
repository.save(data)
}
@Test(groups = Array("addContract"))
def testAddContract() {
- val contract = new AtsContract("BAC", "STK", None, None, None, None, Some("SMART"), "USD", None, None, Some(false), None, None)
+ val contract = AtsContractUtil.makeContract("BAC", "STK", None, None, None, None, Some("SMART"), "USD", None, None, Some(false), None, None)
contractRepository.save(contract);
}
@@ -47,4 +49,17 @@ class AtsContractsRepositoryTest extends AbstractTestNGSpringContextTests with T
logger.debug(new XStream().toXML(contracts));
}
+ @Test(dependsOnGroups = Array("addContract"))
+ def testDeleteOneRequestMarketData() {
+ val contracts = contractRepository.findAll()
+ logger.debug(new XStream().toXML(contracts));
+ }
+
+ @Test(dependsOnGroups = Array("addContract"))
+ def testDeleteAllRequestMarketData() {
+ this.repository.deleteAll();
+ logger.debug(new XStream().toXML(contracts));
+ }
+
+
}
Please sign in to comment.
Something went wrong with that request. Please try again.