Skip to main content

Getting started

# Inherit from default Listener class to handle updates from the server
class Listener(lb.Listener):
def __init__(self):
self.logged_in = False

def on_login_accepted(self, event_id):
self.logged_in = True

# A helper method to wait on the server response
def waitForCallback(condition) -> bool:
timeout = time.time() + 5 # 5 second timeouts
while True:
if (time.time() > timeout):
return False
if condition():
return True

# create an instance of a class that receives all order updates
listener = Listener()

# create the api proxy implicitly sending login request
api = lb.TradingApi(listener, account, user, password, 0, host, True)

# wait for the login response
if not waitForCallback(lambda : listener.logged_in):
printError("Login failed")
raise Exception("Login failed")
printSuccess("Logged in")

# buy 100 shares of AAPL at 145.21, routing to ARCP
api.place_order(order_id = 1, symbol = "AAPL", quantity = 100, price = 145.21, side = lb.Side.Buy, route = "ARCP")

Lime Python SDK is distributed as a wheel package via Install the package from command line by running pip3 install lime-trading-api --force-reinstall. To get started faster, pull a code example from Make sure you are connected to Lime network as described below and run the example as python -host <host> -a <account> -u <user> -p <password>

To connect to your trading account you need to have the following prerequisites:

  • Established network connectivity to Lime data centers. This can be done in miltiple ways. You can either start a VPN using a desktop application from Cisco that we provide you, or for better latency we can establish a cross connect or IPSEC VPN.
  • We will tell you the IP address and port of a Lime Trading Server
  • Your account name. In FIX world it would be your SenderCompId.
  • Your Lime Direct username and password. These are only used for API connections to Lime Direct

The first thing to do is to create a TradingApi instance passing connection parameters. After instantiation, the object attempts to connect and login automatically.

Listener listeneran instance of a class implementing Listener that will receive order updates
string accounthostname or IP address to connect to
string userusername provided by Lime
string passwordpassword provided by Lime
int event_idlast known event id received from the server.
string host_namehostname or IP address to connect to
bool cancel_on_disconnectTrue if you want Lime to immediately cancel all open orders on this account if this session disconnects

The TradingAPI class uses a Listener in order to provide access to asyncronous events from the server The default Listener interface does not implement any event handlers, to access events you should inherit from Listener and override its methods. Remember to call Listener.__init__ though!