ccxt 4.3.3__py2.py3-none-any.whl → 4.3.5__py2.py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of ccxt might be problematic. Click here for more details.

@@ -41,7 +41,7 @@ class whitebit(Exchange, ImplicitAPI):
41
41
  'swap': False,
42
42
  'future': False,
43
43
  'option': False,
44
- 'cancelAllOrders': False,
44
+ 'cancelAllOrders': True,
45
45
  'cancelOrder': True,
46
46
  'cancelOrders': False,
47
47
  'createOrder': True,
@@ -186,11 +186,13 @@ class whitebit(Exchange, ImplicitAPI):
186
186
  'ping',
187
187
  'markets',
188
188
  'futures',
189
+ 'platform/status',
189
190
  ],
190
191
  },
191
192
  'private': {
192
193
  'post': [
193
194
  'collateral-account/balance',
195
+ 'collateral-account/balance-summary',
194
196
  'collateral-account/positions/history',
195
197
  'collateral-account/leverage',
196
198
  'collateral-account/positions/open',
@@ -207,21 +209,40 @@ class whitebit(Exchange, ImplicitAPI):
207
209
  'main-account/withdraw',
208
210
  'main-account/withdraw-pay',
209
211
  'main-account/transfer',
212
+ 'main-account/smart/plans',
213
+ 'main-account/smart/investment',
214
+ 'main-account/smart/investment/close',
215
+ 'main-account/smart/investments',
216
+ 'main-account/fee',
217
+ 'main-account/smart/interest-payment-history',
210
218
  'trade-account/balance',
211
219
  'trade-account/executed-history',
212
220
  'trade-account/order',
213
221
  'trade-account/order/history',
214
222
  'order/collateral/limit',
215
223
  'order/collateral/market',
216
- 'order/collateral/trigger_market',
224
+ 'order/collateral/stop-limit',
225
+ 'order/collateral/trigger-market',
217
226
  'order/new',
218
227
  'order/market',
219
228
  'order/stock_market',
220
229
  'order/stop_limit',
221
230
  'order/stop_market',
222
231
  'order/cancel',
232
+ 'order/cancel/all',
233
+ 'order/kill-switch',
234
+ 'order/kill-switch/status',
235
+ 'order/bulk',
236
+ 'order/modify',
223
237
  'orders',
238
+ 'oco-orders',
239
+ 'order/collateral/oco',
240
+ 'order/oco-cancel',
241
+ 'order/oto-cancel',
224
242
  'profile/websocket_token',
243
+ 'convert/estimate',
244
+ 'convert/confirm',
245
+ 'convert/history',
225
246
  ],
226
247
  },
227
248
  },
@@ -1203,6 +1224,58 @@ class whitebit(Exchange, ImplicitAPI):
1203
1224
  response = await self.v4PrivatePostOrderStockMarket(self.extend(request, params))
1204
1225
  return self.parse_order(response)
1205
1226
 
1227
+ async def edit_order(self, id: str, symbol: str, type: OrderType, side: OrderSide, amount: Num = None, price: Num = None, params={}):
1228
+ """
1229
+ edit a trade order
1230
+ :see: https://docs.whitebit.com/private/http-trade-v4/#modify-order
1231
+ :param str id: cancel order id
1232
+ :param str symbol: unified symbol of the market to create an order in
1233
+ :param str type: 'market' or 'limit'
1234
+ :param str side: 'buy' or 'sell'
1235
+ :param float amount: how much of currency you want to trade in units of base currency
1236
+ :param float price: the price at which the order is to be fullfilled, in units of the base currency, ignored in market orders
1237
+ :param dict [params]: extra parameters specific to the exchange API endpoint
1238
+ :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
1239
+ """
1240
+ if id is None:
1241
+ raise ArgumentsRequired(self.id + ' editOrder() requires a id argument')
1242
+ if symbol is None:
1243
+ raise ArgumentsRequired(self.id + ' editOrder() requires a symbol argument')
1244
+ await self.load_markets()
1245
+ market = self.market(symbol)
1246
+ request = {
1247
+ 'orderId': id,
1248
+ 'market': market['id'],
1249
+ }
1250
+ clientOrderId = self.safe_string_2(params, 'clOrdId', 'clientOrderId')
1251
+ if clientOrderId is not None:
1252
+ # Update clientOrderId of the order
1253
+ request['clientOrderId'] = clientOrderId
1254
+ isLimitOrder = type == 'limit'
1255
+ stopPrice = self.safe_number_n(params, ['triggerPrice', 'stopPrice', 'activation_price'])
1256
+ isStopOrder = (stopPrice is not None)
1257
+ params = self.omit(params, ['clOrdId', 'clientOrderId', 'triggerPrice', 'stopPrice'])
1258
+ if isStopOrder:
1259
+ request['activation_price'] = self.price_to_precision(symbol, stopPrice)
1260
+ if isLimitOrder:
1261
+ # stop limit order
1262
+ request['amount'] = self.amount_to_precision(symbol, amount)
1263
+ request['price'] = self.price_to_precision(symbol, price)
1264
+ else:
1265
+ # stop market order
1266
+ if side == 'buy':
1267
+ # Use total parameter instead of amount for modify buy stop market order
1268
+ request['total'] = self.amount_to_precision(symbol, amount)
1269
+ else:
1270
+ request['amount'] = self.amount_to_precision(symbol, amount)
1271
+ else:
1272
+ request['amount'] = self.amount_to_precision(symbol, amount)
1273
+ if isLimitOrder:
1274
+ # limit order
1275
+ request['price'] = self.price_to_precision(symbol, price)
1276
+ response = await self.v4PrivatePostOrderModify(self.extend(request, params))
1277
+ return self.parse_order(response)
1278
+
1206
1279
  async def cancel_order(self, id: str, symbol: Str = None, params={}):
