* Create a signed spot order * @see https://developers.binance.com/docs/binance-spot-api-docs/rest-api/trading-endpoints#new-order-trade * @see https://developers.binance.com/docs/binance-spot-api-docs/rest-api/public-api-endpoints#test-new-order-trade * @see https://developers.binanc
(type: OrderType, side: OrderSide, symbol: string, quantity: number, price?: number, params: Dict = {})
| 840 | * @return {undefined} |
| 841 | */ |
| 842 | async order(type: OrderType, side: OrderSide, symbol: string, quantity: number, price?: number, params: Dict = {}): Promise<Order> { |
| 843 | const isOCO = type === 'OCO' || params.type === 'OCO'; |
| 844 | let endpoint = isOCO ? 'v3/orderList/oco' : 'v3/order'; |
| 845 | if (params.test) { |
| 846 | delete params.test; |
| 847 | endpoint += '/test'; |
| 848 | } |
| 849 | const request = { |
| 850 | symbol: symbol, |
| 851 | side: side, |
| 852 | // type: type |
| 853 | } as Dict; |
| 854 | if (!isOCO) request.type = type; |
| 855 | if (params.quoteOrderQty && params.quoteOrderQty > 0) |
| 856 | request.quoteOrderQty = params.quoteOrderQty; |
| 857 | else |
| 858 | request.quantity = quantity; |
| 859 | |
| 860 | if (!isOCO && request.type.includes('LIMIT')) { |
| 861 | request.price = price; |
| 862 | if (request.type !== 'LIMIT_MAKER') { |
| 863 | request.timeInForce = 'GTC'; |
| 864 | } |
| 865 | } |
| 866 | if (!isOCO && request.type == 'MARKET' && typeof params.quoteOrderQty !== 'undefined') { |
| 867 | request.quoteOrderQty = params.quoteOrderQty; |
| 868 | delete request.quantity; |
| 869 | } |
| 870 | // if (typeof params.timeInForce !== 'undefined') opt.timeInForce = params.timeInForce; |
| 871 | // if (typeof params.newOrderRespType !== 'undefined') opt.newOrderRespType = params.newOrderRespType; |
| 872 | if (!params.newClientOrderId && !params.listClientOrderId) { |
| 873 | const id = this.SPOT_PREFIX + this.uuid22(); |
| 874 | if (!isOCO) { |
| 875 | request.newClientOrderId = id; |
| 876 | } else { |
| 877 | request.listClientOrderId = id; |
| 878 | } |
| 879 | } |
| 880 | |
| 881 | const allowedTypesForStopAndTrailing = ['STOP_LOSS', 'STOP_LOSS_LIMIT', 'TAKE_PROFIT', 'TAKE_PROFIT_LIMIT', 'OCO']; |
| 882 | if (params.trailingDelta) { |
| 883 | request.trailingDelta = params.trailingDelta; |
| 884 | |
| 885 | if (!isOCO && !allowedTypesForStopAndTrailing.includes(request.type)) { |
| 886 | throw Error('trailingDelta: Must set "type" to one of the following: STOP_LOSS, STOP_LOSS_LIMIT, TAKE_PROFIT, TAKE_PROFIT_LIMIT, OCO'); |
| 887 | } |
| 888 | } |
| 889 | |
| 890 | /* |
| 891 | * STOP_LOSS |
| 892 | * STOP_LOSS_LIMIT |
| 893 | * TAKE_PROFIT |
| 894 | * TAKE_PROFIT_LIMIT |
| 895 | * LIMIT_MAKER |
| 896 | */ |
| 897 | // if (typeof params.icebergQty !== 'undefined') request.icebergQty = params.icebergQty; |
| 898 | if (params.stopPrice) { |
| 899 | request.stopPrice = params.stopPrice; |
no test coverage detected