Reprint must indicate the source: Http://blog.csdn.net/minimicall?
Viewmode=contents,http://cloudtrade.top
Listing: Listing.
For example, a stock is only traded on a stock exchange. That is, listed transactions.
The usual, through source code learning:
package org.cryptocoinpartners.schema;import Java.util.arraylist;import Java.util.list;import Javax.persistence.cacheable;import Javax.persistence.entity;import Javax.persistence.Index; Import Javax.persistence.manytoone;import Javax.persistence.namedqueries;import javax.persistence.NamedQuery; Import Javax.persistence.noresultexception;import Javax.persistence.postpersist;import javax.persistence.Table; Import Javax.persistence.transient;import Org.cryptocoinpartners.enumeration.feemethod;import org.cryptocoinpartners.util.persistutil;/** * represents the possibility to trade one Asset for another * * @SuppressWarnin GS ("unuseddeclaration") @Entity//In database creation listing this table @cacheable//cacheable
Named Query @namedqueries ({@NamedQuery (name = "Listing.findbyquotebase", query = "Select a from Listing a where base=?1 and quo Te=?2 and prompt is NULL '), @NamedQuery (name = "Listing.findbyquotebaseprompt", query = "Select a from Listing a where Base=?1 and Quote=?2 and Prompt=?3 ")}) @Table (indexes = {@Index (columnlist =" base "), @Index (columnlist =" quote "), @Ind Ex (columnlist = "Prompt")})//@Table (name = "Listing", uniqueconstraints = {@UniqueConstraint (ColumnNames = {"Base", "Qu Ote "," Prompt "}),//@UniqueConstraint (ColumnNames = {" Base "," quote "})}) public class Listing extends EntityBase {
<pre name= "code" class= "Java" > protected Asset Base; protected Asset quote; Private Prompt Prompt;
@ManyToOne (optional = False)//@Column (unique = true) public Asset getbase () {return base; } @PostPersist private void Postpersist () {//Persistutil.clear (); Persistutil.refresh (this); Persistutil.merge (this); Persistutil.close (); Persistutil.evict (this); } @ManyToOne (optional = False)//@Column (unique = true) public Asset GetQuote () {return quote; } @ManyToOne (optional = true) public Prompt getprompt () {return Prompt; }/** would create the listing if it doesn ' t exist */public static listing Forpair (Asset base, Asset quote) { try {Listing Listing = Persistutil.namedqueryzeroone (Listing.class, "listing.findbyquotebase", base, quote); if (listing = = null) {listing = new listing (base, quote); Persistutil.insert (listing); } return listing; } catch (Noresultexception e) { Final Listing Listing = new Listing (base, quote); Persistutil.insert (listing); return listing; }} public static Listing Forpair (Asset base, Asset quote, Prompt Prompt) {try {Listing Listing = Persistutil.namedqueryzeroone (Listing.class, "listing.findbyquotebaseprompt", base, quote, Prompt); if (listing = = null) {listing = new listing (base, quote, Prompt); Persistutil.insert (listing); } return listing; } catch (Noresultexception e) {final Listing Listing = new Listing (base, quote, Prompt); Persistutil.insert (listing); return listing; }} @Override public String toString () {return getsymbol (); } @Transient Public String Getsymbol () {if (prompt! = null) return Base.getsymbol () + '. ' + quote . Getsymbol () + '. ' + prompt; return Base.getsymbol () + '. ' + Quote.getsymbol ();} @Transient protected Double Getmultiplier () {if (prompt! = null) return Prompt.getmultiplier (); return Getcontractsize () * getticksize (); } @Transient protected Double Gettickvalue () {if (prompt! = null) return Prompt.gettickvalue (); return 1; } @Transient protected Double getcontractsize () {if (prompt! = null) return Prompt.getcontractsiz E (); return 1; } @Transient protected Double getticksize () {if (prompt! = null) return prompt.getticksize (); return Getpricebasis (); } @Transient protected Amount Getmultiplierasamount () {return new Discreteamount ((long) getmultiplier (), get Volumebasis ()); } @Transient protected Double getvolumebasis () {double volumebasis = 0; if (prompt! = null) Volumebasis = Prompt.getvolumebasis (); return volumebasis = = 0? GetBase (). Getbasis (): volumebasis; } @TrAnsient public Feemethod Getmarginmethod () {Feemethod marginmethod = null; if (prompt! = null) Marginmethod = Prompt.getmarginmethod (); return Marginmethod = = null? Null:marginmethod; } @Transient Public Feemethod Getmarginfeemethod () {Feemethod marginfeemethod = null; if (prompt! = null) Marginfeemethod = Prompt.getmarginfeemethod (); return Marginfeemethod = = null? Null:marginfeemethod; } @Transient protected Double getpricebasis () {double pricebasis = 0; if (prompt! = null) Pricebasis = Prompt.getpricebasis (); return pricebasis = = 0? GetQuote (). Getbasis (): pricebasis; } @Transient protected Asset gettradedcurrency () {if (prompt! = null && prompt.gettradedcurrency ()! = null) return prompt.gettradedcurrency (); return GetQuote (); } @Transient Public Feemethod Getfeemethod () {if (prompt! = null &&amP Prompt.getfeemethod ()! = null) return Prompt.getfeemethod (); return null; } @Transient public Double getfeerate () {if (prompt! = null && prompt.getfeerate ()! = 0) return Prompt.getfeerate (); return 0; } @Transient protected int getmargin () {if (prompt! = null && prompt.getmargin ()! = 0) Re Turn prompt.getmargin (); return 0; } public static list<string> Allsymbols () {list<string> result = new arraylist<> (); List<listing> listings = Persistutil.querylist (Listing.class, "select X from Listing x"); for (Listing listing:listings) Result.add ((Listing.getsymbol ())); return result; }//JPA protected Listing () {} protected void SetBase (Asset base) {this.base = base; } protected void Setquote (Asset quote) {this.quote = quote; } protected void Setprompt (Prompt Prompt) {This.prompt = prompt; } public Listing (Asset base, Asset quote) {this.base = base; this.quote = quote; } public Listing (Asset base, Asset quote, Prompt Prompt) {this.base = base; this.quote = quote; This.prompt = prompt; public static Listing Forsymbol (String symbol) {symbol = Symbol.touppercase (); final int dot = Symbol.indexof ('. '); if (dot = =-1) throw new IllegalArgumentException ("Invalid Listing symbol: \" "+ symbol +" \ "); Final String basesymbol = symbol.substring (0, Dot); Asset base = Asset.forsymbol (Basesymbol); if (base = = null) throw new IllegalArgumentException ("Invalid base symbol: \" "+ Basesymbol +" \ ""); int len = symbol.substring (dot + 1, symbol.length ()). IndexOf ('. '); Len = (len! =-1)? Math.min (Symbol.length (), dot + 1 + symbol.substring (dot + 1, symbol.length ()). IndexOf ('. ')): Symbol.length (); Final String Quotesymbol = syMbol.substring (dot + 1, len); Final String Promptsymbol = (symbol.length () > Len)? Symbol.substring (len + 1, Symbol.length ()): null; Asset quote = Asset.forsymbol (Quotesymbol); if (quote = = null) throw new IllegalArgumentException ("Invalid quote symbol: \" "+ Quotesymbol +" \ "); if (Promptsymbol = = null) return Listing.forpair (base, quote); Prompt Prompt = Prompt.forsymbol (Promptsymbol); Return Listing.forpair (base, quote, Prompt); } @Override public boolean equals (Object obj) {if (obj instanceof Listing) {Listing Listing = (L isting) obj; if (!listing.getbase (). Equals (GetBase ())) {return false; } if (!listing.getquote (). Equals (GetQuote ())) {return false; if (listing.getprompt () = null) if (this.getprompt () = null) {if (!listi Ng.getprompt (). Equals (Getprompt ())) return false; } else {return false; } return true; } return false; } @Override public int hashcode () {return getprompt ()! = null? GetQuote (). Hashcode () + getbase (). Hashcode () + getprompt (). Hashcode (): GetQuote (). Hashcode () + getbase (). Hashcode (); }}
protected Asset Base; protected Asset quote; Private Prompt Prompt;
The quantitative trading road of Program Ape (--cointrader) listing listed entity (13)