ccxt 4.2.95__py2.py3-none-any.whl → 4.2.96__py2.py3-none-any.whl
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.
- ccxt/__init__.py +1 -1
- ccxt/abstract/coinbase.py +1 -0
- ccxt/async_support/__init__.py +1 -1
- ccxt/async_support/base/exchange.py +1 -1
- ccxt/async_support/coinbase.py +586 -102
- ccxt/async_support/gemini.py +26 -11
- ccxt/base/exchange.py +2 -2
- ccxt/coinbase.py +586 -102
- ccxt/gemini.py +26 -11
- ccxt/pro/__init__.py +1 -1
- ccxt/pro/coinbase.py +19 -4
- {ccxt-4.2.95.dist-info → ccxt-4.2.96.dist-info}/METADATA +4 -4
- {ccxt-4.2.95.dist-info → ccxt-4.2.96.dist-info}/RECORD +15 -15
- {ccxt-4.2.95.dist-info → ccxt-4.2.96.dist-info}/WHEEL +0 -0
- {ccxt-4.2.95.dist-info → ccxt-4.2.96.dist-info}/top_level.txt +0 -0
ccxt/async_support/coinbase.py
CHANGED
@@ -7,10 +7,11 @@ from ccxt.async_support.base.exchange import Exchange
|
|
7
7
|
from ccxt.abstract.coinbase import ImplicitAPI
|
8
8
|
import asyncio
|
9
9
|
import hashlib
|
10
|
-
from ccxt.base.types import Account, Balances, Currencies, Currency, Int, Market, Num, Order, OrderBook, OrderSide, OrderType, Str, Strings, Ticker, Tickers, Trade, Transaction
|
10
|
+
from ccxt.base.types import Account, Balances, Currencies, Currency, Int, Market, MarketInterface, Num, Order, OrderBook, OrderSide, OrderType, Str, Strings, Ticker, Tickers, Trade, Transaction
|
11
11
|
from typing import List
|
12
12
|
from ccxt.base.errors import ExchangeError
|
13
13
|
from ccxt.base.errors import AuthenticationError
|
14
|
+
from ccxt.base.errors import PermissionDenied
|
14
15
|
from ccxt.base.errors import ArgumentsRequired
|
15
16
|
from ccxt.base.errors import BadRequest
|
16
17
|
from ccxt.base.errors import InvalidOrder
|
@@ -52,7 +53,7 @@ class coinbase(Exchange, ImplicitAPI):
|
|
52
53
|
'cancelOrder': True,
|
53
54
|
'cancelOrders': True,
|
54
55
|
'closeAllPositions': False,
|
55
|
-
'closePosition':
|
56
|
+
'closePosition': True,
|
56
57
|
'createDepositAddress': True,
|
57
58
|
'createLimitBuyOrder': True,
|
58
59
|
'createLimitSellOrder': True,
|
@@ -107,9 +108,9 @@ class coinbase(Exchange, ImplicitAPI):
|
|
107
108
|
'fetchOrder': True,
|
108
109
|
'fetchOrderBook': True,
|
109
110
|
'fetchOrders': True,
|
110
|
-
'fetchPosition':
|
111
|
+
'fetchPosition': True,
|
111
112
|
'fetchPositionMode': False,
|
112
|
-
'fetchPositions':
|
113
|
+
'fetchPositions': True,
|
113
114
|
'fetchPositionsRisk': False,
|
114
115
|
'fetchPremiumIndexOHLCV': False,
|
115
116
|
'fetchTicker': True,
|
@@ -252,6 +253,8 @@ class coinbase(Exchange, ImplicitAPI):
|
|
252
253
|
'brokerage/convert/trade/{trade_id}': 1,
|
253
254
|
'brokerage/cfm/sweeps/schedule': 1,
|
254
255
|
'brokerage/intx/allocate': 1,
|
256
|
+
# futures
|
257
|
+
'brokerage/orders/close_position': 1,
|
255
258
|
},
|
256
259
|
'put': {
|
257
260
|
'brokerage/portfolios/{portfolio_uuid}': 1,
|
@@ -318,6 +321,8 @@ class coinbase(Exchange, ImplicitAPI):
|
|
318
321
|
'internal_server_error': ExchangeError, # 500 Internal server error
|
319
322
|
'UNSUPPORTED_ORDER_CONFIGURATION': BadRequest,
|
320
323
|
'INSUFFICIENT_FUND': BadRequest,
|
324
|
+
'PERMISSION_DENIED': PermissionDenied,
|
325
|
+
'INVALID_ARGUMENT': BadRequest,
|
321
326
|
},
|
322
327
|
'broad': {
|
323
328
|
'request timestamp expired': InvalidNonce, # {"errors":[{"id":"authentication_error","message":"request timestamp expired"}]}
|
@@ -532,6 +537,26 @@ class coinbase(Exchange, ImplicitAPI):
|
|
532
537
|
accounts[lastIndex] = last
|
533
538
|
return self.parse_accounts(accounts, params)
|
534
539
|
|
540
|
+
async def fetch_portfolios(self, params={}) -> List[Account]:
|
541
|
+
"""
|
542
|
+
fetch all the portfolios
|
543
|
+
:see: https://docs.cloud.coinbase.com/advanced-trade-api/reference/retailbrokerageapi_getportfolios
|
544
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
545
|
+
:returns dict: a dictionary of `account structures <https://docs.ccxt.com/#/?id=account-structure>` indexed by the account type
|
546
|
+
"""
|
547
|
+
response = await self.v3PrivateGetBrokeragePortfolios(params)
|
548
|
+
portfolios = self.safe_list(response, 'portfolios', [])
|
549
|
+
result = []
|
550
|
+
for i in range(0, len(portfolios)):
|
551
|
+
portfolio = portfolios[i]
|
552
|
+
result.append({
|
553
|
+
'id': self.safe_string(portfolio, 'uuid'),
|
554
|
+
'type': self.safe_string(portfolio, 'type'),
|
555
|
+
'code': None,
|
556
|
+
'info': portfolio,
|
557
|
+
})
|
558
|
+
return result
|
559
|
+
|
535
560
|
def parse_account(self, account):
|
536
561
|
#
|
537
562
|
# fetchAccountsV2
|
@@ -1116,15 +1141,64 @@ class coinbase(Exchange, ImplicitAPI):
|
|
1116
1141
|
return result
|
1117
1142
|
|
1118
1143
|
async def fetch_markets_v3(self, params={}):
|
1119
|
-
|
1144
|
+
spotUnresolvedPromises = [
|
1120
1145
|
self.v3PrivateGetBrokerageProducts(params),
|
1121
1146
|
self.v3PrivateGetBrokerageTransactionSummary(params),
|
1122
1147
|
]
|
1123
|
-
|
1124
|
-
|
1125
|
-
|
1148
|
+
unresolvedContractPromises = [
|
1149
|
+
self.v3PrivateGetBrokerageProducts(self.extend(params, {'product_type': 'FUTURE'})),
|
1150
|
+
self.v3PrivateGetBrokerageProducts(self.extend(params, {'product_type': 'FUTURE', 'contract_expiry_type': 'PERPETUAL'})),
|
1151
|
+
self.v3PrivateGetBrokerageTransactionSummary(self.extend(params, {'product_type': 'FUTURE'})),
|
1152
|
+
self.v3PrivateGetBrokerageTransactionSummary(self.extend(params, {'product_type': 'FUTURE', 'contract_expiry_type': 'PERPETUAL'})),
|
1153
|
+
]
|
1154
|
+
promises = await asyncio.gather(*spotUnresolvedPromises)
|
1155
|
+
contractPromises = None
|
1156
|
+
try:
|
1157
|
+
contractPromises = await asyncio.gather(*unresolvedContractPromises) # some users don't have access to contracts
|
1158
|
+
except Exception as e:
|
1159
|
+
contractPromises = []
|
1160
|
+
spot = self.safe_dict(promises, 0, {})
|
1161
|
+
fees = self.safe_dict(promises, 1, {})
|
1162
|
+
expiringFutures = self.safe_dict(contractPromises, 0, {})
|
1163
|
+
perpetualFutures = self.safe_dict(contractPromises, 1, {})
|
1164
|
+
expiringFees = self.safe_dict(contractPromises, 2, {})
|
1165
|
+
perpetualFees = self.safe_dict(contractPromises, 3, {})
|
1166
|
+
#
|
1167
|
+
# {
|
1168
|
+
# "total_volume": 0,
|
1169
|
+
# "total_fees": 0,
|
1170
|
+
# "fee_tier": {
|
1171
|
+
# "pricing_tier": "",
|
1172
|
+
# "usd_from": "0",
|
1173
|
+
# "usd_to": "10000",
|
1174
|
+
# "taker_fee_rate": "0.006",
|
1175
|
+
# "maker_fee_rate": "0.004"
|
1176
|
+
# },
|
1177
|
+
# "margin_rate": null,
|
1178
|
+
# "goods_and_services_tax": null,
|
1179
|
+
# "advanced_trade_only_volume": 0,
|
1180
|
+
# "advanced_trade_only_fees": 0,
|
1181
|
+
# "coinbase_pro_volume": 0,
|
1182
|
+
# "coinbase_pro_fees": 0
|
1183
|
+
# }
|
1184
|
+
#
|
1185
|
+
feeTier = self.safe_dict(fees, 'fee_tier', {})
|
1186
|
+
expiringFeeTier = self.safe_dict(expiringFees, 'fee_tier', {}) # fee tier null?
|
1187
|
+
perpetualFeeTier = self.safe_dict(perpetualFees, 'fee_tier', {}) # fee tier null?
|
1188
|
+
data = self.safe_list(spot, 'products', [])
|
1189
|
+
result = []
|
1190
|
+
for i in range(0, len(data)):
|
1191
|
+
result.append(self.parse_spot_market(data[i], feeTier))
|
1192
|
+
futureData = self.safe_list(expiringFutures, 'products', [])
|
1193
|
+
for i in range(0, len(futureData)):
|
1194
|
+
result.append(self.parse_contract_market(futureData[i], expiringFeeTier))
|
1195
|
+
perpetualData = self.safe_list(perpetualFutures, 'products', [])
|
1196
|
+
for i in range(0, len(perpetualData)):
|
1197
|
+
result.append(self.parse_contract_market(perpetualData[i], perpetualFeeTier))
|
1198
|
+
return result
|
1199
|
+
|
1200
|
+
def parse_spot_market(self, market, feeTier) -> MarketInterface:
|
1126
1201
|
#
|
1127
|
-
# [
|
1128
1202
|
# {
|
1129
1203
|
# "product_id": "TONE-USD",
|
1130
1204
|
# "price": "0.01523",
|
@@ -1153,96 +1227,260 @@ class coinbase(Exchange, ImplicitAPI):
|
|
1153
1227
|
# "base_currency_id": "TONE",
|
1154
1228
|
# "fcm_trading_session_details": null,
|
1155
1229
|
# "mid_market_price": ""
|
1156
|
-
# }
|
1157
|
-
# ...
|
1158
|
-
# ]
|
1230
|
+
# }
|
1159
1231
|
#
|
1160
|
-
|
1161
|
-
|
1232
|
+
id = self.safe_string(market, 'product_id')
|
1233
|
+
baseId = self.safe_string(market, 'base_currency_id')
|
1234
|
+
quoteId = self.safe_string(market, 'quote_currency_id')
|
1235
|
+
base = self.safe_currency_code(baseId)
|
1236
|
+
quote = self.safe_currency_code(quoteId)
|
1237
|
+
marketType = self.safe_string_lower(market, 'product_type')
|
1238
|
+
tradingDisabled = self.safe_bool(market, 'trading_disabled')
|
1239
|
+
stablePairs = self.safe_list(self.options, 'stablePairs', [])
|
1240
|
+
return self.safe_market_structure({
|
1241
|
+
'id': id,
|
1242
|
+
'symbol': base + '/' + quote,
|
1243
|
+
'base': base,
|
1244
|
+
'quote': quote,
|
1245
|
+
'settle': None,
|
1246
|
+
'baseId': baseId,
|
1247
|
+
'quoteId': quoteId,
|
1248
|
+
'settleId': None,
|
1249
|
+
'type': marketType,
|
1250
|
+
'spot': (marketType == 'spot'),
|
1251
|
+
'margin': None,
|
1252
|
+
'swap': False,
|
1253
|
+
'future': False,
|
1254
|
+
'option': False,
|
1255
|
+
'active': not tradingDisabled,
|
1256
|
+
'contract': False,
|
1257
|
+
'linear': None,
|
1258
|
+
'inverse': None,
|
1259
|
+
'taker': 0.00001 if self.in_array(id, stablePairs) else self.safe_number(feeTier, 'taker_fee_rate'),
|
1260
|
+
'maker': 0.0 if self.in_array(id, stablePairs) else self.safe_number(feeTier, 'maker_fee_rate'),
|
1261
|
+
'contractSize': None,
|
1262
|
+
'expiry': None,
|
1263
|
+
'expiryDatetime': None,
|
1264
|
+
'strike': None,
|
1265
|
+
'optionType': None,
|
1266
|
+
'precision': {
|
1267
|
+
'amount': self.safe_number(market, 'base_increment'),
|
1268
|
+
'price': self.safe_number_2(market, 'price_increment', 'quote_increment'),
|
1269
|
+
},
|
1270
|
+
'limits': {
|
1271
|
+
'leverage': {
|
1272
|
+
'min': None,
|
1273
|
+
'max': None,
|
1274
|
+
},
|
1275
|
+
'amount': {
|
1276
|
+
'min': self.safe_number(market, 'base_min_size'),
|
1277
|
+
'max': self.safe_number(market, 'base_max_size'),
|
1278
|
+
},
|
1279
|
+
'price': {
|
1280
|
+
'min': None,
|
1281
|
+
'max': None,
|
1282
|
+
},
|
1283
|
+
'cost': {
|
1284
|
+
'min': self.safe_number(market, 'quote_min_size'),
|
1285
|
+
'max': self.safe_number(market, 'quote_max_size'),
|
1286
|
+
},
|
1287
|
+
},
|
1288
|
+
'created': None,
|
1289
|
+
'info': market,
|
1290
|
+
})
|
1291
|
+
|
1292
|
+
def parse_contract_market(self, market, feeTier) -> MarketInterface:
|
1293
|
+
# expiring
|
1162
1294
|
#
|
1163
|
-
#
|
1164
|
-
#
|
1165
|
-
#
|
1166
|
-
#
|
1167
|
-
#
|
1168
|
-
#
|
1169
|
-
#
|
1170
|
-
#
|
1171
|
-
#
|
1172
|
-
#
|
1173
|
-
#
|
1174
|
-
#
|
1175
|
-
#
|
1176
|
-
#
|
1177
|
-
#
|
1178
|
-
#
|
1179
|
-
#
|
1295
|
+
# {
|
1296
|
+
# "product_id":"BIT-26APR24-CDE",
|
1297
|
+
# "price":"71145",
|
1298
|
+
# "price_percentage_change_24h":"-2.36722931247427",
|
1299
|
+
# "volume_24h":"108549",
|
1300
|
+
# "volume_percentage_change_24h":"155.78255337197794",
|
1301
|
+
# "base_increment":"1",
|
1302
|
+
# "quote_increment":"0.01",
|
1303
|
+
# "quote_min_size":"0",
|
1304
|
+
# "quote_max_size":"100000000",
|
1305
|
+
# "base_min_size":"1",
|
1306
|
+
# "base_max_size":"100000000",
|
1307
|
+
# "base_name":"",
|
1308
|
+
# "quote_name":"US Dollar",
|
1309
|
+
# "watched":false,
|
1310
|
+
# "is_disabled":false,
|
1311
|
+
# "new":false,
|
1312
|
+
# "status":"",
|
1313
|
+
# "cancel_only":false,
|
1314
|
+
# "limit_only":false,
|
1315
|
+
# "post_only":false,
|
1316
|
+
# "trading_disabled":false,
|
1317
|
+
# "auction_mode":false,
|
1318
|
+
# "product_type":"FUTURE",
|
1319
|
+
# "quote_currency_id":"USD",
|
1320
|
+
# "base_currency_id":"",
|
1321
|
+
# "fcm_trading_session_details":{
|
1322
|
+
# "is_session_open":true,
|
1323
|
+
# "open_time":"2024-04-08T22:00:00Z",
|
1324
|
+
# "close_time":"2024-04-09T21:00:00Z"
|
1325
|
+
# },
|
1326
|
+
# "mid_market_price":"71105",
|
1327
|
+
# "alias":"",
|
1328
|
+
# "alias_to":[
|
1329
|
+
# ],
|
1330
|
+
# "base_display_symbol":"",
|
1331
|
+
# "quote_display_symbol":"USD",
|
1332
|
+
# "view_only":false,
|
1333
|
+
# "price_increment":"5",
|
1334
|
+
# "display_name":"BTC 26 APR 24",
|
1335
|
+
# "product_venue":"FCM",
|
1336
|
+
# "future_product_details":{
|
1337
|
+
# "venue":"cde",
|
1338
|
+
# "contract_code":"BIT",
|
1339
|
+
# "contract_expiry":"2024-04-26T15:00:00Z",
|
1340
|
+
# "contract_size":"0.01",
|
1341
|
+
# "contract_root_unit":"BTC",
|
1342
|
+
# "group_description":"Nano Bitcoin Futures",
|
1343
|
+
# "contract_expiry_timezone":"Europe/London",
|
1344
|
+
# "group_short_description":"Nano BTC",
|
1345
|
+
# "risk_managed_by":"MANAGED_BY_FCM",
|
1346
|
+
# "contract_expiry_type":"EXPIRING",
|
1347
|
+
# "contract_display_name":"BTC 26 APR 24"
|
1348
|
+
# }
|
1349
|
+
# }
|
1180
1350
|
#
|
1181
|
-
|
1182
|
-
|
1183
|
-
|
1184
|
-
|
1185
|
-
|
1186
|
-
|
1187
|
-
|
1188
|
-
|
1189
|
-
|
1190
|
-
|
1191
|
-
|
1192
|
-
|
1193
|
-
|
1194
|
-
|
1195
|
-
|
1196
|
-
|
1197
|
-
|
1198
|
-
|
1199
|
-
|
1200
|
-
|
1201
|
-
|
1202
|
-
|
1203
|
-
|
1204
|
-
|
1205
|
-
|
1206
|
-
|
1207
|
-
|
1208
|
-
|
1209
|
-
|
1210
|
-
|
1211
|
-
|
1212
|
-
|
1213
|
-
|
1214
|
-
|
1215
|
-
|
1216
|
-
|
1217
|
-
|
1218
|
-
|
1219
|
-
|
1220
|
-
|
1221
|
-
|
1222
|
-
|
1351
|
+
# perpetual
|
1352
|
+
#
|
1353
|
+
# {
|
1354
|
+
# "product_id":"ETH-PERP-INTX",
|
1355
|
+
# "price":"3630.98",
|
1356
|
+
# "price_percentage_change_24h":"0.65142426292038",
|
1357
|
+
# "volume_24h":"114020.1501",
|
1358
|
+
# "volume_percentage_change_24h":"63.33650787154869",
|
1359
|
+
# "base_increment":"0.0001",
|
1360
|
+
# "quote_increment":"0.01",
|
1361
|
+
# "quote_min_size":"10",
|
1362
|
+
# "quote_max_size":"50000000",
|
1363
|
+
# "base_min_size":"0.0001",
|
1364
|
+
# "base_max_size":"50000",
|
1365
|
+
# "base_name":"",
|
1366
|
+
# "quote_name":"USDC",
|
1367
|
+
# "watched":false,
|
1368
|
+
# "is_disabled":false,
|
1369
|
+
# "new":false,
|
1370
|
+
# "status":"",
|
1371
|
+
# "cancel_only":false,
|
1372
|
+
# "limit_only":false,
|
1373
|
+
# "post_only":false,
|
1374
|
+
# "trading_disabled":false,
|
1375
|
+
# "auction_mode":false,
|
1376
|
+
# "product_type":"FUTURE",
|
1377
|
+
# "quote_currency_id":"USDC",
|
1378
|
+
# "base_currency_id":"",
|
1379
|
+
# "fcm_trading_session_details":null,
|
1380
|
+
# "mid_market_price":"3630.975",
|
1381
|
+
# "alias":"",
|
1382
|
+
# "alias_to":[],
|
1383
|
+
# "base_display_symbol":"",
|
1384
|
+
# "quote_display_symbol":"USDC",
|
1385
|
+
# "view_only":false,
|
1386
|
+
# "price_increment":"0.01",
|
1387
|
+
# "display_name":"ETH PERP",
|
1388
|
+
# "product_venue":"INTX",
|
1389
|
+
# "future_product_details":{
|
1390
|
+
# "venue":"",
|
1391
|
+
# "contract_code":"ETH",
|
1392
|
+
# "contract_expiry":null,
|
1393
|
+
# "contract_size":"1",
|
1394
|
+
# "contract_root_unit":"ETH",
|
1395
|
+
# "group_description":"",
|
1396
|
+
# "contract_expiry_timezone":"",
|
1397
|
+
# "group_short_description":"",
|
1398
|
+
# "risk_managed_by":"MANAGED_BY_VENUE",
|
1399
|
+
# "contract_expiry_type":"PERPETUAL",
|
1400
|
+
# "perpetual_details":{
|
1401
|
+
# "open_interest":"0",
|
1402
|
+
# "funding_rate":"0.000016",
|
1403
|
+
# "funding_time":"2024-04-09T09:00:00.000008Z",
|
1404
|
+
# "max_leverage":"10"
|
1405
|
+
# },
|
1406
|
+
# "contract_display_name":"ETH PERPETUAL"
|
1407
|
+
# }
|
1408
|
+
# }
|
1409
|
+
#
|
1410
|
+
id = self.safe_string(market, 'product_id')
|
1411
|
+
futureProductDetails = self.safe_dict(market, 'future_product_details', {})
|
1412
|
+
contractExpiryType = self.safe_string(futureProductDetails, 'contract_expiry_type')
|
1413
|
+
contractSize = self.safe_number(futureProductDetails, 'contract_size')
|
1414
|
+
contractExpire = self.safe_string(futureProductDetails, 'contract_expiry')
|
1415
|
+
isSwap = (contractExpiryType == 'PERPETUAL')
|
1416
|
+
baseId = self.safe_string(futureProductDetails, 'contract_root_unit')
|
1417
|
+
quoteId = self.safe_string(market, 'quote_currency_id')
|
1418
|
+
base = self.safe_currency_code(baseId)
|
1419
|
+
quote = self.safe_currency_code(quoteId)
|
1420
|
+
tradingDisabled = self.safe_bool(market, 'is_disabled')
|
1421
|
+
symbol = base + '/' + quote
|
1422
|
+
type = None
|
1423
|
+
if isSwap:
|
1424
|
+
type = 'swap'
|
1425
|
+
symbol = symbol + ':' + quote
|
1426
|
+
else:
|
1427
|
+
type = 'future'
|
1428
|
+
symbol = symbol + ':' + quote + '-' + self.yymmdd(contractExpire)
|
1429
|
+
takerFeeRate = self.safe_number(feeTier, 'taker_fee_rate')
|
1430
|
+
makerFeeRate = self.safe_number(feeTier, 'maker_fee_rate')
|
1431
|
+
taker = takerFeeRate if takerFeeRate else self.parse_number('0.06')
|
1432
|
+
maker = makerFeeRate if makerFeeRate else self.parse_number('0.04')
|
1433
|
+
return self.safe_market_structure({
|
1434
|
+
'id': id,
|
1435
|
+
'symbol': symbol,
|
1436
|
+
'base': base,
|
1437
|
+
'quote': quote,
|
1438
|
+
'settle': quote,
|
1439
|
+
'baseId': baseId,
|
1440
|
+
'quoteId': quoteId,
|
1441
|
+
'settleId': quoteId,
|
1442
|
+
'type': type,
|
1443
|
+
'spot': False,
|
1444
|
+
'margin': False,
|
1445
|
+
'swap': isSwap,
|
1446
|
+
'future': not isSwap,
|
1447
|
+
'option': False,
|
1448
|
+
'active': not tradingDisabled,
|
1449
|
+
'contract': True,
|
1450
|
+
'linear': True,
|
1451
|
+
'inverse': False,
|
1452
|
+
'taker': taker,
|
1453
|
+
'maker': maker,
|
1454
|
+
'contractSize': contractSize,
|
1455
|
+
'expiry': self.parse8601(contractExpire),
|
1456
|
+
'expiryDatetime': contractExpire,
|
1457
|
+
'strike': None,
|
1458
|
+
'optionType': None,
|
1459
|
+
'precision': {
|
1460
|
+
'amount': self.safe_number(market, 'base_increment'),
|
1461
|
+
'price': self.safe_number_2(market, 'price_increment', 'quote_increment'),
|
1462
|
+
},
|
1463
|
+
'limits': {
|
1464
|
+
'leverage': {
|
1465
|
+
'min': None,
|
1466
|
+
'max': None,
|
1223
1467
|
},
|
1224
|
-
'
|
1225
|
-
'
|
1226
|
-
|
1227
|
-
'max': None,
|
1228
|
-
},
|
1229
|
-
'amount': {
|
1230
|
-
'min': self.safe_number(market, 'base_min_size'),
|
1231
|
-
'max': self.safe_number(market, 'base_max_size'),
|
1232
|
-
},
|
1233
|
-
'price': {
|
1234
|
-
'min': None,
|
1235
|
-
'max': None,
|
1236
|
-
},
|
1237
|
-
'cost': {
|
1238
|
-
'min': self.safe_number(market, 'quote_min_size'),
|
1239
|
-
'max': self.safe_number(market, 'quote_max_size'),
|
1240
|
-
},
|
1468
|
+
'amount': {
|
1469
|
+
'min': self.safe_number(market, 'base_min_size'),
|
1470
|
+
'max': self.safe_number(market, 'base_max_size'),
|
1241
1471
|
},
|
1242
|
-
'
|
1243
|
-
|
1244
|
-
|
1245
|
-
|
1472
|
+
'price': {
|
1473
|
+
'min': None,
|
1474
|
+
'max': None,
|
1475
|
+
},
|
1476
|
+
'cost': {
|
1477
|
+
'min': self.safe_number(market, 'quote_min_size'),
|
1478
|
+
'max': self.safe_number(market, 'quote_max_size'),
|
1479
|
+
},
|
1480
|
+
},
|
1481
|
+
'created': None,
|
1482
|
+
'info': market,
|
1483
|
+
})
|
1246
1484
|
|
1247
1485
|
async def fetch_currencies_from_cache(self, params={}):
|
1248
1486
|
options = self.safe_dict(self.options, 'fetchCurrencies', {})
|
@@ -1723,19 +1961,23 @@ class coinbase(Exchange, ImplicitAPI):
|
|
1723
1961
|
query for balance and get the amount of funds available for trading or funds locked in orders
|
1724
1962
|
:see: https://docs.cloud.coinbase.com/advanced-trade-api/reference/retailbrokerageapi_getaccounts
|
1725
1963
|
:see: https://docs.cloud.coinbase.com/sign-in-with-coinbase/docs/api-accounts#list-accounts
|
1964
|
+
:see: https://docs.cloud.coinbase.com/advanced-trade-api/reference/retailbrokerageapi_getfcmbalancesummary
|
1726
1965
|
:param dict [params]: extra parameters specific to the exchange API endpoint
|
1727
1966
|
:param boolean [params.v3]: default False, set True to use v3 api endpoint
|
1728
|
-
:param dict [params.type]: "spot"(default) or "swap"
|
1967
|
+
:param dict [params.type]: "spot"(default) or "swap" or "future"
|
1729
1968
|
:returns dict: a `balance structure <https://docs.ccxt.com/#/?id=balance-structure>`
|
1730
1969
|
"""
|
1731
1970
|
await self.load_markets()
|
1732
1971
|
request = {}
|
1733
1972
|
response = None
|
1734
1973
|
isV3 = self.safe_bool(params, 'v3', False)
|
1735
|
-
|
1736
|
-
|
1974
|
+
params = self.omit(params, ['v3'])
|
1975
|
+
marketType = None
|
1976
|
+
marketType, params = self.handle_market_type_and_params('fetchBalance', None, params)
|
1737
1977
|
method = self.safe_string(self.options, 'fetchBalance', 'v3PrivateGetBrokerageAccounts')
|
1738
|
-
if
|
1978
|
+
if marketType == 'future':
|
1979
|
+
response = await self.v3PrivateGetBrokerageCfmBalanceSummary(self.extend(request, params))
|
1980
|
+
elif (isV3) or (method == 'v3PrivateGetBrokerageAccounts'):
|
1739
1981
|
request['limit'] = 250
|
1740
1982
|
response = await self.v3PrivateGetBrokerageAccounts(self.extend(request, params))
|
1741
1983
|
else:
|
@@ -1812,7 +2054,7 @@ class coinbase(Exchange, ImplicitAPI):
|
|
1812
2054
|
# "size": 9
|
1813
2055
|
# }
|
1814
2056
|
#
|
1815
|
-
params['type'] =
|
2057
|
+
params['type'] = marketType
|
1816
2058
|
return self.parse_custom_balance(response, params)
|
1817
2059
|
|
1818
2060
|
async def fetch_ledger(self, code: Str = None, since: Int = None, limit: Int = None, params={}):
|
@@ -2249,6 +2491,11 @@ class coinbase(Exchange, ImplicitAPI):
|
|
2249
2491
|
:param str [params.end_time]: '2023-05-25T17:01:05.092Z' for 'GTD' orders
|
2250
2492
|
:param float [params.cost]: *spot market buy only* the quote quantity that can be used alternative for the amount
|
2251
2493
|
:param boolean [params.preview]: default to False, wether to use the test/preview endpoint or not
|
2494
|
+
:param float [params.leverage]: default to 1, the leverage to use for the order
|
2495
|
+
:param str [params.marginMode]: 'cross' or 'isolated'
|
2496
|
+
:param str [params.retail_portfolio_id]: portfolio uid
|
2497
|
+
:param boolean [params.is_max]: Used in conjunction with tradable_balance to indicate the user wants to use their entire tradable balance
|
2498
|
+
:param str [params.tradable_balance]: amount of tradable balance
|
2252
2499
|
:returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
|
2253
2500
|
"""
|
2254
2501
|
await self.load_markets()
|
@@ -2342,7 +2589,7 @@ class coinbase(Exchange, ImplicitAPI):
|
|
2342
2589
|
else:
|
2343
2590
|
if isStop or isStopLoss or isTakeProfit:
|
2344
2591
|
raise NotSupported(self.id + ' createOrder() only stop limit orders are supported')
|
2345
|
-
if side == 'buy':
|
2592
|
+
if market['spot'] and (side == 'buy'):
|
2346
2593
|
total = None
|
2347
2594
|
createMarketBuyOrderRequiresPrice = True
|
2348
2595
|
createMarketBuyOrderRequiresPrice, params = self.handle_option_and_params(params, 'createOrder', 'createMarketBuyOrderRequiresPrice', True)
|
@@ -2371,7 +2618,13 @@ class coinbase(Exchange, ImplicitAPI):
|
|
2371
2618
|
'base_size': self.amount_to_precision(symbol, amount),
|
2372
2619
|
},
|
2373
2620
|
}
|
2374
|
-
|
2621
|
+
marginMode = self.safe_string(params, 'marginMode')
|
2622
|
+
if marginMode is not None:
|
2623
|
+
if marginMode == 'isolated':
|
2624
|
+
request['margin_type'] = 'ISOLATED'
|
2625
|
+
elif marginMode == 'cross':
|
2626
|
+
request['margin_type'] = 'CROSS'
|
2627
|
+
params = self.omit(params, ['timeInForce', 'triggerPrice', 'stopLossPrice', 'takeProfitPrice', 'stopPrice', 'stop_price', 'stopDirection', 'stop_direction', 'clientOrderId', 'postOnly', 'post_only', 'end_time', 'marginMode'])
|
2375
2628
|
preview = self.safe_bool_2(params, 'preview', 'test', False)
|
2376
2629
|
response = None
|
2377
2630
|
if preview:
|
@@ -3562,6 +3815,235 @@ class coinbase(Exchange, ImplicitAPI):
|
|
3562
3815
|
data = self.safe_dict(response, 'data', {})
|
3563
3816
|
return self.parse_transaction(data)
|
3564
3817
|
|
3818
|
+
async def close_position(self, symbol: str, side: OrderSide = None, params={}) -> Order:
|
3819
|
+
"""
|
3820
|
+
*futures only* closes open positions for a market
|
3821
|
+
:see: https://coinbase-api.github.io/docs/#/en-us/swapV2/trade-api.html#One-Click%20Close%20All%20Positions
|
3822
|
+
:param str symbol: Unified CCXT market symbol
|
3823
|
+
:param str [side]: not used by coinbase
|
3824
|
+
:param dict [params]: extra parameters specific to the coinbase api endpoint
|
3825
|
+
* @param {str} params.clientOrderId *mandatory* the client order id of the position to close
|
3826
|
+
:param float [params.size]: the size of the position to close, optional
|
3827
|
+
:returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
|
3828
|
+
"""
|
3829
|
+
await self.load_markets()
|
3830
|
+
market = self.market(symbol)
|
3831
|
+
if not market['future']:
|
3832
|
+
raise NotSupported(self.id + ' closePosition() only supported for futures markets')
|
3833
|
+
clientOrderId = self.safe_string_2(params, 'client_order_id', 'clientOrderId')
|
3834
|
+
params = self.omit(params, 'clientOrderId')
|
3835
|
+
request = {
|
3836
|
+
'product_id': market['id'],
|
3837
|
+
}
|
3838
|
+
if clientOrderId is None:
|
3839
|
+
raise ArgumentsRequired(self.id + ' closePosition() requires a clientOrderId parameter')
|
3840
|
+
request['client_order_id'] = clientOrderId
|
3841
|
+
response = await self.v3PrivatePostBrokerageOrdersClosePosition(self.extend(request, params))
|
3842
|
+
order = self.safe_dict(response, 'success_response', {})
|
3843
|
+
return self.parse_order(order)
|
3844
|
+
|
3845
|
+
async def fetch_positions(self, symbols: Strings = None, params={}):
|
3846
|
+
"""
|
3847
|
+
fetch all open positions
|
3848
|
+
:see: https://docs.cloud.coinbase.com/advanced-trade-api/reference/retailbrokerageapi_getfcmpositions
|
3849
|
+
:see: https://docs.cloud.coinbase.com/advanced-trade-api/reference/retailbrokerageapi_getintxpositions
|
3850
|
+
:param str[] [symbols]: list of unified market symbols
|
3851
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
3852
|
+
:param str [params.portfolio]: the portfolio UUID to fetch positions for
|
3853
|
+
:returns dict[]: a list of `position structure <https://docs.ccxt.com/#/?id=position-structure>`
|
3854
|
+
"""
|
3855
|
+
await self.load_markets()
|
3856
|
+
symbols = self.market_symbols(symbols)
|
3857
|
+
market = None
|
3858
|
+
if symbols is not None:
|
3859
|
+
market = self.market(symbols[0])
|
3860
|
+
type = None
|
3861
|
+
type, params = self.handle_market_type_and_params('fetchPositions', market, params)
|
3862
|
+
response = None
|
3863
|
+
if type == 'future':
|
3864
|
+
response = await self.v3PrivateGetBrokerageCfmPositions(params)
|
3865
|
+
else:
|
3866
|
+
portfolio = None
|
3867
|
+
portfolio, params = self.handle_option_and_params(params, 'fetchPositions', 'portfolio')
|
3868
|
+
if portfolio is None:
|
3869
|
+
raise ArgumentsRequired(self.id + ' fetchPositions() requires a "portfolio" value in params(eg: dbcb91e7-2bc9-515), or set.options["portfolio"]. You can get a list of portfolios with fetchPortfolios()')
|
3870
|
+
request = {
|
3871
|
+
'portfolio_uuid': portfolio,
|
3872
|
+
}
|
3873
|
+
response = await self.v3PrivateGetBrokerageIntxPositionsPortfolioUuid(self.extend(request, params))
|
3874
|
+
positions = self.safe_list(response, 'positions', [])
|
3875
|
+
return self.parse_positions(positions, symbols)
|
3876
|
+
|
3877
|
+
async def fetch_position(self, symbol: str, params={}):
|
3878
|
+
"""
|
3879
|
+
fetch data on a single open contract trade position
|
3880
|
+
:see: https://docs.cloud.coinbase.com/advanced-trade-api/reference/retailbrokerageapi_getintxposition
|
3881
|
+
:see: https://docs.cloud.coinbase.com/advanced-trade-api/reference/retailbrokerageapi_getfcmposition
|
3882
|
+
:param str symbol: unified market symbol of the market the position is held in, default is None
|
3883
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
3884
|
+
:param str [params.product_id]: *futures only* the product id of the position to fetch, required for futures markets only
|
3885
|
+
:param str [params.portfolio]: *perpetual/swaps only* the portfolio UUID to fetch the position for, required for perpetual/swaps markets only
|
3886
|
+
:returns dict: a `position structure <https://docs.ccxt.com/#/?id=position-structure>`
|
3887
|
+
"""
|
3888
|
+
await self.load_markets()
|
3889
|
+
market = self.market(symbol)
|
3890
|
+
response = None
|
3891
|
+
if market['future']:
|
3892
|
+
productId = self.safe_string(market, 'product_id')
|
3893
|
+
if productId is None:
|
3894
|
+
raise ArgumentsRequired(self.id + ' fetchPosition() requires a "product_id" in params')
|
3895
|
+
futureRequest = {
|
3896
|
+
'product_id': productId,
|
3897
|
+
}
|
3898
|
+
response = await self.v3PrivateGetBrokerageCfmPositionsProductId(self.extend(futureRequest, params))
|
3899
|
+
else:
|
3900
|
+
portfolio = None
|
3901
|
+
portfolio, params = self.handle_option_and_params(params, 'fetchPositions', 'portfolio')
|
3902
|
+
if portfolio is None:
|
3903
|
+
raise ArgumentsRequired(self.id + ' fetchPosition() requires a "portfolio" value in params(eg: dbcb91e7-2bc9-515), or set.options["portfolio"]. You can get a list of portfolios with fetchPortfolios()')
|
3904
|
+
request = {
|
3905
|
+
'symbol': market['id'],
|
3906
|
+
'portfolio_uuid': portfolio,
|
3907
|
+
}
|
3908
|
+
response = await self.v3PrivateGetBrokerageIntxPositionsPortfolioUuidSymbol(self.extend(request, params))
|
3909
|
+
position = self.safe_dict(response, 'position', {})
|
3910
|
+
return self.parse_position(position, market)
|
3911
|
+
|
3912
|
+
def parse_position(self, position, market: Market = None):
|
3913
|
+
#
|
3914
|
+
# {
|
3915
|
+
# "product_id": "1r4njf84-0-0",
|
3916
|
+
# "product_uuid": "cd34c18b-3665-4ed8-9305-3db277c49fc5",
|
3917
|
+
# "symbol": "ADA-PERP-INTX",
|
3918
|
+
# "vwap": {
|
3919
|
+
# "value": "0.6171",
|
3920
|
+
# "currency": "USDC"
|
3921
|
+
# },
|
3922
|
+
# "position_side": "POSITION_SIDE_LONG",
|
3923
|
+
# "net_size": "20",
|
3924
|
+
# "buy_order_size": "0",
|
3925
|
+
# "sell_order_size": "0",
|
3926
|
+
# "im_contribution": "0.1",
|
3927
|
+
# "unrealized_pnl": {
|
3928
|
+
# "value": "0.074",
|
3929
|
+
# "currency": "USDC"
|
3930
|
+
# },
|
3931
|
+
# "mark_price": {
|
3932
|
+
# "value": "0.6208",
|
3933
|
+
# "currency": "USDC"
|
3934
|
+
# },
|
3935
|
+
# "liquidation_price": {
|
3936
|
+
# "value": "0",
|
3937
|
+
# "currency": "USDC"
|
3938
|
+
# },
|
3939
|
+
# "leverage": "1",
|
3940
|
+
# "im_notional": {
|
3941
|
+
# "value": "12.342",
|
3942
|
+
# "currency": "USDC"
|
3943
|
+
# },
|
3944
|
+
# "mm_notional": {
|
3945
|
+
# "value": "0.814572",
|
3946
|
+
# "currency": "USDC"
|
3947
|
+
# },
|
3948
|
+
# "position_notional": {
|
3949
|
+
# "value": "12.342",
|
3950
|
+
# "currency": "USDC"
|
3951
|
+
# },
|
3952
|
+
# "margin_type": "MARGIN_TYPE_CROSS",
|
3953
|
+
# "liquidation_buffer": "19.677828",
|
3954
|
+
# "liquidation_percentage": "4689.3506",
|
3955
|
+
# "portfolio_summary": {
|
3956
|
+
# "portfolio_uuid": "018ebd63-1f6d-7c8e-ada9-0761c5a2235f",
|
3957
|
+
# "collateral": "20.4184",
|
3958
|
+
# "position_notional": "12.342",
|
3959
|
+
# "open_position_notional": "12.342",
|
3960
|
+
# "pending_fees": "0",
|
3961
|
+
# "borrow": "0",
|
3962
|
+
# "accrued_interest": "0",
|
3963
|
+
# "rolling_debt": "0",
|
3964
|
+
# "portfolio_initial_margin": "0.1",
|
3965
|
+
# "portfolio_im_notional": {
|
3966
|
+
# "value": "12.342",
|
3967
|
+
# "currency": "USDC"
|
3968
|
+
# },
|
3969
|
+
# "portfolio_maintenance_margin": "0.066",
|
3970
|
+
# "portfolio_mm_notional": {
|
3971
|
+
# "value": "0.814572",
|
3972
|
+
# "currency": "USDC"
|
3973
|
+
# },
|
3974
|
+
# "liquidation_percentage": "4689.3506",
|
3975
|
+
# "liquidation_buffer": "19.677828",
|
3976
|
+
# "margin_type": "MARGIN_TYPE_CROSS",
|
3977
|
+
# "margin_flags": "PORTFOLIO_MARGIN_FLAGS_UNSPECIFIED",
|
3978
|
+
# "liquidation_status": "PORTFOLIO_LIQUIDATION_STATUS_NOT_LIQUIDATING",
|
3979
|
+
# "unrealized_pnl": {
|
3980
|
+
# "value": "0.074",
|
3981
|
+
# "currency": "USDC"
|
3982
|
+
# },
|
3983
|
+
# "buying_power": {
|
3984
|
+
# "value": "8.1504",
|
3985
|
+
# "currency": "USDC"
|
3986
|
+
# },
|
3987
|
+
# "total_balance": {
|
3988
|
+
# "value": "20.4924",
|
3989
|
+
# "currency": "USDC"
|
3990
|
+
# },
|
3991
|
+
# "max_withdrawal": {
|
3992
|
+
# "value": "8.0764",
|
3993
|
+
# "currency": "USDC"
|
3994
|
+
# }
|
3995
|
+
# },
|
3996
|
+
# "entry_vwap": {
|
3997
|
+
# "value": "0.6091",
|
3998
|
+
# "currency": "USDC"
|
3999
|
+
# }
|
4000
|
+
# }
|
4001
|
+
#
|
4002
|
+
marketId = self.safe_string(position, 'symbol', '')
|
4003
|
+
market = self.safe_market(marketId, market)
|
4004
|
+
rawMargin = self.safe_string(position, 'margin_type')
|
4005
|
+
marginMode = None
|
4006
|
+
if rawMargin is not None:
|
4007
|
+
marginMode = 'cross' if (rawMargin == 'MARGIN_TYPE_CROSS') else 'isolated'
|
4008
|
+
notionalObject = self.safe_dict(position, 'position_notional', {})
|
4009
|
+
positionSide = self.safe_string(position, 'position_side')
|
4010
|
+
side = 'long' if (positionSide == 'POSITION_SIDE_LONG') else 'short'
|
4011
|
+
unrealizedPNLObject = self.safe_dict(position, 'unrealized_pnl', {})
|
4012
|
+
liquidationPriceObject = self.safe_dict(position, 'liquidation_price', {})
|
4013
|
+
liquidationPrice = self.safe_number(liquidationPriceObject, 'value')
|
4014
|
+
vwapObject = self.safe_dict(position, 'vwap', {})
|
4015
|
+
summaryObject = self.safe_dict(position, 'portfolio_summary', {})
|
4016
|
+
return self.safe_position({
|
4017
|
+
'info': position,
|
4018
|
+
'id': self.safe_string(position, 'product_id'),
|
4019
|
+
'symbol': self.safe_symbol(marketId, market),
|
4020
|
+
'notional': self.safe_number(notionalObject, 'value'),
|
4021
|
+
'marginMode': marginMode,
|
4022
|
+
'liquidationPrice': liquidationPrice,
|
4023
|
+
'entryPrice': self.safe_number(vwapObject, 'value'),
|
4024
|
+
'unrealizedPnl': self.safe_number(unrealizedPNLObject, 'value'),
|
4025
|
+
'realizedPnl': None,
|
4026
|
+
'percentage': None,
|
4027
|
+
'contracts': self.safe_number(position, 'net_size'),
|
4028
|
+
'contractSize': market['contractSize'],
|
4029
|
+
'markPrice': None,
|
4030
|
+
'lastPrice': None,
|
4031
|
+
'side': side,
|
4032
|
+
'hedged': None,
|
4033
|
+
'timestamp': None,
|
4034
|
+
'datetime': None,
|
4035
|
+
'lastUpdateTimestamp': None,
|
4036
|
+
'maintenanceMargin': None,
|
4037
|
+
'maintenanceMarginPercentage': None,
|
4038
|
+
'collateral': self.safe_number(summaryObject, 'collateral'),
|
4039
|
+
'initialMargin': None,
|
4040
|
+
'initialMarginPercentage': None,
|
4041
|
+
'leverage': self.safe_number(position, 'leverage'),
|
4042
|
+
'marginRatio': None,
|
4043
|
+
'stopLossPrice': None,
|
4044
|
+
'takeProfitPrice': None,
|
4045
|
+
})
|
4046
|
+
|
3565
4047
|
def sign(self, path, api=[], method='GET', params={}, headers=None, body=None):
|
3566
4048
|
version = api[0]
|
3567
4049
|
signed = api[1] == 'private'
|
@@ -3604,7 +4086,9 @@ class coinbase(Exchange, ImplicitAPI):
|
|
3604
4086
|
# it may not work for v2
|
3605
4087
|
uri = method + ' ' + url.replace('https://', '')
|
3606
4088
|
quesPos = uri.find('?')
|
3607
|
-
|
4089
|
+
# Due to we use mb_strpos, quesPos could be False in php. In that case, the quesPos >= 0 is True
|
4090
|
+
# Also it's not possible that the question mark is first character, only check > 0 here.
|
4091
|
+
if quesPos > 0:
|
3608
4092
|
uri = uri[0:quesPos]
|
3609
4093
|
nonce = self.random_bytes(16)
|
3610
4094
|
request = {
|