# -*- coding: utf-8 -*-

import os
from random import randint
import sys
from pprint import pprint

root = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
sys.path.append(root + '/python')

import ccxt  # noqa: E402


print('CCXT Version:', ccxt.__version__)

exchange = ccxt.huobi({
    'apiKey': 'ez2xc4vb6n-da8c4c7d-76cbde5b-7cc77',
    'secret': '03454cfd-cf15e71b-fe87eadf-16a79',
    'options': {
        'defaultType': 'future',
    },
})

markets = exchange.load_markets()


# exchange.verbose = True  # uncomment for debugging purposes if necessary


# # ## Create a linear future (limit) order 
# symbol = 'ADA/USDT:USDT'
# order_type = 'limit'
# side = 'buy'
# offset = 'open'
# # contract_type = 'this_week'
# cli_order_id = randint(0,1000)
# leverage = 1 
# amount = 1 # 1 contract = 10 ADA
# price = 1

# params = {'offset': offset, 'lever_rate': leverage, 'client_order_id': cli_order_id}

# try:
#     order = exchange.create_order(symbol, order_type, side, amount, price, params)
#     print(order)
# except Exception as e:
#     print(type(e).__name__, str(e))


## Create a inverse swap (limit) order that will 
symbol = 'ADA/USD:ADA'
order_type = 'limit'
side = 'buy'
offset = 'open'
cli_order_id = randint(0,1000)
leverage = 1 
amount = 1
price = 1

params = {'offset': offset, 'lever_rate': leverage, 'client_order_id': cli_order_id}

try:
    order = exchange.create_order(symbol, order_type, side, amount, price, params)
    print(order)
    cancelOrder = exchange.cancel_order(order['id'], symbol)
except Exception as e:
    print(type(e).__name__, str(e))

@@ -449,22 +449,20 @@
 Type': '
-future
+swap
 ',%0A    %7D
@@ -586,19 +586,38 @@
 %0A%0A# 
-# ## Create
+Example 1: Creating/cancelling
  a l
@@ -626,14 +626,12 @@
 ear 
-future
+swap
  (li
@@ -642,18 +642,16 @@
  order %0A
-# 
 symbol =
@@ -667,18 +667,16 @@
 T:USDT'%0A
-# 
 order_ty
@@ -688,18 +688,16 @@
 'limit'%0A
-# 
 side = '
@@ -701,18 +701,16 @@
 = 'buy'%0A
-# 
 offset =
@@ -721,42 +721,8 @@
 en'%0A
-# # contract_type = 'this_week'%0A# 
 cli_
@@ -748,18 +748,16 @@
 0,1000)%0A
-# 
 leverage
@@ -762,18 +762,16 @@
 ge = 1 %0A
-# 
 amount =
@@ -776,33 +776,9 @@
  = 1
- # 1 contract = 10 ADA%0A# 
+%0A
 pric
@@ -784,18 +784,16 @@
 ce = 1%0A%0A
-# 
 params =
@@ -874,17 +874,13 @@
 d%7D%0A%0A
-# 
 try:%0A
-# 
     
@@ -958,18 +958,16 @@
 params)%0A
-# 
     prin
@@ -975,18 +975,77 @@
 (order)%0A
-#
  
+   cancelOrder = exchange.cancel_order(order%5B'id'%5D, symbol)%0A
 except E
@@ -1063,14 +1063,12 @@
  e:%0A
-#
     
- 
 prin
@@ -1102,18 +1102,39 @@
 %0A%0A%0A#
-# Create a
+ Example 2: Creating/cancelling
  inv
@@ -1160,19 +1160,8 @@
 rder
- that will 
 %0Asym

complete swaps example