ATS
An algorithmic trading system completely written in C++
Public Member Functions | List of all members
ats::BinanceExchangeManager Class Reference

The BinanceExchangeManager class is a class that defines the interface for managing orders on the Binance exchange. More...

#include <BinanceExchangeManager.h>

Inheritance diagram for ats::BinanceExchangeManager:
ats::ExchangeManager

Public Member Functions

 BinanceExchangeManager (OrderManager &orderManager, bool isSimulation=true, time_t updateInterval=1, std::string apiKey="", std::string secretKey="")
 Constructor for BinanceExchangeManager class. More...
 
 ~BinanceExchangeManager ()
 Destructor for BinanceExchangeManager class.
 
void start ()
 Start the BinanceExchangeManager thread.
 
void run ()
 The BinanceExchangeManager processing function.
 
void stop ()
 Stop the BinanceExchangeManager thread.
 
bool isRunning ()
 Check if the BinanceExchangeManager thread is running. More...
 
bool isSimulation ()
 Check if the EMS is connected to the test network. More...
 
void updateOpenOrders ()
 Update open orders on the local OMS.
 
double sendOrder (Order &order) override
 Send an order to the Binance exchange. More...
 
void modifyOrder (Order &oldOrder, Order &newOrder) override
 Modify an existing order on the Binance exchange. More...
 
void cancelOrder (long orderId, std::string symbol)
 Cancel an existing order on the Binance exchange. More...
 
void cancelOrder (Order &order) override
 Cancel an existing order on the Binance exchange. More...
 
void getOrderStatus (Order &order, Json::Value &result) override
 Gets the status of the given order. More...
 
std::vector< OrdergetOpenOrders (std::string symbol="") override
 Gets all open orders for the current user. More...
 
std::vector< TradegetTradeHistory (std::string symbol) override
 Gets the trade history for the specified symbol. More...
 
double getPrice (std::string symbol) override
 Gets the current price for the specified symbol. More...
 
void getKlines (Json::Value &result, std::string symbol, std::string interval, time_t start_date=0, time_t end_date=0, int limit=500) override
 Gets Klines for a symbol. More...
 
Order jsonToOrder (Json::Value &result)
 Converts a JSON object to an Order object. More...
 
Trade jsonToTrade (Json::Value &result)
 Converts a JSON object to a Trade object. More...
 
void getUserInfo (Json::Value &result)
 Gets the current user's information. More...
 
std::map< std::string, double > getBalances () override
 Gets user's balances. More...
 
virtual OrderBook getOrderBook (std::string symbol) override
 Retrieves the order book. More...
 
- Public Member Functions inherited from ats::ExchangeManager
 ExchangeManager (OrderManager &oms)
 Constructor for ExchangeManager class. More...
 
virtual ~ExchangeManager ()=default
 Virtual destructor for ExchangeManager class.
 

Additional Inherited Members

- Protected Attributes inherited from ats::ExchangeManager
OrderManagermOrderManager
 

Detailed Description

The BinanceExchangeManager class is a class that defines the interface for managing orders on the Binance exchange.

Constructor & Destructor Documentation

◆ BinanceExchangeManager()

ats::BinanceExchangeManager::BinanceExchangeManager ( OrderManager orderManager,
bool  isSimulation = true,
time_t  updateInterval = 1,
std::string  apiKey = "",
std::string  secretKey = "" 
)
explicit

Constructor for BinanceExchangeManager class.

Parameters
orderManagerReference to the OrderManager object.
isSimulationA boolean indicating whether the exchange is a simulation or not.
updateIntervalOpen orders update period.
api_keyThe API key for the Binance exchange account.
secret_keyThe secret key for the Binance exchange account.

Member Function Documentation

◆ cancelOrder() [1/2]

void ats::BinanceExchangeManager::cancelOrder ( long  orderId,
std::string  symbol 
)

Cancel an existing order on the Binance exchange.

Parameters
orderIdThe orderId of the order to cancel.
symbolThe symbol of the order to cancel.

◆ cancelOrder() [2/2]

void ats::BinanceExchangeManager::cancelOrder ( Order order)
overridevirtual

