(self)
| 1278 | return True |
| 1279 | |
| 1280 | async def test_binance(self): |
| 1281 | exchange = self.init_offline_exchange('binance') |
| 1282 | spot_id = 'x-TKT5PX2F' |
| 1283 | swap_id = 'x-cvBPrNm9' |
| 1284 | inverse_swap_id = 'x-xcKtGhcu' |
| 1285 | spot_order_request = None |
| 1286 | try: |
| 1287 | await exchange.create_order('BTC/USDT', 'limit', 'buy', 1, 20000) |
| 1288 | except Exception as e: |
| 1289 | spot_order_request = self.urlencoded_to_dict(exchange.last_request_body) |
| 1290 | client_order_id = spot_order_request['newClientOrderId'] |
| 1291 | spot_id_string = str(spot_id) |
| 1292 | assert client_order_id.startswith(spot_id_string), 'binance - spot clientOrderId: ' + client_order_id + ' does not start with spotId' + spot_id_string |
| 1293 | swap_order_request = None |
| 1294 | try: |
| 1295 | await exchange.create_order('BTC/USDT:USDT', 'limit', 'buy', 1, 20000) |
| 1296 | except Exception as e: |
| 1297 | swap_order_request = self.urlencoded_to_dict(exchange.last_request_body) |
| 1298 | swap_inverse_order_request = None |
| 1299 | try: |
| 1300 | await exchange.create_order('BTC/USD:BTC', 'limit', 'buy', 1, 20000) |
| 1301 | except Exception as e: |
| 1302 | swap_inverse_order_request = self.urlencoded_to_dict(exchange.last_request_body) |
| 1303 | # linear swap |
| 1304 | client_order_id_swap = swap_order_request['newClientOrderId'] |
| 1305 | swap_id_string = str(swap_id) |
| 1306 | assert client_order_id_swap.startswith(swap_id_string), 'binance - swap clientOrderId: ' + client_order_id_swap + ' does not start with swapId' + swap_id_string |
| 1307 | # inverse swap |
| 1308 | client_order_id_inverse = swap_inverse_order_request['newClientOrderId'] |
| 1309 | assert client_order_id_inverse.startswith(inverse_swap_id), 'binance - swap clientOrderIdInverse: ' + client_order_id_inverse + ' does not start with swapId' + inverse_swap_id |
| 1310 | # linear swap conditional order |
| 1311 | swap_algo_order_request = None |
| 1312 | try: |
| 1313 | await exchange.create_order('BTC/USDT:USDT', 'limit', 'buy', 0.002, 102000, { |
| 1314 | 'triggerPrice': 101000, |
| 1315 | }) |
| 1316 | check_order_request = self.urlencoded_to_dict(exchange.last_request_body) |
| 1317 | algo_order_id_defined = (check_order_request['algoOrderId'] is not None) |
| 1318 | assert algo_order_id_defined, 'binance - swap clientOrderId needs to be sent as algoOrderId but algoOrderId is not defined' |
| 1319 | client_algo_id_swap = swap_algo_order_request['clientAlgoId'] |
| 1320 | swap_algo_id_string = str(swap_id) |
| 1321 | assert client_algo_id_swap.startswith(swap_algo_id_string), 'binance - swap clientOrderId: ' + client_algo_id_swap + ' does not start with swapId' + swap_algo_id_string |
| 1322 | except Exception as e: |
| 1323 | swap_algo_order_request = self.urlencoded_to_dict(exchange.last_request_body) |
| 1324 | create_orders_request = None |
| 1325 | try: |
| 1326 | orders = [{ |
| 1327 | 'symbol': 'BTC/USDT:USDT', |
| 1328 | 'type': 'limit', |
| 1329 | 'side': 'sell', |
| 1330 | 'amount': 1, |
| 1331 | 'price': 100000, |
| 1332 | }, { |
| 1333 | 'symbol': 'BTC/USDT:USDT', |
| 1334 | 'type': 'market', |
| 1335 | 'side': 'buy', |
| 1336 | 'amount': 1, |
| 1337 | }] |
no test coverage detected