ccxt 4.1.1 → 4.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/dist/ccxt.browser.js +545 -159
- package/dist/ccxt.browser.min.js +2 -2
- package/dist/cjs/ccxt.js +1 -1
- package/dist/cjs/src/base/Exchange.js +6 -0
- package/dist/cjs/src/binance.js +84 -0
- package/dist/cjs/src/bingx.js +140 -124
- package/dist/cjs/src/bitget.js +1 -1
- package/dist/cjs/src/bitmart.js +176 -0
- package/dist/cjs/src/bitrue.js +1 -1
- package/dist/cjs/src/bybit.js +27 -8
- package/dist/cjs/src/coinbasepro.js +1 -0
- package/dist/cjs/src/deribit.js +1 -1
- package/dist/cjs/src/okx.js +27 -11
- package/dist/cjs/src/pro/binance.js +11 -5
- package/dist/cjs/src/pro/coinbasepro.js +70 -8
- package/js/ccxt.d.ts +1 -1
- package/js/ccxt.js +1 -1
- package/js/src/abstract/coinbaseprime.d.ts +1 -0
- package/js/src/abstract/coinbasepro.d.ts +1 -0
- package/js/src/base/Exchange.d.ts +2 -0
- package/js/src/base/Exchange.js +6 -0
- package/js/src/binance.js +84 -0
- package/js/src/bingx.js +140 -124
- package/js/src/bitget.js +1 -1
- package/js/src/bitmart.d.ts +3 -0
- package/js/src/bitmart.js +176 -0
- package/js/src/bitrue.js +1 -1
- package/js/src/bybit.js +27 -8
- package/js/src/coinbasepro.js +1 -0
- package/js/src/deribit.js +1 -1
- package/js/src/okx.js +27 -11
- package/js/src/pro/binance.js +11 -5
- package/js/src/pro/coinbasepro.d.ts +3 -24
- package/js/src/pro/coinbasepro.js +70 -8
- package/package.json +1 -1
- package/skip-tests.json +6 -1
package/dist/cjs/src/bingx.js
CHANGED
|
@@ -1525,6 +1525,8 @@ class bingx extends bingx$1 {
|
|
|
1525
1525
|
* @param {float} [price] the price at which the order is to be fullfilled, in units of the quote currency, ignored in market orders
|
|
1526
1526
|
* @param {object} [params] extra parameters specific to the bingx api endpoint
|
|
1527
1527
|
* @param {bool} [params.postOnly] true to place a post only order
|
|
1528
|
+
* @param {string} [params.timeInForce] spot supports 'PO' and 'IOC', swap supports 'PO', 'GTC', 'IOC' and 'FOK'
|
|
1529
|
+
* @param {bool} [params.reduceOnly] *swap only* true or false whether the order is reduce only
|
|
1528
1530
|
* @param {float} [params.triggerPrice] *swap only* triggerPrice at which the attached take profit / stop loss order will be triggered
|
|
1529
1531
|
* @param {float} [params.stopLossPrice] *swap only* stop loss trigger price
|
|
1530
1532
|
* @param {float} [params.takeProfitPrice] *swap only* take profit trigger price
|
|
@@ -1532,8 +1534,10 @@ class bingx extends bingx$1 {
|
|
|
1532
1534
|
*/
|
|
1533
1535
|
await this.loadMarkets();
|
|
1534
1536
|
const market = this.market(symbol);
|
|
1537
|
+
let postOnly = undefined;
|
|
1535
1538
|
let response = undefined;
|
|
1536
|
-
|
|
1539
|
+
let marketType = undefined;
|
|
1540
|
+
[marketType, params] = this.handleMarketTypeAndParams('createOrder', market, params);
|
|
1537
1541
|
type = type.toUpperCase();
|
|
1538
1542
|
const request = {
|
|
1539
1543
|
'symbol': market['id'],
|
|
@@ -1541,51 +1545,16 @@ class bingx extends bingx$1 {
|
|
|
1541
1545
|
'side': side.toUpperCase(),
|
|
1542
1546
|
};
|
|
1543
1547
|
const isMarketOrder = type === 'MARKET';
|
|
1544
|
-
const
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
if (
|
|
1550
|
-
|
|
1551
|
-
if (
|
|
1552
|
-
|
|
1553
|
-
}
|
|
1554
|
-
stopLossPrice = this.safeValue(params, 'stopLossPrice');
|
|
1555
|
-
takeProfitPrice = this.safeValue(params, 'takeProfitPrice');
|
|
1556
|
-
}
|
|
1557
|
-
if ((stopLossPrice !== undefined) && (takeProfitPrice !== undefined)) {
|
|
1558
|
-
throw new errors.InvalidOrder('Order is either a takeProfit order or a stopLoss order');
|
|
1559
|
-
}
|
|
1560
|
-
if ((type === 'LIMIT') || (type === 'TRIGGER_LIMIT')) {
|
|
1561
|
-
request['price'] = this.priceToPrecision(symbol, price);
|
|
1562
|
-
if ((stopPrice !== undefined)) {
|
|
1563
|
-
request['type'] = 'TRIGGER_LIMIT';
|
|
1564
|
-
request['stopPrice'] = stopPrice;
|
|
1565
|
-
}
|
|
1566
|
-
if (type === 'TRIGGER_LIMIT') {
|
|
1567
|
-
if (stopPrice === undefined) {
|
|
1568
|
-
throw new errors.InvalidOrder('TRIGGER_LIMIT requires a triggerPrice / stopPrice');
|
|
1569
|
-
}
|
|
1570
|
-
request['stopPrice'] = stopPrice;
|
|
1571
|
-
}
|
|
1572
|
-
}
|
|
1573
|
-
if (isMarketOrder || (type === 'TRIGGER_MARKET')) {
|
|
1574
|
-
if ((stopPrice !== undefined)) {
|
|
1575
|
-
request['type'] = 'TRIGGER_MARKET';
|
|
1576
|
-
request['stopPrice'] = stopPrice;
|
|
1548
|
+
const isSpot = marketType === 'spot';
|
|
1549
|
+
const timeInForce = this.safeStringUpper(params, 'timeInForce');
|
|
1550
|
+
if (timeInForce === 'IOC') {
|
|
1551
|
+
request['timeInForce'] = 'IOC';
|
|
1552
|
+
}
|
|
1553
|
+
if (isSpot) {
|
|
1554
|
+
[postOnly, params] = this.handlePostOnly(isMarketOrder, timeInForce === 'POC', params);
|
|
1555
|
+
if (postOnly || (timeInForce === 'POC')) {
|
|
1556
|
+
request['timeInForce'] = 'POC';
|
|
1577
1557
|
}
|
|
1578
|
-
if (type === 'TRIGGER_MARKET') {
|
|
1579
|
-
if (stopPrice === undefined) {
|
|
1580
|
-
throw new errors.InvalidOrder('TRIGGER_MARKET requires a triggerPrice / stopPrice');
|
|
1581
|
-
}
|
|
1582
|
-
request['stopPrice'] = stopPrice;
|
|
1583
|
-
}
|
|
1584
|
-
}
|
|
1585
|
-
const exchangeSpecificTifParam = this.safeStringUpperN(params, ['force', 'timeInForce']);
|
|
1586
|
-
let postOnly = undefined;
|
|
1587
|
-
[postOnly, params] = this.handlePostOnly(isMarketOrder, exchangeSpecificTifParam === 'POC', params);
|
|
1588
|
-
if (isSpotMarket) {
|
|
1589
1558
|
const createMarketBuyOrderRequiresPrice = this.safeValue(this.options, 'createMarketBuyOrderRequiresPrice', true);
|
|
1590
1559
|
if (createMarketBuyOrderRequiresPrice && isMarketOrder && (side === 'buy')) {
|
|
1591
1560
|
if (price === undefined) {
|
|
@@ -1601,35 +1570,77 @@ class bingx extends bingx$1 {
|
|
|
1601
1570
|
else {
|
|
1602
1571
|
request['quantity'] = this.amountToPrecision(symbol, amount);
|
|
1603
1572
|
}
|
|
1573
|
+
if (!isMarketOrder) {
|
|
1574
|
+
request['price'] = this.priceToPrecision(symbol, price);
|
|
1575
|
+
}
|
|
1576
|
+
response = await this.spotV1PrivatePostTradeOrder(this.extend(request, params));
|
|
1604
1577
|
}
|
|
1605
1578
|
else {
|
|
1579
|
+
[postOnly, params] = this.handlePostOnly(isMarketOrder, timeInForce === 'PostOnly', params);
|
|
1580
|
+
if (postOnly || (timeInForce === 'PostOnly')) {
|
|
1581
|
+
request['timeInForce'] = 'PostOnly';
|
|
1582
|
+
}
|
|
1583
|
+
else if (timeInForce === 'GTC') {
|
|
1584
|
+
request['timeInForce'] = 'GTC';
|
|
1585
|
+
}
|
|
1586
|
+
else if (timeInForce === 'FOK') {
|
|
1587
|
+
request['timeInForce'] = 'FOK';
|
|
1588
|
+
}
|
|
1589
|
+
if ((type === 'LIMIT') || (type === 'TRIGGER_LIMIT') || (type === 'STOP') || (type === 'TAKE_PROFIT')) {
|
|
1590
|
+
request['price'] = this.priceToPrecision(symbol, price);
|
|
1591
|
+
}
|
|
1592
|
+
const triggerPrice = this.safeNumber2(params, 'stopPrice', 'triggerPrice');
|
|
1593
|
+
const stopLossPrice = this.safeNumber(params, 'stopLossPrice');
|
|
1594
|
+
const takeProfitPrice = this.safeNumber(params, 'takeProfitPrice');
|
|
1595
|
+
const isTriggerOrder = triggerPrice !== undefined;
|
|
1596
|
+
const isStopLossPriceOrder = stopLossPrice !== undefined;
|
|
1597
|
+
const isTakeProfitPriceOrder = takeProfitPrice !== undefined;
|
|
1598
|
+
if (isTriggerOrder) {
|
|
1599
|
+
request['stopPrice'] = this.priceToPrecision(symbol, triggerPrice);
|
|
1600
|
+
if (isMarketOrder || (type === 'TRIGGER_MARKET')) {
|
|
1601
|
+
request['type'] = 'TRIGGER_MARKET';
|
|
1602
|
+
}
|
|
1603
|
+
else if ((type === 'LIMIT') || (type === 'TRIGGER_LIMIT')) {
|
|
1604
|
+
request['type'] = 'TRIGGER_LIMIT';
|
|
1605
|
+
}
|
|
1606
|
+
}
|
|
1607
|
+
else if (isStopLossPriceOrder || isTakeProfitPriceOrder) {
|
|
1608
|
+
// This can be used to set the stop loss and take profit, but the position needs to be opened first
|
|
1609
|
+
if (isStopLossPriceOrder) {
|
|
1610
|
+
request['stopPrice'] = this.priceToPrecision(symbol, stopLossPrice);
|
|
1611
|
+
if (isMarketOrder || (type === 'STOP_MARKET')) {
|
|
1612
|
+
request['type'] = 'STOP_MARKET';
|
|
1613
|
+
}
|
|
1614
|
+
else if ((type === 'LIMIT') || (type === 'STOP')) {
|
|
1615
|
+
request['type'] = 'STOP';
|
|
1616
|
+
}
|
|
1617
|
+
}
|
|
1618
|
+
else if (isTakeProfitPriceOrder) {
|
|
1619
|
+
request['stopPrice'] = this.priceToPrecision(symbol, takeProfitPrice);
|
|
1620
|
+
if (isMarketOrder || (type === 'TAKE_PROFIT_MARKET')) {
|
|
1621
|
+
request['type'] = 'TAKE_PROFIT_MARKET';
|
|
1622
|
+
}
|
|
1623
|
+
else if ((type === 'LIMIT') || (type === 'TAKE_PROFIT')) {
|
|
1624
|
+
request['type'] = 'TAKE_PROFIT';
|
|
1625
|
+
}
|
|
1626
|
+
}
|
|
1627
|
+
}
|
|
1628
|
+
const reduceOnly = this.safeValue(params, 'reduceOnly', false);
|
|
1629
|
+
let positionSide = undefined;
|
|
1630
|
+
if (reduceOnly) {
|
|
1631
|
+
positionSide = (side === 'buy') ? 'SHORT' : 'LONG';
|
|
1632
|
+
}
|
|
1633
|
+
else {
|
|
1634
|
+
positionSide = (side === 'buy') ? 'LONG' : 'SHORT';
|
|
1635
|
+
}
|
|
1636
|
+
request['positionSide'] = positionSide;
|
|
1606
1637
|
request['quantity'] = this.amountToPrecision(symbol, amount);
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
request['type'] = 'STOP_MARKET';
|
|
1610
|
-
request['stopPrice'] = this.priceToPrecision(symbol, stopLossPrice);
|
|
1611
|
-
}
|
|
1612
|
-
if ((takeProfitPrice !== undefined)) {
|
|
1613
|
-
request['type'] = 'TAKE_PROFIT_MARKET';
|
|
1614
|
-
request['stopPrice'] = this.priceToPrecision(symbol, takeProfitPrice);
|
|
1615
|
-
}
|
|
1616
|
-
if (postOnly) {
|
|
1617
|
-
request['timeInForce'] = 'POC';
|
|
1618
|
-
}
|
|
1619
|
-
else if (exchangeSpecificTifParam === 'POC') {
|
|
1620
|
-
request['timeInForce'] = 'POC';
|
|
1621
|
-
}
|
|
1622
|
-
else if (!isSpotMarket) {
|
|
1623
|
-
request['timeInForce'] = 'GTC';
|
|
1624
|
-
}
|
|
1625
|
-
if (isSpotMarket) {
|
|
1626
|
-
response = await this.spotV1PrivatePostTradeOrder(this.extend(request, query));
|
|
1627
|
-
}
|
|
1628
|
-
else {
|
|
1629
|
-
response = await this.swapV2PrivatePostTradeOrder(this.extend(request, query));
|
|
1638
|
+
params = this.omit(params, ['reduceOnly', 'triggerPrice', 'stopLossPrice', 'takeProfitPrice']);
|
|
1639
|
+
response = await this.swapV2PrivatePostTradeOrder(this.extend(request, params));
|
|
1630
1640
|
}
|
|
1631
1641
|
//
|
|
1632
1642
|
// spot
|
|
1643
|
+
//
|
|
1633
1644
|
// {
|
|
1634
1645
|
// "code": 0,
|
|
1635
1646
|
// "msg": "",
|
|
@@ -1649,23 +1660,25 @@ class bingx extends bingx$1 {
|
|
|
1649
1660
|
//
|
|
1650
1661
|
// swap
|
|
1651
1662
|
//
|
|
1652
|
-
//
|
|
1653
|
-
//
|
|
1654
|
-
//
|
|
1655
|
-
//
|
|
1656
|
-
//
|
|
1657
|
-
//
|
|
1658
|
-
//
|
|
1659
|
-
//
|
|
1660
|
-
//
|
|
1661
|
-
//
|
|
1662
|
-
//
|
|
1663
|
-
//
|
|
1664
|
-
//
|
|
1663
|
+
// {
|
|
1664
|
+
// "code": 0,
|
|
1665
|
+
// "msg": "",
|
|
1666
|
+
// "data": {
|
|
1667
|
+
// "order": {
|
|
1668
|
+
// "symbol": "BTC-USDT",
|
|
1669
|
+
// "orderId": 1709036527545438208,
|
|
1670
|
+
// "side": "BUY",
|
|
1671
|
+
// "positionSide": "LONG",
|
|
1672
|
+
// "type": "TRIGGER_LIMIT",
|
|
1673
|
+
// "clientOrderID": "",
|
|
1674
|
+
// "workingType": ""
|
|
1675
|
+
// }
|
|
1676
|
+
// }
|
|
1677
|
+
// }
|
|
1665
1678
|
//
|
|
1666
|
-
const data = this.safeValue(response, 'data');
|
|
1667
|
-
const
|
|
1668
|
-
return this.parseOrder(
|
|
1679
|
+
const data = this.safeValue(response, 'data', {});
|
|
1680
|
+
const order = this.safeValue(data, 'order', data);
|
|
1681
|
+
return this.parseOrder(order, market);
|
|
1669
1682
|
}
|
|
1670
1683
|
parseOrder(order, market = undefined) {
|
|
1671
1684
|
//
|
|
@@ -1735,65 +1748,68 @@ class bingx extends bingx$1 {
|
|
|
1735
1748
|
//
|
|
1736
1749
|
// fetchOrder, fetchOpenOrders, fetchClosedOrders
|
|
1737
1750
|
//
|
|
1738
|
-
//
|
|
1739
|
-
//
|
|
1740
|
-
//
|
|
1741
|
-
//
|
|
1742
|
-
//
|
|
1743
|
-
//
|
|
1744
|
-
//
|
|
1745
|
-
//
|
|
1746
|
-
//
|
|
1747
|
-
//
|
|
1748
|
-
//
|
|
1749
|
-
//
|
|
1750
|
-
//
|
|
1751
|
-
//
|
|
1752
|
-
//
|
|
1753
|
-
//
|
|
1754
|
-
//
|
|
1755
|
-
//
|
|
1751
|
+
// {
|
|
1752
|
+
// "symbol": "BTC-USDT",
|
|
1753
|
+
// "orderId": 1709036527545438208,
|
|
1754
|
+
// "side": "BUY",
|
|
1755
|
+
// "positionSide": "LONG",
|
|
1756
|
+
// "type": "TRIGGER_LIMIT",
|
|
1757
|
+
// "origQty": "0.0010",
|
|
1758
|
+
// "price": "22000.0",
|
|
1759
|
+
// "executedQty": "0.0000",
|
|
1760
|
+
// "avgPrice": "0.0",
|
|
1761
|
+
// "cumQuote": "",
|
|
1762
|
+
// "stopPrice": "23000.0",
|
|
1763
|
+
// "profit": "",
|
|
1764
|
+
// "commission": "",
|
|
1765
|
+
// "status": "NEW",
|
|
1766
|
+
// "time": 1696301035187,
|
|
1767
|
+
// "updateTime": 1696301035187,
|
|
1768
|
+
// "clientOrderId": "",
|
|
1769
|
+
// "leverage": "",
|
|
1770
|
+
// "takeProfit": "",
|
|
1771
|
+
// "stopLoss": "",
|
|
1772
|
+
// "advanceAttr": 0,
|
|
1773
|
+
// "positionID": 0,
|
|
1774
|
+
// "takeProfitEntrustPrice": 0,
|
|
1775
|
+
// "stopLossEntrustPrice": 0,
|
|
1776
|
+
// "orderType": "",
|
|
1777
|
+
// "workingType": "MARK_PRICE"
|
|
1778
|
+
// }
|
|
1756
1779
|
//
|
|
1757
1780
|
const positionSide = this.safeString(order, 'positionSide');
|
|
1758
1781
|
const marketType = (positionSide === undefined) ? 'spot' : 'swap';
|
|
1759
1782
|
const marketId = this.safeString(order, 'symbol');
|
|
1760
1783
|
const symbol = this.safeSymbol(marketId, market, '-', marketType);
|
|
1761
|
-
const orderId = this.safeString(order, 'orderId');
|
|
1762
|
-
const side = this.safeStringLower(order, 'side');
|
|
1763
|
-
const type = this.safeStringLower(order, 'type');
|
|
1764
1784
|
const timestamp = this.safeInteger2(order, 'time', 'transactTime');
|
|
1765
|
-
const lastTradeTimestamp = this.safeInteger(order, 'updateTime');
|
|
1766
|
-
const price = this.safeString(order, 'price');
|
|
1767
|
-
const average = this.safeString(order, 'avgPrice');
|
|
1768
|
-
const amount = this.safeString(order, 'origQty');
|
|
1769
|
-
const filled = this.safeString(order, 'executedQty');
|
|
1770
|
-
const statusId = this.safeString(order, 'status');
|
|
1771
1785
|
const fee = {
|
|
1772
1786
|
'currency': this.safeString(order, 'feeAsset'),
|
|
1773
1787
|
'rate': this.safeString2(order, 'fee', 'commission'),
|
|
1774
1788
|
};
|
|
1775
|
-
const clientOrderId = this.safeString(order, 'clientOrderId');
|
|
1776
1789
|
return this.safeOrder({
|
|
1777
1790
|
'info': order,
|
|
1778
|
-
'id': orderId,
|
|
1779
|
-
'clientOrderId': clientOrderId,
|
|
1791
|
+
'id': this.safeString(order, 'orderId'),
|
|
1792
|
+
'clientOrderId': this.safeString(order, 'clientOrderId'),
|
|
1780
1793
|
'timestamp': timestamp,
|
|
1781
1794
|
'datetime': this.iso8601(timestamp),
|
|
1782
|
-
'lastTradeTimestamp':
|
|
1795
|
+
'lastTradeTimestamp': this.safeInteger(order, 'updateTime'),
|
|
1796
|
+
'lastUpdateTimestamp': this.safeInteger(order, 'updateTime'),
|
|
1783
1797
|
'symbol': symbol,
|
|
1784
|
-
'type': type,
|
|
1798
|
+
'type': this.safeStringLower(order, 'type'),
|
|
1785
1799
|
'timeInForce': undefined,
|
|
1786
1800
|
'postOnly': undefined,
|
|
1787
|
-
'side': side,
|
|
1788
|
-
'price': price,
|
|
1789
|
-
'stopPrice': this.safeNumber(order, '
|
|
1790
|
-
'triggerPrice': this.safeNumber(order, '
|
|
1791
|
-
'
|
|
1801
|
+
'side': this.safeStringLower(order, 'side'),
|
|
1802
|
+
'price': this.safeString(order, 'price'),
|
|
1803
|
+
'stopPrice': this.safeNumber(order, 'stopPrice'),
|
|
1804
|
+
'triggerPrice': this.safeNumber(order, 'stopPrice'),
|
|
1805
|
+
'stopLossPrice': this.safeNumber(order, 'stopLoss'),
|
|
1806
|
+
'takeProfitPrice': this.safeNumber(order, 'takeProfit'),
|
|
1807
|
+
'average': this.safeString(order, 'avgPrice'),
|
|
1792
1808
|
'cost': undefined,
|
|
1793
|
-
'amount':
|
|
1794
|
-
'filled':
|
|
1809
|
+
'amount': this.safeString(order, 'origQty'),
|
|
1810
|
+
'filled': this.safeString(order, 'executedQty'),
|
|
1795
1811
|
'remaining': undefined,
|
|
1796
|
-
'status': this.parseOrderStatus(
|
|
1812
|
+
'status': this.parseOrderStatus(this.safeString(order, 'status')),
|
|
1797
1813
|
'fee': fee,
|
|
1798
1814
|
'trades': undefined,
|
|
1799
1815
|
}, market);
|
package/dist/cjs/src/bitget.js
CHANGED
|
@@ -3802,7 +3802,7 @@ class bitget extends bitget$1 {
|
|
|
3802
3802
|
//
|
|
3803
3803
|
const data = this.safeValue(response, 'data');
|
|
3804
3804
|
if (data !== undefined) {
|
|
3805
|
-
return this.
|
|
3805
|
+
return this.safeValue(data, 'orderList', data);
|
|
3806
3806
|
}
|
|
3807
3807
|
const parsedData = JSON.parse(response);
|
|
3808
3808
|
return this.safeValue(parsedData, 'data', []);
|
package/dist/cjs/src/bitmart.js
CHANGED
|
@@ -71,7 +71,9 @@ class bitmart extends bitmart$1 {
|
|
|
71
71
|
'fetchOrderBook': true,
|
|
72
72
|
'fetchOrders': false,
|
|
73
73
|
'fetchOrderTrades': true,
|
|
74
|
+
'fetchPosition': true,
|
|
74
75
|
'fetchPositionMode': false,
|
|
76
|
+
'fetchPositions': true,
|
|
75
77
|
'fetchStatus': true,
|
|
76
78
|
'fetchTicker': true,
|
|
77
79
|
'fetchTickers': true,
|
|
@@ -3756,6 +3758,180 @@ class bitmart extends bitmart$1 {
|
|
|
3756
3758
|
'previousFundingDatetime': undefined,
|
|
3757
3759
|
};
|
|
3758
3760
|
}
|
|
3761
|
+
async fetchPosition(symbol, params = {}) {
|
|
3762
|
+
/**
|
|
3763
|
+
* @method
|
|
3764
|
+
* @name bitmart#fetchPosition
|
|
3765
|
+
* @description fetch data on a single open contract trade position
|
|
3766
|
+
* @see https://developer-pro.bitmart.com/en/futures/#get-current-position-keyed
|
|
3767
|
+
* @param {string} symbol unified market symbol of the market the position is held in
|
|
3768
|
+
* @param {object} [params] extra parameters specific to the bitmart api endpoint
|
|
3769
|
+
* @returns {object} a [position structure]{@link https://github.com/ccxt/ccxt/wiki/Manual#position-structure}
|
|
3770
|
+
*/
|
|
3771
|
+
await this.loadMarkets();
|
|
3772
|
+
const market = this.market(symbol);
|
|
3773
|
+
const request = {
|
|
3774
|
+
'symbol': market['id'],
|
|
3775
|
+
};
|
|
3776
|
+
const response = await this.privateGetContractPrivatePosition(this.extend(request, params));
|
|
3777
|
+
//
|
|
3778
|
+
// {
|
|
3779
|
+
// "code": 1000,
|
|
3780
|
+
// "message": "Ok",
|
|
3781
|
+
// "data": [
|
|
3782
|
+
// {
|
|
3783
|
+
// "symbol": "BTCUSDT",
|
|
3784
|
+
// "leverage": "10",
|
|
3785
|
+
// "timestamp": 1696392515269,
|
|
3786
|
+
// "current_fee": "0.0014250028",
|
|
3787
|
+
// "open_timestamp": 1696392256998,
|
|
3788
|
+
// "current_value": "27.4039",
|
|
3789
|
+
// "mark_price": "27.4039",
|
|
3790
|
+
// "position_value": "27.4079",
|
|
3791
|
+
// "position_cross": "3.75723474",
|
|
3792
|
+
// "maintenance_margin": "0.1370395",
|
|
3793
|
+
// "close_vol": "0",
|
|
3794
|
+
// "close_avg_price": "0",
|
|
3795
|
+
// "open_avg_price": "27407.9",
|
|
3796
|
+
// "entry_price": "27407.9",
|
|
3797
|
+
// "current_amount": "1",
|
|
3798
|
+
// "unrealized_value": "-0.004",
|
|
3799
|
+
// "realized_value": "-0.01644474",
|
|
3800
|
+
// "position_type": 1
|
|
3801
|
+
// }
|
|
3802
|
+
// ],
|
|
3803
|
+
// "trace":"4cad855074664097ac5ba5257c47305d.67.16963925142065945"
|
|
3804
|
+
// }
|
|
3805
|
+
//
|
|
3806
|
+
const data = this.safeValue(response, 'data', []);
|
|
3807
|
+
const first = this.safeValue(data, 0, {});
|
|
3808
|
+
return this.parsePosition(first, market);
|
|
3809
|
+
}
|
|
3810
|
+
async fetchPositions(symbols = undefined, params = {}) {
|
|
3811
|
+
/**
|
|
3812
|
+
* @method
|
|
3813
|
+
* @name bitmart#fetchPositions
|
|
3814
|
+
* @description fetch all open contract positions
|
|
3815
|
+
* @see https://developer-pro.bitmart.com/en/futures/#get-current-position-keyed
|
|
3816
|
+
* @param {string[]|undefined} symbols list of unified market symbols
|
|
3817
|
+
* @param {object} [params] extra parameters specific to the bitmart api endpoint
|
|
3818
|
+
* @returns {object[]} a list of [position structures]{@link https://github.com/ccxt/ccxt/wiki/Manual#position-structure}
|
|
3819
|
+
*/
|
|
3820
|
+
await this.loadMarkets();
|
|
3821
|
+
let market = undefined;
|
|
3822
|
+
let symbolsLength = undefined;
|
|
3823
|
+
if (symbols !== undefined) {
|
|
3824
|
+
symbolsLength = symbols.length;
|
|
3825
|
+
const first = this.safeString(symbols, 0);
|
|
3826
|
+
market = this.market(first);
|
|
3827
|
+
}
|
|
3828
|
+
const request = {};
|
|
3829
|
+
if (symbolsLength === 1) {
|
|
3830
|
+
// only supports symbols as undefined or sending one symbol
|
|
3831
|
+
request['symbol'] = market['id'];
|
|
3832
|
+
}
|
|
3833
|
+
const response = await this.privateGetContractPrivatePosition(this.extend(request, params));
|
|
3834
|
+
//
|
|
3835
|
+
// {
|
|
3836
|
+
// "code": 1000,
|
|
3837
|
+
// "message": "Ok",
|
|
3838
|
+
// "data": [
|
|
3839
|
+
// {
|
|
3840
|
+
// "symbol": "BTCUSDT",
|
|
3841
|
+
// "leverage": "10",
|
|
3842
|
+
// "timestamp": 1696392515269,
|
|
3843
|
+
// "current_fee": "0.0014250028",
|
|
3844
|
+
// "open_timestamp": 1696392256998,
|
|
3845
|
+
// "current_value": "27.4039",
|
|
3846
|
+
// "mark_price": "27.4039",
|
|
3847
|
+
// "position_value": "27.4079",
|
|
3848
|
+
// "position_cross": "3.75723474",
|
|
3849
|
+
// "maintenance_margin": "0.1370395",
|
|
3850
|
+
// "close_vol": "0",
|
|
3851
|
+
// "close_avg_price": "0",
|
|
3852
|
+
// "open_avg_price": "27407.9",
|
|
3853
|
+
// "entry_price": "27407.9",
|
|
3854
|
+
// "current_amount": "1",
|
|
3855
|
+
// "unrealized_value": "-0.004",
|
|
3856
|
+
// "realized_value": "-0.01644474",
|
|
3857
|
+
// "position_type": 1
|
|
3858
|
+
// },
|
|
3859
|
+
// ],
|
|
3860
|
+
// "trace":"4cad855074664097ac5ba5257c47305d.67.16963925142065945"
|
|
3861
|
+
// }
|
|
3862
|
+
//
|
|
3863
|
+
const positions = this.safeValue(response, 'data', []);
|
|
3864
|
+
const result = [];
|
|
3865
|
+
for (let i = 0; i < positions.length; i++) {
|
|
3866
|
+
result.push(this.parsePosition(positions[i]));
|
|
3867
|
+
}
|
|
3868
|
+
symbols = this.marketSymbols(symbols);
|
|
3869
|
+
return this.filterByArrayPositions(result, 'symbol', symbols, false);
|
|
3870
|
+
}
|
|
3871
|
+
parsePosition(position, market = undefined) {
|
|
3872
|
+
//
|
|
3873
|
+
// {
|
|
3874
|
+
// "symbol": "BTCUSDT",
|
|
3875
|
+
// "leverage": "10",
|
|
3876
|
+
// "timestamp": 1696392515269,
|
|
3877
|
+
// "current_fee": "0.0014250028",
|
|
3878
|
+
// "open_timestamp": 1696392256998,
|
|
3879
|
+
// "current_value": "27.4039",
|
|
3880
|
+
// "mark_price": "27.4039",
|
|
3881
|
+
// "position_value": "27.4079",
|
|
3882
|
+
// "position_cross": "3.75723474",
|
|
3883
|
+
// "maintenance_margin": "0.1370395",
|
|
3884
|
+
// "close_vol": "0",
|
|
3885
|
+
// "close_avg_price": "0",
|
|
3886
|
+
// "open_avg_price": "27407.9",
|
|
3887
|
+
// "entry_price": "27407.9",
|
|
3888
|
+
// "current_amount": "1",
|
|
3889
|
+
// "unrealized_value": "-0.004",
|
|
3890
|
+
// "realized_value": "-0.01644474",
|
|
3891
|
+
// "position_type": 1
|
|
3892
|
+
// }
|
|
3893
|
+
//
|
|
3894
|
+
const marketId = this.safeString(position, 'symbol');
|
|
3895
|
+
market = this.safeMarket(marketId, market);
|
|
3896
|
+
const symbol = market['symbol'];
|
|
3897
|
+
const timestamp = this.safeInteger(position, 'timestamp');
|
|
3898
|
+
const side = this.safeInteger(position, 'position_type');
|
|
3899
|
+
const maintenanceMargin = this.safeString(position, 'maintenance_margin');
|
|
3900
|
+
const notional = this.safeString(position, 'current_value');
|
|
3901
|
+
const collateral = this.safeString(position, 'position_cross');
|
|
3902
|
+
const maintenanceMarginPercentage = Precise["default"].stringDiv(maintenanceMargin, notional);
|
|
3903
|
+
const marginRatio = Precise["default"].stringDiv(maintenanceMargin, collateral);
|
|
3904
|
+
return this.safePosition({
|
|
3905
|
+
'info': position,
|
|
3906
|
+
'id': undefined,
|
|
3907
|
+
'symbol': symbol,
|
|
3908
|
+
'timestamp': timestamp,
|
|
3909
|
+
'datetime': this.iso8601(timestamp),
|
|
3910
|
+
'lastUpdateTimestamp': undefined,
|
|
3911
|
+
'hedged': undefined,
|
|
3912
|
+
'side': (side === 1) ? 'long' : 'short',
|
|
3913
|
+
'contracts': this.safeNumber(position, 'current_amount'),
|
|
3914
|
+
'contractSize': this.safeNumber(market, 'contractSize'),
|
|
3915
|
+
'entryPrice': this.safeNumber(position, 'entry_price'),
|
|
3916
|
+
'markPrice': this.safeNumber(position, 'mark_price'),
|
|
3917
|
+
'lastPrice': undefined,
|
|
3918
|
+
'notional': this.parseNumber(notional),
|
|
3919
|
+
'leverage': this.safeNumber(position, 'leverage'),
|
|
3920
|
+
'collateral': this.parseNumber(collateral),
|
|
3921
|
+
'initialMargin': undefined,
|
|
3922
|
+
'initialMarginPercentage': undefined,
|
|
3923
|
+
'maintenanceMargin': this.parseNumber(maintenanceMargin),
|
|
3924
|
+
'maintenanceMarginPercentage': this.parseNumber(maintenanceMarginPercentage),
|
|
3925
|
+
'unrealizedPnl': this.safeNumber(position, 'unrealized_value'),
|
|
3926
|
+
'realizedPnl': this.safeNumber(position, 'realized_value'),
|
|
3927
|
+
'liquidationPrice': undefined,
|
|
3928
|
+
'marginMode': undefined,
|
|
3929
|
+
'percentage': undefined,
|
|
3930
|
+
'marginRatio': this.parseNumber(marginRatio),
|
|
3931
|
+
'stopLossPrice': undefined,
|
|
3932
|
+
'takeProfitPrice': undefined,
|
|
3933
|
+
});
|
|
3934
|
+
}
|
|
3759
3935
|
nonce() {
|
|
3760
3936
|
return this.milliseconds();
|
|
3761
3937
|
}
|
package/dist/cjs/src/bitrue.js
CHANGED
|
@@ -829,7 +829,7 @@ class bitrue extends bitrue$1 {
|
|
|
829
829
|
'last': last,
|
|
830
830
|
'previousClose': undefined,
|
|
831
831
|
'change': undefined,
|
|
832
|
-
'percentage': this.safeString(ticker, 'percentChange'),
|
|
832
|
+
'percentage': Precise["default"].stringMul(this.safeString(ticker, 'percentChange'), '10000'),
|
|
833
833
|
'average': undefined,
|
|
834
834
|
'baseVolume': this.safeString(ticker, 'baseVolume'),
|
|
835
835
|
'quoteVolume': this.safeString(ticker, 'quoteVolume'),
|
package/dist/cjs/src/bybit.js
CHANGED
|
@@ -4008,6 +4008,16 @@ class bybit extends bybit$1 {
|
|
|
4008
4008
|
* @param {float} amount how much of currency you want to trade in units of base currency
|
|
4009
4009
|
* @param {float} price the price at which the order is to be fullfilled, in units of the base currency, ignored in market orders
|
|
4010
4010
|
* @param {object} [params] extra parameters specific to the bybit api endpoint
|
|
4011
|
+
* @param {float} [params.triggerPrice] The price that a trigger order is triggered at
|
|
4012
|
+
* @param {float} [params.stopLossPrice] The price that a stop loss order is triggered at
|
|
4013
|
+
* @param {float} [params.takeProfitPrice] The price that a take profit order is triggered at
|
|
4014
|
+
* @param {object} [params.takeProfit] *takeProfit object in params* containing the triggerPrice that the attached take profit order will be triggered
|
|
4015
|
+
* @param {float} [params.takeProfit.triggerPrice] take profit trigger price
|
|
4016
|
+
* @param {object} [params.stopLoss] *stopLoss object in params* containing the triggerPrice that the attached stop loss order will be triggered
|
|
4017
|
+
* @param {float} [params.stopLoss.triggerPrice] stop loss trigger price
|
|
4018
|
+
* @param {string} [params.triggerBy] 'IndexPrice', 'MarkPrice' or 'LastPrice', default is 'LastPrice', required if no initial value for triggerPrice
|
|
4019
|
+
* @param {string} [params.slTriggerBy] 'IndexPrice', 'MarkPrice' or 'LastPrice', default is 'LastPrice', required if no initial value for stopLoss
|
|
4020
|
+
* @param {string} [params.tpTriggerby] 'IndexPrice', 'MarkPrice' or 'LastPrice', default is 'LastPrice', required if no initial value for takeProfit
|
|
4011
4021
|
* @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
|
|
4012
4022
|
*/
|
|
4013
4023
|
this.checkRequiredSymbol('editOrder', symbol);
|
|
@@ -4050,9 +4060,9 @@ class bybit extends bybit$1 {
|
|
|
4050
4060
|
if (amount !== undefined) {
|
|
4051
4061
|
request['qty'] = this.amountToPrecision(symbol, amount);
|
|
4052
4062
|
}
|
|
4053
|
-
let triggerPrice = this.
|
|
4054
|
-
const stopLossTriggerPrice = this.
|
|
4055
|
-
const takeProfitTriggerPrice = this.
|
|
4063
|
+
let triggerPrice = this.safeString2(params, 'triggerPrice', 'stopPrice');
|
|
4064
|
+
const stopLossTriggerPrice = this.safeString(params, 'stopLossPrice');
|
|
4065
|
+
const takeProfitTriggerPrice = this.safeString(params, 'takeProfitPrice');
|
|
4056
4066
|
const stopLoss = this.safeValue(params, 'stopLoss');
|
|
4057
4067
|
const takeProfit = this.safeValue(params, 'takeProfit');
|
|
4058
4068
|
const isStopLossTriggerOrder = stopLossTriggerPrice !== undefined;
|
|
@@ -4063,16 +4073,25 @@ class bybit extends bybit$1 {
|
|
|
4063
4073
|
triggerPrice = isStopLossTriggerOrder ? stopLossTriggerPrice : takeProfitTriggerPrice;
|
|
4064
4074
|
}
|
|
4065
4075
|
if (triggerPrice !== undefined) {
|
|
4066
|
-
|
|
4076
|
+
const triggerPriceRequest = (triggerPrice === '0') ? triggerPrice : this.priceToPrecision(symbol, triggerPrice);
|
|
4077
|
+
request['triggerPrice'] = triggerPriceRequest;
|
|
4078
|
+
const triggerBy = this.safeString(params, 'triggerBy', 'LastPrice');
|
|
4079
|
+
request['triggerBy'] = triggerBy;
|
|
4067
4080
|
}
|
|
4068
4081
|
if (isStopLoss || isTakeProfit) {
|
|
4069
4082
|
if (isStopLoss) {
|
|
4070
|
-
const slTriggerPrice = this.
|
|
4071
|
-
|
|
4083
|
+
const slTriggerPrice = this.safeString2(stopLoss, 'triggerPrice', 'stopPrice', stopLoss);
|
|
4084
|
+
const stopLossRequest = (slTriggerPrice === '0') ? slTriggerPrice : this.priceToPrecision(symbol, slTriggerPrice);
|
|
4085
|
+
request['stopLoss'] = stopLossRequest;
|
|
4086
|
+
const slTriggerBy = this.safeString(params, 'slTriggerBy', 'LastPrice');
|
|
4087
|
+
request['slTriggerBy'] = slTriggerBy;
|
|
4072
4088
|
}
|
|
4073
4089
|
if (isTakeProfit) {
|
|
4074
|
-
const tpTriggerPrice = this.
|
|
4075
|
-
|
|
4090
|
+
const tpTriggerPrice = this.safeString2(takeProfit, 'triggerPrice', 'stopPrice', takeProfit);
|
|
4091
|
+
const takeProfitRequest = (tpTriggerPrice === '0') ? tpTriggerPrice : this.priceToPrecision(symbol, tpTriggerPrice);
|
|
4092
|
+
request['takeProfit'] = takeProfitRequest;
|
|
4093
|
+
const tpTriggerBy = this.safeString(params, 'tpTriggerBy', 'LastPrice');
|
|
4094
|
+
request['tpTriggerBy'] = tpTriggerBy;
|
|
4076
4095
|
}
|
|
4077
4096
|
}
|
|
4078
4097
|
const clientOrderId = this.safeString(params, 'clientOrderId');
|
package/dist/cjs/src/deribit.js
CHANGED
|
@@ -490,7 +490,7 @@ class deribit extends deribit$1 {
|
|
|
490
490
|
const defaultCode = this.safeValue(this.options, 'code', 'BTC');
|
|
491
491
|
const options = this.safeValue(this.options, methodName, {});
|
|
492
492
|
const code = this.safeValue(options, 'code', defaultCode);
|
|
493
|
-
return this.
|
|
493
|
+
return this.safeValue2(params, 'code', code);
|
|
494
494
|
}
|
|
495
495
|
async fetchStatus(params = {}) {
|
|
496
496
|
/**
|