public class Client
extends java.lang.Object
The trading client creates background threads. If a trading client
instance is discarded without disconnect
being called on
it, these threads will linger in the background and prevent you from
logging back into the same account.
In general, calls into the trading client will not block and will return immediately. The only exception is if the socket to the trading-server is full. In this case, the call will block until there is enough space in the socket to write all necessary data.
Instances of the trading client are not safe for use by multiple
threads. If such synchronization is required, then one should use
their own synchronization primitives to ensure this. Calling back
into the trading client via a Callback
method is never
safe, as the client is not re-entrant.
Modifier and Type | Class and Description |
---|---|
static class |
Client.NotConnectedException
Thrown by the trading client to indicate an attempt was made to
use it before it successfully connected or after it had
disconnected.
|
Modifier and Type | Field and Description |
---|---|
static long |
CURRENT_EVENT
When instantiating a trading client, provide this as the last
event-id to indicate you want no replays at all and to start at
the current event.
|
static int |
DEFAULT_PORT
Default port to use when connecting to the trading-server.
|
static long |
MARKET_PRICE
Represents a market price when placing a new order.
|
static int |
PERCENT_SCALE
Minimum Trigger Percentage is scaled.
|
static int |
PRICE_SCALE
All prices are scaled by this constant.
|
static long |
SAME_PRICE
When cancel-replacing, means that the price of the replacement
order should remain the same as the original order.
|
static int |
SAME_QUANTITY
When cancel-replacing, means that the quantity of the replacement
order should remain the same as the original order.
|
Constructor and Description |
---|
Client(Callback callback,
java.lang.String hostname,
int port,
java.lang.String account,
java.lang.String username,
java.lang.String password,
long lastEventId,
boolean cancelOnDisconnect)
Connect to a trading-server.
|
Modifier and Type | Method and Description |
---|---|
void |
cancel(long orderId)
Attempt to cancel the specified order.
|
void |
cancelAll()
Attempt to cancel all open orders.
|
void |
disconnect()
Disconnect from the trading-server.
|
void |
partialCancel(long orderId,
int quantityLeft)
Attempt to partially cancel the specified order.
|
void |
place(long orderId,
int quantity,
long price,
Side side,
java.lang.String symbol,
java.lang.String route)
Places a new US-Equities order.
|
void |
place(long orderId,
int quantity,
long price,
Side side,
java.lang.String symbol,
java.lang.String route,
OrderOptions options)
Places a new US-Equities order.
|
void |
placeAlgo(long orderId,
int quantity,
long price,
Side side,
java.lang.String symbol,
java.lang.String route,
java.lang.String strategy)
Places a new Algo order for a US-Equities security.
|
void |
placeAlgo(long orderId,
int quantity,
long price,
Side side,
java.lang.String symbol,
java.lang.String route,
java.lang.String strategy,
AlgoOrderOptions options)
Places a new Algo order for a US-Equities security.
|
void |
placeUSOptions(long orderId,
int quantity,
long price,
Side side,
PositionEffect positionEffect,
USOptionsSymbol symbol,
java.lang.String route)
Places a new US-Options order.
|
void |
placeUSOptions(long orderId,
int quantity,
long price,
Side side,
PositionEffect positionEffect,
USOptionsSymbol symbol,
java.lang.String route,
USOptionsOrderOptions options)
Places a new US-Options order.
|
void |
placeUSOptionsAlgo(long orderId,
int quantity,
long price,
Side side,
PositionEffect positionEffect,
USOptionsSymbol symbol,
java.lang.String route,
java.lang.String strategy)
Places a new Algo order for a US-Options security.
|
void |
placeUSOptionsAlgo(long orderId,
int quantity,
long price,
Side side,
PositionEffect positionEffect,
USOptionsSymbol symbol,
java.lang.String route,
java.lang.String strategy,
USOptionsAlgoOrderOptions options)
Places a new Algo order for a US-Options security.
|
void |
replace(long originalOrderId,
long orderId,
int newQuantity,
long newPrice)
Cancel-replaces an existing US-Equities order.
|
void |
replace(long originalOrderId,
long orderId,
int newQuantity,
long newPrice,
ReplaceOptions options)
Cancel-replaces an existing US-Equities order.
|
void |
replaceAlgo(long originalOrderId,
long orderId,
int newQuantity,
long newPrice)
Cancel-replaces an existing Algo-US-Equities
order.
|
void |
replaceAlgo(long originalOrderId,
long orderId,
int newQuantity,
long newPrice,
AlgoReplaceOptions options)
Cancel-replaces an existing Algo-US-Equities
order.
|
void |
replaceUSOptions(long originalOrderId,
long orderId,
int newQuantity,
long newPrice)
Cancel-replaces an existing US-Options order.
|
void |
replaceUSOptionsAlgo(long originalOrderId,
long orderId,
int newQuantity,
long newPrice)
Cancel-replaces an existing Algo-US-Options
order.
|
void |
replaceUSOptionsAlgo(long originalOrderId,
long orderId,
int newQuantity,
long newPrice,
USOptionsAlgoReplaceOptions options)
Cancel-replaces an existing Algo-US-Options
order.
|
public static final int DEFAULT_PORT
public static final long MARKET_PRICE
public static final long SAME_PRICE
public static final int PRICE_SCALE
public static final int SAME_QUANTITY
public static final long CURRENT_EVENT
public static final int PERCENT_SCALE
public Client(Callback callback, java.lang.String hostname, int port, java.lang.String account, java.lang.String username, java.lang.String password, long lastEventId, boolean cancelOnDisconnect)
A successful connect results in a onConnect
callback, while an unsuccessful connect results in a
onDisconnect
callback. Note that you may receive
either of these callbacks before the constructor even returns. In
addition, immediately after onConnect
, the
trading-server may replay missed events (based on the provided
last event-id parameter).
disconnect
can be used to disconnect the client
after connection, or to abort a connection attempt before it has
succeeded.
callback
- interface to receive order eventshostname
- hostname to connect toport
- port to connect to (DEFAULT_PORT
unless told otherwise)account
- account to log intousername
- user to use for authenticationpassword
- user passwordlastEventId
- last event-id received via a callback from a
previous client instance (or CURRENT_EVENT
if no
replaying is desired)cancelOnDisconnect
- whether the trading-server will
automatically attempt to cancel any live orders upon a
disconnectjava.lang.IllegalArgumentException
Callback.onConnect()
,
Callback.onDisconnect(java.lang.String)
public void disconnect()
onDisconnect
callback signals that the client has
successfully disconnected. At that point it is safe to dispose of
the client as no more callbacks will trigger at that point.
If the client is already disconnected, than this call is a no-op. If the client is attempting to connect, but has not yet successfully connected, this call will abort the connection attempt.
public void place(long orderId, int quantity, long price, Side side, java.lang.String symbol, java.lang.String route) throws Client.NotConnectedException
Once placed, the order will either be accepted (designated
by an onOrderAck
callback), or rejected
(designated by an onOrderReject
callback). Note that
you may receive either of these callbacks before the
place
call even returns.
orderId
- client specified identifierquantity
- desired size of tradeprice
- desired price of trade (scaled by PRICE_SCALE
), or MARKET_PRICE
for market
ordersside
- type of tradesymbol
- security to be tradedroute
- destination venue marketjava.lang.IllegalArgumentException
Client.NotConnectedException
Callback.onOrderAck(long, long, long, limebrokerage.trading.api.AckOptions)
,
Callback.onOrderReject(long, long, java.lang.String)
public void place(long orderId, int quantity, long price, Side side, java.lang.String symbol, java.lang.String route, OrderOptions options) throws Client.NotConnectedException
Once placed, the order will either be accepted (designated
by an onOrderAck
callback), or rejected
(designated by an onOrderReject
callback). Note that
you may receive either of these callbacks before the
place
call even returns.
This method is identical to the version of place
without the options parameter, but allows one to specify
additional special order options.
orderId
- client specified identifierquantity
- desired size of tradeprice
- desired price of trade (scaled by PRICE_SCALE
), or MARKET_PRICE
for market
ordersside
- type of tradesymbol
- security to be tradedroute
- destination venue marketoptions
- desired special options (must not be null)java.lang.IllegalArgumentException
Client.NotConnectedException
Callback.onOrderAck(long, long, long, limebrokerage.trading.api.AckOptions)
,
Callback.onOrderReject(long, long, java.lang.String)
public void placeUSOptions(long orderId, int quantity, long price, Side side, PositionEffect positionEffect, USOptionsSymbol symbol, java.lang.String route) throws Client.NotConnectedException
Once placed, the order will either be accepted (designated
by an onOrderAck
callback), or rejected
(designated by an onOrderReject
callback). Note that
you may receive either of these callbacks before the
placeUSOptions
call even returns.
orderId
- client specified identifierquantity
- desired size of tradeprice
- desired price of trade (scaled by PRICE_SCALE
), or MARKET_PRICE
for market
ordersside
- type of tradepositionEffect
- effect of trade on positionsymbol
- contract to be tradedroute
- destination venue marketjava.lang.IllegalArgumentException
Client.NotConnectedException
Callback.onOrderAck(long, long, long, limebrokerage.trading.api.AckOptions)
,
Callback.onOrderReject(long, long, java.lang.String)
public void placeUSOptions(long orderId, int quantity, long price, Side side, PositionEffect positionEffect, USOptionsSymbol symbol, java.lang.String route, USOptionsOrderOptions options) throws Client.NotConnectedException
Once placed, the order will either be accepted (designated
by an onOrderAck
callback), or rejected
(designated by an onOrderReject
callback). Note that
you may receive either of these callbacks before the
placeUSOptions
call even returns.
This method is identical to the version of place
without the options parameter, but allows one to specify
additional special order options.
orderId
- client specified identifierquantity
- desired size of tradeprice
- desired price of trade (scaled by PRICE_SCALE
), or MARKET_PRICE
for market
ordersside
- type of tradepositionEffect
- effect of trade on positionsymbol
- contract to be tradedroute
- destination venue marketoptions
- desired special options (must not be null)java.lang.IllegalArgumentException
Client.NotConnectedException
Callback.onOrderAck(long, long, long, limebrokerage.trading.api.AckOptions)
,
Callback.onOrderReject(long, long, java.lang.String)
public void placeAlgo(long orderId, int quantity, long price, Side side, java.lang.String symbol, java.lang.String route, java.lang.String strategy) throws Client.NotConnectedException
Once placed, the order will either be accepted (designated
by an onOrderAck
callback), or rejected
(designated by an onOrderReject
callback). Note that
you may receive either of these callbacks before the
place
call even returns.
orderId
- client specified identifierquantity
- desired size of tradeprice
- desired price of trade (scaled by PRICE_SCALE
), or MARKET_PRICE
for market
ordersside
- type of tradesymbol
- security to be tradedroute
- destination venue marketstrategy
- name of the strategy to executejava.lang.IllegalArgumentException
Client.NotConnectedException
Callback.onOrderAck(long, long, long, limebrokerage.trading.api.AckOptions)
,
Callback.onOrderReject(long, long, java.lang.String)
public void placeAlgo(long orderId, int quantity, long price, Side side, java.lang.String symbol, java.lang.String route, java.lang.String strategy, AlgoOrderOptions options) throws Client.NotConnectedException
Once placed, the order will either be accepted (designated
by an onOrderAck
callback), or rejected
(designated by an onOrderReject
callback). Note that
you may receive either of these callbacks before the
place
call even returns.
This method is identical to the version of place
without the options parameter, but allows one to specify
additional special order options.
orderId
- client specified identifierquantity
- desired size of tradeprice
- desired price of trade (scaled by PRICE_SCALE
), or MARKET_PRICE
for market
ordersside
- type of tradesymbol
- security to be tradedroute
- destination venue marketstrategy
- name of the strategy to executeoptions
- desired special options (must not be null)java.lang.IllegalArgumentException
Client.NotConnectedException
Callback.onOrderAck(long, long, long, limebrokerage.trading.api.AckOptions)
,
Callback.onOrderReject(long, long, java.lang.String)
public void placeUSOptionsAlgo(long orderId, int quantity, long price, Side side, PositionEffect positionEffect, USOptionsSymbol symbol, java.lang.String route, java.lang.String strategy) throws Client.NotConnectedException
Once placed, the order will either be accepted (designated
by an onOrderAck
callback), or rejected
(designated by an onOrderReject
callback). Note that
you may receive either of these callbacks before the
placeUSOptions
call even returns.
orderId
- client specified identifierquantity
- desired size of tradeprice
- desired price of trade (scaled by PRICE_SCALE
), or MARKET_PRICE
for market
ordersside
- type of tradepositionEffect
- effect of trade on positionsymbol
- contract to be tradedroute
- destination venue marketstrategy
- name of the strategy to executejava.lang.IllegalArgumentException
Client.NotConnectedException
Callback.onOrderAck(long, long, long, limebrokerage.trading.api.AckOptions)
,
Callback.onOrderReject(long, long, java.lang.String)
public void placeUSOptionsAlgo(long orderId, int quantity, long price, Side side, PositionEffect positionEffect, USOptionsSymbol symbol, java.lang.String route, java.lang.String strategy, USOptionsAlgoOrderOptions options) throws Client.NotConnectedException
Once placed, the order will either be accepted (designated
by an onOrderAck
callback), or rejected
(designated by an onOrderReject
callback). Note that
you may receive either of these callbacks before the
placeUSOptions
call even returns.
This method is identical to the version of place
without the options parameter, but allows one to specify
additional special order options.
orderId
- client specified identifierquantity
- desired size of tradeprice
- desired price of trade (scaled by PRICE_SCALE
), or MARKET_PRICE
for market
ordersside
- type of tradepositionEffect
- effect of trade on positionsymbol
- contract to be tradedroute
- destination venue marketstrategy
- name of the strategy to executeoptions
- desired special options (must not be null)java.lang.IllegalArgumentException
Client.NotConnectedException
Callback.onOrderAck(long, long, long, limebrokerage.trading.api.AckOptions)
,
Callback.onOrderReject(long, long, java.lang.String)
public void replace(long originalOrderId, long orderId, int newQuantity, long newPrice) throws Client.NotConnectedException
Replaces logically create a new order with a new order-id. Therefore the request requires both the order-id of the original order, and the desired order-id of the replacement order.
Once placed, the replace will either be accepted
(designated by an onReplaceAck
callback), or
rejected (designated by an onReplaceReject
callback). If the replace is acked, the original order is dead,
and the replacement order is live. If the replace is rejected,
the replacement order is dead, and the original order continues
to be live (if it was live to begin with). Note that you may
receive either of these callbacks before the replace
call even returns.
originalOrderId
- client identifier of order to be replacedorderId
- client identifier of replacement ordernewQuantity
- quantity of replacement order (or SAME_QUANTITY
if unchanged from original)newPrice
- price of replacement order (scaled by PRICE_SCALE
) or SAME_PRICE
if unchanged from originalClient.NotConnectedException
Callback.onReplaceAck(long, long, long, long, limebrokerage.trading.api.AckOptions)
,
Callback.onReplaceReject(long, long, long, java.lang.String)
public void replace(long originalOrderId, long orderId, int newQuantity, long newPrice, ReplaceOptions options) throws Client.NotConnectedException
Replaces logically create a new order with a new order-id. Therefore the request requires both the order-id of the original order, and the desired order-id of the replacement order.
Once placed, the replace will either be accepted
(designated by an onReplaceAck
callback), or
rejected (designated by an onReplaceReject
callback). If the replace is acked, the original order is dead,
and the replacement order is live. If the replace is rejected,
the replacement order is dead, and the original order continues
to be live (if it was live to begin with). Note that you may
receive either of these callbacks before the replace
call even returns.
This method is identical to the version of replace
without the options parameter, but allows one to specify
additional special replace options.
originalOrderId
- client identifier of order to be replacedorderId
- client identifier of replacement ordernewQuantity
- quantity of replacement order (or SAME_QUANTITY
if unchanged from original)newPrice
- price of replacement order (scaled by PRICE_SCALE
) or SAME_PRICE
if unchanged from originaloptions
- special optionsClient.NotConnectedException
Callback.onReplaceAck(long, long, long, long, limebrokerage.trading.api.AckOptions)
,
Callback.onReplaceReject(long, long, long, java.lang.String)
public void replaceUSOptions(long originalOrderId, long orderId, int newQuantity, long newPrice) throws Client.NotConnectedException
Replaces logically create a new order with a new order-id. Therefore the request requires both the order-id of the original order, and the desired order-id of the replacement order.
Once placed, the replace will either be accepted
(designated by an onReplaceAck
callback), or
rejected (designated by an onReplaceReject
callback). If the replace is acked, the original order is dead,
and the replacement order is live. If the replace is rejected,
the replacement order is dead, and the original order continues
to be live (if it was live to begin with). Note that you may
receive either of these callbacks before the replaceUSOptions
call even returns.
originalOrderId
- client identifier of order to be replacedorderId
- client identifier of replacement ordernewQuantity
- quantity of replacement order (or SAME_QUANTITY
if unchanged from original)newPrice
- price of replacement order (scaled by PRICE_SCALE
) or SAME_PRICE
if unchanged from originalClient.NotConnectedException
Callback.onReplaceAck(long, long, long, long, limebrokerage.trading.api.AckOptions)
,
Callback.onReplaceReject(long, long, long, java.lang.String)
public void replaceAlgo(long originalOrderId, long orderId, int newQuantity, long newPrice) throws Client.NotConnectedException
Replaces logically create a new order with a new order-id. Therefore the request requires both the order-id of the original order, and the desired order-id of the replacement order.
Once placed, the replace will either be accepted
(designated by an onReplaceAck
callback), or
rejected (designated by an onReplaceReject
callback). If the replace is acked, the original order is dead,
and the replacement order is live. If the replace is rejected,
the replacement order is dead, and the original order continues
to be live (if it was live to begin with). Note that you may
receive either of these callbacks before the replace
call even returns.
originalOrderId
- client identifier of order to be replacedorderId
- client identifier of replacement ordernewQuantity
- quantity of replacement order (or SAME_QUANTITY
if unchanged from original)newPrice
- price of replacement order (scaled by PRICE_SCALE
) or SAME_PRICE
if unchanged from originalClient.NotConnectedException
Callback.onReplaceAck(long, long, long, long, limebrokerage.trading.api.AckOptions)
,
Callback.onReplaceReject(long, long, long, java.lang.String)
public void replaceAlgo(long originalOrderId, long orderId, int newQuantity, long newPrice, AlgoReplaceOptions options) throws Client.NotConnectedException
Replaces logically create a new order with a new order-id. Therefore the request requires both the order-id of the original order, and the desired order-id of the replacement order.
Once placed, the replace will either be accepted
(designated by an onReplaceAck
callback), or
rejected (designated by an onReplaceReject
callback). If the replace is acked, the original order is dead,
and the replacement order is live. If the replace is rejected,
the replacement order is dead, and the original order continues
to be live (if it was live to begin with). Note that you may
receive either of these callbacks before the replace
call even returns.
This method is identical to the version of replace
without the options parameter, but allows one to specify
additional special replace options.
originalOrderId
- client identifier of order to be replacedorderId
- client identifier of replacement ordernewQuantity
- quantity of replacement order (or SAME_QUANTITY
if unchanged from original)newPrice
- price of replacement order (scaled by PRICE_SCALE
) or SAME_PRICE
if unchanged from originaloptions
- special optionsClient.NotConnectedException
Callback.onReplaceAck(long, long, long, long, limebrokerage.trading.api.AckOptions)
,
Callback.onReplaceReject(long, long, long, java.lang.String)
public void replaceUSOptionsAlgo(long originalOrderId, long orderId, int newQuantity, long newPrice) throws Client.NotConnectedException
Replaces logically create a new order with a new order-id. Therefore the request requires both the order-id of the original order, and the desired order-id of the replacement order.
Once placed, the replace will either be accepted
(designated by an onReplaceAck
callback), or
rejected (designated by an onReplaceReject
callback). If the replace is acked, the original order is dead,
and the replacement order is live. If the replace is rejected,
the replacement order is dead, and the original order continues
to be live (if it was live to begin with). Note that you may
receive either of these callbacks before the replace
call even returns.
originalOrderId
- client identifier of order to be replacedorderId
- client identifier of replacement ordernewQuantity
- quantity of replacement order (or SAME_QUANTITY
if unchanged from original)newPrice
- price of replacement order (scaled by PRICE_SCALE
) or SAME_PRICE
if unchanged from originalClient.NotConnectedException
Callback.onReplaceAck(long, long, long, long, limebrokerage.trading.api.AckOptions)
,
Callback.onReplaceReject(long, long, long, java.lang.String)
public void replaceUSOptionsAlgo(long originalOrderId, long orderId, int newQuantity, long newPrice, USOptionsAlgoReplaceOptions options) throws Client.NotConnectedException
Replaces logically create a new order with a new order-id. Therefore the request requires both the order-id of the original order, and the desired order-id of the replacement order.
Once placed, the replace will either be accepted
(designated by an onReplaceAck
callback), or
rejected (designated by an onReplaceReject
callback). If the replace is acked, the original order is dead,
and the replacement order is live. If the replace is rejected,
the replacement order is dead, and the original order continues
to be live (if it was live to begin with). Note that you may
receive either of these callbacks before the replace
call even returns.
This method is identical to the version of replace
without the options parameter, but allows one to specify
additional special replace options.
originalOrderId
- client identifier of order to be replacedorderId
- client identifier of replacement ordernewQuantity
- quantity of replacement order (or SAME_QUANTITY
if unchanged from original)newPrice
- price of replacement order (scaled by PRICE_SCALE
) or SAME_PRICE
if unchanged from originaloptions
- special optionsClient.NotConnectedException
Callback.onReplaceAck(long, long, long, long, limebrokerage.trading.api.AckOptions)
,
Callback.onReplaceReject(long, long, long, java.lang.String)
public void cancel(long orderId) throws Client.NotConnectedException
onCancelAck
callback), or fail (possibly resulting in a
onCancelReject
callback).orderId
- client identifier of the order to cancelClient.NotConnectedException
Callback.onCancelAck(long, long)
,
Callback.onCancelReject(long, long, java.lang.String)
public void partialCancel(long orderId, int quantityLeft) throws Client.NotConnectedException
onPartialCancelAck
callback), or fail (possibly resulting in a
onCancelReject
callback).orderId
- client identifier of the order to cancelquantityLeft
- quantity to remain openClient.NotConnectedException
Callback.onPartialCancelAck(long, long, int)
,
Callback.onCancelReject(long, long, java.lang.String)
public void cancelAll() throws Client.NotConnectedException
cancel
on every open order (though done
directly on the trading-server).
The cancel requests can fail or succeed on an individual order
basis, so one will receive a sequence of onCancelAck
and possibly onCancelReject
callbacks for every open
order in response to this request.
Securities are offered by Lime Trading Corp., member FINRA & SIPC,NFA. All investing incurs risk, including but not limited to loss of principal. Further information may be found on our Disclosures Page.
Please read the following documents Characteristics and Risks of Standardized Options before trading options.
Options involve risk and are not suitable for all investors as the special risks inherent to options trading may expose investors to potentially rapid and substantial losses. Options trading privileges are subject to Lime Trading Corp. review and approval. Hedging and protective strategies generally involve additional costs and do not assure a profit or guarantee against loss. With long options, investors may lose 100% of funds invested. Covered calls provide income, downside protection only to the extent of the premium received, and limit upside potential to the strike price plus premium received. Multi-leg option orders are not a standard option trade. There is no national best bid or offer for multi-leg orders. Multi-leg trades are executed on the exchanges at the discretion of specialists or market makers, who cannot be held to a net price on a multi-leg order. Therefore, you may not receive the national best bid or offer on each individual leg of an order. Multi-leg orders are executed as a single trade on the same exchange. Legs cannot be executed separately on different exchanges to get the national best bid or offer for each leg. Each individual leg of a multi-leg order can be subject to early exercise risk, possibly taking away the protection that the multi-leg position may provide. Partial or full assignment on a leg may originate a margin call or losses greater than you anticipated when you entered into the position. When a multi-leg order is canceled or filled, additional reporting may be required by the specialist or market maker. Reporting fills and cancels may cause delays and create risks, especially in fast moving markets. Other risks might be associated with multi-leg options trading.