[#22] Handle order update ws events
This commit is contained in:
parent
2c13099a2c
commit
1085c58ebc
@ -80,6 +80,9 @@ export default class BinanceApiClient extends APIClient {
|
|||||||
case BinanceWSEvent.TRADE_EVENT:
|
case BinanceWSEvent.TRADE_EVENT:
|
||||||
this.#fireTradeEvent(data);
|
this.#fireTradeEvent(data);
|
||||||
break;
|
break;
|
||||||
|
case BinanceWSEvent.EXECUTION_REPORT:
|
||||||
|
this.#requestOrderUpdate(data.orderId, data.originalClientOrderId, data.symbol);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
this.getLogger().warn("Unknown event type!", data);
|
this.getLogger().warn("Unknown event type!", data);
|
||||||
}
|
}
|
||||||
@ -328,35 +331,42 @@ export default class BinanceApiClient extends APIClient {
|
|||||||
*/
|
*/
|
||||||
requestTransactionUpdate(transaction, type = "buy"){
|
requestTransactionUpdate(transaction, type = "buy"){
|
||||||
const id = type == "buy" ? transaction.buySettings.apiID : transaction.sellSettings.apiID;
|
const id = type == "buy" ? transaction.buySettings.apiID : transaction.sellSettings.apiID;
|
||||||
|
this.#requestOrderUpdate(id, transaction.id, transaction.symbol.getKey());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {string} orderId
|
||||||
|
* @param {string} clientId
|
||||||
|
* @param {string} symbol
|
||||||
|
*/
|
||||||
|
#requestOrderUpdate(orderId, clientId, symbol){
|
||||||
this.#restClient.getOrder({
|
this.#restClient.getOrder({
|
||||||
"symbol": transaction.symbol.getKey(),
|
"symbol": symbol,
|
||||||
"orderId": id,
|
"orderId": orderId,
|
||||||
"origClientOrderId": transaction.id
|
"origClientOrderId": clientId,
|
||||||
}).then(resp => {
|
}).then(resp => {
|
||||||
const event = new TransactionUpdateEvent(resp.clientOrderId, resp.orderId, resp.status, resp.updateTime);
|
const event = new TransactionUpdateEvent(resp.clientOrderId, resp.orderId, resp.status, resp.updateTime);
|
||||||
this.#requestTransactionFills(transaction, type, event);
|
this.#requestTransactionFills(orderId, clientId, symbol, event);
|
||||||
}).catch(e => {
|
}).catch(e => {
|
||||||
this.getLogger().error("Unable to get order status for " + transaction.id, {code: e.code, msg: e.message, url: e.requestUrl});
|
this.getLogger().error("Unable to get order status for " + clientId + "(" + orderId + ")", {code: e.code, msg: e.message, url: e.requestUrl});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {Transaction} transaction
|
* @param {string} orderId
|
||||||
* @param {"buy" | "sell"} type
|
* @param {string} clientId
|
||||||
|
* @param {string} symbol
|
||||||
* @param {TransactionUpdateEvent} event
|
* @param {TransactionUpdateEvent} event
|
||||||
*/
|
*/
|
||||||
#requestTransactionFills(transaction, type, event){
|
#requestTransactionFills(orderId, clientId, symbol, event){
|
||||||
const id = type == "buy" ? transaction.buySettings.apiID : transaction.sellSettings.apiID;
|
|
||||||
|
|
||||||
this.#restClient.getAccountTradeList({
|
this.#restClient.getAccountTradeList({
|
||||||
"symbol": transaction.symbol.getKey(),
|
"symbol": symbol,
|
||||||
"orderId": id,
|
"orderId": orderId,
|
||||||
}).then(resp => {
|
}).then(resp => {
|
||||||
resp.forEach(trade => event.fills.push(new TransactionFill(trade.price, trade.qty)));
|
resp.forEach(trade => event.fills.push(new TransactionFill(trade.price, trade.qty)));
|
||||||
this.dispatchAccountEvent(event);
|
this.dispatchAccountEvent(event);
|
||||||
}).catch(e => {
|
}).catch(e => {
|
||||||
this.getLogger().error("Unable to get order fills for " + transaction.id, {code: e.code, msg: e.message, url: e.requestUrl});
|
this.getLogger().error("Unable to get order fills for " + clientId + "(" + orderId + ")", {code: e.code, msg: e.message, url: e.requestUrl});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user