Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release v3.4.1 #160

Merged
merged 1 commit into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 3.4.1 - 2024-08-19
### Updated
- Updated dependencies
- Upgraded deprecated spot endpoint `POST /api/v3/order/oco` to `POST /api/v3/orderList/oco`
- Upgraded deprecated Websocket API endpoint `orderList.place` to `orderList.place.oco`

## 3.4.0 - 2024-06-19
### Changed
- Updated dependencies
Expand Down
23 changes: 13 additions & 10 deletions __tests__/spot/trade/newOCOOrder.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,51 +11,54 @@ const {
symbol,
side,
quantity,
price,
stopPrice
aboveType,
belowType
} = require('../../testUtils/mockData')

describe('#newOCOOrder', () => {
describe('throw MissingParameterError', () => {
it('missing symbol', () => {
expect(() => {
SpotClient.newOCOOrder('', side, quantity, price, stopPrice)
SpotClient.newOCOOrder('', side, quantity, aboveType, belowType)
}).toThrow(MissingParameterError)
})

it('missing side', () => {
expect(() => {
SpotClient.newOCOOrder(symbol, '', quantity, price, stopPrice)
SpotClient.newOCOOrder(symbol, '', quantity, aboveType, belowType)
}).toThrow(MissingParameterError)
})

it('missing quantity', () => {
expect(() => {
SpotClient.newOCOOrder(symbol, side, '', price, stopPrice)
SpotClient.newOCOOrder(symbol, side, '', aboveType, belowType)
}).toThrow(MissingParameterError)
})

it('missing price', () => {
expect(() => {
SpotClient.newOCOOrder(symbol, side, quantity, '', stopPrice)
SpotClient.newOCOOrder(symbol, side, quantity, '', belowType)
}).toThrow(MissingParameterError)
})

it('missing stopPrice', () => {
expect(() => {
SpotClient.newOCOOrder(symbol, side, quantity, price, '')
SpotClient.newOCOOrder(symbol, side, quantity, aboveType, '')
}).toThrow(MissingParameterError)
})
})

it('should return new oco order', () => {
const parameters = {
limitClientOrderId: 'my_order_id',
limitIcebergQty: 1
abovePrice: 530,
belowPrice: 520,
belowStopPrice: 519,
belowTimeInForce: 'GTC'
}
nockPostMock(`/api/v3/order/oco?${buildQueryString({ symbol, side, quantity, price, stopPrice, ...parameters })}`)(mockResponse)
nockPostMock(`/api/v3/orderList/oco?${buildQueryString({ symbol, side, quantity, aboveType, belowType, ...parameters })}`)(mockResponse)

return SpotClient.newOCOOrder(symbol, side, quantity, price, stopPrice, parameters).then(response => {
return SpotClient.newOCOOrder(symbol, side, quantity, aboveType, belowType, parameters).then(response => {
expect(response).toBeDefined()
expect(response.data).toEqual(mockResponse)
})
Expand Down
2 changes: 2 additions & 0 deletions __tests__/testUtils/mockData.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ const mockResponse = {

module.exports = {
mockResponse,
aboveType: 'LIMIT_MAKER',
amount: 10,
asset: 'BNB',
belowType: 'STOP_LOSS_LIMIT',
coin: 'BNB',
collateralCoin: 'BUSD',
email: '[email protected]',
Expand Down
9 changes: 5 additions & 4 deletions examples/spot/trade/newOCOOrder.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ const apiKey = ''
const apiSecret = ''
const client = new Spot(apiKey, apiSecret, { baseURL: 'https://testnet.binance.vision' })

client.newOCOOrder('BNBUSDT', 'BUY', 1, 10, 12, {
listClientOrderId: 'my_oco_order',
stopLimitPrice: 13,
stopLimitTimeInForce: 'GTC'
client.newOCOOrder('BNBUSDT', 'SELL', 1, 'LIMIT_MAKER', 'STOP_LOSS_LIMIT', {
abovePrice: 530,
belowPrice: 520,
belowStopPrice: 519,
belowTimeInForce: 'GTC'
}).then(response => client.logger.log(response.data))
.catch(error => client.logger.error(error))
10 changes: 5 additions & 5 deletions examples/websocketAPI/spot/trade/newOCOOrder.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ const wsURL = 'wss://ws-api.testnet.binance.vision/ws-api/v3' // we setup wsURL
const callbacks = {
open: (client) => {
logger.debug('Connected with Websocket server')
client.newOCOOrder('BNBUSDT', 'BUY', 300, 0.1, {
client.newOCOOrder('BNBUSDT', 'SELL', 1, 'LIMIT_MAKER', 'STOP_LOSS_LIMIT', {
listClientOrderId: 'my_list_order',
stopPrice: 330,
stopLimitPrice: 340,
stopLimitTimeInForce: 'GTC',
newOrderRespType: 'FULL'
abovePrice: 530,
belowPrice: 520,
belowStopPrice: 519,
belowTimeInForce: 'GTC'
})
},
close: () => logger.debug('Disconnected with Websocket server'),
Expand Down
20 changes: 10 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@binance/connector",
"version": "3.4.0",
"version": "3.4.1",
"description": "This is a lightweight library that works as a connector to the Binance public API.",
"main": "src/index.js",
"scripts": {
Expand Down Expand Up @@ -44,7 +44,7 @@
"src/**/*"
],
"dependencies": {
"axios": "^1.6",
"axios": "^1.7.4",
"ws": "^8.17.1"
},
"jest": {
Expand Down
46 changes: 26 additions & 20 deletions src/modules/restful/trade.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,45 +252,51 @@ const Trade = superclass => class extends superclass {
}

/**
* New OCO (TRADE)<br>
* New Order List - OCO (TRADE)<br>
*
* POST /api/v3/order/oco<br>
* POST /api/v3/orderList/oco<br>
*
* {@link https://binance-docs.github.io/apidocs/spot/en/#new-oco-trade}
*
* @param {string} symbol
* @param {string} side
* @param {number} quantity
* @param {number} price
* @param {number} stopPrice
* @param {string} aboveType
* @param {string} belowType
* @param {object} [options]
* @param {string} [options.listClientOrderId]
* @param {string} [options.limitClientOrderId]
* @param {number} [options.limitStrategyId]
* @param {number} [options.limitStrategytype] - The value cannot be less than 1000000.
* @param {number} [options.limitIcebergQty]
* @param {number} [options.trailingDelta]
* @param {string} [options.stopClientOrderId]
* @param {number} [options.stopStrategyId]
* @param {number} [options.stopStrategytype] - The value cannot be less than 1000000.
* @param {number} [options.stopLimitPrice]
* @param {number} [options.stopIcebergQty]
* @param {string} [options.stopLimitTimeInForce]
* @param {string} [options.aboveClientOrderId]
* @param {number} [options.aboveIcebergQty]
* @param {number} [options.abovePrice]
* @param {number} [options.aboveStopPrice]
* @param {number} [options.aboveTrailingDelta]
* @param {number} [options.aboveTimeInForce]
* @param {number} [options.aboveStrategyId]
* @param {number} [options.aboveStrategyType]
* @param {string} [options.belowClientOrderId]
* @param {number} [options.belowIcebergQty]
* @param {number} [options.belowPrice]
* @param {number} [options.belowStopPrice]
* @param {number} [options.belowTrailingDelta]
* @param {string} [options.belowTimeInForce]
* @param {number} [options.belowStrategyId]
* @param {number} [options.belowStrategyType]
* @param {string} [options.newOrderRespType]
* @param {string} [options.selfTradePreventionMode]
* @param {number} [options.recvWindow] - The value cannot be greater than 60000
*/
newOCOOrder (symbol, side, quantity, price, stopPrice, options = {}) {
validateRequiredParameters({ symbol, side, quantity, price, stopPrice })
newOCOOrder (symbol, side, quantity, aboveType, belowType, options = {}) {
validateRequiredParameters({ symbol, side, quantity, aboveType, belowType })

return this.signRequest(
'POST',
'/api/v3/order/oco',
'/api/v3/orderList/oco',
Object.assign(options, {
symbol: symbol.toUpperCase(),
side: side.toUpperCase(),
quantity,
price,
stopPrice
aboveType,
belowType
})
)
}
Expand Down
46 changes: 26 additions & 20 deletions src/modules/websocket/api/trade.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,41 +199,47 @@ const Trade = superclass => class extends superclass {
}

/**
* Place new OCO< br>
* Place new Order list< br>
*
* Send in a new OCO order.<br>
*
* {@link https://binance-docs.github.io/apidocs/websocket_api/en/#place-new-oco-trade}
*
* @param {string} symbol
* @param {string} side
* @param {number} price
* @param {number} quantity
* @param {string} aboveType
* @param {string} belowType
* @param {object} [options]
* @param {string} [options.listClientOrderId]
* @param {string} [options.limitClientOrderId]
* @param {number} [options.limitIcebergQty]
* @param {number} [options.limitStrategyId]
* @param {number} [options.limitStrategyType]
* @param {number} [options.stopPrice]
* @param {number} [options.trailingDelta]
* @param {number} [options.stopClientOrderId]
* @param {number} [options.stopLimitPrice]
* @param {string} [options.stopLimitTimeInForce]
* @param {number} [options.stopIcebergQty]
* @param {number} [options.stopStrategyId]
* @param {string} [options.stopStrategyType]
* @param {number} [options.newOrderRespType]
* @param {number} [options.selfTradePreventionMode]
* @param {number} [options.recvWindow]
* @param {string} [options.aboveClientOrderId]
* @param {number} [options.aboveIcebergQty]
* @param {number} [options.abovePrice]
* @param {number} [options.aboveStopPrice]
* @param {number} [options.aboveTrailingDelta]
* @param {number} [options.aboveTimeInForce]
* @param {number} [options.aboveStrategyId]
* @param {number} [options.aboveStrategyType]
* @param {string} [options.belowClientOrderId]
* @param {number} [options.belowIcebergQty]
* @param {number} [options.belowPrice]
* @param {number} [options.belowStopPrice]
* @param {number} [options.belowTrailingDelta]
* @param {string} [options.belowTimeInForce]
* @param {number} [options.belowStrategyId]
* @param {number} [options.belowStrategyType]
* @param {string} [options.newOrderRespType]
* @param {string} [options.selfTradePreventionMode]
* @param {number} [options.recvWindow] - The value cannot be greater than 60000
*
*/
newOCOOrder (symbol, side, price, quantity, options = {}) {
this.sendSignatureMessage('orderList.place', {
newOCOOrder (symbol, side, quantity, aboveType, belowType, options = {}) {
this.sendSignatureMessage('orderList.place.oco', {
symbol,
side,
price,
quantity,
aboveType,
belowType,
...options
})
}
Expand Down
Loading