Skip to content

Commit

Permalink
huobi examples edits #11409 #11495
Browse files Browse the repository at this point in the history
  • Loading branch information
kroitor committed Feb 11, 2022
1 parent 4d9169f commit 498d7d6
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 70 deletions.
20 changes: 8 additions & 12 deletions examples/js/huobi-futures.js
Expand Up @@ -13,54 +13,50 @@ const exchange = new ccxt.huobi ({

// exchange.verbose = true // uncomment for debugging purposes if necessary

// Example 1: Creating/cancelling a linear future (limit) order
let symbol = 'ETH/USDT:USDT-220121' // the last segment it's the date of expiration (can bee next week, next quarter,...) adjust it accordingly
// creating and canceling a linear future (limit) order
let symbol = 'ETH/USDT:USDT-220121' // the last segment is the date of expiration (can be next week, next quarter, ...) adjust it accordingly
let type = 'limit'
let side = 'buy'
let offset= 'open'
let clientOrderId = Math.floor (Math.random () * 100);
let leverage = 1
let amount = 1
let price = 1
let params = {
'offset': offset,
'lever_rate': leverage,
'client_order_id': clientOrderId
}

try {
// Checking balance
// fetching current balance
const balance = await exchange.fetchBalance()
// console.log(balance)

// Order creation
// placing an order
const order = await exchange.createOrder (symbol, type, side, amount, price, params)
console.log (order)

// Check opened order
// fetching open orders
const openOrders = await exchange.fetchOpenOrders(symbol)
console.log(openOrders)

// Order cancelation
// canceling an order
const cancel = await exchange.cancelOrder (order['id'], symbol)
console.log (cancel)
} catch (e) {
console.log (e.constructor.name, e.message)
}

// Example 2: Creating/cancelling a inverse future (limit) order
symbol = 'ADA/USD:ADA-220121' // he last segment it's the date of expiration (can bee next week, next quarter,...) adjust it accordingly
// creating and canceling a inverse future (limit) order
symbol = 'ADA/USD:ADA-220121' // the last segment is the date of expiration (can be next week, next quarter, ...) adjust it accordingly
type = 'limit'
side = 'buy'
offset= 'open'
clientOrderId = Math.floor (Math.random () * 100);
leverage = 1
amount = 1
price = 1 // 1 contract = 10 ADA = 10 usd in this case
params = {
'offset': offset,
'lever_rate': leverage,
'client_order_id': clientOrderId
}

try {
Expand Down
16 changes: 6 additions & 10 deletions examples/js/huobi-swaps.js
Expand Up @@ -13,54 +13,50 @@ const exchange = new ccxt.huobi ({

// exchange.verbose = true // uncomment for debugging purposes if necessary

// Example 1: Creating/cancelling a linear swap (limit) order
// creating and canceling a linear swap (limit) order
let symbol = 'ADA/USDT:USDT'
let type = 'limit'
let side = 'buy'
let offset= 'open'
let clientOrderId = Math.floor (Math.random () * 10);
let leverage = 1
let amount = 1
let price = 1 // 1 contract = 10 ADA = 10 usd in this case
let params = {
'offset': offset,
'lever_rate': leverage,
'client_order_id': clientOrderId
}

try {
// Checking balance
// fetching current balance
const balance = await exchange.fetchBalance()
// console.log(balance)

// Order creation
// placing an order
const order = await exchange.createOrder (symbol, type, side, amount, price, params)
console.log (order)

// Check opened order
// fetching open orders
const openOrders = await exchange.fetchOpenOrders(symbol)
console.log(openOrders)

// Order cancelations
// canceling an order
const cancel = await exchange.cancelOrder (order['id'], symbol)
console.log (cancel)
} catch (e) {
console.log (e.constructor.name, e.message)
}

// Example 2: Creating/cancelling inverse swap (limit) order
// creating and canceling an inverse swap (limit) order
symbol = 'ADA/USD:ADA'
type = 'limit'
side = 'buy'
offset = 'open'
clientOrderId = Math.floor (Math.random () * 10);
leverage = 1
amount = 1
price = 1 // 1 contract = 10 ADA = 10 usd in this case
params = {
'offset': offset,
'lever_rate': leverage,
'client_order_id': clientOrderId
}

try {
Expand Down
6 changes: 2 additions & 4 deletions examples/php/huobi-futures.php
Expand Up @@ -19,20 +19,18 @@

$markets = $exchange->load_markets ();

// Example: Creating/cancelling a linear swap (limit) order
$symbol = 'ADA/USD:ADA-220121'; //The last segment it's the date of expiration (can bee next week, next quarter,...) adjust it accordingly
// creating and canceling a linear swap (limit) order
$symbol = 'ADA/USD:ADA-220121'; // the last segment is the date of expiration (can be next week, next quarter, ...) adjust it accordingly
$order_type = 'limit';
$side = 'buy';
$offset = 'open';
$cli_order_id = random_int (0,100);
$leverage = 1;
$amount = 1;
$price = 1;

$params = array (
'offset' => $offset,
'lever_rate' => $leverage,
'client_order_id' => $cli_order_id
);

$order = $exchange->create_order ($symbol, $order_type, $side, $amount, $price, $params);
Expand Down
4 changes: 1 addition & 3 deletions examples/php/huobi-swaps.php
Expand Up @@ -16,20 +16,18 @@

$markets = $exchange->load_markets ();

// Example: Creating a linear swap (limit) order
// creating a linear swap (limit) order
$symbol = 'ADA/USDT:USDT';
$order_type = 'limit';
$side = 'buy';
$offset = 'open';
$cli_order_id = random_int (0,100);
$leverage = 1;
$amount = 1;
$price = 1;

$params = array (
'offset' => $offset,
'lever_rate' => $leverage,
'client_order_id' => $cli_order_id
);

$order = $exchange->create_order ($symbol, $order_type, $side, $amount, $price, $params);
Expand Down
34 changes: 16 additions & 18 deletions examples/py/huobi-futures.py
Expand Up @@ -25,64 +25,62 @@

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

# Example 1: Creating/canceling a linear future (limit) order
symbol = 'ETH/USDT:USDT-220121' # the last segment it's the date of expiration (can bee next week, next quarter,...) adjust it accordingly
# creating and canceling a linear future (limit) order
symbol = 'ETH/USDT:USDT-220121' # the last segment is the date of expiration (can be next week, next quarter, ...) adjust it accordingly
order_type = 'limit'
side = 'buy'
offset = 'open'
cli_order_id = randint(0,1000)
leverage = 1
leverage = 1
amount = 1
price = 1

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

try:
# Current Balance
# fetching current balance
balance = exchange.fetch_balance()
print(balance)

# Order creation
# placing an order
order = exchange.create_order(symbol, order_type, side, amount, price, params)
print(order)

# List open positions
# listing open orders
open_orders = exchange.fetch_open_orders(symbol)
# print(open_orders)

#Order cancelation
# canceling an order
cancelOrder = exchange.cancel_order(order['id'], symbol)
print(cancelOrder)
except Exception as e:
print(type(e).__name__, str(e))


# Example 2: Creating/canceling a inverse future (limit) order
symbol = 'ADA/USD:ADA-220121' # the last segment it's the date of expiration (can bee next week, next quarter,...) adjust it accordingly
# creating and canceling a inverse future (limit) order
symbol = 'ADA/USD:ADA-220121' # the last segment is the date of expiration (can be next week, next quarter, ...) adjust it accordingly
order_type = 'limit'
side = 'buy'
offset = 'open'
cli_order_id = randint(0,1000)
leverage = 1
leverage = 1
amount = 1 # 1 contract = 10 ADA
price = 1

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

try:
# Current Balance
# fetching current balance
balance = exchange.fetch_balance()
# print(balance)

# Order creation
# placing an order
order = exchange.create_order(symbol, order_type, side, amount, price, params)
print(order)

# List open positions
# listing open orders
open_orders = exchange.fetch_open_orders(symbol)
# print(open_orders)

# Order cancelation
# canceling an order
cancelOrder = exchange.cancel_order(order['id'], symbol)
print(cancelOrder)
except Exception as e:
Expand Down
10 changes: 4 additions & 6 deletions examples/py/huobi-spot.py
Expand Up @@ -25,18 +25,17 @@

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

# Example 1: Creating/canceling a stop buy-limit order
# creating and canceling a stop-limit buy order
symbol = 'ADA/USDT'
order_type = 'limit'
side = 'buy'
offset = 'open'
cli_order_id = randint(0,1000)
amount = 10
price = 0.5
stopPrice = 0.6
operator = 'lte'

params = {'offset': offset, 'client_order_id': cli_order_id, 'stopPrice': stopPrice, 'operator': operator}
params = {'offset': offset, 'stopPrice': stopPrice, 'operator': operator}

try:

Expand All @@ -55,18 +54,17 @@
print(type(e).__name__, str(e))


# Example 2: Creating/canceling a stop sell-limit order
# creating and canceling a stop limit sell order
symbol = 'ADA/USDT'
order_type = 'limit'
side = 'sell'
offset = 'open'
cli_order_id = randint(0,1000)
amount = 10
price = 5
stopPrice = 5
operator = 'gte'

params = {'offset': offset, 'client_order_id': cli_order_id, 'stopPrice': stopPrice, 'operator': operator}
params = {'offset': offset, 'stopPrice': stopPrice, 'operator': operator}

try:

Expand Down
32 changes: 15 additions & 17 deletions examples/py/huobi-swaps.py
Expand Up @@ -27,64 +27,62 @@
# exchange.verbose = True # uncomment for debugging purposes if necessary


# Example 1: Creating/cancelling a linear swap (limit) order
# creating and canceling a linear swap (limit) order
symbol = 'ADA/USDT:USDT'
order_type = 'limit'
side = 'buy'
offset = 'open'
cli_order_id = randint(0,1000)
leverage = 1
leverage = 1
amount = 1
price = 1

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

try:
# Current Balance
# fetching current balance
balance = exchange.fetch_balance()
# print(balance)
# Order creation

# placing an order
order = exchange.create_order(symbol, order_type, side, amount, price, params)
# print(order)

# List open positions
# listing open orders
open_orders = exchange.fetch_open_orders(symbol)
# print(open_orders)

#Order cancelation
# canceling an order
cancelOrder = exchange.cancel_order(order['id'], symbol)
print(cancelOrder)
except Exception as e:
print(type(e).__name__, str(e))


# Example 2: Creating/cancelling inverse swap (limit) order
# creating and canceling inverse swap (limit) order
symbol = 'ADA/USD:ADA'
order_type = 'limit'
side = 'buy'
offset = 'open'
cli_order_id = randint(0,1000)
leverage = 1
leverage = 1
amount = 1
price = 1

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

try:
# Current Balance
# fetching current balance
balance = exchange.fetch_balance()
# print(balance)

# Order creation
# placing an order
order = exchange.create_order(symbol, order_type, side, amount, price, params)
print(order)

# List open positions
# listing open orders
open_orders = exchange.fetch_open_orders(symbol)
# print(open_orders)

#Order cancelation
# canceling an order
cancelOrder = exchange.cancel_order(order['id'], symbol)
except Exception as e:
print(type(e).__name__, str(e))

0 comments on commit 498d7d6

Please sign in to comment.