1207
1280
  """
1208
1281
  cancels an open order
@@ -1222,6 +1295,43 @@ class whitebit(Exchange, ImplicitAPI):
1222
1295
  }
1223
1296
  return await self.v4PrivatePostOrderCancel(self.extend(request, params))
1224
1297
 
1298
+ async def cancel_all_orders(self, symbol: Str = None, params={}):
1299
+ """
1300
+ cancel all open orders
1301
+ :see: https://docs.whitebit.com/private/http-trade-v4/#cancel-all-orders
1302
+ :param str symbol: unified market symbol, only orders in the market of self symbol are cancelled when symbol is not None
1303
+ :param dict [params]: extra parameters specific to the exchange API endpoint
1304
+ :param str [params.type]: market type, ['swap', 'spot']
1305
+ :param boolean [params.isMargin]: cancel all margin orders
1306
+ :returns dict[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
1307
+ """
1308
+ await self.load_markets()
1309
+ market = None
1310
+ request = {}
1311
+ if symbol is not None:
1312
+ market = self.market(symbol)
1313
+ request['market'] = market['id']
1314
+ type = None
1315
+ type, params = self.handle_market_type_and_params('cancelAllOrders', market, params)
1316
+ requestType = []
1317
+ if type == 'spot':
1318
+ isMargin = None
1319
+ isMargin, params = self.handle_option_and_params(params, 'cancelAllOrders', 'isMargin', False)
1320
+ if isMargin:
1321
+ requestType.append('margin')
1322
+ else:
1323
+ requestType.append('spot')
1324
+ elif type == 'swap':
1325
+ requestType.append('futures')
1326
+ else:
1327
+ raise NotSupported(self.id + ' cancelAllOrders() does not support ' + type + ' type')
1328
+ request['type'] = requestType
1329
+ response = await self.v4PrivatePostOrderCancelAll(self.extend(request, params))
1330
+ #
1331
+ # []
1332
+ #
1333
+ return response
1334
+
1225
1335
  def parse_balance(self, response) -> Balances:
1226
1336
  balanceKeys = list(response.keys())
1227
1337
  result = {}
ccxt/base/exchange.py CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  # -----------------------------------------------------------------------------
6
6
 
7
- __version__ = '4.3.3'
7
+ __version__ = '4.3.5'
8
8
 
9
9
  # -----------------------------------------------------------------------------
10
10
 
@@ -3735,6 +3735,9 @@ class Exchange(object):
3735
3735
  def fetch_position(self, symbol: str, params={}):
3736
3736
  raise NotSupported(self.id + ' fetchPosition() is not supported yet')
3737
3737
 
3738
+ def fetch_position_ws(self, symbol: str, params={}):
3739
+ raise NotSupported(self.id + ' fetchPositionWs() is not supported yet')
3740
+
3738
3741
  def watch_position(self, symbol: Str = None, params={}):
3739
3742
  raise NotSupported(self.id + ' watchPosition() is not supported yet')
3740
3743
 
@@ -3753,9 +3756,21 @@ class Exchange(object):
3753
3756
  """
3754
3757
  raise NotSupported(self.id + ' fetchPositionsForSymbol() is not supported yet')
3755
3758
 
3759
+ def fetch_positions_for_symbol_ws(self, symbol: str, params={}):
3760
+ """
3761
+ fetches all open positions for specific symbol, unlike fetchPositions(which is designed to work with multiple symbols) so self method might be preffered for one-market position, because of less rate-limit consumption and speed
3762
+ :param str symbol: unified market symbol
3763
+ :param dict params: extra parameters specific to the endpoint
3764
+ :returns dict[]: a list of `position structure <https://docs.ccxt.com/#/?id=position-structure>` with maximum 3 items - possible one position for "one-way" mode, and possible two positions(long & short) for "two-way"(a.k.a. hedge) mode
3765
+ """
3766
+ raise NotSupported(self.id + ' fetchPositionsForSymbol() is not supported yet')
3767
+
3756
3768
  def fetch_positions(self, symbols: List[str] = None, params={}):
3757
3769
  raise NotSupported(self.id + ' fetchPositions() is not supported yet')
3758
3770
 
3771
+ def fetch_positions_ws(self, symbols: List[str] = None, params={}):
3772
+ raise NotSupported(self.id + ' fetchPositions() is not supported yet')
3773
+
3759
3774
  def fetch_positions_risk(self, symbols: List[str] = None, params={}):
3760
3775
  raise NotSupported(self.id + ' fetchPositionsRisk() is not supported yet')
3761
3776
 
@@ -4069,12 +4084,29 @@ class Exchange(object):
4069
4084
  else:
4070
4085
  raise NotSupported(self.id + ' fetchTicker() is not supported yet')
4071
4086
 
4087
+ def fetch_ticker_ws(self, symbol: str, params={}):
4088
+ if self.has['fetchTickersWs']:
4089
+ self.load_markets()
4090
+ market = self.market(symbol)
4091
+ symbol = market['symbol']
4092
+ tickers = self.fetchTickerWs(symbol, params)
4093
+ ticker = self.safe_dict(tickers, symbol)
4094
+ if ticker is None:
4095
+ raise NullResponse(self.id + ' fetchTickers() could not find a ticker for ' + symbol)
4096
+ else:
4097
+ return ticker
4098
+ else:
4099
+ raise NotSupported(self.id + ' fetchTicker() is not supported yet')
4100
+
4072
4101
  def watch_ticker(self, symbol: str, params={}):
4073
4102
  raise NotSupported(self.id + ' watchTicker() is not supported yet')
4074
4103
 
4075
4104
  def fetch_tickers(self, symbols: List[str] = None, params={}):
4076
4105
  raise NotSupported(self.id + ' fetchTickers() is not supported yet')
4077
4106
 
4107
+ def fetch_tickers_ws(self, symbols: List[str] = None, params={}):
4108
+ raise NotSupported(self.id + ' fetchTickers() is not supported yet')
4109
+
4078
4110
  def fetch_order_books(self, symbols: List[str] = None, limit: Int = None, params={}):
4079
4111
  raise NotSupported(self.id + ' fetchOrderBooks() is not supported yet')
4080
4112
 
@@ -4124,6 +4156,28 @@ class Exchange(object):
4124
4156
  return self.create_order(symbol, type, side, amount, price, params)
4125
4157
  raise NotSupported(self.id + ' createTrailingAmountOrder() is not supported yet')
4126
4158
 
4159
+ def create_trailing_amount_order_ws(self, symbol: str, type: OrderType, side: OrderSide, amount: float, price: Num = None, trailingAmount=None, trailingTriggerPrice=None, params={}):
4160
+ """
4161
+ create a trailing order by providing the symbol, type, side, amount, price and trailingAmount
4162
+ :param str symbol: unified symbol of the market to create an order in
4163
+ :param str type: 'market' or 'limit'
4164
+ :param str side: 'buy' or 'sell'
4165
+ :param float amount: how much you want to trade in units of the base currency, or number of contracts
4166
+ :param float [price]: the price for the order to be filled at, in units of the quote currency, ignored in market orders
4167
+ :param float trailingAmount: the quote amount to trail away from the current market price
4168
+ :param float [trailingTriggerPrice]: the price to activate a trailing order, default uses the price argument
4169
+ :param dict [params]: extra parameters specific to the exchange API endpoint
4170
+ :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
4171
+ """
4172
+ if trailingAmount is None:
4173
+ raise ArgumentsRequired(self.id + ' createTrailingAmountOrderWs() requires a trailingAmount argument')
4174
+ params['trailingAmount'] = trailingAmount
4175
+ if trailingTriggerPrice is not None:
4176
+ params['trailingTriggerPrice'] = trailingTriggerPrice
4177
+ if self.has['createTrailingAmountOrderWs']:
4178
+ return self.createOrderWs(symbol, type, side, amount, price, params)
4179
+ raise NotSupported(self.id + ' createTrailingAmountOrderWs() is not supported yet')
4180
+
4127
4181
  def create_trailing_percent_order(self, symbol: str, type: OrderType, side: OrderSide, amount: float, price: Num = None, trailingPercent=None, trailingTriggerPrice=None, params={}):
4128
4182
  """
4129
4183
  create a trailing order by providing the symbol, type, side, amount, price and trailingPercent
@@ -4146,6 +4200,28 @@ class Exchange(object):
4146
4200
  return self.create_order(symbol, type, side, amount, price, params)
4147
4201
  raise NotSupported(self.id + ' createTrailingPercentOrder() is not supported yet')
4148
4202
 
4203
+ def create_trailing_percent_order_ws(self, symbol: str, type: OrderType, side: OrderSide, amount: float, price: Num = None, trailingPercent=None, trailingTriggerPrice=None, params={}):
4204
+ """
4205
+ create a trailing order by providing the symbol, type, side, amount, price and trailingPercent
4206
+ :param str symbol: unified symbol of the market to create an order in
4207
+ :param str type: 'market' or 'limit'
4208
+ :param str side: 'buy' or 'sell'
4209
+ :param float amount: how much you want to trade in units of the base currency, or number of contracts
4210
+ :param float [price]: the price for the order to be filled at, in units of the quote currency, ignored in market orders
4211
+ :param float trailingPercent: the percent to trail away from the current market price
4212
+ :param float [trailingTriggerPrice]: the price to activate a trailing order, default uses the price argument
4213
+ :param dict [params]: extra parameters specific to the exchange API endpoint
4214
+ :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
4215
+ """
4216
+ if trailingPercent is None:
4217
+ raise ArgumentsRequired(self.id + ' createTrailingPercentOrderWs() requires a trailingPercent argument')
4218
+ params['trailingPercent'] = trailingPercent
4219
+ if trailingTriggerPrice is not None:
4220
+ params['trailingTriggerPrice'] = trailingTriggerPrice
4221
+ if self.has['createTrailingPercentOrderWs']:
4222
+ return self.createOrderWs(symbol, type, side, amount, price, params)
4223
+ raise NotSupported(self.id + ' createTrailingPercentOrderWs() is not supported yet')
4224
+
4149
4225
  def create_market_order_with_cost(self, symbol: str, side: OrderSide, cost: float, params={}):
4150
4226
  """
4151
4227
  create a market order by providing the symbol, side and cost
@@ -4183,6 +4259,19 @@ class Exchange(object):
4183
4259
  return self.create_order(symbol, 'market', 'sell', cost, 1, params)
4184
4260
  raise NotSupported(self.id + ' createMarketSellOrderWithCost() is not supported yet')
4185
4261
 
4262
+ def create_market_order_with_cost_ws(self, symbol: str, side: OrderSide, cost: float, params={}):
4263
+ """
4264
+ create a market order by providing the symbol, side and cost
4265
+ :param str symbol: unified symbol of the market to create an order in
4266
+ :param str side: 'buy' or 'sell'
4267
+ :param float cost: how much you want to trade in units of the quote currency
4268
+ :param dict [params]: extra parameters specific to the exchange API endpoint
4269
+ :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
4270
+ """
4271
+ if self.has['createMarketOrderWithCostWs'] or (self.has['createMarketBuyOrderWithCostWs'] and self.has['createMarketSellOrderWithCostWs']):
4272
+ return self.createOrderWs(symbol, 'market', side, cost, 1, params)
4273
+ raise NotSupported(self.id + ' createMarketOrderWithCostWs() is not supported yet')
4274
+
4186
4275
  def create_trigger_order(self, symbol: str, type: OrderType, side: OrderSide, amount: float, price: Num = None, triggerPrice: Num = None, params={}):
4187
4276
  """
4188
4277
  create a trigger stop order(type 1)
@@ -4202,6 +4291,25 @@ class Exchange(object):
4202
4291
  return self.create_order(symbol, type, side, amount, price, params)
4203
4292
  raise NotSupported(self.id + ' createTriggerOrder() is not supported yet')
4204
4293
 
4294
+ def create_trigger_order_ws(self, symbol: str, type: OrderType, side: OrderSide, amount: float, price: Num = None, triggerPrice: Num = None, params={}):
4295
+ """
4296
+ create a trigger stop order(type 1)
4297
+ :param str symbol: unified symbol of the market to create an order in
4298
+ :param str type: 'market' or 'limit'
4299
+ :param str side: 'buy' or 'sell'
4300
+ :param float amount: how much you want to trade in units of the base currency or the number of contracts
4301
+ :param float [price]: the price to fulfill the order, in units of the quote currency, ignored in market orders
4302
+ :param float triggerPrice: the price to trigger the stop order, in units of the quote currency
4303
+ :param dict [params]: extra parameters specific to the exchange API endpoint
4304
+ :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
4305
+ """
4306
+ if triggerPrice is None:
4307
+ raise ArgumentsRequired(self.id + ' createTriggerOrderWs() requires a triggerPrice argument')
4308
+ params['triggerPrice'] = triggerPrice
4309
+ if self.has['createTriggerOrderWs']:
4310
+ return self.createOrderWs(symbol, type, side, amount, price, params)
4311
+ raise NotSupported(self.id + ' createTriggerOrderWs() is not supported yet')
4312
+
4205
4313
  def create_stop_loss_order(self, symbol: str, type: OrderType, side: OrderSide, amount: float, price: Num = None, stopLossPrice: Num = None, params={}):
4206
4314
  """
4207
4315
  create a trigger stop loss order(type 2)
@@ -4221,6 +4329,25 @@ class Exchange(object):
4221
4329
  return self.create_order(symbol, type, side, amount, price, params)
4222
4330
  raise NotSupported(self.id + ' createStopLossOrder() is not supported yet')
4223
4331
 
4332
+ def create_stop_loss_order_ws(self, symbol: str, type: OrderType, side: OrderSide, amount: float, price: Num = None, stopLossPrice: Num = None, params={}):
4333
+ """
4334
+ create a trigger stop loss order(type 2)
4335
+ :param str symbol: unified symbol of the market to create an order in
4336
+ :param str type: 'market' or 'limit'
4337
+ :param str side: 'buy' or 'sell'
4338
+ :param float amount: how much you want to trade in units of the base currency or the number of contracts
4339
+ :param float [price]: the price to fulfill the order, in units of the quote currency, ignored in market orders
4340
+ :param float stopLossPrice: the price to trigger the stop loss order, in units of the quote currency
4341
+ :param dict [params]: extra parameters specific to the exchange API endpoint
4342
+ :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
4343
+ """
4344
+ if stopLossPrice is None:
4345
+ raise ArgumentsRequired(self.id + ' createStopLossOrderWs() requires a stopLossPrice argument')
4346
+ params['stopLossPrice'] = stopLossPrice
4347
+ if self.has['createStopLossOrderWs']:
4348
+ return self.createOrderWs(symbol, type, side, amount, price, params)
4349
+ raise NotSupported(self.id + ' createStopLossOrderWs() is not supported yet')
4350
+
4224
4351
  def create_take_profit_order(self, symbol: str, type: OrderType, side: OrderSide, amount: float, price: Num = None, takeProfitPrice: Num = None, params={}):
4225
4352
  """
4226
4353
  create a trigger take profit order(type 2)
@@ -4240,6 +4367,25 @@ class Exchange(object):
4240
4367
  return self.create_order(symbol, type, side, amount, price, params)
4241
4368
  raise NotSupported(self.id + ' createTakeProfitOrder() is not supported yet')
4242
4369
 
4370
+ def create_take_profit_order_ws(self, symbol: str, type: OrderType, side: OrderSide, amount: float, price: Num = None, takeProfitPrice: Num = None, params={}):
4371
+ """
4372
+ create a trigger take profit order(type 2)
4373
+ :param str symbol: unified symbol of the market to create an order in
4374
+ :param str type: 'market' or 'limit'
4375
+ :param str side: 'buy' or 'sell'
4376
+ :param float amount: how much you want to trade in units of the base currency or the number of contracts
4377
+ :param float [price]: the price to fulfill the order, in units of the quote currency, ignored in market orders
4378
+ :param float takeProfitPrice: the price to trigger the take profit order, in units of the quote currency
4379
+ :param dict [params]: extra parameters specific to the exchange API endpoint
4380
+ :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
4381
+ """
4382
+ if takeProfitPrice is None:
4383
+ raise ArgumentsRequired(self.id + ' createTakeProfitOrderWs() requires a takeProfitPrice argument')
4384
+ params['takeProfitPrice'] = takeProfitPrice
4385
+ if self.has['createTakeProfitOrderWs']:
4386
+ return self.createOrderWs(symbol, type, side, amount, price, params)
4387
+ raise NotSupported(self.id + ' createTakeProfitOrderWs() is not supported yet')
4388
+
4243
4389
  def create_order_with_take_profit_and_stop_loss(self, symbol: str, type: OrderType, side: OrderSide, amount: float, price: Num = None, takeProfit: Num = None, stopLoss: Num = None, params={}):
4244
4390
  """
4245
4391
  create an order with a stop loss or take profit attached(type 3)
@@ -4261,6 +4407,12 @@ class Exchange(object):
4261
4407
  :param float [params.stopLossAmount]: *not available on all exchanges* the amount for a stop loss
4262
4408
  :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
4263
4409
  """
4410
+ params = self.set_take_profit_and_stop_loss_params(symbol, type, side, amount, price, takeProfit, stopLoss, params)
4411
+ if self.has['createOrderWithTakeProfitAndStopLoss']:
4412
+ return self.create_order(symbol, type, side, amount, price, params)
4413
+ raise NotSupported(self.id + ' createOrderWithTakeProfitAndStopLoss() is not supported yet')
4414
+
4415
+ def set_take_profit_and_stop_loss_params(self, symbol: str, type: OrderType, side: OrderSide, amount: float, price: Num = None, takeProfit: Num = None, stopLoss: Num = None, params={}):
4264
4416
  if (takeProfit is None) and (stopLoss is None):
4265
4417
  raise ArgumentsRequired(self.id + ' createOrderWithTakeProfitAndStopLoss() requires either a takeProfit or stopLoss argument')
4266
4418
  if takeProfit is not None:
@@ -4296,9 +4448,33 @@ class Exchange(object):
4296
4448
  if stopLossAmount is not None:
4297
4449
  params['stopLoss']['amount'] = self.parse_to_numeric(stopLossAmount)
4298
4450
  params = self.omit(params, ['takeProfitType', 'takeProfitPriceType', 'takeProfitLimitPrice', 'takeProfitAmount', 'stopLossType', 'stopLossPriceType', 'stopLossLimitPrice', 'stopLossAmount'])
4299
- if self.has['createOrderWithTakeProfitAndStopLoss']:
4300
- return self.create_order(symbol, type, side, amount, price, params)
4301
- raise NotSupported(self.id + ' createOrderWithTakeProfitAndStopLoss() is not supported yet')
4451
+ return params
4452
+
4453
+ def create_order_with_take_profit_and_stop_loss_ws(self, symbol: str, type: OrderType, side: OrderSide, amount: float, price: Num = None, takeProfit: Num = None, stopLoss: Num = None, params={}):
4454
+ """
4455
+ create an order with a stop loss or take profit attached(type 3)
4456
+ :param str symbol: unified symbol of the market to create an order in
4457
+ :param str type: 'market' or 'limit'
4458
+ :param str side: 'buy' or 'sell'
4459
+ :param float amount: how much you want to trade in units of the base currency or the number of contracts
4460
+ :param float [price]: the price to fulfill the order, in units of the quote currency, ignored in market orders
4461
+ :param float [takeProfit]: the take profit price, in units of the quote currency
4462
+ :param float [stopLoss]: the stop loss price, in units of the quote currency
4463
+ :param dict [params]: extra parameters specific to the exchange API endpoint
4464
+ :param str [params.takeProfitType]: *not available on all exchanges* 'limit' or 'market'
4465
+ :param str [params.stopLossType]: *not available on all exchanges* 'limit' or 'market'
4466
+ :param str [params.takeProfitPriceType]: *not available on all exchanges* 'last', 'mark' or 'index'
4467
+ :param str [params.stopLossPriceType]: *not available on all exchanges* 'last', 'mark' or 'index'
4468
+ :param float [params.takeProfitLimitPrice]: *not available on all exchanges* limit price for a limit take profit order
4469
+ :param float [params.stopLossLimitPrice]: *not available on all exchanges* stop loss for a limit stop loss order
4470
+ :param float [params.takeProfitAmount]: *not available on all exchanges* the amount for a take profit
4471
+ :param float [params.stopLossAmount]: *not available on all exchanges* the amount for a stop loss
4472
+ :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
4473
+ """
4474
+ params = self.set_take_profit_and_stop_loss_params(symbol, type, side, amount, price, takeProfit, stopLoss, params)
4475
+ if self.has['createOrderWithTakeProfitAndStopLossWs']:
4476
+ return self.createOrderWs(symbol, type, side, amount, price, params)
4477
+ raise NotSupported(self.id + ' createOrderWithTakeProfitAndStopLossWs() is not supported yet')
4302
4478
 
4303
4479
  def create_orders(self, orders: List[OrderRequest], params={}):
4304
4480
  raise NotSupported(self.id + ' createOrders() is not supported yet')
@@ -4512,21 +4688,39 @@ class Exchange(object):
4512
4688
  def create_limit_order(self, symbol: str, side: OrderSide, amount: float, price: float, params={}):
4513
4689
  return self.create_order(symbol, 'limit', side, amount, price, params)
4514
4690
 
4691
+ def create_limit_order_ws(self, symbol: str, side: OrderSide, amount: float, price: float, params={}):
4692
+ return self.createOrderWs(symbol, 'limit', side, amount, price, params)
4693
+
4515
4694
  def create_market_order(self, symbol: str, side: OrderSide, amount: float, price: Num = None, params={}):
4516
4695
  return self.create_order(symbol, 'market', side, amount, price, params)
4517
4696
 
4697
+ def create_market_order_ws(self, symbol: str, side: OrderSide, amount: float, price: Num = None, params={}):
4698
+ return self.createOrderWs(symbol, 'market', side, amount, price, params)
4699
+
4518
4700
  def create_limit_buy_order(self, symbol: str, amount: float, price: float, params={}):
4519
4701
  return self.create_order(symbol, 'limit', 'buy', amount, price, params)
4520
4702
 
4703
+ def create_limit_buy_order_ws(self, symbol: str, amount: float, price: float, params={}):
4704
+ return self.createOrderWs(symbol, 'limit', 'buy', amount, price, params)
4705
+
4521
4706
  def create_limit_sell_order(self, symbol: str, amount: float, price: float, params={}):
4522
4707
  return self.create_order(symbol, 'limit', 'sell', amount, price, params)
4523
4708
 
4709
+ def create_limit_sell_order_ws(self, symbol: str, amount: float, price: float, params={}):
4710
+ return self.createOrderWs(symbol, 'limit', 'sell', amount, price, params)
4711
+
4524
4712
  def create_market_buy_order(self, symbol: str, amount: float, params={}):
4525
4713
  return self.create_order(symbol, 'market', 'buy', amount, None, params)
4526
4714
 
4715
+ def create_market_buy_order_ws(self, symbol: str, amount: float, params={}):
4716
+ return self.createOrderWs(symbol, 'market', 'buy', amount, None, params)
4717
+
4527
4718
  def create_market_sell_order(self, symbol: str, amount: float, params={}):
4528
4719
  return self.create_order(symbol, 'market', 'sell', amount, None, params)
4529
4720
 
4721
+ def create_market_sell_order_ws(self, symbol: str, amount: float, params={}):
4722
+ return self.createOrderWs(symbol, 'market', 'sell', amount, None, params)
4723
+
4530
4724
  def cost_to_precision(self, symbol: str, cost):
4531
4725
  market = self.market(symbol)
4532
4726
  return self.decimal_to_precision(cost, TRUNCATE, market['precision']['price'], self.precisionMode, self.paddingMode)
@@ -4643,12 +4837,24 @@ class Exchange(object):
4643
4837
  query = self.extend(params, {'postOnly': True})
4644
4838
  return self.create_order(symbol, type, side, amount, price, query)
4645
4839
 
4840
+ def create_post_only_order_ws(self, symbol: str, type: OrderType, side: OrderSide, amount: float, price: Num = None, params={}):
4841
+ if not self.has['createPostOnlyOrderWs']:
4842
+ raise NotSupported(self.id + 'createPostOnlyOrderWs() is not supported yet')
4843
+ query = self.extend(params, {'postOnly': True})
4844
+ return self.createOrderWs(symbol, type, side, amount, price, query)
4845
+
4646
4846
  def create_reduce_only_order(self, symbol: str, type: OrderType, side: OrderSide, amount: float, price: Num = None, params={}):
4647
4847
  if not self.has['createReduceOnlyOrder']:
4648
4848
  raise NotSupported(self.id + 'createReduceOnlyOrder() is not supported yet')
4649
4849
  query = self.extend(params, {'reduceOnly': True})
4650
4850
  return self.create_order(symbol, type, side, amount, price, query)
4651
4851
 
4852
+ def create_reduce_only_order_ws(self, symbol: str, type: OrderType, side: OrderSide, amount: float, price: Num = None, params={}):
4853
+ if not self.has['createReduceOnlyOrderWs']:
4854
+ raise NotSupported(self.id + 'createReduceOnlyOrderWs() is not supported yet')
4855
+ query = self.extend(params, {'reduceOnly': True})
4856
+ return self.createOrderWs(symbol, type, side, amount, price, query)
4857
+
4652
4858
  def create_stop_order(self, symbol: str, type: OrderType, side: OrderSide, amount: float, price: Num = None, stopPrice: Num = None, params={}):
4653
4859
  if not self.has['createStopOrder']:
4654
4860
  raise NotSupported(self.id + ' createStopOrder() is not supported yet')
@@ -4657,18 +4863,38 @@ class Exchange(object):
4657
4863
  query = self.extend(params, {'stopPrice': stopPrice})
4658
4864
  return self.create_order(symbol, type, side, amount, price, query)
4659
4865
 
4866
+ def create_stop_order_ws(self, symbol: str, type: OrderType, side: OrderSide, amount: float, price: Num = None, stopPrice: Num = None, params={}):
4867
+ if not self.has['createStopOrderWs']:
4868
+ raise NotSupported(self.id + ' createStopOrderWs() is not supported yet')
4869
+ if stopPrice is None:
4870
+ raise ArgumentsRequired(self.id + ' createStopOrderWs() requires a stopPrice argument')
4871
+ query = self.extend(params, {'stopPrice': stopPrice})
4872
+ return self.createOrderWs(symbol, type, side, amount, price, query)
4873
+
4660
4874
  def create_stop_limit_order(self, symbol: str, side: OrderSide, amount: float, price: float, stopPrice: float, params={}):
4661
4875
  if not self.has['createStopLimitOrder']:
4662
4876
  raise NotSupported(self.id + ' createStopLimitOrder() is not supported yet')
4663
4877
  query = self.extend(params, {'stopPrice': stopPrice})
4664
4878
  return self.create_order(symbol, 'limit', side, amount, price, query)
4665
4879
 
4880
+ def create_stop_limit_order_ws(self, symbol: str, side: OrderSide, amount: float, price: float, stopPrice: float, params={}):
4881
+ if not self.has['createStopLimitOrderWs']:
4882
+ raise NotSupported(self.id + ' createStopLimitOrderWs() is not supported yet')
4883
+ query = self.extend(params, {'stopPrice': stopPrice})
4884
+ return self.createOrderWs(symbol, 'limit', side, amount, price, query)
4885
+
4666
4886
  def create_stop_market_order(self, symbol: str, side: OrderSide, amount: float, stopPrice: float, params={}):
4667
4887
  if not self.has['createStopMarketOrder']:
4668
4888
  raise NotSupported(self.id + ' createStopMarketOrder() is not supported yet')
4669
4889
  query = self.extend(params, {'stopPrice': stopPrice})
4670
4890
  return self.create_order(symbol, 'market', side, amount, None, query)
4671
4891
 
4892
+ def create_stop_market_order_ws(self, symbol: str, side: OrderSide, amount: float, stopPrice: float, params={}):
4893
+ if not self.has['createStopMarketOrderWs']:
4894
+ raise NotSupported(self.id + ' createStopMarketOrderWs() is not supported yet')
4895
+ query = self.extend(params, {'stopPrice': stopPrice})
4896
+ return self.createOrderWs(symbol, 'market', side, amount, None, query)
4897
+
4672
4898
  def safe_currency_code(self, currencyId: Str, currency: Currency = None):
4673
4899
  currency = self.safe_currency(currencyId, currency)
4674
4900
  return currency['code']
ccxt/binance.py CHANGED
@@ -4741,6 +4741,24 @@ class binance(Exchange, ImplicitAPI):
4741
4741
  params = self.omit(params, ['quoteOrderQty', 'cost', 'stopPrice', 'newClientOrderId', 'clientOrderId', 'postOnly'])
4742
4742
  return self.extend(request, params)
4743
4743
 
4744
+ def edit_contract_order_request(self, id: str, symbol: str, type: OrderType, side: OrderSide, amount: float, price: Num = None, params={}):
4745
+ market = self.market(symbol)
4746
+ if not market['contract']:
4747
+ raise NotSupported(self.id + ' editContractOrder() does not support ' + market['type'] + ' orders')
4748
+ request = {
4749
+ 'symbol': market['id'],
4750
+ 'side': side.upper(),
4751
+ }
4752
+ clientOrderId = self.safe_string_n(params, ['newClientOrderId', 'clientOrderId', 'origClientOrderId'])
4753
+ request['orderId'] = id
4754
+ request['quantity'] = self.amount_to_precision(symbol, amount)
4755
+ if price is not None:
4756
+ request['price'] = self.price_to_precision(symbol, price)
4757
+ if clientOrderId is not None:
4758
+ request['origClientOrderId'] = clientOrderId
4759
+ params = self.omit(params, ['clientOrderId', 'newClientOrderId'])
4760
+ return request
4761
+
4744
4762
  def edit_contract_order(self, id: str, symbol: str, type: OrderType, side: OrderSide, amount: float, price: Num = None, params={}):
4745
4763
  """
4746
4764
  edit a trade order
@@ -4757,20 +4775,7 @@ class binance(Exchange, ImplicitAPI):
4757
4775
  """
4758
4776
  self.load_markets()
4759
4777
  market = self.market(symbol)
4760
- if not market['contract']:
4761
- raise NotSupported(self.id + ' editContractOrder() does not support ' + market['type'] + ' orders')
4762
- request = {
4763
- 'symbol': market['id'],
4764
- 'side': side.upper(),
4765
- }
4766
- clientOrderId = self.safe_string_n(params, ['newClientOrderId', 'clientOrderId', 'origClientOrderId'])
4767
- request['orderId'] = id
4768
- request['quantity'] = self.amount_to_precision(symbol, amount)
4769
- if price is not None:
4770
- request['price'] = self.price_to_precision(symbol, price)
4771
- if clientOrderId is not None:
4772
- request['origClientOrderId'] = clientOrderId
4773
- params = self.omit(params, ['clientOrderId', 'newClientOrderId'])
4778
+ request = self.edit_contract_order_request(id, symbol, type, side, amount, price, params)
4774
4779
  response = None
4775
4780
  if market['linear']:
4776
4781
  response = self.fapiPrivatePutOrder(self.extend(request, params))