Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import 'dotenv/config';
import Binance from 'binance-api-node';
/* Authenticated client, can make signed calls */
export const client = Binance({
apiKey: process.env.API_KEY,
apiSecret: process.env.API_SECRET,
});
/* Public REST Endpoints */
// Get the current exchange trading rules and symbol information.
export const exchangeInfo = client.exchangeInfo();
// Get the order book for a symbol.
export const book = (symbol, limit = 5) => client
.book({ symbol, limit })
.then(res => res)
.catch(error => error);
// Retrieves Candlestick for a symbol. Candlesticks are uniquely identified by their open time.
export const candles = (symbol, interval = '1h', limit = 500) => client
.candles({ symbol, interval, limit })
throw result.error;
}
const { pair, cancelPrice, nonBnbFees } = options;
let {
amount,
buyPrice,
buyLimitPrice,
stopPrice,
stopLimitPrice,
targetPrice,
scaleOutAmount
} = options;
const binance = Binance({
apiKey: process.env.APIKEY || "",
apiSecret: process.env.APISECRET || ""
});
let isCancelling = false;
const cancelOrderAsync = async (
symbol: string,
orderId: number
): Promise => {
if (!isCancelling) {
isCancelling = true;
try {
const response = await binance.cancelOrder({ symbol, orderId });
debug("Cancel response: %o", response);
startListening (): void {
const client = BinanceApi()
client.ws.trades(['BTCUSDT'], trade => this.onPriceUpdate('BTCUSDT', Number(trade.price)))
}