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