()
| 53 | |
| 54 | # Example 2 :: Swap : fetch balance, open a position and close it |
| 55 | async def example_2(): |
| 56 | exchange.options['defaultType'] = 'swap'; # very important set swap as default type |
| 57 | markets = await exchange.load_markets(True) |
| 58 | |
| 59 | # fetch swap balance |
| 60 | balance = await exchange.fetch_balance() |
| 61 | print(balance) |
| 62 | |
| 63 | # create market order and open position |
| 64 | symbol = 'LTC/USDT:USDT' |
| 65 | type = 'market' |
| 66 | side = 'buy' |
| 67 | amount = 0.1 |
| 68 | price = None |
| 69 | create_order = await exchange.create_order(symbol, type, side, amount, price) |
| 70 | print('Create order id:', create_order['id']) |
| 71 | |
| 72 | # check opened position |
| 73 | symbols = [ symbol ] |
| 74 | positions = await exchange.fetch_positions(symbols) |
| 75 | print(positions) |
| 76 | |
| 77 | # Close position by issuing a order in the opposite direction |
| 78 | side = 'sell' |
| 79 | params = { |
| 80 | 'reduce_only': True |
| 81 | } |
| 82 | close_position_order = await exchange.createOrder(symbol, type, side, amount, price, params) |
| 83 | print(close_position_order) |
| 84 | |
| 85 | # ------------------------------------------------------------------------------------------- |
| 86 |
no test coverage detected
searching dependent graphs…