Brokerage
Documentation for Brokerage.
Brokerage.Client.cancelQuote
Brokerage.Client.createPortfolio
Brokerage.Client.createSeveralPortfolios
Brokerage.Client.createUser
Brokerage.Client.deletePortfolio
Brokerage.Client.getActiveBuyOrders
Brokerage.Client.getActiveOrders
Brokerage.Client.getActiveSellOrders
Brokerage.Client.getBidAsk
Brokerage.Client.getBidAskOrders
Brokerage.Client.getBidAskVolume
Brokerage.Client.getBookDepth
Brokerage.Client.getCash
Brokerage.Client.getHoldings
Brokerage.Client.getMarketSchedule
Brokerage.Client.getMidPrice
Brokerage.Client.getPriceSeries
Brokerage.Client.getTradeVolume
Brokerage.Client.hedgeTrade
Brokerage.Client.loginUser
Brokerage.Client.placeCancelOrder
Brokerage.Client.placeLimitOrder
Brokerage.Client.placeMarketOrder
Brokerage.Client.provideLiquidity
Brokerage.Client.cancelQuote
— MethodcancelQuote(ticker::Int, order_id::Int, order_side::String, limit_price::Float64,
acct_id::Int)
Cancel a limit order for a given asset. Intended for use by market makers; the method does not consolidate cash and share balances and is used to track market maker cancellation volume over time.
Arguments
ticker::Int
: the assigned ticker ID of the asset being tradedorder_id::Int
: the assigned ID of the order to be cancelledorder_side::String
: the side of the order, either "BUYORDER" or "SELLORDER"limit_price::Float64
: the limit price of the order to be cancelledacct_id::Int
: the assigned ID of the account placing the order. This ID must be registered as a market maker account (i.e., it must be a number less than or equal to the value of theMM_COUNTER
constant in the Mapper module).
Brokerage.Client.createPortfolio
— MethodcreatePortfolio(name::String, cash::Float64, holdings::Dict{Int64, Int64}) -> Int64
Create a new portfolio with the given name, cash, and holdings.
Arguments
name::String
: the name of the new portfoliocash::Float64
: the amount of cash in the new portfolioholdings::Dict{Int64, Int64}
: the holdings of the new portfolio, mapping asset IDs to the number of shares held. E.g.,Dict(1 => 10, 2 => 12)
means that the portfolio holds 10 shares of asset 1 and 12 shares of asset 2.
Returns
Int64
: the ID of the newly created portfolio
Brokerage.Client.createSeveralPortfolios
— MethodcreateSeveralPortfolios(num_users::Int64, name::String, min_cash::Float64,
max_cash::Float64, min_holdings::Int64, max_holdings::Int64)
Efficient method to create several portfolios. Individual portfolio cash balances and share holdings are randomly drawn using the given maximum and minimum bounds.
Arguments
num_users::Int64
: the number of portfolios to be createdname::String
: the base name of the new portfoliosmin_cash::Float64
: the minimum amount of cash in each new portfoliomax_cash::Float64
: the maximum amount of cash in each new portfoliomin_holdings::Int64
: the minimum number of shares of each asset in each new portfoliomax_holdings::Int64
: the maximum number of shares of each asset in each new portfolio
Brokerage.Client.createUser
— MethodcreateUser(username::String, password::String) -> User
Create a new user with the given username and password.
Arguments
username::String
: the username of the new userpassword::String
: the password of the new user
Returns
User
: the newly created user
Brokerage.Client.deletePortfolio
— MethoddeletePortfolio(id::Int64)
Delete the portfolio with the given ID.
Arguments
id::Int64
: the ID of the portfolio to be deleted
Brokerage.Client.getActiveBuyOrders
— MethodgetActiveBuyOrders(acct_id::Int, ticker::Int)
-> Vector{Tuple{Int64, Order{Int64, Float64, Int64, Int64}}}
Get all open buy orders assigned to a given account for a given asset.
Arguments
acct_id::Int
: the assigned ID of the account whose open buy orders are to be queriedticker::Int
: the assigned ticker ID of the asset whose open buy orders are to be queried
Returns
Vector{Tuple{Int64, Order{Int64, Float64, Int64, Int64}}}
: a vector of tuples, where each tuple contains an order ID and the corresponding buy order (composed of Order Size::Int64, Price::Float64, Order IDs::Int64, Account IDs::Int64).
Brokerage.Client.getActiveOrders
— MethodgetActiveOrders(acct_id::Int, ticker::Int) -> AVLTree{Int64, Order{Int64, Float64, Int64, Int64}}
Get all open orders assigned to a given account for a given asset.
Arguments
acct_id::Int
: the assigned ID of the account whose open orders are to be queriedticker::Int
: the assigned ticker ID of the asset whose open orders are to be queried
Returns
AVLTree{Int64, Order{Int64, Float64, Int64, Int64}}
: an AVL tree mapping order IDs to orders. The AVLTree is an account map where the keys are order IDs and the values are the corresponding orders (composed of Order Size::Int64, Price::Float64, Order IDs::Int64, Account IDs::Int64).
Brokerage.Client.getActiveSellOrders
— MethodgetActiveSellOrders(acct_id::Int, ticker::Int)
-> Vector{Tuple{Int64, Order{Int64, Float64, Int64, Int64}}}
Get all open sell orders assigned to a given account for a given asset.
Arguments
acct_id::Int
: the assigned ID of the account whose open sell orders are to be queriedticker::Int
: the assigned ticker ID of the asset whose open sell orders are to be queried
Returns
Vector{Tuple{Int64, Order{Int64, Float64, Int64, Int64}}}
: a vector of tuples, where each tuple contains an order ID and the corresponding sell order (composed of Order Size::Int64, Price::Float64, Order IDs::Int64, Account IDs::Int64).
Brokerage.Client.getBidAsk
— MethodgetBidAsk(ticker::Int) -> Tuple{Float64, Float64}
Get the best bid and ask prices in the order book for a given asset.
Arguments
ticker::Int
: the assigned ticker ID of the asset whose order book is to be queried
Returns
Tuple{Float64, Float64}
: a tuple of the best bid and ask prices in the order book, where the first element is the best bid price and the second element is the best ask
Brokerage.Client.getBidAskOrders
— MethodgetBidAskOrders(ticker::Int) -> Tuple{Int32, Int32}
Get the total number of orders on each side of the order book for a given asset.
Arguments
ticker::Int
: the assigned ticker ID of the asset whose order book is to be queried
Returns
Tuple{Int32, Int32}
: a tuple of the total number of orders on each side of the order book, where the first element is the total number of buy orders and the second element is the total number of sell orders
Brokerage.Client.getBidAskVolume
— MethodgetBidAskVolume(ticker::Int) -> Tuple{Int64, Int64}
Get the total bid and ask volume in the order book for a given asset.
Arguments
ticker::Int
: the assigned ticker ID of the asset whose order book is to be queried
Returns
Tuple{Int64, Int64}
: a tuple of the total bid and ask volume in the order book, where the first element is the total bid volume and the second element is the total ask volume
Brokerage.Client.getBookDepth
— MethodgetBookDepth(ticker::Int) -> Dict{Symbol, Dict{Symbol, Any}}
Get the order book depth for a given asset.
Arguments
ticker::Int
: the assigned ticker ID of the asset whose order book is to be queried
Returns
Dict{Symbol, Dict{Symbol, Any}}
: a nested dictionary of prices, volumes, and order counts up to a depth of 5 price levels
Brokerage.Client.getCash
— MethodgetCash(id::Int64) -> Float64
Get the cash balance of the portfolio with the given ID.
Arguments
id::Int64
: the ID of the portfolio whose cash balance is to be retrieved
Returns
Float64
: the cash balance of the portfolio
Brokerage.Client.getHoldings
— MethodgetHoldings(id::Int64) -> NamedTuple
Get the holdings of the portfolio with the given ID.
Arguments
id::Int64
: the ID of the portfolio whose holdings are to be retrieved
Returns
NamedTuple
: a named tuple mapping asset IDs to the number of shares held. E.g.,NamedTuple(1 = 10, 2 = 12)
means that the portfolio holds 10 shares of asset 1 and 12 shares of asset 2.
Brokerage.Client.getMarketSchedule
— MethodgetMarketSchedule() -> Tuple{DateTime, DateTime}
Get the market open and close times.
Returns
Tuple{DateTime, DateTime}
: a tuple of the market open and close times
Brokerage.Client.getMidPrice
— MethodgetMidPrice(ticker::Int) -> Float64
Get the mid price of the order book for a given asset.
Arguments
ticker::Int
: the assigned ticker ID of the asset whose order book is to be queried
Returns
Float64
: the mid price of the order book (the average of the best bid and best ask prices)
Brokerage.Client.getPriceSeries
— MethodgetPriceSeries(ticker::Int) -> Vector{Float64}
Get the price series for a given asset. The price series vector is maintained as a CircularBuffer, where the most recent price is at the end of the vector. The length of the vector is determined by the PRICE_BUFFER_CAPACITY
constant in the OMS module.
Arguments
ticker::Int
: the assigned ticker ID of the asset whose price series is to be queried
Returns
Vector{Float64}
: a vector of the price series for the given asset
Brokerage.Client.getTradeVolume
— MethodgetTradeVolume(ticker::Int) -> Int64
Get the total trading volume for a given asset.
Arguments
ticker::Int
: the assigned ticker ID of the asset whose trading volume is to be queried
Returns
Int64
: the total trading volume for the given asset
Brokerage.Client.hedgeTrade
— MethodhedgeTrade(ticker::Int, order_side::String, fill_amount::Int, acct_id::Int)
Hedge a trade for a given asset. This method allows a market maker to place a market order on the order book without having a corresponding cash balance or share holding.
Arguments
ticker::Int
: the assigned ticker ID of the asset being tradedorder_side::String
: the side of the order, either "BUYORDER" or "SELLORDER"fill_amount::Int
: the number of shares to be tradedacct_id::Int
: the assigned ID of the account placing the order. This ID must be registered as a market maker account (i.e., it must be a number less than or equal to the value of theMM_COUNTER
constant in the Mapper module).
Brokerage.Client.loginUser
— MethodloginUser(username::String, password::String) -> User
Login an existing user with the given username and password.
Arguments
username::String
: the username of the user to be logged inpassword::String
: the password of the user to be logged in
Returns
User
: the logged in user
Brokerage.Client.placeCancelOrder
— MethodplaceCancelOrder(ticker::Int, order_id::Int, order_side::String, limit_price::Float64,
acct_id::Int)
Place a cancel order for a given asset and given limit order.
Arguments
ticker::Int
: the assigned ticker ID of the asset being tradedorder_id::Int
: the assigned ID of the order to be cancelledorder_side::String
: the side of the order, either "BUYORDER" or "SELLORDER"limit_price::Float64
: the limit price of the order to be cancelledacct_id::Int
: the assigned ID of the account placing the order
Brokerage.Client.placeLimitOrder
— MethodplaceLimitOrder(ticker::Int, order_side::String, limit_price::Float64, limit_size::Int,
acct_id::Int)
Place a limit order for a given asset.
Arguments
ticker::Int
: the assigned ticker ID of the asset being tradedorder_side::String
: the side of the order, either "BUYORDER" or "SELLORDER"limit_price::Float64
: the price at which the order will be executedlimit_size::Int
: the number of shares to be tradedacct_id::Int
: the assigned ID of the account placing the order
Brokerage.Client.placeMarketOrder
— MethodplaceMarketOrder(ticker::Int, order_side::String, fill_amount::Int, acct_id::Int;
byfunds::Bool=false)
Place a market order for a given asset.
Arguments
ticker::Int
: the assigned ticker ID of the asset being tradedorder_side::String
: the side of the order, either "BUYORDER" or "SELLORDER"fill_amount::Int
: the number of shares to be tradedacct_id::Int
: the assigned ID of the account placing the order
Keywords
byfunds::Bool=false
: if true, thefill_amount
is interpreted as a dollar amount of funds to be spent on the order. If false, thefill_amount
is interpreted as a number of shares to be traded.
Brokerage.Client.provideLiquidity
— MethodprovideLiquidity(ticker::Int, order_side::String, limit_price::Float64, limit_size::Int,
acct_id::Int; send_id::Bool=false) -> Int64 if send_id else nothing
Provide liquidity to the order book for a given asset. This method allows a market maker to place a limit order on the order book without having a corresponding cash balance or share holding. Each order is assigned a unique ID, which is returned by this method if the keyword argument send_id
is set to true
.
Arguments
ticker::Int
: the assigned ticker ID of the asset being tradedorder_side::String
: the side of the order, either "BUYORDER" or "SELLORDER"limit_price::Float64
: the price at which the order will be executedlimit_size::Int
: the number of shares to be tradedacct_id::Int
: the assigned ID of the account placing the order. This ID must be registered as a market maker account (i.e., it must be a number less than or equal to the value of theMM_COUNTER
constant in the Mapper module).
Keywords
send_id::Bool=false
: if true, the ID of the order is returned by this method. If false, nothing is returned.
Returns
Int64
: the ID of the order ifsend_id
istrue