()
| 25 | |
| 26 | # Example 1 :: Swap : open position and set trailing stop and close it |
| 27 | async def example_2(): |
| 28 | exchange.options['defaultType'] = 'swap'; # very important set swap as default type |
| 29 | markets = await exchange.load_markets() |
| 30 | |
| 31 | symbol = 'LTC/USDT:USDT' |
| 32 | market = exchange.market(symbol) |
| 33 | |
| 34 | # fetch swap balance |
| 35 | balance = await exchange.fetch_balance() |
| 36 | print(balance) |
| 37 | |
| 38 | # set trailing stop |
| 39 | |
| 40 | # create market order and open position |
| 41 | type = 'market' |
| 42 | side = 'buy' |
| 43 | amount = 0.1 |
| 44 | price = None |
| 45 | create_order = await exchange.create_order(symbol, type, side, amount, price) |
| 46 | print('Create order id:', create_order['id']) |
| 47 | |
| 48 | # set trailing stop |
| 49 | trailing_stop = 30 # YOUR TRAILING STOP |
| 50 | rawSide = 'Buy' # or 'Sell' |
| 51 | params = { |
| 52 | 'symbol': market['id'], |
| 53 | 'side': rawSide, |
| 54 | 'trailing_stop': trailing_stop |
| 55 | } |
| 56 | trailing_response = await exchange.privatePostPrivateLinearPositionTradingStop(params) |
| 57 | print(trailing_response) |
| 58 | |
| 59 | # check opened position |
| 60 | symbols = [ symbol ] |
| 61 | positions = await exchange.fetch_positions(symbols) |
| 62 | print(positions) |
| 63 | |
| 64 | # Close position by issuing a order in the opposite direction |
| 65 | params = { |
| 66 | 'reduce_only': True |
| 67 | } |
| 68 | close_position_order = await exchange.createOrder(symbol, type, side, amount, price, params) |
| 69 | print(close_position_order) |
| 70 | |
| 71 | # ------------------------------------------------------------------------------------------- |
| 72 |
no test coverage detected
searching dependent graphs…