Cancel an existing order on the Binance exchange.

Parameters
orderThe Order to be cancelled.

Implements ats::ExchangeManager.

◆ getBalances()

std::map< std::string, double > ats::BinanceExchangeManager::getBalances ( )
overridevirtual

Gets user's balances.

Returns
Map of pairs {asset, Qty}.

Implements ats::ExchangeManager.

◆ getKlines()

void ats::BinanceExchangeManager::getKlines ( Json::Value &  result,
std::string  symbol,
std::string  interval,
time_t  start_date = 0,
time_t  end_date = 0,
int  limit = 500 
)
overridevirtual

Gets Klines for a symbol.

Parameters
resultJson object to write the response to
symbolSymbol to get the Klines for
intervalKline interval
start_dateStart date
end_dateEnd date
limitLimit, should be less than or equal to 1000

Implements ats::ExchangeManager.

◆ getOpenOrders()

std::vector< Order > ats::BinanceExchangeManager::getOpenOrders ( std::string  symbol = "")
overridevirtual

Gets all open orders for the current user.

Parameters
symbolThe symbol to retrieve the orders for, all open orders if omitted.
Returns
A vector of all open orders.

Implements ats::ExchangeManager.

◆ getOrderBook()

OrderBook ats::BinanceExchangeManager::getOrderBook ( std::string  symbol)
overridevirtual

Retrieves the order book.

Parameters
symbolThe symbol to retrieve the order book for.
Returns
The bid and ask vectors.

Implements ats::ExchangeManager.

◆ getOrderStatus()

void ats::BinanceExchangeManager::getOrderStatus ( Order order,
Json::Value &  result 
)
overridevirtual

Gets the status of the given order.

Parameters
orderThe order to check the status of.
resultThe JSON object containing the result of the operation.

Implements ats::ExchangeManager.

◆ getPrice()

double ats::BinanceExchangeManager::getPrice ( std::string  symbol)
overridevirtual

Gets the current price for the specified symbol.

Parameters
symbolThe symbol to get the price for.
Returns
The current price for the specified symbol.

Implements ats::ExchangeManager.

◆ getTradeHistory()

std::vector< Trade > ats::BinanceExchangeManager::getTradeHistory ( std::string  symbol)
overridevirtual

Gets the trade history for the specified symbol.

Parameters
symbolThe symbol to get the trade history for.
Returns
A vector of all trades for the specified symbol.

Implements ats::ExchangeManager.

◆ getUserInfo()

void ats::BinanceExchangeManager::getUserInfo ( Json::Value &  result)

Gets the current user's information.

Parameters
resultThe JSON object containing the result of the operation.

◆ isRunning()

bool ats::BinanceExchangeManager::isRunning ( )

Check if the BinanceExchangeManager thread is running.

Returns
A boolean indicating whether the BinanceExchangeManager thread is running or not.

◆ isSimulation()

bool ats::BinanceExchangeManager::isSimulation ( )

Check if the EMS is connected to the test network.

Returns
A boolean indicating whether the EMS is connected to the test network.

◆ jsonToOrder()

Order ats::BinanceExchangeManager::jsonToOrder ( Json::Value &  result)

Converts a JSON object to an Order object.

Parameters
resultThe JSON object to convert.
Returns
An Order object created from the JSON object.

◆ jsonToTrade()

Trade ats::BinanceExchangeManager::jsonToTrade ( Json::Value &  result)

Converts a JSON object to a Trade object.

Parameters
resultThe JSON object to convert.
Returns
A Trade object created from the JSON object.

◆ modifyOrder()

void ats::BinanceExchangeManager::modifyOrder ( Order oldOrder,
Order newOrder 
)
overridevirtual

Modify an existing order on the Binance exchange.

Parameters
oldOrderThe old Order object to be modified.
newOrderThe new Order object.

Implements ats::ExchangeManager.

◆ sendOrder()

double ats::BinanceExchangeManager::sendOrder ( Order order)
overridevirtual

Send an order to the Binance exchange.

Parameters
orderThe Order object to be sent.
Returns
Filled quantity.

Implements ats::ExchangeManager.


The documentation for this class was generated from the following files: