Package com.longportwhale.trade
Class TradeContext
- java.lang.Object
-
- com.longportwhale.trade.TradeContext
-
- All Implemented Interfaces:
AutoCloseable
public class TradeContext extends Object implements AutoCloseable
Trade context
-
-
Constructor Summary
Constructors Constructor Description TradeContext()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()static CompletableFuture<TradeContext>create(Config config)Create a TradeContext objectvoidsetOnOrderChange(OrderChangedHandler handler)Set order changed event callback, after receiving the order changed event, it will call back to this handler.CompletableFuture<Void>subscribe(TopicType[] topics)SubscribeCompletableFuture<Void>unsubscribe(TopicType[] topics)Unsubscribe
-
-
-
Method Detail
-
create
public static CompletableFuture<TradeContext> create(Config config) throws OpenApiException
Create a TradeContext object- Parameters:
config- Config object- Returns:
- A Future representing the result of the operation
- Throws:
OpenApiException- If an error occurs
-
close
public void close() throws Exception- Specified by:
closein interfaceAutoCloseable- Throws:
Exception
-
setOnOrderChange
public void setOnOrderChange(OrderChangedHandler handler)
Set order changed event callback, after receiving the order changed event, it will call back to this handler.- Parameters:
handler- A order changed handler
-
subscribe
public CompletableFuture<Void> subscribe(TopicType[] topics) throws OpenApiException
Subscribeimport com.longportwhale.*; import com.longportwhale.trade.*; import java.math.BigDecimal; class Main { public static void main(String[] args) throws Exception { try (Config config = Config.fromEnv(); TradeContext ctx = TradeContext.create(config).get()) { ctx.setOnOrderChange((order_changed) -> { System.out.println(order_changed); }); ctx.subscribe(new TopicType[] { TopicType.Private }).get(); Thread.sleep(3000); } } }- Parameters:
topics- Topics- Returns:
- A Future representing the result of the operation
- Throws:
OpenApiException- If an error occurs
-
unsubscribe
public CompletableFuture<Void> unsubscribe(TopicType[] topics) throws OpenApiException
Unsubscribe- Parameters:
topics- Topics- Returns:
- A Future representing the result of the operation
- Throws:
OpenApiException- If an error occurs
-
-