@@ -785,7 +785,7 @@ export default class Binance {
785785 * @see https://developers.binance.com/docs/binance-spot-api-docs/rest-api/trading-endpoints#new-order-trade
786786 * @see https://developers.binance.com/docs/binance-spot-api-docs/rest-api/public-api-endpoints#test-new-order-trade
787787 * @see https://developers.binance.com/docs/binance-spot-api-docs/rest-api/trading-endpoints#new-order-list---oco-trade
788- * @param {OrderType } type - LIMIT, MARKET, STOP_LOSS, STOP_LOSS_LIMIT, TAKE_PROFIT, TAKE_PROFIT_LIMIT, LIMIT_MAKER
788+ * @param {OrderType } type - LIMIT, MARKET, STOP_LOSS, STOP_LOSS_LIMIT, TAKE_PROFIT, TAKE_PROFIT_LIMIT, LIMIT_MAKER, OCO
789789 * @param {OrderSide } side - BUY or SELL
790790 * @param {string } symbol - The symbol to buy or sell
791791 * @param {string } quantity - The quantity to buy or sell
@@ -797,52 +797,50 @@ export default class Binance {
797797 * @return {undefined }
798798 */
799799 async order ( type : OrderType , side : OrderSide , symbol : string , quantity : number , price ?: number , params : Dict = { } ) : Promise < Order > {
800- let endpoint = params . type === 'OCO' ? 'v3/orderList/oco' : 'v3/order' ;
800+ const isOCO = type === 'OCO' || params . type === 'OCO' ;
801+ let endpoint = isOCO ? 'v3/orderList/oco' : 'v3/order' ;
801802 if ( params . test ) {
802803 delete params . test ;
803804 endpoint += '/test' ;
804805 }
805806 const request = {
806807 symbol : symbol ,
807808 side : side ,
808- type : type
809+ // type: type
809810 } as Dict ;
811+ if ( ! isOCO ) request . type = type ;
810812 if ( params . quoteOrderQty && params . quoteOrderQty > 0 )
811813 request . quoteOrderQty = params . quoteOrderQty ;
812814 else
813815 request . quantity = quantity ;
814816
815- if ( request . type . includes ( 'LIMIT' ) ) {
817+ if ( ! isOCO && request . type . includes ( 'LIMIT' ) ) {
816818 request . price = price ;
817819 if ( request . type !== 'LIMIT_MAKER' ) {
818820 request . timeInForce = 'GTC' ;
819821 }
820822 }
821- if ( request . type == 'MARKET' && typeof params . quoteOrderQty !== 'undefined' ) {
823+ if ( ! isOCO && request . type == 'MARKET' && typeof params . quoteOrderQty !== 'undefined' ) {
822824 request . quoteOrderQty = params . quoteOrderQty ;
823825 delete request . quantity ;
824826 }
825- if ( request . type === 'OCO' ) {
826- request . price = price ;
827- request . stopLimitPrice = params . stopLimitPrice ;
828- request . stopLimitTimeInForce = 'GTC' ;
829- delete request . type ;
830- // if (typeof params.listClientOrderId !== 'undefined') opt.listClientOrderId = params.listClientOrderId;
831- // if (typeof params.limitClientOrderId !== 'undefined') opt.limitClientOrderId = params.limitClientOrderId;
832- // if (typeof params.stopClientOrderId !== 'undefined') opt.stopClientOrderId = params.stopClientOrderId;
833- }
834827 // if (typeof params.timeInForce !== 'undefined') opt.timeInForce = params.timeInForce;
835828 // if (typeof params.newOrderRespType !== 'undefined') opt.newOrderRespType = params.newOrderRespType;
836- if ( ! params . newClientOrderId ) {
837- request . newClientOrderId = this . SPOT_PREFIX + this . uuid22 ( ) ;
829+ if ( ! params . newClientOrderId && ! params . listClientOrderId ) {
830+ const id = this . SPOT_PREFIX + this . uuid22 ( ) ;
831+ if ( ! isOCO ) {
832+ request . newClientOrderId = id ;
833+ } else {
834+ request . listClientOrderId = id ;
835+ }
838836 }
839837
840- const allowedTypesForStopAndTrailing = [ 'STOP_LOSS' , 'STOP_LOSS_LIMIT' , 'TAKE_PROFIT' , 'TAKE_PROFIT_LIMIT' ] ;
838+ const allowedTypesForStopAndTrailing = [ 'STOP_LOSS' , 'STOP_LOSS_LIMIT' , 'TAKE_PROFIT' , 'TAKE_PROFIT_LIMIT' , 'OCO' ] ;
841839 if ( params . trailingDelta ) {
842840 request . trailingDelta = params . trailingDelta ;
843841
844- if ( ! allowedTypesForStopAndTrailing . includes ( request . type ) ) {
845- throw Error ( 'trailingDelta: Must set "type" to one of the following: STOP_LOSS, STOP_LOSS_LIMIT, TAKE_PROFIT, TAKE_PROFIT_LIMIT' ) ;
842+ if ( ! isOCO && ! allowedTypesForStopAndTrailing . includes ( request . type ) ) {
843+ throw Error ( 'trailingDelta: Must set "type" to one of the following: STOP_LOSS, STOP_LOSS_LIMIT, TAKE_PROFIT, TAKE_PROFIT_LIMIT, OCO ' ) ;
846844 }
847845 }
848846
@@ -856,8 +854,8 @@ export default class Binance {
856854 // if (typeof params.icebergQty !== 'undefined') request.icebergQty = params.icebergQty;
857855 if ( params . stopPrice ) {
858856 request . stopPrice = params . stopPrice ;
859- if ( ! allowedTypesForStopAndTrailing . includes ( request . type ) ) {
860- throw Error ( 'stopPrice: Must set "type" to one of the following: STOP_LOSS, STOP_LOSS_LIMIT, TAKE_PROFIT, TAKE_PROFIT_LIMIT' ) ;
857+ if ( ! isOCO && ! allowedTypesForStopAndTrailing . includes ( request . type ) ) {
858+ throw Error ( 'stopPrice: Must set "type" to one of the following: STOP_LOSS, STOP_LOSS_LIMIT, TAKE_PROFIT, TAKE_PROFIT_LIMIT, OCO ' ) ;
861859 }
862860 }
863861 const response = await this . privateSpotRequest ( endpoint , this . extend ( request , params ) , 'POST' ) ;
@@ -875,6 +873,43 @@ export default class Binance {
875873 return response ;
876874 }
877875
876+ /**
877+ * Create a OCO spot order
878+ * @see https://developers.binance.com/docs/binance-spot-api-docs/rest-api/trading-endpoints#new-order-list---oco-trade
879+ * @param {OrderSide } side - BUY or SELL
880+ * @param {string } symbol - The symbol to buy or sell
881+ * @param {string } quantity - The quantity to buy or sell
882+ * @param {string } price - The price per unit to transact each unit at
883+ * @param {object } params - additional order settings
884+ * @param {string } params.aboveType - The type of the above order
885+ * @param {string } params.belowType - The type of the below order
886+ * @param {string } params.abovePrice - The price of the above order
887+ * @param {string } params.aboveStopPrice - The stop price of the above order
888+ * @param {string } params.aboveTrailingDelta - The trailing delta of the above order
889+ * @param {string } params.aboveTimeInForce - The time in force of the above order
890+ * @param {string } params.belowPrice - The price of the below order
891+ * @param {string } params.belowStopPrice - The stop price of the below order
892+ * @param {string } params.belowTrailingDelta - The trailing delta of the below order
893+ * @param {string } params.belowTimeInForce - The time in force of the below order
894+ * @return {undefined }
895+ */
896+ async ocoOrder ( side : OrderSide , symbol : string , quantity : number , params : Dict = { } ) : Promise < any > {
897+ const request = {
898+ symbol : symbol ,
899+ side : side ,
900+ quantity : quantity ,
901+ } as Dict ;
902+
903+ if ( ! params . listClientOrderId ) {
904+ const id = this . SPOT_PREFIX + this . uuid22 ( ) ;
905+ request . listClientOrderId = id ;
906+ }
907+
908+ const endpoint = 'v3/orderList/oco' ;
909+ const response = await this . privateSpotRequest ( endpoint , this . extend ( request , params ) , 'POST' ) ;
910+ return response ;
911+ }
912+
878913 /**
879914 * Creates a buy order
880915 * @param {string } symbol - the symbol to buy
0 commit comments