Skip to content

Commit

Permalink
1, Add AlpacaToolFactory.groovy, finished load the AlpacaToolFactory.
Browse files Browse the repository at this point in the history
2, The manner of invoking trading api needs to be optimized and normalized.
  • Loading branch information
phoenixyuanying committed Aug 12, 2023
1 parent a1cb63d commit fa49839
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 0 deletions.
4 changes: 4 additions & 0 deletions framework/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,10 @@ dependencies {
// only include this if using Endpoint and MessageHandler annotations:
// execWarRuntime ('org.eclipse.jetty:jetty-annotations:10.0.15') // Apache 2.0
execWarRuntimeOnly 'org.apache.logging.log4j:log4j-slf4j18-impl:2.18.0'

//Alpaca API
api group: 'net.jacobpeterson', name: 'alpaca-java', version: '9.1.4'
api group: 'com.squareup.okhttp3', name: 'okhttp', version: '3.2.0'
}

// setup task dependencies to make sure the start sourceSets always get run
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package org.moqui.impl.tools

/**
* @Title: AlpacaToolFactory
* @Package org.moqui.impl.tools
* @Description: //TODO
* @author lucasyuan
* @date 8/13/23
* @version V1.0
*/
import groovy.transform.CompileStatic;
import net.jacobpeterson.alpaca.AlpacaAPI;
import org.moqui.context.ExecutionContextFactory;
import org.moqui.context.ToolFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* @author ianyuan
* @version V1.0
* @Title: AlpacaToolFactory
* @Package com.edt.tradecube.alpaca.marketdata
* @Description: //TODO
* @date 8/6/23
*/
@CompileStatic
public class AlpacaToolFactory implements ToolFactory {

protected final static Logger logger = LoggerFactory.getLogger(AlpacaToolFactory.class);
final static String TOOL_NAME = "Alpaca";

protected ExecutionContextFactory ecf = null;

/** AlpacaAPI instance */
private AlpacaAPI alpacaAPI = null;
@Override
public void init(ExecutionContextFactory ecf) {

if( alpacaAPI == null ){
this.ecf = ecf;
alpacaAPI = new AlpacaAPI();
}

}

@Override
public String getName() {
return TOOL_NAME;
}

@Override
public void preFacadeInit(ExecutionContextFactory ecf) {

if( alpacaAPI == null ){
this.ecf = ecf;
alpacaAPI = new AlpacaAPI();
}

}

@Override
public AlpacaAPI getInstance(Object... parameters) {
if (alpacaAPI == null) throw new IllegalStateException("AlpacaToolFactory not initialized");
return this.alpacaAPI;
}

@Override
public void destroy() {
}
}
1 change: 1 addition & 0 deletions framework/src/main/resources/MoquiDefaultConf.xml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
<tool-factory class="org.moqui.impl.tools.JackrabbitRunToolFactory" init-priority="40" disabled="true"/>
<!-- SubEtha SMTP ToolFactory starts an SMTP server using the MOQUI_LOCAL EmailServer settings, emails received trigger EMECA rules -->
<tool-factory class="org.moqui.impl.tools.SubEthaSmtpToolFactory" init-priority="50" disabled="true"/>
<tool-factory class="org.moqui.impl.tools.AlpacaToolFactory" init-priority="20" disabled="false"/>
</tools>

<cache-list warm-on-start="true" local-factory="MCache" distributed-factory="MCache">
Expand Down
10 changes: 10 additions & 0 deletions framework/src/main/resources/alpaca.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

#paper trading
key_id = PK0Y91VLYX2I8A3G8AOJ
secret_key = p3vvkuE7Q0L96r5Mbexoj7jvOPFpjwL927nLqVLS
#live trading
#key_id = AKFVIRWOD6CRKMR5Z4SR
#secret_key = ck32dBEgnTnTR0U19LkfrAEcIrcJwL2bEkT6sAQN
endpoint_api_type=paper
data_api_type=iex
user_agent=JavaRuntimeEnvironment/ OkHttp/4.9.1

0 comments on commit fa49839

Please sign in to comment.