ccxt-ir 4.3.46.0.1__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.
Files changed (772) hide show
  1. ccxt/__init__.py +358 -0
  2. ccxt/abantether.py +316 -0
  3. ccxt/abstract/__init__.py +0 -0
  4. ccxt/abstract/abantether.py +5 -0
  5. ccxt/abstract/ace.py +15 -0
  6. ccxt/abstract/afratether.py +6 -0
  7. ccxt/abstract/alpaca.py +70 -0
  8. ccxt/abstract/arzinja.py +5 -0
  9. ccxt/abstract/arzplus.py +7 -0
  10. ccxt/abstract/ascendex.py +77 -0
  11. ccxt/abstract/bequant.py +115 -0
  12. ccxt/abstract/bigone.py +45 -0
  13. ccxt/abstract/binance.py +712 -0
  14. ccxt/abstract/binancecoinm.py +712 -0
  15. ccxt/abstract/binanceus.py +764 -0
  16. ccxt/abstract/binanceusdm.py +712 -0
  17. ccxt/abstract/bingx.py +113 -0
  18. ccxt/abstract/bit2c.py +27 -0
  19. ccxt/abstract/bitbank.py +27 -0
  20. ccxt/abstract/bitbay.py +53 -0
  21. ccxt/abstract/bitbns.py +40 -0
  22. ccxt/abstract/bitcoincom.py +115 -0
  23. ccxt/abstract/bitfinex.py +69 -0
  24. ccxt/abstract/bitfinex2.py +139 -0
  25. ccxt/abstract/bitflyer.py +38 -0
  26. ccxt/abstract/bitget.py +508 -0
  27. ccxt/abstract/bithumb.py +32 -0
  28. ccxt/abstract/bitimen.py +7 -0
  29. ccxt/abstract/bitir.py +7 -0
  30. ccxt/abstract/bitmart.py +99 -0
  31. ccxt/abstract/bitmex.py +97 -0
  32. ccxt/abstract/bitopro.py +29 -0
  33. ccxt/abstract/bitpanda.py +35 -0
  34. ccxt/abstract/bitpin.py +7 -0
  35. ccxt/abstract/bitrue.py +72 -0
  36. ccxt/abstract/bitso.py +43 -0
  37. ccxt/abstract/bitstamp.py +258 -0
  38. ccxt/abstract/bitteam.py +29 -0
  39. ccxt/abstract/bitvavo.py +27 -0
  40. ccxt/abstract/bl3p.py +19 -0
  41. ccxt/abstract/blockchaincom.py +28 -0
  42. ccxt/abstract/blofin.py +37 -0
  43. ccxt/abstract/btcalpha.py +18 -0
  44. ccxt/abstract/btcbox.py +13 -0
  45. ccxt/abstract/btcmarkets.py +39 -0
  46. ccxt/abstract/btcturk.py +20 -0
  47. ccxt/abstract/bybit.py +298 -0
  48. ccxt/abstract/cex.py +33 -0
  49. ccxt/abstract/coinbase.py +94 -0
  50. ccxt/abstract/coinbaseadvanced.py +94 -0
  51. ccxt/abstract/coinbaseexchange.py +67 -0
  52. ccxt/abstract/coinbaseinternational.py +39 -0
  53. ccxt/abstract/coincatch.py +94 -0
  54. ccxt/abstract/coincheck.py +33 -0
  55. ccxt/abstract/coinex.py +237 -0
  56. ccxt/abstract/coinlist.py +54 -0
  57. ccxt/abstract/coinmate.py +62 -0
  58. ccxt/abstract/coinmetro.py +34 -0
  59. ccxt/abstract/coinone.py +67 -0
  60. ccxt/abstract/coinsph.py +54 -0
  61. ccxt/abstract/coinspot.py +28 -0
  62. ccxt/abstract/cryptocom.py +107 -0
  63. ccxt/abstract/currencycom.py +68 -0
  64. ccxt/abstract/delta.py +50 -0
  65. ccxt/abstract/deribit.py +125 -0
  66. ccxt/abstract/digifinex.py +91 -0
  67. ccxt/abstract/eterex.py +5 -0
  68. ccxt/abstract/excoino.py +7 -0
  69. ccxt/abstract/exir.py +8 -0
  70. ccxt/abstract/exmo.py +55 -0
  71. ccxt/abstract/exnovin.py +6 -0
  72. ccxt/abstract/farhadexchange.py +5 -0
  73. ccxt/abstract/fmfwio.py +115 -0
  74. ccxt/abstract/gate.py +265 -0
  75. ccxt/abstract/gateio.py +265 -0
  76. ccxt/abstract/gemini.py +58 -0
  77. ccxt/abstract/hashkey.py +67 -0
  78. ccxt/abstract/hitbtc.py +115 -0
  79. ccxt/abstract/hitbtc3.py +115 -0
  80. ccxt/abstract/hitobit.py +8 -0
  81. ccxt/abstract/hollaex.py +33 -0
  82. ccxt/abstract/htx.py +548 -0
  83. ccxt/abstract/huobi.py +548 -0
  84. ccxt/abstract/huobijp.py +114 -0
  85. ccxt/abstract/hyperliquid.py +6 -0
  86. ccxt/abstract/idex.py +26 -0
  87. ccxt/abstract/independentreserve.py +37 -0
  88. ccxt/abstract/indodax.py +26 -0
  89. ccxt/abstract/jibitex.py +7 -0
  90. ccxt/abstract/kraken.py +57 -0
  91. ccxt/abstract/krakenfutures.py +38 -0
  92. ccxt/abstract/kucoin.py +214 -0
  93. ccxt/abstract/kucoinfutures.py +233 -0
  94. ccxt/abstract/kuna.py +182 -0
  95. ccxt/abstract/latoken.py +56 -0
  96. ccxt/abstract/lbank.py +61 -0
  97. ccxt/abstract/luno.py +37 -0
  98. ccxt/abstract/lykke.py +29 -0
  99. ccxt/abstract/mercado.py +25 -0
  100. ccxt/abstract/mexc.py +178 -0
  101. ccxt/abstract/ndax.py +97 -0
  102. ccxt/abstract/nobitex.py +7 -0
  103. ccxt/abstract/novadax.py +29 -0
  104. ccxt/abstract/oceanex.py +22 -0
  105. ccxt/abstract/okcoin.py +74 -0
  106. ccxt/abstract/okexchange.py +8 -0
  107. ccxt/abstract/okx.py +324 -0
  108. ccxt/abstract/ompfinex.py +7 -0
  109. ccxt/abstract/onetrading.py +35 -0
  110. ccxt/abstract/oxfun.py +34 -0
  111. ccxt/abstract/p2b.py +22 -0
  112. ccxt/abstract/paradex.py +40 -0
  113. ccxt/abstract/paymium.py +28 -0
  114. ccxt/abstract/phemex.py +115 -0
  115. ccxt/abstract/poloniex.py +69 -0
  116. ccxt/abstract/poloniexfutures.py +48 -0
  117. ccxt/abstract/probit.py +23 -0
  118. ccxt/abstract/ramzinex.py +7 -0
  119. ccxt/abstract/sarmayex.py +5 -0
  120. ccxt/abstract/sarrafex.py +7 -0
  121. ccxt/abstract/tabdeal.py +7 -0
  122. ccxt/abstract/tetherland.py +5 -0
  123. ccxt/abstract/timex.py +62 -0
  124. ccxt/abstract/tokocrypto.py +37 -0
  125. ccxt/abstract/tradeogre.py +16 -0
  126. ccxt/abstract/twox.py +5 -0
  127. ccxt/abstract/ubitex.py +7 -0
  128. ccxt/abstract/upbit.py +38 -0
  129. ccxt/abstract/vertex.py +19 -0
  130. ccxt/abstract/wallex.py +8 -0
  131. ccxt/abstract/wavesexchange.py +154 -0
  132. ccxt/abstract/wazirx.py +30 -0
  133. ccxt/abstract/whitebit.py +98 -0
  134. ccxt/abstract/woo.py +83 -0
  135. ccxt/abstract/woofipro.py +119 -0
  136. ccxt/abstract/xt.py +152 -0
  137. ccxt/abstract/yobit.py +16 -0
  138. ccxt/abstract/zaif.py +38 -0
  139. ccxt/abstract/zonda.py +53 -0
  140. ccxt/ace.py +1012 -0
  141. ccxt/afratether.py +293 -0
  142. ccxt/alpaca.py +1083 -0
  143. ccxt/arzinja.py +285 -0
  144. ccxt/arzplus.py +412 -0
  145. ccxt/ascendex.py +3330 -0
  146. ccxt/async_support/__init__.py +337 -0
  147. ccxt/async_support/abantether.py +316 -0
  148. ccxt/async_support/ace.py +1012 -0
  149. ccxt/async_support/afratether.py +293 -0
  150. ccxt/async_support/alpaca.py +1083 -0
  151. ccxt/async_support/arzinja.py +285 -0
  152. ccxt/async_support/arzplus.py +412 -0
  153. ccxt/async_support/ascendex.py +3330 -0
  154. ccxt/async_support/base/__init__.py +1 -0
  155. ccxt/async_support/base/exchange.py +1966 -0
  156. ccxt/async_support/base/throttler.py +50 -0
  157. ccxt/async_support/base/ws/__init__.py +38 -0
  158. ccxt/async_support/base/ws/aiohttp_client.py +125 -0
  159. ccxt/async_support/base/ws/cache.py +212 -0
  160. ccxt/async_support/base/ws/client.py +193 -0
  161. ccxt/async_support/base/ws/fast_client.py +96 -0
  162. ccxt/async_support/base/ws/functions.py +59 -0
  163. ccxt/async_support/base/ws/future.py +58 -0
  164. ccxt/async_support/base/ws/order_book.py +78 -0
  165. ccxt/async_support/base/ws/order_book_side.py +174 -0
  166. ccxt/async_support/bequant.py +33 -0
  167. ccxt/async_support/bigone.py +2113 -0
  168. ccxt/async_support/binance.py +12234 -0
  169. ccxt/async_support/binancecoinm.py +45 -0
  170. ccxt/async_support/binanceus.py +211 -0
  171. ccxt/async_support/binanceusdm.py +58 -0
  172. ccxt/async_support/bingx.py +4325 -0
  173. ccxt/async_support/bit2c.py +866 -0
  174. ccxt/async_support/bitbank.py +1001 -0
  175. ccxt/async_support/bitbay.py +17 -0
  176. ccxt/async_support/bitbns.py +1154 -0
  177. ccxt/async_support/bitcoincom.py +17 -0
  178. ccxt/async_support/bitfinex.py +1617 -0
  179. ccxt/async_support/bitfinex2.py +3552 -0
  180. ccxt/async_support/bitflyer.py +995 -0
  181. ccxt/async_support/bitget.py +8273 -0
  182. ccxt/async_support/bithumb.py +1061 -0
  183. ccxt/async_support/bitimen.py +401 -0
  184. ccxt/async_support/bitir.py +490 -0
  185. ccxt/async_support/bitmart.py +4415 -0
  186. ccxt/async_support/bitmex.py +2756 -0
  187. ccxt/async_support/bitopro.py +1630 -0
  188. ccxt/async_support/bitpanda.py +16 -0
  189. ccxt/async_support/bitpin.py +454 -0
  190. ccxt/async_support/bitrue.py +3027 -0
  191. ccxt/async_support/bitso.py +1670 -0
  192. ccxt/async_support/bitstamp.py +2203 -0
  193. ccxt/async_support/bitteam.py +2239 -0
  194. ccxt/async_support/bitvavo.py +1968 -0
  195. ccxt/async_support/bl3p.py +485 -0
  196. ccxt/async_support/blockchaincom.py +1104 -0
  197. ccxt/async_support/blofin.py +2066 -0
  198. ccxt/async_support/btcalpha.py +891 -0
  199. ccxt/async_support/btcbox.py +544 -0
  200. ccxt/async_support/btcmarkets.py +1221 -0
  201. ccxt/async_support/btcturk.py +911 -0
  202. ccxt/async_support/bybit.py +8159 -0
  203. ccxt/async_support/cex.py +1605 -0
  204. ccxt/async_support/coinbase.py +4475 -0
  205. ccxt/async_support/coinbaseadvanced.py +17 -0
  206. ccxt/async_support/coinbaseexchange.py +1734 -0
  207. ccxt/async_support/coinbaseinternational.py +1899 -0
  208. ccxt/async_support/coincatch.py +5069 -0
  209. ccxt/async_support/coincheck.py +815 -0
  210. ccxt/async_support/coinex.py +5526 -0
  211. ccxt/async_support/coinlist.py +2243 -0
  212. ccxt/async_support/coinmate.py +1067 -0
  213. ccxt/async_support/coinmetro.py +1797 -0
  214. ccxt/async_support/coinone.py +1127 -0
  215. ccxt/async_support/coinsph.py +1850 -0
  216. ccxt/async_support/coinspot.py +534 -0
  217. ccxt/async_support/cryptocom.py +2822 -0
  218. ccxt/async_support/currencycom.py +1950 -0
  219. ccxt/async_support/delta.py +3376 -0
  220. ccxt/async_support/deribit.py +3437 -0
  221. ccxt/async_support/digifinex.py +3960 -0
  222. ccxt/async_support/eterex.py +286 -0
  223. ccxt/async_support/excoino.py +399 -0
  224. ccxt/async_support/exir.py +375 -0
  225. ccxt/async_support/exmo.py +2462 -0
  226. ccxt/async_support/exnovin.py +360 -0
  227. ccxt/async_support/farhadexchange.py +266 -0
  228. ccxt/async_support/fmfwio.py +34 -0
  229. ccxt/async_support/gate.py +6976 -0
  230. ccxt/async_support/gateio.py +16 -0
  231. ccxt/async_support/gemini.py +1825 -0
  232. ccxt/async_support/hashkey.py +4150 -0
  233. ccxt/async_support/hitbtc.py +3423 -0
  234. ccxt/async_support/hitbtc3.py +16 -0
  235. ccxt/async_support/hitobit.py +391 -0
  236. ccxt/async_support/hollaex.py +1813 -0
  237. ccxt/async_support/htx.py +8506 -0
  238. ccxt/async_support/huobi.py +16 -0
  239. ccxt/async_support/huobijp.py +1801 -0
  240. ccxt/async_support/hyperliquid.py +2431 -0
  241. ccxt/async_support/idex.py +1766 -0
  242. ccxt/async_support/independentreserve.py +784 -0
  243. ccxt/async_support/indodax.py +1247 -0
  244. ccxt/async_support/jibitex.py +395 -0
  245. ccxt/async_support/kraken.py +2894 -0
  246. ccxt/async_support/krakenfutures.py +2601 -0
  247. ccxt/async_support/kucoin.py +4602 -0
  248. ccxt/async_support/kucoinfutures.py +2698 -0
  249. ccxt/async_support/kuna.py +1841 -0
  250. ccxt/async_support/latoken.py +1664 -0
  251. ccxt/async_support/lbank.py +2683 -0
  252. ccxt/async_support/luno.py +1067 -0
  253. ccxt/async_support/lykke.py +1270 -0
  254. ccxt/async_support/mercado.py +842 -0
  255. ccxt/async_support/mexc.py +5369 -0
  256. ccxt/async_support/ndax.py +2354 -0
  257. ccxt/async_support/nobitex.py +419 -0
  258. ccxt/async_support/novadax.py +1484 -0
  259. ccxt/async_support/oceanex.py +903 -0
  260. ccxt/async_support/okcoin.py +2936 -0
  261. ccxt/async_support/okexchange.py +349 -0
  262. ccxt/async_support/okx.py +7827 -0
  263. ccxt/async_support/ompfinex.py +472 -0
  264. ccxt/async_support/onetrading.py +1911 -0
  265. ccxt/async_support/oxfun.py +2773 -0
  266. ccxt/async_support/p2b.py +1194 -0
  267. ccxt/async_support/paradex.py +2015 -0
  268. ccxt/async_support/paymium.py +564 -0
  269. ccxt/async_support/phemex.py +4473 -0
  270. ccxt/async_support/poloniex.py +2232 -0
  271. ccxt/async_support/poloniexfutures.py +1717 -0
  272. ccxt/async_support/probit.py +1734 -0
  273. ccxt/async_support/ramzinex.py +476 -0
  274. ccxt/async_support/sarmayex.py +357 -0
  275. ccxt/async_support/sarrafex.py +478 -0
  276. ccxt/async_support/tabdeal.py +364 -0
  277. ccxt/async_support/tetherland.py +349 -0
  278. ccxt/async_support/timex.py +1593 -0
  279. ccxt/async_support/tokocrypto.py +2405 -0
  280. ccxt/async_support/tradeogre.py +608 -0
  281. ccxt/async_support/twox.py +326 -0
  282. ccxt/async_support/ubitex.py +409 -0
  283. ccxt/async_support/upbit.py +1833 -0
  284. ccxt/async_support/vertex.py +2922 -0
  285. ccxt/async_support/wallex.py +445 -0
  286. ccxt/async_support/wavesexchange.py +2473 -0
  287. ccxt/async_support/wazirx.py +1224 -0
  288. ccxt/async_support/whitebit.py +2469 -0
  289. ccxt/async_support/woo.py +3114 -0
  290. ccxt/async_support/woofipro.py +2533 -0
  291. ccxt/async_support/xt.py +4454 -0
  292. ccxt/async_support/yobit.py +1283 -0
  293. ccxt/async_support/zaif.py +725 -0
  294. ccxt/async_support/zonda.py +1828 -0
  295. ccxt/base/__init__.py +27 -0
  296. ccxt/base/decimal_to_precision.py +174 -0
  297. ccxt/base/errors.py +242 -0
  298. ccxt/base/exchange.py +5941 -0
  299. ccxt/base/precise.py +287 -0
  300. ccxt/base/types.py +502 -0
  301. ccxt/bequant.py +33 -0
  302. ccxt/bigone.py +2112 -0
  303. ccxt/binance.py +12233 -0
  304. ccxt/binancecoinm.py +45 -0
  305. ccxt/binanceus.py +211 -0
  306. ccxt/binanceusdm.py +58 -0
  307. ccxt/bingx.py +4324 -0
  308. ccxt/bit2c.py +866 -0
  309. ccxt/bitbank.py +1001 -0
  310. ccxt/bitbay.py +17 -0
  311. ccxt/bitbns.py +1154 -0
  312. ccxt/bitcoincom.py +17 -0
  313. ccxt/bitfinex.py +1617 -0
  314. ccxt/bitfinex2.py +3552 -0
  315. ccxt/bitflyer.py +995 -0
  316. ccxt/bitget.py +8272 -0
  317. ccxt/bithumb.py +1061 -0
  318. ccxt/bitimen.py +401 -0
  319. ccxt/bitir.py +490 -0
  320. ccxt/bitmart.py +4415 -0
  321. ccxt/bitmex.py +2756 -0
  322. ccxt/bitopro.py +1630 -0
  323. ccxt/bitpanda.py +16 -0
  324. ccxt/bitpin.py +454 -0
  325. ccxt/bitrue.py +3026 -0
  326. ccxt/bitso.py +1670 -0
  327. ccxt/bitstamp.py +2203 -0
  328. ccxt/bitteam.py +2239 -0
  329. ccxt/bitvavo.py +1968 -0
  330. ccxt/bl3p.py +485 -0
  331. ccxt/blockchaincom.py +1104 -0
  332. ccxt/blofin.py +2066 -0
  333. ccxt/btcalpha.py +891 -0
  334. ccxt/btcbox.py +544 -0
  335. ccxt/btcmarkets.py +1221 -0
  336. ccxt/btcturk.py +911 -0
  337. ccxt/bybit.py +8158 -0
  338. ccxt/cex.py +1605 -0
  339. ccxt/coinbase.py +4474 -0
  340. ccxt/coinbaseadvanced.py +17 -0
  341. ccxt/coinbaseexchange.py +1734 -0
  342. ccxt/coinbaseinternational.py +1899 -0
  343. ccxt/coincatch.py +5069 -0
  344. ccxt/coincheck.py +815 -0
  345. ccxt/coinex.py +5525 -0
  346. ccxt/coinlist.py +2243 -0
  347. ccxt/coinmate.py +1067 -0
  348. ccxt/coinmetro.py +1797 -0
  349. ccxt/coinone.py +1127 -0
  350. ccxt/coinsph.py +1850 -0
  351. ccxt/coinspot.py +534 -0
  352. ccxt/cryptocom.py +2822 -0
  353. ccxt/currencycom.py +1950 -0
  354. ccxt/delta.py +3376 -0
  355. ccxt/deribit.py +3437 -0
  356. ccxt/digifinex.py +3959 -0
  357. ccxt/eterex.py +286 -0
  358. ccxt/excoino.py +399 -0
  359. ccxt/exir.py +375 -0
  360. ccxt/exmo.py +2462 -0
  361. ccxt/exnovin.py +360 -0
  362. ccxt/farhadexchange.py +266 -0
  363. ccxt/fmfwio.py +34 -0
  364. ccxt/gate.py +6975 -0
  365. ccxt/gateio.py +16 -0
  366. ccxt/gemini.py +1824 -0
  367. ccxt/hashkey.py +4150 -0
  368. ccxt/hitbtc.py +3423 -0
  369. ccxt/hitbtc3.py +16 -0
  370. ccxt/hitobit.py +391 -0
  371. ccxt/hollaex.py +1813 -0
  372. ccxt/htx.py +8505 -0
  373. ccxt/huobi.py +16 -0
  374. ccxt/huobijp.py +1801 -0
  375. ccxt/hyperliquid.py +2430 -0
  376. ccxt/idex.py +1766 -0
  377. ccxt/independentreserve.py +784 -0
  378. ccxt/indodax.py +1247 -0
  379. ccxt/jibitex.py +395 -0
  380. ccxt/kraken.py +2894 -0
  381. ccxt/krakenfutures.py +2601 -0
  382. ccxt/kucoin.py +4601 -0
  383. ccxt/kucoinfutures.py +2698 -0
  384. ccxt/kuna.py +1841 -0
  385. ccxt/latoken.py +1664 -0
  386. ccxt/lbank.py +2682 -0
  387. ccxt/luno.py +1067 -0
  388. ccxt/lykke.py +1270 -0
  389. ccxt/mercado.py +842 -0
  390. ccxt/mexc.py +5369 -0
  391. ccxt/ndax.py +2354 -0
  392. ccxt/nobitex.py +419 -0
  393. ccxt/novadax.py +1484 -0
  394. ccxt/oceanex.py +903 -0
  395. ccxt/okcoin.py +2936 -0
  396. ccxt/okexchange.py +349 -0
  397. ccxt/okx.py +7826 -0
  398. ccxt/ompfinex.py +472 -0
  399. ccxt/onetrading.py +1911 -0
  400. ccxt/oxfun.py +2772 -0
  401. ccxt/p2b.py +1194 -0
  402. ccxt/paradex.py +2015 -0
  403. ccxt/paymium.py +564 -0
  404. ccxt/phemex.py +4473 -0
  405. ccxt/poloniex.py +2232 -0
  406. ccxt/poloniexfutures.py +1717 -0
  407. ccxt/pro/__init__.py +149 -0
  408. ccxt/pro/alpaca.py +685 -0
  409. ccxt/pro/ascendex.py +916 -0
  410. ccxt/pro/bequant.py +38 -0
  411. ccxt/pro/binance.py +3488 -0
  412. ccxt/pro/binancecoinm.py +28 -0
  413. ccxt/pro/binanceus.py +48 -0
  414. ccxt/pro/binanceusdm.py +31 -0
  415. ccxt/pro/bingx.py +1264 -0
  416. ccxt/pro/bitcoincom.py +34 -0
  417. ccxt/pro/bitfinex.py +621 -0
  418. ccxt/pro/bitfinex2.py +1083 -0
  419. ccxt/pro/bitget.py +1692 -0
  420. ccxt/pro/bithumb.py +368 -0
  421. ccxt/pro/bitmart.py +1449 -0
  422. ccxt/pro/bitmex.py +1656 -0
  423. ccxt/pro/bitopro.py +445 -0
  424. ccxt/pro/bitpanda.py +15 -0
  425. ccxt/pro/bitrue.py +447 -0
  426. ccxt/pro/bitstamp.py +522 -0
  427. ccxt/pro/bitvavo.py +1270 -0
  428. ccxt/pro/blockchaincom.py +738 -0
  429. ccxt/pro/blofin.py +692 -0
  430. ccxt/pro/bybit.py +2000 -0
  431. ccxt/pro/cex.py +1440 -0
  432. ccxt/pro/coinbase.py +678 -0
  433. ccxt/pro/coinbaseadvanced.py +16 -0
  434. ccxt/pro/coinbaseexchange.py +895 -0
  435. ccxt/pro/coinbaseinternational.py +620 -0
  436. ccxt/pro/coincatch.py +1464 -0
  437. ccxt/pro/coincheck.py +199 -0
  438. ccxt/pro/coinex.py +1061 -0
  439. ccxt/pro/coinone.py +395 -0
  440. ccxt/pro/cryptocom.py +947 -0
  441. ccxt/pro/currencycom.py +536 -0
  442. ccxt/pro/deribit.py +892 -0
  443. ccxt/pro/exmo.py +629 -0
  444. ccxt/pro/gate.py +1416 -0
  445. ccxt/pro/gateio.py +15 -0
  446. ccxt/pro/gemini.py +865 -0
  447. ccxt/pro/hashkey.py +802 -0
  448. ccxt/pro/hitbtc.py +1216 -0
  449. ccxt/pro/hollaex.py +563 -0
  450. ccxt/pro/htx.py +2215 -0
  451. ccxt/pro/huobi.py +15 -0
  452. ccxt/pro/huobijp.py +570 -0
  453. ccxt/pro/hyperliquid.py +525 -0
  454. ccxt/pro/idex.py +672 -0
  455. ccxt/pro/independentreserve.py +270 -0
  456. ccxt/pro/kraken.py +1356 -0
  457. ccxt/pro/krakenfutures.py +1492 -0
  458. ccxt/pro/kucoin.py +1133 -0
  459. ccxt/pro/kucoinfutures.py +1081 -0
  460. ccxt/pro/lbank.py +843 -0
  461. ccxt/pro/luno.py +303 -0
  462. ccxt/pro/mexc.py +1122 -0
  463. ccxt/pro/ndax.py +506 -0
  464. ccxt/pro/okcoin.py +698 -0
  465. ccxt/pro/okx.py +1851 -0
  466. ccxt/pro/onetrading.py +1275 -0
  467. ccxt/pro/oxfun.py +950 -0
  468. ccxt/pro/p2b.py +419 -0
  469. ccxt/pro/paradex.py +352 -0
  470. ccxt/pro/phemex.py +1441 -0
  471. ccxt/pro/poloniex.py +1166 -0
  472. ccxt/pro/poloniexfutures.py +990 -0
  473. ccxt/pro/probit.py +551 -0
  474. ccxt/pro/upbit.py +520 -0
  475. ccxt/pro/vertex.py +943 -0
  476. ccxt/pro/wazirx.py +749 -0
  477. ccxt/pro/whitebit.py +864 -0
  478. ccxt/pro/woo.py +1078 -0
  479. ccxt/pro/woofipro.py +1183 -0
  480. ccxt/pro/xt.py +1067 -0
  481. ccxt/probit.py +1734 -0
  482. ccxt/ramzinex.py +476 -0
  483. ccxt/sarmayex.py +357 -0
  484. ccxt/sarrafex.py +478 -0
  485. ccxt/static_dependencies/__init__.py +1 -0
  486. ccxt/static_dependencies/ecdsa/__init__.py +14 -0
  487. ccxt/static_dependencies/ecdsa/_version.py +520 -0
  488. ccxt/static_dependencies/ecdsa/curves.py +56 -0
  489. ccxt/static_dependencies/ecdsa/der.py +221 -0
  490. ccxt/static_dependencies/ecdsa/ecdsa.py +310 -0
  491. ccxt/static_dependencies/ecdsa/ellipticcurve.py +197 -0
  492. ccxt/static_dependencies/ecdsa/keys.py +332 -0
  493. ccxt/static_dependencies/ecdsa/numbertheory.py +531 -0
  494. ccxt/static_dependencies/ecdsa/rfc6979.py +100 -0
  495. ccxt/static_dependencies/ecdsa/util.py +266 -0
  496. ccxt/static_dependencies/ethereum/__init__.py +7 -0
  497. ccxt/static_dependencies/ethereum/abi/__init__.py +16 -0
  498. ccxt/static_dependencies/ethereum/abi/abi.py +19 -0
  499. ccxt/static_dependencies/ethereum/abi/base.py +152 -0
  500. ccxt/static_dependencies/ethereum/abi/codec.py +217 -0
  501. ccxt/static_dependencies/ethereum/abi/constants.py +3 -0
  502. ccxt/static_dependencies/ethereum/abi/decoding.py +565 -0
  503. ccxt/static_dependencies/ethereum/abi/encoding.py +720 -0
  504. ccxt/static_dependencies/ethereum/abi/exceptions.py +139 -0
  505. ccxt/static_dependencies/ethereum/abi/grammar.py +443 -0
  506. ccxt/static_dependencies/ethereum/abi/packed.py +13 -0
  507. ccxt/static_dependencies/ethereum/abi/py.typed +0 -0
  508. ccxt/static_dependencies/ethereum/abi/registry.py +643 -0
  509. ccxt/static_dependencies/ethereum/abi/tools/__init__.py +3 -0
  510. ccxt/static_dependencies/ethereum/abi/tools/_strategies.py +230 -0
  511. ccxt/static_dependencies/ethereum/abi/utils/__init__.py +0 -0
  512. ccxt/static_dependencies/ethereum/abi/utils/numeric.py +83 -0
  513. ccxt/static_dependencies/ethereum/abi/utils/padding.py +27 -0
  514. ccxt/static_dependencies/ethereum/abi/utils/string.py +19 -0
  515. ccxt/static_dependencies/ethereum/account/__init__.py +3 -0
  516. ccxt/static_dependencies/ethereum/account/encode_typed_data/__init__.py +4 -0
  517. ccxt/static_dependencies/ethereum/account/encode_typed_data/encoding_and_hashing.py +239 -0
  518. ccxt/static_dependencies/ethereum/account/encode_typed_data/helpers.py +40 -0
  519. ccxt/static_dependencies/ethereum/account/messages.py +263 -0
  520. ccxt/static_dependencies/ethereum/account/py.typed +0 -0
  521. ccxt/static_dependencies/ethereum/hexbytes/__init__.py +5 -0
  522. ccxt/static_dependencies/ethereum/hexbytes/_utils.py +54 -0
  523. ccxt/static_dependencies/ethereum/hexbytes/main.py +65 -0
  524. ccxt/static_dependencies/ethereum/hexbytes/py.typed +0 -0
  525. ccxt/static_dependencies/ethereum/typing/__init__.py +63 -0
  526. ccxt/static_dependencies/ethereum/typing/abi.py +6 -0
  527. ccxt/static_dependencies/ethereum/typing/bls.py +7 -0
  528. ccxt/static_dependencies/ethereum/typing/discovery.py +5 -0
  529. ccxt/static_dependencies/ethereum/typing/encoding.py +7 -0
  530. ccxt/static_dependencies/ethereum/typing/enums.py +17 -0
  531. ccxt/static_dependencies/ethereum/typing/ethpm.py +9 -0
  532. ccxt/static_dependencies/ethereum/typing/evm.py +20 -0
  533. ccxt/static_dependencies/ethereum/typing/networks.py +1122 -0
  534. ccxt/static_dependencies/ethereum/typing/py.typed +0 -0
  535. ccxt/static_dependencies/ethereum/utils/__init__.py +115 -0
  536. ccxt/static_dependencies/ethereum/utils/abi.py +72 -0
  537. ccxt/static_dependencies/ethereum/utils/address.py +171 -0
  538. ccxt/static_dependencies/ethereum/utils/applicators.py +151 -0
  539. ccxt/static_dependencies/ethereum/utils/conversions.py +190 -0
  540. ccxt/static_dependencies/ethereum/utils/currency.py +107 -0
  541. ccxt/static_dependencies/ethereum/utils/curried/__init__.py +269 -0
  542. ccxt/static_dependencies/ethereum/utils/debug.py +20 -0
  543. ccxt/static_dependencies/ethereum/utils/decorators.py +132 -0
  544. ccxt/static_dependencies/ethereum/utils/encoding.py +6 -0
  545. ccxt/static_dependencies/ethereum/utils/exceptions.py +4 -0
  546. ccxt/static_dependencies/ethereum/utils/functional.py +75 -0
  547. ccxt/static_dependencies/ethereum/utils/hexadecimal.py +74 -0
  548. ccxt/static_dependencies/ethereum/utils/humanize.py +188 -0
  549. ccxt/static_dependencies/ethereum/utils/logging.py +159 -0
  550. ccxt/static_dependencies/ethereum/utils/module_loading.py +31 -0
  551. ccxt/static_dependencies/ethereum/utils/numeric.py +43 -0
  552. ccxt/static_dependencies/ethereum/utils/py.typed +0 -0
  553. ccxt/static_dependencies/ethereum/utils/toolz.py +76 -0
  554. ccxt/static_dependencies/ethereum/utils/types.py +54 -0
  555. ccxt/static_dependencies/ethereum/utils/typing/__init__.py +18 -0
  556. ccxt/static_dependencies/ethereum/utils/typing/misc.py +14 -0
  557. ccxt/static_dependencies/ethereum/utils/units.py +31 -0
  558. ccxt/static_dependencies/keccak/__init__.py +3 -0
  559. ccxt/static_dependencies/keccak/keccak.py +197 -0
  560. ccxt/static_dependencies/lark/__init__.py +38 -0
  561. ccxt/static_dependencies/lark/__pyinstaller/__init__.py +6 -0
  562. ccxt/static_dependencies/lark/__pyinstaller/hook-lark.py +14 -0
  563. ccxt/static_dependencies/lark/ast_utils.py +59 -0
  564. ccxt/static_dependencies/lark/common.py +86 -0
  565. ccxt/static_dependencies/lark/exceptions.py +292 -0
  566. ccxt/static_dependencies/lark/grammar.py +130 -0
  567. ccxt/static_dependencies/lark/grammars/__init__.py +0 -0
  568. ccxt/static_dependencies/lark/indenter.py +143 -0
  569. ccxt/static_dependencies/lark/lark.py +658 -0
  570. ccxt/static_dependencies/lark/lexer.py +678 -0
  571. ccxt/static_dependencies/lark/load_grammar.py +1428 -0
  572. ccxt/static_dependencies/lark/parse_tree_builder.py +391 -0
  573. ccxt/static_dependencies/lark/parser_frontends.py +257 -0
  574. ccxt/static_dependencies/lark/parsers/__init__.py +0 -0
  575. ccxt/static_dependencies/lark/parsers/cyk.py +340 -0
  576. ccxt/static_dependencies/lark/parsers/earley.py +314 -0
  577. ccxt/static_dependencies/lark/parsers/earley_common.py +42 -0
  578. ccxt/static_dependencies/lark/parsers/earley_forest.py +801 -0
  579. ccxt/static_dependencies/lark/parsers/grammar_analysis.py +203 -0
  580. ccxt/static_dependencies/lark/parsers/lalr_analysis.py +332 -0
  581. ccxt/static_dependencies/lark/parsers/lalr_interactive_parser.py +158 -0
  582. ccxt/static_dependencies/lark/parsers/lalr_parser.py +122 -0
  583. ccxt/static_dependencies/lark/parsers/lalr_parser_state.py +110 -0
  584. ccxt/static_dependencies/lark/parsers/xearley.py +165 -0
  585. ccxt/static_dependencies/lark/reconstruct.py +107 -0
  586. ccxt/static_dependencies/lark/tools/__init__.py +70 -0
  587. ccxt/static_dependencies/lark/tools/nearley.py +202 -0
  588. ccxt/static_dependencies/lark/tools/serialize.py +32 -0
  589. ccxt/static_dependencies/lark/tools/standalone.py +196 -0
  590. ccxt/static_dependencies/lark/tree.py +267 -0
  591. ccxt/static_dependencies/lark/tree_matcher.py +186 -0
  592. ccxt/static_dependencies/lark/tree_templates.py +180 -0
  593. ccxt/static_dependencies/lark/utils.py +343 -0
  594. ccxt/static_dependencies/lark/visitors.py +596 -0
  595. ccxt/static_dependencies/marshmallow/__init__.py +81 -0
  596. ccxt/static_dependencies/marshmallow/base.py +65 -0
  597. ccxt/static_dependencies/marshmallow/class_registry.py +94 -0
  598. ccxt/static_dependencies/marshmallow/decorators.py +231 -0
  599. ccxt/static_dependencies/marshmallow/error_store.py +60 -0
  600. ccxt/static_dependencies/marshmallow/exceptions.py +71 -0
  601. ccxt/static_dependencies/marshmallow/fields.py +2114 -0
  602. ccxt/static_dependencies/marshmallow/orderedset.py +89 -0
  603. ccxt/static_dependencies/marshmallow/schema.py +1228 -0
  604. ccxt/static_dependencies/marshmallow/types.py +12 -0
  605. ccxt/static_dependencies/marshmallow/utils.py +378 -0
  606. ccxt/static_dependencies/marshmallow/validate.py +678 -0
  607. ccxt/static_dependencies/marshmallow/warnings.py +2 -0
  608. ccxt/static_dependencies/marshmallow_dataclass/__init__.py +1047 -0
  609. ccxt/static_dependencies/marshmallow_dataclass/collection_field.py +51 -0
  610. ccxt/static_dependencies/marshmallow_dataclass/lazy_class_attribute.py +45 -0
  611. ccxt/static_dependencies/marshmallow_dataclass/mypy.py +71 -0
  612. ccxt/static_dependencies/marshmallow_dataclass/typing.py +14 -0
  613. ccxt/static_dependencies/marshmallow_dataclass/union_field.py +82 -0
  614. ccxt/static_dependencies/marshmallow_oneofschema/__init__.py +1 -0
  615. ccxt/static_dependencies/marshmallow_oneofschema/one_of_schema.py +193 -0
  616. ccxt/static_dependencies/msgpack/__init__.py +55 -0
  617. ccxt/static_dependencies/msgpack/exceptions.py +48 -0
  618. ccxt/static_dependencies/msgpack/ext.py +168 -0
  619. ccxt/static_dependencies/msgpack/fallback.py +951 -0
  620. ccxt/static_dependencies/parsimonious/__init__.py +10 -0
  621. ccxt/static_dependencies/parsimonious/exceptions.py +105 -0
  622. ccxt/static_dependencies/parsimonious/expressions.py +479 -0
  623. ccxt/static_dependencies/parsimonious/grammar.py +487 -0
  624. ccxt/static_dependencies/parsimonious/nodes.py +325 -0
  625. ccxt/static_dependencies/parsimonious/utils.py +40 -0
  626. ccxt/static_dependencies/starknet/__init__.py +0 -0
  627. ccxt/static_dependencies/starknet/cairo/__init__.py +0 -0
  628. ccxt/static_dependencies/starknet/cairo/data_types.py +123 -0
  629. ccxt/static_dependencies/starknet/cairo/deprecated_parse/__init__.py +0 -0
  630. ccxt/static_dependencies/starknet/cairo/deprecated_parse/cairo_types.py +77 -0
  631. ccxt/static_dependencies/starknet/cairo/deprecated_parse/parser.py +46 -0
  632. ccxt/static_dependencies/starknet/cairo/deprecated_parse/parser_transformer.py +138 -0
  633. ccxt/static_dependencies/starknet/cairo/felt.py +64 -0
  634. ccxt/static_dependencies/starknet/cairo/type_parser.py +121 -0
  635. ccxt/static_dependencies/starknet/cairo/v1/__init__.py +0 -0
  636. ccxt/static_dependencies/starknet/cairo/v1/type_parser.py +59 -0
  637. ccxt/static_dependencies/starknet/cairo/v2/__init__.py +0 -0
  638. ccxt/static_dependencies/starknet/cairo/v2/type_parser.py +77 -0
  639. ccxt/static_dependencies/starknet/ccxt_utils.py +7 -0
  640. ccxt/static_dependencies/starknet/common.py +15 -0
  641. ccxt/static_dependencies/starknet/constants.py +39 -0
  642. ccxt/static_dependencies/starknet/hash/__init__.py +0 -0
  643. ccxt/static_dependencies/starknet/hash/address.py +79 -0
  644. ccxt/static_dependencies/starknet/hash/compiled_class_hash_objects.py +111 -0
  645. ccxt/static_dependencies/starknet/hash/selector.py +16 -0
  646. ccxt/static_dependencies/starknet/hash/storage.py +12 -0
  647. ccxt/static_dependencies/starknet/hash/utils.py +78 -0
  648. ccxt/static_dependencies/starknet/models/__init__.py +0 -0
  649. ccxt/static_dependencies/starknet/models/typed_data.py +45 -0
  650. ccxt/static_dependencies/starknet/serialization/__init__.py +24 -0
  651. ccxt/static_dependencies/starknet/serialization/_calldata_reader.py +40 -0
  652. ccxt/static_dependencies/starknet/serialization/_context.py +142 -0
  653. ccxt/static_dependencies/starknet/serialization/data_serializers/__init__.py +10 -0
  654. ccxt/static_dependencies/starknet/serialization/data_serializers/_common.py +82 -0
  655. ccxt/static_dependencies/starknet/serialization/data_serializers/array_serializer.py +43 -0
  656. ccxt/static_dependencies/starknet/serialization/data_serializers/bool_serializer.py +37 -0
  657. ccxt/static_dependencies/starknet/serialization/data_serializers/byte_array_serializer.py +66 -0
  658. ccxt/static_dependencies/starknet/serialization/data_serializers/cairo_data_serializer.py +71 -0
  659. ccxt/static_dependencies/starknet/serialization/data_serializers/enum_serializer.py +71 -0
  660. ccxt/static_dependencies/starknet/serialization/data_serializers/felt_serializer.py +50 -0
  661. ccxt/static_dependencies/starknet/serialization/data_serializers/named_tuple_serializer.py +58 -0
  662. ccxt/static_dependencies/starknet/serialization/data_serializers/option_serializer.py +43 -0
  663. ccxt/static_dependencies/starknet/serialization/data_serializers/output_serializer.py +40 -0
  664. ccxt/static_dependencies/starknet/serialization/data_serializers/payload_serializer.py +72 -0
  665. ccxt/static_dependencies/starknet/serialization/data_serializers/struct_serializer.py +36 -0
  666. ccxt/static_dependencies/starknet/serialization/data_serializers/tuple_serializer.py +36 -0
  667. ccxt/static_dependencies/starknet/serialization/data_serializers/uint256_serializer.py +76 -0
  668. ccxt/static_dependencies/starknet/serialization/data_serializers/uint_serializer.py +100 -0
  669. ccxt/static_dependencies/starknet/serialization/data_serializers/unit_serializer.py +32 -0
  670. ccxt/static_dependencies/starknet/serialization/errors.py +10 -0
  671. ccxt/static_dependencies/starknet/serialization/factory.py +229 -0
  672. ccxt/static_dependencies/starknet/serialization/function_serialization_adapter.py +110 -0
  673. ccxt/static_dependencies/starknet/serialization/tuple_dataclass.py +59 -0
  674. ccxt/static_dependencies/starknet/utils/__init__.py +0 -0
  675. ccxt/static_dependencies/starknet/utils/constructor_args_translator.py +86 -0
  676. ccxt/static_dependencies/starknet/utils/iterable.py +13 -0
  677. ccxt/static_dependencies/starknet/utils/schema.py +13 -0
  678. ccxt/static_dependencies/starknet/utils/typed_data.py +182 -0
  679. ccxt/static_dependencies/starkware/__init__.py +0 -0
  680. ccxt/static_dependencies/starkware/crypto/__init__.py +0 -0
  681. ccxt/static_dependencies/starkware/crypto/fast_pedersen_hash.py +50 -0
  682. ccxt/static_dependencies/starkware/crypto/math_utils.py +78 -0
  683. ccxt/static_dependencies/starkware/crypto/signature.py +2344 -0
  684. ccxt/static_dependencies/starkware/crypto/utils.py +63 -0
  685. ccxt/static_dependencies/sympy/__init__.py +0 -0
  686. ccxt/static_dependencies/sympy/core/__init__.py +0 -0
  687. ccxt/static_dependencies/sympy/core/intfunc.py +35 -0
  688. ccxt/static_dependencies/sympy/external/__init__.py +0 -0
  689. ccxt/static_dependencies/sympy/external/gmpy.py +345 -0
  690. ccxt/static_dependencies/sympy/external/importtools.py +187 -0
  691. ccxt/static_dependencies/sympy/external/ntheory.py +637 -0
  692. ccxt/static_dependencies/sympy/external/pythonmpq.py +341 -0
  693. ccxt/static_dependencies/toolz/__init__.py +26 -0
  694. ccxt/static_dependencies/toolz/_signatures.py +784 -0
  695. ccxt/static_dependencies/toolz/_version.py +520 -0
  696. ccxt/static_dependencies/toolz/compatibility.py +30 -0
  697. ccxt/static_dependencies/toolz/curried/__init__.py +101 -0
  698. ccxt/static_dependencies/toolz/curried/exceptions.py +22 -0
  699. ccxt/static_dependencies/toolz/curried/operator.py +22 -0
  700. ccxt/static_dependencies/toolz/dicttoolz.py +339 -0
  701. ccxt/static_dependencies/toolz/functoolz.py +1049 -0
  702. ccxt/static_dependencies/toolz/itertoolz.py +1057 -0
  703. ccxt/static_dependencies/toolz/recipes.py +46 -0
  704. ccxt/static_dependencies/toolz/utils.py +9 -0
  705. ccxt/static_dependencies/typing_inspect/__init__.py +0 -0
  706. ccxt/static_dependencies/typing_inspect/typing_inspect.py +851 -0
  707. ccxt/tabdeal.py +364 -0
  708. ccxt/test/__init__.py +3 -0
  709. ccxt/test/base/__init__.py +29 -0
  710. ccxt/test/base/test_account.py +26 -0
  711. ccxt/test/base/test_balance.py +56 -0
  712. ccxt/test/base/test_borrow_interest.py +35 -0
  713. ccxt/test/base/test_borrow_rate.py +32 -0
  714. ccxt/test/base/test_calculate_fee.py +51 -0
  715. ccxt/test/base/test_crypto.py +127 -0
  716. ccxt/test/base/test_currency.py +76 -0
  717. ccxt/test/base/test_datetime.py +109 -0
  718. ccxt/test/base/test_decimal_to_precision.py +392 -0
  719. ccxt/test/base/test_deep_extend.py +68 -0
  720. ccxt/test/base/test_deposit_withdrawal.py +50 -0
  721. ccxt/test/base/test_exchange_datetime_functions.py +76 -0
  722. ccxt/test/base/test_funding_rate_history.py +29 -0
  723. ccxt/test/base/test_last_price.py +31 -0
  724. ccxt/test/base/test_ledger_entry.py +45 -0
  725. ccxt/test/base/test_ledger_item.py +48 -0
  726. ccxt/test/base/test_leverage_tier.py +33 -0
  727. ccxt/test/base/test_liquidation.py +50 -0
  728. ccxt/test/base/test_margin_mode.py +24 -0
  729. ccxt/test/base/test_margin_modification.py +35 -0
  730. ccxt/test/base/test_market.py +193 -0
  731. ccxt/test/base/test_number.py +411 -0
  732. ccxt/test/base/test_ohlcv.py +33 -0
  733. ccxt/test/base/test_open_interest.py +32 -0
  734. ccxt/test/base/test_order.py +64 -0
  735. ccxt/test/base/test_order_book.py +69 -0
  736. ccxt/test/base/test_position.py +60 -0
  737. ccxt/test/base/test_shared_methods.py +353 -0
  738. ccxt/test/base/test_status.py +24 -0
  739. ccxt/test/base/test_throttle.py +126 -0
  740. ccxt/test/base/test_ticker.py +92 -0
  741. ccxt/test/base/test_trade.py +47 -0
  742. ccxt/test/base/test_trading_fee.py +26 -0
  743. ccxt/test/base/test_transaction.py +39 -0
  744. ccxt/test/test_async.py +1649 -0
  745. ccxt/test/test_sync.py +1648 -0
  746. ccxt/test/tests_async.py +1558 -0
  747. ccxt/test/tests_helpers.py +287 -0
  748. ccxt/test/tests_init.py +39 -0
  749. ccxt/test/tests_sync.py +1555 -0
  750. ccxt/tetherland.py +349 -0
  751. ccxt/timex.py +1593 -0
  752. ccxt/tokocrypto.py +2405 -0
  753. ccxt/tradeogre.py +608 -0
  754. ccxt/twox.py +326 -0
  755. ccxt/ubitex.py +409 -0
  756. ccxt/upbit.py +1833 -0
  757. ccxt/vertex.py +2922 -0
  758. ccxt/wallex.py +445 -0
  759. ccxt/wavesexchange.py +2472 -0
  760. ccxt/wazirx.py +1224 -0
  761. ccxt/whitebit.py +2469 -0
  762. ccxt/woo.py +3114 -0
  763. ccxt/woofipro.py +2533 -0
  764. ccxt/xt.py +4453 -0
  765. ccxt/yobit.py +1283 -0
  766. ccxt/zaif.py +725 -0
  767. ccxt/zonda.py +1828 -0
  768. ccxt_ir-4.3.46.0.1.dist-info/LICENSE.txt +21 -0
  769. ccxt_ir-4.3.46.0.1.dist-info/METADATA +655 -0
  770. ccxt_ir-4.3.46.0.1.dist-info/RECORD +772 -0
  771. ccxt_ir-4.3.46.0.1.dist-info/WHEEL +6 -0
  772. ccxt_ir-4.3.46.0.1.dist-info/top_level.txt +1 -0
ccxt/coinbase.py ADDED
@@ -0,0 +1,4474 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ # PLEASE DO NOT EDIT THIS FILE, IT IS GENERATED AND WILL BE OVERWRITTEN:
4
+ # https://github.com/ccxt/ccxt/blob/master/CONTRIBUTING.md#how-to-contribute-code
5
+
6
+ from ccxt.base.exchange import Exchange
7
+ from ccxt.abstract.coinbase import ImplicitAPI
8
+ import hashlib
9
+ from ccxt.base.types import Account, Balances, Conversion, Currencies, Currency, Int, Market, MarketInterface, Num, Order, OrderBook, OrderSide, OrderType, Str, Strings, Ticker, Tickers, Trade, TradingFees, Transaction
10
+ from typing import List
11
+ from ccxt.base.errors import ExchangeError
12
+ from ccxt.base.errors import AuthenticationError
13
+ from ccxt.base.errors import PermissionDenied
14
+ from ccxt.base.errors import ArgumentsRequired
15
+ from ccxt.base.errors import BadRequest
16
+ from ccxt.base.errors import InvalidOrder
17
+ from ccxt.base.errors import OrderNotFound
18
+ from ccxt.base.errors import NotSupported
19
+ from ccxt.base.errors import RateLimitExceeded
20
+ from ccxt.base.errors import InvalidNonce
21
+ from ccxt.base.decimal_to_precision import TICK_SIZE
22
+ from ccxt.base.precise import Precise
23
+
24
+
25
+ class coinbase(Exchange, ImplicitAPI):
26
+
27
+ def describe(self):
28
+ return self.deep_extend(super(coinbase, self).describe(), {
29
+ 'id': 'coinbase',
30
+ 'name': 'Coinbase Advanced',
31
+ 'countries': ['US'],
32
+ 'pro': True,
33
+ 'certified': True,
34
+ # rate-limits:
35
+ # ADVANCED API: https://docs.cloud.coinbase.com/advanced-trade-api/docs/rest-api-rate-limits
36
+ # - max 30 req/second for private data, 10 req/s for public data
37
+ # DATA API : https://docs.cloud.coinbase.com/sign-in-with-coinbase/docs/rate-limiting
38
+ # - max 10000 req/hour(to prevent userland mistakes we apply ~3 req/second RL per call
39
+ 'rateLimit': 34,
40
+ 'version': 'v2',
41
+ 'userAgent': self.userAgents['chrome'],
42
+ 'headers': {
43
+ 'CB-VERSION': '2018-05-30',
44
+ },
45
+ 'has': {
46
+ 'CORS': True,
47
+ 'spot': True,
48
+ 'margin': False,
49
+ 'swap': False,
50
+ 'future': False,
51
+ 'option': False,
52
+ 'addMargin': False,
53
+ 'cancelOrder': True,
54
+ 'cancelOrders': True,
55
+ 'closeAllPositions': False,
56
+ 'closePosition': True,
57
+ 'createConvertTrade': True,
58
+ 'createDepositAddress': True,
59
+ 'createLimitBuyOrder': True,
60
+ 'createLimitSellOrder': True,
61
+ 'createMarketBuyOrder': True,
62
+ 'createMarketBuyOrderWithCost': True,
63
+ 'createMarketOrderWithCost': False,
64
+ 'createMarketSellOrder': True,
65
+ 'createMarketSellOrderWithCost': False,
66
+ 'createOrder': True,
67
+ 'createPostOnlyOrder': True,
68
+ 'createReduceOnlyOrder': False,
69
+ 'createStopLimitOrder': True,
70
+ 'createStopMarketOrder': False,
71
+ 'createStopOrder': True,
72
+ 'deposit': True,
73
+ 'editOrder': True,
74
+ 'fetchAccounts': True,
75
+ 'fetchBalance': True,
76
+ 'fetchBidsAsks': True,
77
+ 'fetchBorrowRateHistories': False,
78
+ 'fetchBorrowRateHistory': False,
79
+ 'fetchCanceledOrders': True,
80
+ 'fetchClosedOrders': True,
81
+ 'fetchConvertQuote': True,
82
+ 'fetchConvertTrade': True,
83
+ 'fetchConvertTradeHistory': False,
84
+ 'fetchCrossBorrowRate': False,
85
+ 'fetchCrossBorrowRates': False,
86
+ 'fetchCurrencies': True,
87
+ 'fetchDeposit': True,
88
+ 'fetchDepositAddress': 'emulated',
89
+ 'fetchDepositAddresses': False,
90
+ 'fetchDepositAddressesByNetwork': True,
91
+ 'fetchDeposits': True,
92
+ 'fetchFundingHistory': False,
93
+ 'fetchFundingRate': False,
94
+ 'fetchFundingRateHistory': False,
95
+ 'fetchFundingRates': False,
96
+ 'fetchIndexOHLCV': False,
97
+ 'fetchIsolatedBorrowRate': False,
98
+ 'fetchIsolatedBorrowRates': False,
99
+ 'fetchL2OrderBook': False,
100
+ 'fetchLedger': True,
101
+ 'fetchLeverage': False,
102
+ 'fetchLeverageTiers': False,
103
+ 'fetchMarginMode': False,
104
+ 'fetchMarkets': True,
105
+ 'fetchMarkOHLCV': False,
106
+ 'fetchMyBuys': True,
107
+ 'fetchMySells': True,
108
+ 'fetchMyTrades': True,
109
+ 'fetchOHLCV': True,
110
+ 'fetchOpenInterestHistory': False,
111
+ 'fetchOpenOrders': True,
112
+ 'fetchOrder': True,
113
+ 'fetchOrderBook': True,
114
+ 'fetchOrders': True,
115
+ 'fetchPosition': True,
116
+ 'fetchPositionMode': False,
117
+ 'fetchPositions': True,
118
+ 'fetchPositionsRisk': False,
119
+ 'fetchPremiumIndexOHLCV': False,
120
+ 'fetchTicker': True,
121
+ 'fetchTickers': True,
122
+ 'fetchTime': True,
123
+ 'fetchTrades': True,
124
+ 'fetchTradingFee': 'emulated',
125
+ 'fetchTradingFees': True,
126
+ 'fetchWithdrawals': True,
127
+ 'reduceMargin': False,
128
+ 'setLeverage': False,
129
+ 'setMarginMode': False,
130
+ 'setPositionMode': False,
131
+ 'withdraw': True,
132
+ },
133
+ 'urls': {
134
+ 'logo': 'https://user-images.githubusercontent.com/1294454/40811661-b6eceae2-653a-11e8-829e-10bfadb078cf.jpg',
135
+ 'api': {
136
+ 'rest': 'https://api.coinbase.com',
137
+ },
138
+ 'www': 'https://www.coinbase.com',
139
+ 'doc': [
140
+ 'https://developers.coinbase.com/api/v2',
141
+ 'https://docs.cloud.coinbase.com/advanced-trade-api/docs/welcome',
142
+ ],
143
+ 'fees': [
144
+ 'https://support.coinbase.com/customer/portal/articles/2109597-buy-sell-bank-transfer-fees',
145
+ 'https://www.coinbase.com/advanced-fees',
146
+ ],
147
+ 'referral': 'https://www.coinbase.com/join/58cbe25a355148797479dbd2',
148
+ },
149
+ 'requiredCredentials': {
150
+ 'apiKey': True,
151
+ 'secret': True,
152
+ },
153
+ 'api': {
154
+ 'v2': {
155
+ 'public': {
156
+ 'get': {
157
+ 'currencies': 10.6,
158
+ 'currencies/crypto': 10.6,
159
+ 'time': 10.6,
160
+ 'exchange-rates': 10.6,
161
+ 'users/{user_id}': 10.6,
162
+ 'prices/{symbol}/buy': 10.6,
163
+ 'prices/{symbol}/sell': 10.6,
164
+ 'prices/{symbol}/spot': 10.6,
165
+ },
166
+ },
167
+ 'private': {
168
+ 'get': {
169
+ 'accounts': 10.6,
170
+ 'accounts/{account_id}': 10.6,
171
+ 'accounts/{account_id}/addresses': 10.6,
172
+ 'accounts/{account_id}/addresses/{address_id}': 10.6,
173
+ 'accounts/{account_id}/addresses/{address_id}/transactions': 10.6,
174
+ 'accounts/{account_id}/transactions': 10.6,
175
+ 'accounts/{account_id}/transactions/{transaction_id}': 10.6,
176
+ 'accounts/{account_id}/buys': 10.6,
177
+ 'accounts/{account_id}/buys/{buy_id}': 10.6,
178
+ 'accounts/{account_id}/sells': 10.6,
179
+ 'accounts/{account_id}/sells/{sell_id}': 10.6,
180
+ 'accounts/{account_id}/deposits': 10.6,
181
+ 'accounts/{account_id}/deposits/{deposit_id}': 10.6,
182
+ 'accounts/{account_id}/withdrawals': 10.6,
183
+ 'accounts/{account_id}/withdrawals/{withdrawal_id}': 10.6,
184
+ 'payment-methods': 10.6,
185
+ 'payment-methods/{payment_method_id}': 10.6,
186
+ 'user': 10.6,
187
+ 'user/auth': 10.6,
188
+ },
189
+ 'post': {
190
+ 'accounts': 10.6,
191
+ 'accounts/{account_id}/primary': 10.6,
192
+ 'accounts/{account_id}/addresses': 10.6,
193
+ 'accounts/{account_id}/transactions': 10.6,
194
+ 'accounts/{account_id}/transactions/{transaction_id}/complete': 10.6,
195
+ 'accounts/{account_id}/transactions/{transaction_id}/resend': 10.6,
196
+ 'accounts/{account_id}/buys': 10.6,
197
+ 'accounts/{account_id}/buys/{buy_id}/commit': 10.6,
198
+ 'accounts/{account_id}/sells': 10.6,
199
+ 'accounts/{account_id}/sells/{sell_id}/commit': 10.6,
200
+ 'accounts/{account_id}/deposits': 10.6,
201
+ 'accounts/{account_id}/deposits/{deposit_id}/commit': 10.6,
202
+ 'accounts/{account_id}/withdrawals': 10.6,
203
+ 'accounts/{account_id}/withdrawals/{withdrawal_id}/commit': 10.6,
204
+ },
205
+ 'put': {
206
+ 'accounts/{account_id}': 10.6,
207
+ 'user': 10.6,
208
+ },
209
+ 'delete': {
210
+ 'accounts/{id}': 10.6,
211
+ 'accounts/{account_id}/transactions/{transaction_id}': 10.6,
212
+ },
213
+ },
214
+ },
215
+ 'v3': {
216
+ 'public': {
217
+ 'get': {
218
+ 'brokerage/time': 3,
219
+ 'brokerage/market/product_book': 3,
220
+ 'brokerage/market/products': 3,
221
+ 'brokerage/market/products/{product_id}': 3,
222
+ 'brokerage/market/products/{product_id}/candles': 3,
223
+ 'brokerage/market/products/{product_id}/ticker': 3,
224
+ },
225
+ },
226
+ 'private': {
227
+ 'get': {
228
+ 'brokerage/accounts': 1,
229
+ 'brokerage/accounts/{account_uuid}': 1,
230
+ 'brokerage/orders/historical/batch': 1,
231
+ 'brokerage/orders/historical/fills': 1,
232
+ 'brokerage/orders/historical/{order_id}': 1,
233
+ 'brokerage/products': 3,
234
+ 'brokerage/products/{product_id}': 3,
235
+ 'brokerage/products/{product_id}/candles': 3,
236
+ 'brokerage/products/{product_id}/ticker': 3,
237
+ 'brokerage/best_bid_ask': 3,
238
+ 'brokerage/product_book': 3,
239
+ 'brokerage/transaction_summary': 3,
240
+ 'brokerage/portfolios': 1,
241
+ 'brokerage/portfolios/{portfolio_uuid}': 1,
242
+ 'brokerage/convert/trade/{trade_id}': 1,
243
+ 'brokerage/cfm/balance_summary': 1,
244
+ 'brokerage/cfm/positions': 1,
245
+ 'brokerage/cfm/positions/{product_id}': 1,
246
+ 'brokerage/cfm/sweeps': 1,
247
+ 'brokerage/intx/portfolio/{portfolio_uuid}': 1,
248
+ 'brokerage/intx/positions/{portfolio_uuid}': 1,
249
+ 'brokerage/intx/positions/{portfolio_uuid}/{symbol}': 1,
250
+ 'brokerage/payment_methods': 1,
251
+ 'brokerage/payment_methods/{payment_method_id}': 1,
252
+ },
253
+ 'post': {
254
+ 'brokerage/orders': 1,
255
+ 'brokerage/orders/batch_cancel': 1,
256
+ 'brokerage/orders/edit': 1,
257
+ 'brokerage/orders/edit_preview': 1,
258
+ 'brokerage/orders/preview': 1,
259
+ 'brokerage/portfolios': 1,
260
+ 'brokerage/portfolios/move_funds': 1,
261
+ 'brokerage/convert/quote': 1,
262
+ 'brokerage/convert/trade/{trade_id}': 1,
263
+ 'brokerage/cfm/sweeps/schedule': 1,
264
+ 'brokerage/intx/allocate': 1,
265
+ # futures
266
+ 'brokerage/orders/close_position': 1,
267
+ },
268
+ 'put': {
269
+ 'brokerage/portfolios/{portfolio_uuid}': 1,
270
+ },
271
+ 'delete': {
272
+ 'brokerage/portfolios/{portfolio_uuid}': 1,
273
+ 'brokerage/cfm/sweeps': 1,
274
+ },
275
+ },
276
+ },
277
+ },
278
+ 'fees': {
279
+ 'trading': {
280
+ 'taker': self.parse_number('0.006'),
281
+ 'maker': self.parse_number('0.004'),
282
+ 'tierBased': True,
283
+ 'percentage': True,
284
+ 'tiers': {
285
+ 'taker': [
286
+ [self.parse_number('0'), self.parse_number('0.006')],
287
+ [self.parse_number('10000'), self.parse_number('0.004')],
288
+ [self.parse_number('50000'), self.parse_number('0.0025')],
289
+ [self.parse_number('100000'), self.parse_number('0.002')],
290
+ [self.parse_number('1000000'), self.parse_number('0.0018')],
291
+ [self.parse_number('15000000'), self.parse_number('0.0016')],
292
+ [self.parse_number('75000000'), self.parse_number('0.0012')],
293
+ [self.parse_number('250000000'), self.parse_number('0.0008')],
294
+ [self.parse_number('400000000'), self.parse_number('0.0005')],
295
+ ],
296
+ 'maker': [
297
+ [self.parse_number('0'), self.parse_number('0.004')],
298
+ [self.parse_number('10000'), self.parse_number('0.0025')],
299
+ [self.parse_number('50000'), self.parse_number('0.0015')],
300
+ [self.parse_number('100000'), self.parse_number('0.001')],
301
+ [self.parse_number('1000000'), self.parse_number('0.0008')],
302
+ [self.parse_number('15000000'), self.parse_number('0.0006')],
303
+ [self.parse_number('75000000'), self.parse_number('0.0003')],
304
+ [self.parse_number('250000000'), self.parse_number('0.0')],
305
+ [self.parse_number('400000000'), self.parse_number('0.0')],
306
+ ],
307
+ },
308
+ },
309
+ },
310
+ 'precisionMode': TICK_SIZE,
311
+ 'exceptions': {
312
+ 'exact': {
313
+ 'two_factor_required': AuthenticationError, # 402 When sending money over 2fa limit
314
+ 'param_required': ExchangeError, # 400 Missing parameter
315
+ 'validation_error': ExchangeError, # 400 Unable to validate POST/PUT
316
+ 'invalid_request': ExchangeError, # 400 Invalid request
317
+ 'personal_details_required': AuthenticationError, # 400 User’s personal detail required to complete self request
318
+ 'identity_verification_required': AuthenticationError, # 400 Identity verification is required to complete self request
319
+ 'jumio_verification_required': AuthenticationError, # 400 Document verification is required to complete self request
320
+ 'jumio_face_match_verification_required': AuthenticationError, # 400 Document verification including face match is required to complete self request
321
+ 'unverified_email': AuthenticationError, # 400 User has not verified their email
322
+ 'authentication_error': AuthenticationError, # 401 Invalid auth(generic)
323
+ 'invalid_authentication_method': AuthenticationError, # 401 API access is blocked for deleted users.
324
+ 'invalid_token': AuthenticationError, # 401 Invalid Oauth token
325
+ 'revoked_token': AuthenticationError, # 401 Revoked Oauth token
326
+ 'expired_token': AuthenticationError, # 401 Expired Oauth token
327
+ 'invalid_scope': AuthenticationError, # 403 User hasn’t authenticated necessary scope
328
+ 'not_found': ExchangeError, # 404 Resource not found
329
+ 'rate_limit_exceeded': RateLimitExceeded, # 429 Rate limit exceeded
330
+ 'internal_server_error': ExchangeError, # 500 Internal server error
331
+ 'UNSUPPORTED_ORDER_CONFIGURATION': BadRequest,
332
+ 'INSUFFICIENT_FUND': BadRequest,
333
+ 'PERMISSION_DENIED': PermissionDenied,
334
+ 'INVALID_ARGUMENT': BadRequest,
335
+ },
336
+ 'broad': {
337
+ 'request timestamp expired': InvalidNonce, # {"errors":[{"id":"authentication_error","message":"request timestamp expired"}]}
338
+ 'order with self orderID was not found': OrderNotFound, # {"error":"unknown","error_details":"order with self orderID was not found","message":"order with self orderID was not found"}
339
+ },
340
+ },
341
+ 'timeframes': {
342
+ '1m': 'ONE_MINUTE',
343
+ '5m': 'FIVE_MINUTE',
344
+ '15m': 'FIFTEEN_MINUTE',
345
+ '30m': 'THIRTY_MINUTE',
346
+ '1h': 'ONE_HOUR',
347
+ '2h': 'TWO_HOUR',
348
+ '6h': 'SIX_HOUR',
349
+ '1d': 'ONE_DAY',
350
+ },
351
+ 'commonCurrencies': {
352
+ 'CGLD': 'CELO',
353
+ },
354
+ 'options': {
355
+ 'usePrivate': False,
356
+ 'brokerId': 'ccxt',
357
+ 'stablePairs': ['BUSD-USD', 'CBETH-ETH', 'DAI-USD', 'GUSD-USD', 'GYEN-USD', 'PAX-USD', 'PAX-USDT', 'USDC-EUR', 'USDC-GBP', 'USDT-EUR', 'USDT-GBP', 'USDT-USD', 'USDT-USDC', 'WBTC-BTC'],
358
+ 'fetchCurrencies': {
359
+ 'expires': 5000,
360
+ },
361
+ 'accounts': [
362
+ 'wallet',
363
+ 'fiat',
364
+ # 'vault',
365
+ ],
366
+ 'v3Accounts': [
367
+ 'ACCOUNT_TYPE_CRYPTO',
368
+ 'ACCOUNT_TYPE_FIAT',
369
+ ],
370
+ 'networks': {
371
+ 'ERC20': 'ethereum',
372
+ 'XLM': 'stellar',
373
+ },
374
+ 'createMarketBuyOrderRequiresPrice': True,
375
+ 'advanced': True, # set to True if using any v3 endpoints from the advanced trade API
376
+ 'fetchMarkets': 'fetchMarketsV3', # 'fetchMarketsV3' or 'fetchMarketsV2'
377
+ 'fetchTicker': 'fetchTickerV3', # 'fetchTickerV3' or 'fetchTickerV2'
378
+ 'fetchTickers': 'fetchTickersV3', # 'fetchTickersV3' or 'fetchTickersV2'
379
+ 'fetchAccounts': 'fetchAccountsV3', # 'fetchAccountsV3' or 'fetchAccountsV2'
380
+ 'fetchBalance': 'v2PrivateGetAccounts', # 'v2PrivateGetAccounts' or 'v3PrivateGetBrokerageAccounts'
381
+ 'fetchTime': 'v2PublicGetTime', # 'v2PublicGetTime' or 'v3PublicGetBrokerageTime'
382
+ 'user_native_currency': 'USD', # needed to get fees for v3
383
+ },
384
+ })
385
+
386
+ def fetch_time(self, params={}):
387
+ """
388
+ fetches the current integer timestamp in milliseconds from the exchange server
389
+ :see: https://docs.cloud.coinbase.com/sign-in-with-coinbase/docs/api-time#http-request
390
+ :param dict [params]: extra parameters specific to the exchange API endpoint
391
+ :param str [params.method]: 'v2PublicGetTime' or 'v3PublicGetBrokerageTime' default is 'v2PublicGetTime'
392
+ :returns int: the current integer timestamp in milliseconds from the exchange server
393
+ """
394
+ defaultMethod = self.safe_string(self.options, 'fetchTime', 'v2PublicGetTime')
395
+ method = self.safe_string(params, 'method', defaultMethod)
396
+ params = self.omit(params, 'method')
397
+ response = None
398
+ if method == 'v2PublicGetTime':
399
+ response = self.v2PublicGetTime(params)
400
+ #
401
+ # {
402
+ # "data": {
403
+ # "epoch": 1589295679,
404
+ # "iso": "2020-05-12T15:01:19Z"
405
+ # }
406
+ # }
407
+ #
408
+ response = self.safe_dict(response, 'data', {})
409
+ else:
410
+ response = self.v3PublicGetBrokerageTime(params)
411
+ #
412
+ # {
413
+ # "iso": "2024-02-27T03:37:14Z",
414
+ # "epochSeconds": "1709005034",
415
+ # "epochMillis": "1709005034333"
416
+ # }
417
+ #
418
+ return self.safe_timestamp_2(response, 'epoch', 'epochSeconds')
419
+
420
+ def fetch_accounts(self, params={}) -> List[Account]:
421
+ """
422
+ fetch all the accounts associated with a profile
423
+ :see: https://docs.cloud.coinbase.com/advanced-trade-api/reference/retailbrokerageapi_getaccounts
424
+ :see: https://docs.cloud.coinbase.com/sign-in-with-coinbase/docs/api-accounts#list-accounts
425
+ :param dict [params]: extra parameters specific to the exchange API endpoint
426
+ :param boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
427
+ :returns dict: a dictionary of `account structures <https://docs.ccxt.com/#/?id=account-structure>` indexed by the account type
428
+ """
429
+ method = self.safe_string(self.options, 'fetchAccounts', 'fetchAccountsV3')
430
+ if method == 'fetchAccountsV3':
431
+ return self.fetch_accounts_v3(params)
432
+ return self.fetch_accounts_v2(params)
433
+
434
+ def fetch_accounts_v2(self, params={}) -> List[Account]:
435
+ self.load_markets()
436
+ paginate = False
437
+ paginate, params = self.handle_option_and_params(params, 'fetchAccounts', 'paginate')
438
+ if paginate:
439
+ return self.fetch_paginated_call_cursor('fetchAccounts', None, None, None, params, 'next_starting_after', 'starting_after', None, 100)
440
+ request: dict = {
441
+ 'limit': 100,
442
+ }
443
+ response = self.v2PrivateGetAccounts(self.extend(request, params))
444
+ #
445
+ # {
446
+ # "pagination": {
447
+ # "ending_before": null,
448
+ # "starting_after": null,
449
+ # "previous_ending_before": null,
450
+ # "next_starting_after": null,
451
+ # "limit": 244,
452
+ # "order": "desc",
453
+ # "previous_uri": null,
454
+ # "next_uri": null
455
+ # },
456
+ # "data": [
457
+ # {
458
+ # "id": "XLM",
459
+ # "name": "XLM Wallet",
460
+ # "primary": False,
461
+ # "type": "wallet",
462
+ # "currency": {
463
+ # "code": "XLM",
464
+ # "name": "Stellar Lumens",
465
+ # "color": "#000000",
466
+ # "sort_index": 127,
467
+ # "exponent": 7,
468
+ # "type": "crypto",
469
+ # "address_regex": "^G[A-Z2-7]{55}$",
470
+ # "asset_id": "13b83335-5ede-595b-821e-5bcdfa80560f",
471
+ # "destination_tag_name": "XLM Memo ID",
472
+ # "destination_tag_regex": "^[-~]{1,28}$"
473
+ # },
474
+ # "balance": {
475
+ # "amount": "0.0000000",
476
+ # "currency": "XLM"
477
+ # },
478
+ # "created_at": null,
479
+ # "updated_at": null,
480
+ # "resource": "account",
481
+ # "resource_path": "/v2/accounts/XLM",
482
+ # "allow_deposits": True,
483
+ # "allow_withdrawals": True
484
+ # },
485
+ # ]
486
+ # }
487
+ #
488
+ data = self.safe_list(response, 'data', [])
489
+ pagination = self.safe_dict(response, 'pagination', {})
490
+ cursor = self.safe_string(pagination, 'next_starting_after')
491
+ accounts = self.safe_list(response, 'data', [])
492
+ length = len(accounts)
493
+ lastIndex = length - 1
494
+ last = self.safe_dict(accounts, lastIndex)
495
+ if (cursor is not None) and (cursor != ''):
496
+ last['next_starting_after'] = cursor
497
+ accounts[lastIndex] = last
498
+ return self.parse_accounts(data, params)
499
+
500
+ def fetch_accounts_v3(self, params={}) -> List[Account]:
501
+ self.load_markets()
502
+ paginate = False
503
+ paginate, params = self.handle_option_and_params(params, 'fetchAccounts', 'paginate')
504
+ if paginate:
505
+ return self.fetch_paginated_call_cursor('fetchAccounts', None, None, None, params, 'cursor', 'cursor', None, 250)
506
+ request: dict = {
507
+ 'limit': 250,
508
+ }
509
+ response = self.v3PrivateGetBrokerageAccounts(self.extend(request, params))
510
+ #
511
+ # {
512
+ # "accounts": [
513
+ # {
514
+ # "uuid": "11111111-1111-1111-1111-111111111111",
515
+ # "name": "USDC Wallet",
516
+ # "currency": "USDC",
517
+ # "available_balance": {
518
+ # "value": "0.0000000000000000",
519
+ # "currency": "USDC"
520
+ # },
521
+ # "default": True,
522
+ # "active": True,
523
+ # "created_at": "2023-01-04T06:20:06.456Z",
524
+ # "updated_at": "2023-01-04T06:20:07.181Z",
525
+ # "deleted_at": null,
526
+ # "type": "ACCOUNT_TYPE_CRYPTO",
527
+ # "ready": False,
528
+ # "hold": {
529
+ # "value": "0.0000000000000000",
530
+ # "currency": "USDC"
531
+ # }
532
+ # },
533
+ # ...
534
+ # ],
535
+ # "has_next": False,
536
+ # "cursor": "",
537
+ # "size": 9
538
+ # }
539
+ #
540
+ accounts = self.safe_list(response, 'accounts', [])
541
+ length = len(accounts)
542
+ lastIndex = length - 1
543
+ last = self.safe_dict(accounts, lastIndex)
544
+ cursor = self.safe_string(response, 'cursor')
545
+ if (cursor is not None) and (cursor != ''):
546
+ last['cursor'] = cursor
547
+ accounts[lastIndex] = last
548
+ return self.parse_accounts(accounts, params)
549
+
550
+ def fetch_portfolios(self, params={}) -> List[Account]:
551
+ """
552
+ fetch all the portfolios
553
+ :see: https://docs.cloud.coinbase.com/advanced-trade-api/reference/retailbrokerageapi_getportfolios
554
+ :param dict [params]: extra parameters specific to the exchange API endpoint
555
+ :returns dict: a dictionary of `account structures <https://docs.ccxt.com/#/?id=account-structure>` indexed by the account type
556
+ """
557
+ response = self.v3PrivateGetBrokeragePortfolios(params)
558
+ portfolios = self.safe_list(response, 'portfolios', [])
559
+ result = []
560
+ for i in range(0, len(portfolios)):
561
+ portfolio = portfolios[i]
562
+ result.append({
563
+ 'id': self.safe_string(portfolio, 'uuid'),
564
+ 'type': self.safe_string(portfolio, 'type'),
565
+ 'code': None,
566
+ 'info': portfolio,
567
+ })
568
+ return result
569
+
570
+ def parse_account(self, account):
571
+ #
572
+ # fetchAccountsV2
573
+ #
574
+ # {
575
+ # "id": "XLM",
576
+ # "name": "XLM Wallet",
577
+ # "primary": False,
578
+ # "type": "wallet",
579
+ # "currency": {
580
+ # "code": "XLM",
581
+ # "name": "Stellar Lumens",
582
+ # "color": "#000000",
583
+ # "sort_index": 127,
584
+ # "exponent": 7,
585
+ # "type": "crypto",
586
+ # "address_regex": "^G[A-Z2-7]{55}$",
587
+ # "asset_id": "13b83335-5ede-595b-821e-5bcdfa80560f",
588
+ # "destination_tag_name": "XLM Memo ID",
589
+ # "destination_tag_regex": "^[-~]{1,28}$"
590
+ # },
591
+ # "balance": {
592
+ # "amount": "0.0000000",
593
+ # "currency": "XLM"
594
+ # },
595
+ # "created_at": null,
596
+ # "updated_at": null,
597
+ # "resource": "account",
598
+ # "resource_path": "/v2/accounts/XLM",
599
+ # "allow_deposits": True,
600
+ # "allow_withdrawals": True
601
+ # }
602
+ #
603
+ # fetchAccountsV3
604
+ #
605
+ # {
606
+ # "uuid": "11111111-1111-1111-1111-111111111111",
607
+ # "name": "USDC Wallet",
608
+ # "currency": "USDC",
609
+ # "available_balance": {
610
+ # "value": "0.0000000000000000",
611
+ # "currency": "USDC"
612
+ # },
613
+ # "default": True,
614
+ # "active": True,
615
+ # "created_at": "2023-01-04T06:20:06.456Z",
616
+ # "updated_at": "2023-01-04T06:20:07.181Z",
617
+ # "deleted_at": null,
618
+ # "type": "ACCOUNT_TYPE_CRYPTO",
619
+ # "ready": False,
620
+ # "hold": {
621
+ # "value": "0.0000000000000000",
622
+ # "currency": "USDC"
623
+ # }
624
+ # }
625
+ #
626
+ active = self.safe_bool(account, 'active')
627
+ currencyIdV3 = self.safe_string(account, 'currency')
628
+ currency = self.safe_dict(account, 'currency', {})
629
+ currencyId = self.safe_string(currency, 'code', currencyIdV3)
630
+ typeV3 = self.safe_string(account, 'name')
631
+ typeV2 = self.safe_string(account, 'type')
632
+ parts = typeV3.split(' ')
633
+ return {
634
+ 'id': self.safe_string_2(account, 'id', 'uuid'),
635
+ 'type': self.safe_string_lower(parts, 1) if (active is not None) else typeV2,
636
+ 'code': self.safe_currency_code(currencyId),
637
+ 'info': account,
638
+ }
639
+
640
+ def create_deposit_address(self, code: str, params={}):
641
+ """
642
+ create a currency deposit address
643
+ :see: https://docs.cloud.coinbase.com/sign-in-with-coinbase/docs/api-addresses#create-address
644
+ :param str code: unified currency code of the currency for the deposit address
645
+ :param dict [params]: extra parameters specific to the exchange API endpoint
646
+ :returns dict: an `address structure <https://docs.ccxt.com/#/?id=address-structure>`
647
+ """
648
+ accountId = self.safe_string(params, 'account_id')
649
+ params = self.omit(params, 'account_id')
650
+ if accountId is None:
651
+ self.load_accounts()
652
+ for i in range(0, len(self.accounts)):
653
+ account = self.accounts[i]
654
+ if account['code'] == code and account['type'] == 'wallet':
655
+ accountId = account['id']
656
+ break
657
+ if accountId is None:
658
+ raise ExchangeError(self.id + ' createDepositAddress() could not find the account with matching currency code, specify an `account_id` extra param')
659
+ request: dict = {
660
+ 'account_id': accountId,
661
+ }
662
+ response = self.v2PrivatePostAccountsAccountIdAddresses(self.extend(request, params))
663
+ #
664
+ # {
665
+ # "data": {
666
+ # "id": "05b1ebbf-9438-5dd4-b297-2ddedc98d0e4",
667
+ # "address": "coinbasebase",
668
+ # "address_info": {
669
+ # "address": "coinbasebase",
670
+ # "destination_tag": "287594668"
671
+ # },
672
+ # "name": null,
673
+ # "created_at": "2019-07-01T14:39:29Z",
674
+ # "updated_at": "2019-07-01T14:39:29Z",
675
+ # "network": "eosio",
676
+ # "uri_scheme": "eosio",
677
+ # "resource": "address",
678
+ # "resource_path": "/v2/accounts/14cfc769-e852-52f3-b831-711c104d194c/addresses/05b1ebbf-9438-5dd4-b297-2ddedc98d0e4",
679
+ # "warnings": [
680
+ # {
681
+ # "title": "Only send EOS(EOS) to self address",
682
+ # "details": "Sending any other cryptocurrency will result in permanent loss.",
683
+ # "image_url": "https://dynamic-assets.coinbase.com/deaca3d47b10ed4a91a872e9618706eec34081127762d88f2476ac8e99ada4b48525a9565cf2206d18c04053f278f693434af4d4629ca084a9d01b7a286a7e26/asset_icons/1f8489bb280fb0a0fd643c1161312ba49655040e9aaaced5f9ad3eeaf868eadc.png"
684
+ # },
685
+ # {
686
+ # "title": "Both an address and EOS memo are required to receive EOS",
687
+ # "details": "If you send funds without an EOS memo or with an incorrect EOS memo, your funds cannot be credited to your account.",
688
+ # "image_url": "https://www.coinbase.com/assets/receive-warning-2f3269d83547a7748fb39d6e0c1c393aee26669bfea6b9f12718094a1abff155.png"
689
+ # }
690
+ # ],
691
+ # "warning_title": "Only send EOS(EOS) to self address",
692
+ # "warning_details": "Sending any other cryptocurrency will result in permanent loss.",
693
+ # "destination_tag": "287594668",
694
+ # "deposit_uri": "eosio:coinbasebase?dt=287594668",
695
+ # "callback_url": null
696
+ # }
697
+ # }
698
+ #
699
+ data = self.safe_dict(response, 'data', {})
700
+ tag = self.safe_string(data, 'destination_tag')
701
+ address = self.safe_string(data, 'address')
702
+ return {
703
+ 'currency': code,
704
+ 'tag': tag,
705
+ 'address': address,
706
+ 'info': response,
707
+ }
708
+
709
+ def fetch_my_sells(self, symbol: Str = None, since: Int = None, limit: Int = None, params={}):
710
+ """
711
+ * @ignore
712
+ fetch sells
713
+ :see: https://docs.cloud.coinbase.com/sign-in-with-coinbase/docs/api-sells#list-sells
714
+ :param str symbol: not used by coinbase fetchMySells()
715
+ :param int [since]: timestamp in ms of the earliest sell, default is None
716
+ :param int [limit]: max number of sells to return, default is None
717
+ :param dict [params]: extra parameters specific to the exchange API endpoint
718
+ :returns dict: a `list of order structures <https://docs.ccxt.com/#/?id=order-structure>`
719
+ """
720
+ # v2 did't have an endpoint for all historical trades
721
+ request = self.prepare_account_request(limit, params)
722
+ self.load_markets()
723
+ query = self.omit(params, ['account_id', 'accountId'])
724
+ sells = self.v2PrivateGetAccountsAccountIdSells(self.extend(request, query))
725
+ return self.parse_trades(sells['data'], None, since, limit)
726
+
727
+ def fetch_my_buys(self, symbol: Str = None, since: Int = None, limit: Int = None, params={}):
728
+ """
729
+ * @ignore
730
+ fetch buys
731
+ :see: https://docs.cloud.coinbase.com/sign-in-with-coinbase/docs/api-buys#list-buys
732
+ :param str symbol: not used by coinbase fetchMyBuys()
733
+ :param int [since]: timestamp in ms of the earliest buy, default is None
734
+ :param int [limit]: max number of buys to return, default is None
735
+ :param dict [params]: extra parameters specific to the exchange API endpoint
736
+ :returns dict: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
737
+ """
738
+ # v2 did't have an endpoint for all historical trades
739
+ request = self.prepare_account_request(limit, params)
740
+ self.load_markets()
741
+ query = self.omit(params, ['account_id', 'accountId'])
742
+ buys = self.v2PrivateGetAccountsAccountIdBuys(self.extend(request, query))
743
+ return self.parse_trades(buys['data'], None, since, limit)
744
+
745
+ def fetch_transactions_with_method(self, method, code: Str = None, since: Int = None, limit: Int = None, params={}):
746
+ request = None
747
+ request, params = self.prepare_account_request_with_currency_code(code, limit, params)
748
+ self.load_markets()
749
+ response = getattr(self, method)(self.extend(request, params))
750
+ return self.parse_transactions(response['data'], None, since, limit)
751
+
752
+ def fetch_withdrawals(self, code: Str = None, since: Int = None, limit: Int = None, params={}) -> List[Transaction]:
753
+ """
754
+ fetch all withdrawals made from an account
755
+ :see: https://docs.cloud.coinbase.com/sign-in-with-coinbase/docs/api-withdrawals#list-withdrawals
756
+ :param str code: unified currency code
757
+ :param int [since]: the earliest time in ms to fetch withdrawals for
758
+ :param int [limit]: the maximum number of withdrawals structures to retrieve
759
+ :param dict [params]: extra parameters specific to the exchange API endpoint
760
+ :returns dict[]: a list of `transaction structures <https://docs.ccxt.com/#/?id=transaction-structure>`
761
+ """
762
+ # fiat only, for crypto transactions use fetchLedger
763
+ return self.fetch_transactions_with_method('v2PrivateGetAccountsAccountIdWithdrawals', code, since, limit, params)
764
+
765
+ def fetch_deposits(self, code: Str = None, since: Int = None, limit: Int = None, params={}) -> List[Transaction]:
766
+ """
767
+ fetch all deposits made to an account
768
+ :see: https://docs.cloud.coinbase.com/sign-in-with-coinbase/docs/api-deposits#list-deposits
769
+ :param str code: unified currency code
770
+ :param int [since]: the earliest time in ms to fetch deposits for
771
+ :param int [limit]: the maximum number of deposits structures to retrieve
772
+ :param dict [params]: extra parameters specific to the exchange API endpoint
773
+ :returns dict[]: a list of `transaction structures <https://docs.ccxt.com/#/?id=transaction-structure>`
774
+ """
775
+ # fiat only, for crypto transactions use fetchLedger
776
+ return self.fetch_transactions_with_method('v2PrivateGetAccountsAccountIdDeposits', code, since, limit, params)
777
+
778
+ def parse_transaction_status(self, status: Str):
779
+ statuses: dict = {
780
+ 'created': 'pending',
781
+ 'completed': 'ok',
782
+ 'canceled': 'canceled',
783
+ }
784
+ return self.safe_string(statuses, status, status)
785
+
786
+ def parse_transaction(self, transaction: dict, currency: Currency = None) -> Transaction:
787
+ #
788
+ # fiat deposit
789
+ #
790
+ # {
791
+ # "id": "f34c19f3-b730-5e3d-9f72",
792
+ # "status": "completed",
793
+ # "payment_method": {
794
+ # "id": "a022b31d-f9c7-5043-98f2",
795
+ # "resource": "payment_method",
796
+ # "resource_path": "/v2/payment-methods/a022b31d-f9c7-5043-98f2"
797
+ # },
798
+ # "transaction": {
799
+ # "id": "04ed4113-3732-5b0c-af86-b1d2146977d0",
800
+ # "resource": "transaction",
801
+ # "resource_path": "/v2/accounts/91cd2d36-3a91-55b6-a5d4-0124cf105483/transactions/04ed4113-3732-5b0c-af86"
802
+ # },
803
+ # "user_reference": "2VTYTH",
804
+ # "created_at": "2017-02-09T07:01:18Z",
805
+ # "updated_at": "2017-02-09T07:01:26Z",
806
+ # "resource": "deposit",
807
+ # "resource_path": "/v2/accounts/91cd2d36-3a91-55b6-a5d4-0124cf105483/deposits/f34c19f3-b730-5e3d-9f72",
808
+ # "committed": True,
809
+ # "payout_at": "2017-02-12T07:01:17Z",
810
+ # "instant": False,
811
+ # "fee": {"amount": "0.00", "currency": "EUR"},
812
+ # "amount": {"amount": "114.02", "currency": "EUR"},
813
+ # "subtotal": {"amount": "114.02", "currency": "EUR"},
814
+ # "hold_until": null,
815
+ # "hold_days": 0,
816
+ # "hold_business_days": 0,
817
+ # "next_step": null
818
+ # }
819
+ #
820
+ # fiat_withdrawal
821
+ #
822
+ # {
823
+ # "id": "cfcc3b4a-eeb6-5e8c-8058",
824
+ # "status": "completed",
825
+ # "payment_method": {
826
+ # "id": "8b94cfa4-f7fd-5a12-a76a",
827
+ # "resource": "payment_method",
828
+ # "resource_path": "/v2/payment-methods/8b94cfa4-f7fd-5a12-a76a"
829
+ # },
830
+ # "transaction": {
831
+ # "id": "fcc2550b-5104-5f83-a444",
832
+ # "resource": "transaction",
833
+ # "resource_path": "/v2/accounts/91cd2d36-3a91-55b6-a5d4-0124cf105483/transactions/fcc2550b-5104-5f83-a444"
834
+ # },
835
+ # "user_reference": "MEUGK",
836
+ # "created_at": "2018-07-26T08:55:12Z",
837
+ # "updated_at": "2018-07-26T08:58:18Z",
838
+ # "resource": "withdrawal",
839
+ # "resource_path": "/v2/accounts/91cd2d36-3a91-55b6-a5d4-0124cf105483/withdrawals/cfcc3b4a-eeb6-5e8c-8058",
840
+ # "committed": True,
841
+ # "payout_at": "2018-07-31T08:55:12Z",
842
+ # "instant": False,
843
+ # "fee": {"amount": "0.15", "currency": "EUR"},
844
+ # "amount": {"amount": "13130.69", "currency": "EUR"},
845
+ # "subtotal": {"amount": "13130.84", "currency": "EUR"},
846
+ # "idem": "e549dee5-63ed-4e79-8a96",
847
+ # "next_step": null
848
+ # }
849
+ #
850
+ # withdraw
851
+ #
852
+ # {
853
+ # "id": "a1794ecf-5693-55fa-70cf-ef731748ed82",
854
+ # "type": "send",
855
+ # "status": "pending",
856
+ # "amount": {
857
+ # "amount": "-14.008308",
858
+ # "currency": "USDC"
859
+ # },
860
+ # "native_amount": {
861
+ # "amount": "-18.74",
862
+ # "currency": "CAD"
863
+ # },
864
+ # "description": null,
865
+ # "created_at": "2024-01-12T01:27:31Z",
866
+ # "updated_at": "2024-01-12T01:27:31Z",
867
+ # "resource": "transaction",
868
+ # "resource_path": "/v2/accounts/a34bgfad-ed67-538b-bffc-730c98c10da0/transactions/a1794ecf-5693-55fa-70cf-ef731748ed82",
869
+ # "instant_exchange": False,
870
+ # "network": {
871
+ # "status": "pending",
872
+ # "status_description": "Pending(est. less than 10 minutes)",
873
+ # "transaction_fee": {
874
+ # "amount": "4.008308",
875
+ # "currency": "USDC"
876
+ # },
877
+ # "transaction_amount": {
878
+ # "amount": "10.000000",
879
+ # "currency": "USDC"
880
+ # },
881
+ # "confirmations": 0
882
+ # },
883
+ # "to": {
884
+ # "resource": "ethereum_address",
885
+ # "address": "0x9...",
886
+ # "currency": "USDC",
887
+ # "address_info": {
888
+ # "address": "0x9..."
889
+ # }
890
+ # },
891
+ # "idem": "748d8591-dg9a-7831-a45b-crd61dg78762",
892
+ # "details": {
893
+ # "title": "Sent USDC",
894
+ # "subtitle": "To USDC address on Ethereum network",
895
+ # "header": "Sent 14.008308 USDC($18.74)",
896
+ # "health": "warning"
897
+ # },
898
+ # "hide_native_amount": False
899
+ # }
900
+ #
901
+ transactionType = self.safe_string(transaction, 'type')
902
+ amountAndCurrencyObject = None
903
+ feeObject = None
904
+ if transactionType == 'send':
905
+ network = self.safe_dict(transaction, 'network', {})
906
+ amountAndCurrencyObject = self.safe_dict(network, 'transaction_amount', {})
907
+ feeObject = self.safe_dict(network, 'transaction_fee', {})
908
+ else:
909
+ amountAndCurrencyObject = self.safe_dict(transaction, 'subtotal', {})
910
+ feeObject = self.safe_dict(transaction, 'fee', {})
911
+ status = self.parse_transaction_status(self.safe_string(transaction, 'status'))
912
+ if status is None:
913
+ committed = self.safe_bool(transaction, 'committed')
914
+ status = 'ok' if committed else 'pending'
915
+ id = self.safe_string(transaction, 'id')
916
+ currencyId = self.safe_string(amountAndCurrencyObject, 'currency')
917
+ feeCurrencyId = self.safe_string(feeObject, 'currency')
918
+ datetime = self.safe_string(transaction, 'created_at')
919
+ toObject = self.safe_dict(transaction, 'to', {})
920
+ toAddress = self.safe_string(toObject, 'address')
921
+ return {
922
+ 'info': transaction,
923
+ 'id': id,
924
+ 'txid': id,
925
+ 'timestamp': self.parse8601(datetime),
926
+ 'datetime': datetime,
927
+ 'network': None,
928
+ 'address': toAddress,
929
+ 'addressTo': toAddress,
930
+ 'addressFrom': None,
931
+ 'tag': None,
932
+ 'tagTo': None,
933
+ 'tagFrom': None,
934
+ 'type': self.safe_string(transaction, 'resource'),
935
+ 'amount': self.safe_number(amountAndCurrencyObject, 'amount'),
936
+ 'currency': self.safe_currency_code(currencyId, currency),
937
+ 'status': status,
938
+ 'updated': self.parse8601(self.safe_string(transaction, 'updated_at')),
939
+ 'fee': {
940
+ 'cost': self.safe_number(feeObject, 'amount'),
941
+ 'currency': self.safe_currency_code(feeCurrencyId),
942
+ },
943
+ }
944
+
945
+ def parse_trade(self, trade: dict, market: Market = None) -> Trade:
946
+ #
947
+ # fetchMyBuys, fetchMySells
948
+ #
949
+ # {
950
+ # "id": "67e0eaec-07d7-54c4-a72c-2e92826897df",
951
+ # "status": "completed",
952
+ # "payment_method": {
953
+ # "id": "83562370-3e5c-51db-87da-752af5ab9559",
954
+ # "resource": "payment_method",
955
+ # "resource_path": "/v2/payment-methods/83562370-3e5c-51db-87da-752af5ab9559"
956
+ # },
957
+ # "transaction": {
958
+ # "id": "441b9494-b3f0-5b98-b9b0-4d82c21c252a",
959
+ # "resource": "transaction",
960
+ # "resource_path": "/v2/accounts/2bbf394c-193b-5b2a-9155-3b4732659ede/transactions/441b9494-b3f0-5b98-b9b0-4d82c21c252a"
961
+ # },
962
+ # "amount": {"amount": "1.00000000", "currency": "BTC"},
963
+ # "total": {"amount": "10.25", "currency": "USD"},
964
+ # "subtotal": {"amount": "10.10", "currency": "USD"},
965
+ # "created_at": "2015-01-31T20:49:02Z",
966
+ # "updated_at": "2015-02-11T16:54:02-08:00",
967
+ # "resource": "buy",
968
+ # "resource_path": "/v2/accounts/2bbf394c-193b-5b2a-9155-3b4732659ede/buys/67e0eaec-07d7-54c4-a72c-2e92826897df",
969
+ # "committed": True,
970
+ # "instant": False,
971
+ # "fee": {"amount": "0.15", "currency": "USD"},
972
+ # "payout_at": "2015-02-18T16:54:00-08:00"
973
+ # }
974
+ #
975
+ # fetchTrades
976
+ #
977
+ # {
978
+ # "trade_id": "10092327",
979
+ # "product_id": "BTC-USDT",
980
+ # "price": "17488.12",
981
+ # "size": "0.0000623",
982
+ # "time": "2023-01-11T00:52:37.557001Z",
983
+ # "side": "BUY",
984
+ # "bid": "",
985
+ # "ask": ""
986
+ # }
987
+ #
988
+ # fetchMyTrades
989
+ #
990
+ # {
991
+ # "entry_id": "b88b82cc89e326a2778874795102cbafd08dd979a2a7a3c69603fc4c23c2e010",
992
+ # "trade_id": "cdc39e45-bbd3-44ec-bf02-61742dfb16a1",
993
+ # "order_id": "813a53c5-3e39-47bb-863d-2faf685d22d8",
994
+ # "trade_time": "2023-01-18T01:37:38.091377090Z",
995
+ # "trade_type": "FILL",
996
+ # "price": "21220.64",
997
+ # "size": "0.0046830664333996",
998
+ # "commission": "0.0000280983986004",
999
+ # "product_id": "BTC-USDT",
1000
+ # "sequence_timestamp": "2023-01-18T01:37:38.092520Z",
1001
+ # "liquidity_indicator": "UNKNOWN_LIQUIDITY_INDICATOR",
1002
+ # "size_in_quote": True,
1003
+ # "user_id": "1111111-1111-1111-1111-111111111111",
1004
+ # "side": "BUY"
1005
+ # }
1006
+ #
1007
+ symbol = None
1008
+ totalObject = self.safe_dict(trade, 'total', {})
1009
+ amountObject = self.safe_dict(trade, 'amount', {})
1010
+ subtotalObject = self.safe_dict(trade, 'subtotal', {})
1011
+ feeObject = self.safe_dict(trade, 'fee', {})
1012
+ marketId = self.safe_string(trade, 'product_id')
1013
+ market = self.safe_market(marketId, market, '-')
1014
+ if market is not None:
1015
+ symbol = market['symbol']
1016
+ else:
1017
+ baseId = self.safe_string(amountObject, 'currency')
1018
+ quoteId = self.safe_string(totalObject, 'currency')
1019
+ if (baseId is not None) and (quoteId is not None):
1020
+ base = self.safe_currency_code(baseId)
1021
+ quote = self.safe_currency_code(quoteId)
1022
+ symbol = base + '/' + quote
1023
+ sizeInQuote = self.safe_bool(trade, 'size_in_quote')
1024
+ v3Price = self.safe_string(trade, 'price')
1025
+ v3Cost = None
1026
+ v3Amount = self.safe_string(trade, 'size')
1027
+ if sizeInQuote:
1028
+ # calculate base size
1029
+ v3Cost = v3Amount
1030
+ v3Amount = Precise.string_div(v3Amount, v3Price)
1031
+ v3FeeCost = self.safe_string(trade, 'commission')
1032
+ amountString = self.safe_string(amountObject, 'amount', v3Amount)
1033
+ costString = self.safe_string(subtotalObject, 'amount', v3Cost)
1034
+ priceString = None
1035
+ cost = None
1036
+ if (costString is not None) and (amountString is not None):
1037
+ priceString = Precise.string_div(costString, amountString)
1038
+ else:
1039
+ priceString = v3Price
1040
+ if (priceString is not None) and (amountString is not None):
1041
+ cost = Precise.string_mul(priceString, amountString)
1042
+ else:
1043
+ cost = costString
1044
+ feeCurrencyId = self.safe_string(feeObject, 'currency')
1045
+ feeCost = self.safe_number(feeObject, 'amount', self.parse_number(v3FeeCost))
1046
+ if (feeCurrencyId is None) and (market is not None) and (feeCost is not None):
1047
+ feeCurrencyId = market['quote']
1048
+ datetime = self.safe_string_n(trade, ['created_at', 'trade_time', 'time'])
1049
+ side = self.safe_string_lower_2(trade, 'resource', 'side')
1050
+ takerOrMaker = self.safe_string_lower(trade, 'liquidity_indicator')
1051
+ return self.safe_trade({
1052
+ 'info': trade,
1053
+ 'id': self.safe_string_2(trade, 'id', 'trade_id'),
1054
+ 'order': self.safe_string(trade, 'order_id'),
1055
+ 'timestamp': self.parse8601(datetime),
1056
+ 'datetime': datetime,
1057
+ 'symbol': symbol,
1058
+ 'type': None,
1059
+ 'side': None if (side == 'unknown_order_side') else side,
1060
+ 'takerOrMaker': None if (takerOrMaker == 'unknown_liquidity_indicator') else takerOrMaker,
1061
+ 'price': priceString,
1062
+ 'amount': amountString,
1063
+ 'cost': cost,
1064
+ 'fee': {
1065
+ 'cost': feeCost,
1066
+ 'currency': self.safe_currency_code(feeCurrencyId),
1067
+ },
1068
+ })
1069
+
1070
+ def fetch_markets(self, params={}) -> List[Market]:
1071
+ """
1072
+ :see: https://docs.cloud.coinbase.com/advanced-trade-api/reference/retailbrokerageapi_getpublicproducts
1073
+ :see: https://docs.cloud.coinbase.com/sign-in-with-coinbase/docs/api-currencies#get-fiat-currencies
1074
+ :see: https://docs.cloud.coinbase.com/sign-in-with-coinbase/docs/api-exchange-rates#get-exchange-rates
1075
+ retrieves data on all markets for coinbase
1076
+ :param dict [params]: extra parameters specific to the exchange API endpoint
1077
+ :param boolean [params.usePrivate]: use private endpoint for fetching markets
1078
+ :returns dict[]: an array of objects representing market data
1079
+ """
1080
+ method = self.safe_string(self.options, 'fetchMarkets', 'fetchMarketsV3')
1081
+ if method == 'fetchMarketsV3':
1082
+ return self.fetch_markets_v3(params)
1083
+ return self.fetch_markets_v2(params)
1084
+
1085
+ def fetch_markets_v2(self, params={}):
1086
+ response = self.fetch_currencies_from_cache(params)
1087
+ currencies = self.safe_dict(response, 'currencies', {})
1088
+ exchangeRates = self.safe_dict(response, 'exchangeRates', {})
1089
+ data = self.safe_list(currencies, 'data', [])
1090
+ dataById = self.index_by(data, 'id')
1091
+ rates = self.safe_dict(self.safe_dict(exchangeRates, 'data', {}), 'rates', {})
1092
+ baseIds = list(rates.keys())
1093
+ result = []
1094
+ for i in range(0, len(baseIds)):
1095
+ baseId = baseIds[i]
1096
+ base = self.safe_currency_code(baseId)
1097
+ type = 'fiat' if (baseId in dataById) else 'crypto'
1098
+ # https://github.com/ccxt/ccxt/issues/6066
1099
+ if type == 'crypto':
1100
+ for j in range(0, len(data)):
1101
+ quoteCurrency = data[j]
1102
+ quoteId = self.safe_string(quoteCurrency, 'id')
1103
+ quote = self.safe_currency_code(quoteId)
1104
+ result.append({
1105
+ 'id': baseId + '-' + quoteId,
1106
+ 'symbol': base + '/' + quote,
1107
+ 'base': base,
1108
+ 'quote': quote,
1109
+ 'settle': None,
1110
+ 'baseId': baseId,
1111
+ 'quoteId': quoteId,
1112
+ 'settleId': None,
1113
+ 'type': 'spot',
1114
+ 'spot': True,
1115
+ 'margin': False,
1116
+ 'swap': False,
1117
+ 'future': False,
1118
+ 'option': False,
1119
+ 'active': None,
1120
+ 'contract': False,
1121
+ 'linear': None,
1122
+ 'inverse': None,
1123
+ 'contractSize': None,
1124
+ 'expiry': None,
1125
+ 'expiryDatetime': None,
1126
+ 'strike': None,
1127
+ 'optionType': None,
1128
+ 'precision': {
1129
+ 'amount': None,
1130
+ 'price': None,
1131
+ },
1132
+ 'limits': {
1133
+ 'leverage': {
1134
+ 'min': None,
1135
+ 'max': None,
1136
+ },
1137
+ 'amount': {
1138
+ 'min': None,
1139
+ 'max': None,
1140
+ },
1141
+ 'price': {
1142
+ 'min': None,
1143
+ 'max': None,
1144
+ },
1145
+ 'cost': {
1146
+ 'min': self.safe_number(quoteCurrency, 'min_size'),
1147
+ 'max': None,
1148
+ },
1149
+ },
1150
+ 'info': quoteCurrency,
1151
+ })
1152
+ return result
1153
+
1154
+ def fetch_markets_v3(self, params={}):
1155
+ usePrivate = False
1156
+ usePrivate, params = self.handle_option_and_params(params, 'fetchMarkets', 'usePrivate', False)
1157
+ spotUnresolvedPromises = []
1158
+ if usePrivate:
1159
+ spotUnresolvedPromises.append(self.v3PrivateGetBrokerageProducts(params))
1160
+ else:
1161
+ spotUnresolvedPromises.append(self.v3PublicGetBrokerageMarketProducts(params))
1162
+ #
1163
+ # {
1164
+ # products: [
1165
+ # {
1166
+ # product_id: 'BTC-USD',
1167
+ # price: '67060',
1168
+ # price_percentage_change_24h: '3.30054960636883',
1169
+ # volume_24h: '10967.87426597',
1170
+ # volume_percentage_change_24h: '141.73048325503036',
1171
+ # base_increment: '0.00000001',
1172
+ # quote_increment: '0.01',
1173
+ # quote_min_size: '1',
1174
+ # quote_max_size: '150000000',
1175
+ # base_min_size: '0.00000001',
1176
+ # base_max_size: '3400',
1177
+ # base_name: 'Bitcoin',
1178
+ # quote_name: 'US Dollar',
1179
+ # watched: False,
1180
+ # is_disabled: False,
1181
+ # new: False,
1182
+ # status: 'online',
1183
+ # cancel_only: False,
1184
+ # limit_only: False,
1185
+ # post_only: False,
1186
+ # trading_disabled: False,
1187
+ # auction_mode: False,
1188
+ # product_type: 'SPOT',
1189
+ # quote_currency_id: 'USD',
1190
+ # base_currency_id: 'BTC',
1191
+ # fcm_trading_session_details: null,
1192
+ # mid_market_price: '',
1193
+ # alias: '',
1194
+ # alias_to: ['BTC-USDC'],
1195
+ # base_display_symbol: 'BTC',
1196
+ # quote_display_symbol: 'USD',
1197
+ # view_only: False,
1198
+ # price_increment: '0.01',
1199
+ # display_name: 'BTC-USD',
1200
+ # product_venue: 'CBE'
1201
+ # },
1202
+ # ...
1203
+ # ],
1204
+ # num_products: '646'
1205
+ # }
1206
+ #
1207
+ if self.check_required_credentials(False):
1208
+ spotUnresolvedPromises.append(self.v3PrivateGetBrokerageTransactionSummary(params))
1209
+ #
1210
+ # {
1211
+ # total_volume: '9.995989116664404',
1212
+ # total_fees: '0.07996791093331522',
1213
+ # fee_tier: {
1214
+ # pricing_tier: 'Advanced 1',
1215
+ # usd_from: '0',
1216
+ # usd_to: '1000',
1217
+ # taker_fee_rate: '0.008',
1218
+ # maker_fee_rate: '0.006',
1219
+ # aop_from: '',
1220
+ # aop_to: ''
1221
+ # },
1222
+ # margin_rate: null,
1223
+ # goods_and_services_tax: null,
1224
+ # advanced_trade_only_volume: '9.995989116664404',
1225
+ # advanced_trade_only_fees: '0.07996791093331522',
1226
+ # coinbase_pro_volume: '0',
1227
+ # coinbase_pro_fees: '0',
1228
+ # total_balance: '',
1229
+ # has_promo_fee: False
1230
+ # }
1231
+ #
1232
+ unresolvedContractPromises = []
1233
+ try:
1234
+ unresolvedContractPromises = [
1235
+ self.v3PublicGetBrokerageMarketProducts(self.extend(params, {'product_type': 'FUTURE'})),
1236
+ self.v3PublicGetBrokerageMarketProducts(self.extend(params, {'product_type': 'FUTURE', 'contract_expiry_type': 'PERPETUAL'})),
1237
+ ]
1238
+ if self.check_required_credentials(False):
1239
+ unresolvedContractPromises.append(self.extend(params, {'product_type': 'FUTURE'}))
1240
+ unresolvedContractPromises.append(self.extend(params, {'product_type': 'FUTURE', 'contract_expiry_type': 'PERPETUAL'}))
1241
+ except Exception as e:
1242
+ unresolvedContractPromises = [] # the sync version of ccxt won't have the promise.all line so the request is made here. Some users can't access perpetual products
1243
+ promises = spotUnresolvedPromises
1244
+ contractPromises = None
1245
+ try:
1246
+ contractPromises = unresolvedContractPromises # some users don't have access to contracts
1247
+ except Exception as e:
1248
+ contractPromises = []
1249
+ spot = self.safe_dict(promises, 0, {})
1250
+ fees = self.safe_dict(promises, 1, {})
1251
+ expiringFutures = self.safe_dict(contractPromises, 0, {})
1252
+ perpetualFutures = self.safe_dict(contractPromises, 1, {})
1253
+ expiringFees = self.safe_dict(contractPromises, 2, {})
1254
+ perpetualFees = self.safe_dict(contractPromises, 3, {})
1255
+ #
1256
+ # {
1257
+ # "total_volume": 0,
1258
+ # "total_fees": 0,
1259
+ # "fee_tier": {
1260
+ # "pricing_tier": "",
1261
+ # "usd_from": "0",
1262
+ # "usd_to": "10000",
1263
+ # "taker_fee_rate": "0.006",
1264
+ # "maker_fee_rate": "0.004"
1265
+ # },
1266
+ # "margin_rate": null,
1267
+ # "goods_and_services_tax": null,
1268
+ # "advanced_trade_only_volume": 0,
1269
+ # "advanced_trade_only_fees": 0,
1270
+ # "coinbase_pro_volume": 0,
1271
+ # "coinbase_pro_fees": 0
1272
+ # }
1273
+ #
1274
+ feeTier = self.safe_dict(fees, 'fee_tier', {})
1275
+ expiringFeeTier = self.safe_dict(expiringFees, 'fee_tier', {}) # fee tier null?
1276
+ perpetualFeeTier = self.safe_dict(perpetualFees, 'fee_tier', {}) # fee tier null?
1277
+ data = self.safe_list(spot, 'products', [])
1278
+ result = []
1279
+ for i in range(0, len(data)):
1280
+ result.append(self.parse_spot_market(data[i], feeTier))
1281
+ futureData = self.safe_list(expiringFutures, 'products', [])
1282
+ for i in range(0, len(futureData)):
1283
+ result.append(self.parse_contract_market(futureData[i], expiringFeeTier))
1284
+ perpetualData = self.safe_list(perpetualFutures, 'products', [])
1285
+ for i in range(0, len(perpetualData)):
1286
+ result.append(self.parse_contract_market(perpetualData[i], perpetualFeeTier))
1287
+ return result
1288
+
1289
+ def parse_spot_market(self, market, feeTier) -> MarketInterface:
1290
+ #
1291
+ # {
1292
+ # "product_id": "TONE-USD",
1293
+ # "price": "0.01523",
1294
+ # "price_percentage_change_24h": "1.94109772423025",
1295
+ # "volume_24h": "19773129",
1296
+ # "volume_percentage_change_24h": "437.0170530929949",
1297
+ # "base_increment": "1",
1298
+ # "quote_increment": "0.00001",
1299
+ # "quote_min_size": "1",
1300
+ # "quote_max_size": "10000000",
1301
+ # "base_min_size": "26.7187147229469674",
1302
+ # "base_max_size": "267187147.2294696735908216",
1303
+ # "base_name": "TE-FOOD",
1304
+ # "quote_name": "US Dollar",
1305
+ # "watched": False,
1306
+ # "is_disabled": False,
1307
+ # "new": False,
1308
+ # "status": "online",
1309
+ # "cancel_only": False,
1310
+ # "limit_only": False,
1311
+ # "post_only": False,
1312
+ # "trading_disabled": False,
1313
+ # "auction_mode": False,
1314
+ # "product_type": "SPOT",
1315
+ # "quote_currency_id": "USD",
1316
+ # "base_currency_id": "TONE",
1317
+ # "fcm_trading_session_details": null,
1318
+ # "mid_market_price": ""
1319
+ # }
1320
+ #
1321
+ id = self.safe_string(market, 'product_id')
1322
+ baseId = self.safe_string(market, 'base_currency_id')
1323
+ quoteId = self.safe_string(market, 'quote_currency_id')
1324
+ base = self.safe_currency_code(baseId)
1325
+ quote = self.safe_currency_code(quoteId)
1326
+ marketType = self.safe_string_lower(market, 'product_type')
1327
+ tradingDisabled = self.safe_bool(market, 'trading_disabled')
1328
+ stablePairs = self.safe_list(self.options, 'stablePairs', [])
1329
+ return self.safe_market_structure({
1330
+ 'id': id,
1331
+ 'symbol': base + '/' + quote,
1332
+ 'base': base,
1333
+ 'quote': quote,
1334
+ 'settle': None,
1335
+ 'baseId': baseId,
1336
+ 'quoteId': quoteId,
1337
+ 'settleId': None,
1338
+ 'type': marketType,
1339
+ 'spot': (marketType == 'spot'),
1340
+ 'margin': None,
1341
+ 'swap': False,
1342
+ 'future': False,
1343
+ 'option': False,
1344
+ 'active': not tradingDisabled,
1345
+ 'contract': False,
1346
+ 'linear': None,
1347
+ 'inverse': None,
1348
+ 'taker': 0.00001 if self.in_array(id, stablePairs) else self.safe_number(feeTier, 'taker_fee_rate'),
1349
+ 'maker': 0.0 if self.in_array(id, stablePairs) else self.safe_number(feeTier, 'maker_fee_rate'),
1350
+ 'contractSize': None,
1351
+ 'expiry': None,
1352
+ 'expiryDatetime': None,
1353
+ 'strike': None,
1354
+ 'optionType': None,
1355
+ 'precision': {
1356
+ 'amount': self.safe_number(market, 'base_increment'),
1357
+ 'price': self.safe_number_2(market, 'price_increment', 'quote_increment'),
1358
+ },
1359
+ 'limits': {
1360
+ 'leverage': {
1361
+ 'min': None,
1362
+ 'max': None,
1363
+ },
1364
+ 'amount': {
1365
+ 'min': self.safe_number(market, 'base_min_size'),
1366
+ 'max': self.safe_number(market, 'base_max_size'),
1367
+ },
1368
+ 'price': {
1369
+ 'min': None,
1370
+ 'max': None,
1371
+ },
1372
+ 'cost': {
1373
+ 'min': self.safe_number(market, 'quote_min_size'),
1374
+ 'max': self.safe_number(market, 'quote_max_size'),
1375
+ },
1376
+ },
1377
+ 'created': None,
1378
+ 'info': market,
1379
+ })
1380
+
1381
+ def parse_contract_market(self, market, feeTier) -> MarketInterface:
1382
+ # expiring
1383
+ #
1384
+ # {
1385
+ # "product_id":"BIT-26APR24-CDE",
1386
+ # "price":"71145",
1387
+ # "price_percentage_change_24h":"-2.36722931247427",
1388
+ # "volume_24h":"108549",
1389
+ # "volume_percentage_change_24h":"155.78255337197794",
1390
+ # "base_increment":"1",
1391
+ # "quote_increment":"0.01",
1392
+ # "quote_min_size":"0",
1393
+ # "quote_max_size":"100000000",
1394
+ # "base_min_size":"1",
1395
+ # "base_max_size":"100000000",
1396
+ # "base_name":"",
1397
+ # "quote_name":"US Dollar",
1398
+ # "watched":false,
1399
+ # "is_disabled":false,
1400
+ # "new":false,
1401
+ # "status":"",
1402
+ # "cancel_only":false,
1403
+ # "limit_only":false,
1404
+ # "post_only":false,
1405
+ # "trading_disabled":false,
1406
+ # "auction_mode":false,
1407
+ # "product_type":"FUTURE",
1408
+ # "quote_currency_id":"USD",
1409
+ # "base_currency_id":"",
1410
+ # "fcm_trading_session_details":{
1411
+ # "is_session_open":true,
1412
+ # "open_time":"2024-04-08T22:00:00Z",
1413
+ # "close_time":"2024-04-09T21:00:00Z"
1414
+ # },
1415
+ # "mid_market_price":"71105",
1416
+ # "alias":"",
1417
+ # "alias_to":[
1418
+ # ],
1419
+ # "base_display_symbol":"",
1420
+ # "quote_display_symbol":"USD",
1421
+ # "view_only":false,
1422
+ # "price_increment":"5",
1423
+ # "display_name":"BTC 26 APR 24",
1424
+ # "product_venue":"FCM",
1425
+ # "future_product_details":{
1426
+ # "venue":"cde",
1427
+ # "contract_code":"BIT",
1428
+ # "contract_expiry":"2024-04-26T15:00:00Z",
1429
+ # "contract_size":"0.01",
1430
+ # "contract_root_unit":"BTC",
1431
+ # "group_description":"Nano Bitcoin Futures",
1432
+ # "contract_expiry_timezone":"Europe/London",
1433
+ # "group_short_description":"Nano BTC",
1434
+ # "risk_managed_by":"MANAGED_BY_FCM",
1435
+ # "contract_expiry_type":"EXPIRING",
1436
+ # "contract_display_name":"BTC 26 APR 24"
1437
+ # }
1438
+ # }
1439
+ #
1440
+ # perpetual
1441
+ #
1442
+ # {
1443
+ # "product_id":"ETH-PERP-INTX",
1444
+ # "price":"3630.98",
1445
+ # "price_percentage_change_24h":"0.65142426292038",
1446
+ # "volume_24h":"114020.1501",
1447
+ # "volume_percentage_change_24h":"63.33650787154869",
1448
+ # "base_increment":"0.0001",
1449
+ # "quote_increment":"0.01",
1450
+ # "quote_min_size":"10",
1451
+ # "quote_max_size":"50000000",
1452
+ # "base_min_size":"0.0001",
1453
+ # "base_max_size":"50000",
1454
+ # "base_name":"",
1455
+ # "quote_name":"USDC",
1456
+ # "watched":false,
1457
+ # "is_disabled":false,
1458
+ # "new":false,
1459
+ # "status":"",
1460
+ # "cancel_only":false,
1461
+ # "limit_only":false,
1462
+ # "post_only":false,
1463
+ # "trading_disabled":false,
1464
+ # "auction_mode":false,
1465
+ # "product_type":"FUTURE",
1466
+ # "quote_currency_id":"USDC",
1467
+ # "base_currency_id":"",
1468
+ # "fcm_trading_session_details":null,
1469
+ # "mid_market_price":"3630.975",
1470
+ # "alias":"",
1471
+ # "alias_to":[],
1472
+ # "base_display_symbol":"",
1473
+ # "quote_display_symbol":"USDC",
1474
+ # "view_only":false,
1475
+ # "price_increment":"0.01",
1476
+ # "display_name":"ETH PERP",
1477
+ # "product_venue":"INTX",
1478
+ # "future_product_details":{
1479
+ # "venue":"",
1480
+ # "contract_code":"ETH",
1481
+ # "contract_expiry":null,
1482
+ # "contract_size":"1",
1483
+ # "contract_root_unit":"ETH",
1484
+ # "group_description":"",
1485
+ # "contract_expiry_timezone":"",
1486
+ # "group_short_description":"",
1487
+ # "risk_managed_by":"MANAGED_BY_VENUE",
1488
+ # "contract_expiry_type":"PERPETUAL",
1489
+ # "perpetual_details":{
1490
+ # "open_interest":"0",
1491
+ # "funding_rate":"0.000016",
1492
+ # "funding_time":"2024-04-09T09:00:00.000008Z",
1493
+ # "max_leverage":"10"
1494
+ # },
1495
+ # "contract_display_name":"ETH PERPETUAL"
1496
+ # }
1497
+ # }
1498
+ #
1499
+ id = self.safe_string(market, 'product_id')
1500
+ futureProductDetails = self.safe_dict(market, 'future_product_details', {})
1501
+ contractExpiryType = self.safe_string(futureProductDetails, 'contract_expiry_type')
1502
+ contractSize = self.safe_number(futureProductDetails, 'contract_size')
1503
+ contractExpire = self.safe_string(futureProductDetails, 'contract_expiry')
1504
+ expireTimestamp = self.parse8601(contractExpire)
1505
+ expireDateTime = self.iso8601(expireTimestamp)
1506
+ isSwap = (contractExpiryType == 'PERPETUAL')
1507
+ baseId = self.safe_string(futureProductDetails, 'contract_root_unit')
1508
+ quoteId = self.safe_string(market, 'quote_currency_id')
1509
+ base = self.safe_currency_code(baseId)
1510
+ quote = self.safe_currency_code(quoteId)
1511
+ tradingDisabled = self.safe_bool(market, 'is_disabled')
1512
+ symbol = base + '/' + quote
1513
+ type = None
1514
+ if isSwap:
1515
+ type = 'swap'
1516
+ symbol = symbol + ':' + quote
1517
+ else:
1518
+ type = 'future'
1519
+ symbol = symbol + ':' + quote + '-' + self.yymmdd(expireTimestamp)
1520
+ takerFeeRate = self.safe_number(feeTier, 'taker_fee_rate')
1521
+ makerFeeRate = self.safe_number(feeTier, 'maker_fee_rate')
1522
+ taker = takerFeeRate if takerFeeRate else self.parse_number('0.06')
1523
+ maker = makerFeeRate if makerFeeRate else self.parse_number('0.04')
1524
+ return self.safe_market_structure({
1525
+ 'id': id,
1526
+ 'symbol': symbol,
1527
+ 'base': base,
1528
+ 'quote': quote,
1529
+ 'settle': quote,
1530
+ 'baseId': baseId,
1531
+ 'quoteId': quoteId,
1532
+ 'settleId': quoteId,
1533
+ 'type': type,
1534
+ 'spot': False,
1535
+ 'margin': False,
1536
+ 'swap': isSwap,
1537
+ 'future': not isSwap,
1538
+ 'option': False,
1539
+ 'active': not tradingDisabled,
1540
+ 'contract': True,
1541
+ 'linear': True,
1542
+ 'inverse': False,
1543
+ 'taker': taker,
1544
+ 'maker': maker,
1545
+ 'contractSize': contractSize,
1546
+ 'expiry': expireTimestamp,
1547
+ 'expiryDatetime': expireDateTime,
1548
+ 'strike': None,
1549
+ 'optionType': None,
1550
+ 'precision': {
1551
+ 'amount': self.safe_number(market, 'base_increment'),
1552
+ 'price': self.safe_number_2(market, 'price_increment', 'quote_increment'),
1553
+ },
1554
+ 'limits': {
1555
+ 'leverage': {
1556
+ 'min': None,
1557
+ 'max': None,
1558
+ },
1559
+ 'amount': {
1560
+ 'min': self.safe_number(market, 'base_min_size'),
1561
+ 'max': self.safe_number(market, 'base_max_size'),
1562
+ },
1563
+ 'price': {
1564
+ 'min': None,
1565
+ 'max': None,
1566
+ },
1567
+ 'cost': {
1568
+ 'min': self.safe_number(market, 'quote_min_size'),
1569
+ 'max': self.safe_number(market, 'quote_max_size'),
1570
+ },
1571
+ },
1572
+ 'created': None,
1573
+ 'info': market,
1574
+ })
1575
+
1576
+ def fetch_currencies_from_cache(self, params={}):
1577
+ options = self.safe_dict(self.options, 'fetchCurrencies', {})
1578
+ timestamp = self.safe_integer(options, 'timestamp')
1579
+ expires = self.safe_integer(options, 'expires', 1000)
1580
+ now = self.milliseconds()
1581
+ if (timestamp is None) or ((now - timestamp) > expires):
1582
+ promises = [
1583
+ self.v2PublicGetCurrencies(params),
1584
+ self.v2PublicGetCurrenciesCrypto(params),
1585
+ ]
1586
+ promisesResult = promises
1587
+ fiatResponse = self.safe_dict(promisesResult, 0, {})
1588
+ #
1589
+ # [
1590
+ # "data": {
1591
+ # id: 'IMP',
1592
+ # name: 'Isle of Man Pound',
1593
+ # min_size: '0.01'
1594
+ # },
1595
+ # ...
1596
+ # ]
1597
+ #
1598
+ cryptoResponse = self.safe_dict(promisesResult, 1, {})
1599
+ #
1600
+ # {
1601
+ # asset_id: '9476e3be-b731-47fa-82be-347fabc573d9',
1602
+ # code: 'AERO',
1603
+ # name: 'Aerodrome Finance',
1604
+ # color: '#0433FF',
1605
+ # sort_index: '340',
1606
+ # exponent: '8',
1607
+ # type: 'crypto',
1608
+ # address_regex: '^(?:0x)?[0-9a-fA-F]{40}$'
1609
+ # }
1610
+ #
1611
+ fiatData = self.safe_list(fiatResponse, 'data', [])
1612
+ cryptoData = self.safe_list(cryptoResponse, 'data', [])
1613
+ exchangeRates = self.v2PublicGetExchangeRates(params)
1614
+ self.options['fetchCurrencies'] = self.extend(options, {
1615
+ 'currencies': self.array_concat(fiatData, cryptoData),
1616
+ 'exchangeRates': exchangeRates,
1617
+ 'timestamp': now,
1618
+ })
1619
+ return self.safe_dict(self.options, 'fetchCurrencies', {})
1620
+
1621
+ def fetch_currencies(self, params={}) -> Currencies:
1622
+ """
1623
+ fetches all available currencies on an exchange
1624
+ :see: https://docs.cloud.coinbase.com/sign-in-with-coinbase/docs/api-currencies#get-fiat-currencies
1625
+ :see: https://docs.cloud.coinbase.com/sign-in-with-coinbase/docs/api-exchange-rates#get-exchange-rates
1626
+ :param dict [params]: extra parameters specific to the exchange API endpoint
1627
+ :returns dict: an associative dictionary of currencies
1628
+ """
1629
+ response = self.fetch_currencies_from_cache(params)
1630
+ currencies = self.safe_list(response, 'currencies', [])
1631
+ #
1632
+ # fiat
1633
+ #
1634
+ # {
1635
+ # id: 'IMP',
1636
+ # name: 'Isle of Man Pound',
1637
+ # min_size: '0.01'
1638
+ # },
1639
+ #
1640
+ # crypto
1641
+ #
1642
+ # {
1643
+ # asset_id: '9476e3be-b731-47fa-82be-347fabc573d9',
1644
+ # code: 'AERO',
1645
+ # name: 'Aerodrome Finance',
1646
+ # color: '#0433FF',
1647
+ # sort_index: '340',
1648
+ # exponent: '8',
1649
+ # type: 'crypto',
1650
+ # address_regex: '^(?:0x)?[0-9a-fA-F]{40}$'
1651
+ # }
1652
+ #
1653
+ #
1654
+ # {
1655
+ # "data":{
1656
+ # "currency":"USD",
1657
+ # "rates":{
1658
+ # "AED":"3.67",
1659
+ # "AFN":"78.21",
1660
+ # "ALL":"110.42",
1661
+ # "AMD":"474.18",
1662
+ # "ANG":"1.75",
1663
+ # ...
1664
+ # },
1665
+ # }
1666
+ # }
1667
+ #
1668
+ result: dict = {}
1669
+ networks: dict = {}
1670
+ networksById: dict = {}
1671
+ for i in range(0, len(currencies)):
1672
+ currency = currencies[i]
1673
+ assetId = self.safe_string(currency, 'asset_id')
1674
+ id = self.safe_string_2(currency, 'id', 'code')
1675
+ code = self.safe_currency_code(id)
1676
+ name = self.safe_string(currency, 'name')
1677
+ self.options['networks'][code] = name.lower()
1678
+ self.options['networksById'][code] = name.lower()
1679
+ result[code] = {
1680
+ 'info': currency, # the original payload
1681
+ 'id': id,
1682
+ 'code': code,
1683
+ 'type': 'crypto' if (assetId is not None) else 'fiat',
1684
+ 'name': self.safe_string(currency, 'name'),
1685
+ 'active': True,
1686
+ 'deposit': None,
1687
+ 'withdraw': None,
1688
+ 'fee': None,
1689
+ 'precision': None,
1690
+ 'limits': {
1691
+ 'amount': {
1692
+ 'min': self.safe_number(currency, 'min_size'),
1693
+ 'max': None,
1694
+ },
1695
+ 'withdraw': {
1696
+ 'min': None,
1697
+ 'max': None,
1698
+ },
1699
+ },
1700
+ }
1701
+ if assetId is not None:
1702
+ lowerCaseName = name.lower()
1703
+ networks[code] = lowerCaseName
1704
+ networksById[lowerCaseName] = code
1705
+ self.options['networks'] = self.extend(networks, self.options['networks'])
1706
+ self.options['networksById'] = self.extend(networksById, self.options['networksById'])
1707
+ return result
1708
+
1709
+ def fetch_tickers(self, symbols: Strings = None, params={}) -> Tickers:
1710
+ """
1711
+ fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market
1712
+ :see: https://docs.cloud.coinbase.com/advanced-trade-api/reference/retailbrokerageapi_getproducts
1713
+ :see: https://docs.cloud.coinbase.com/sign-in-with-coinbase/docs/api-exchange-rates#get-exchange-rates
1714
+ :param str[]|None symbols: unified symbols of the markets to fetch the ticker for, all market tickers are returned if not assigned
1715
+ :param dict [params]: extra parameters specific to the exchange API endpoint
1716
+ :param boolean [params.usePrivate]: use private endpoint for fetching tickers
1717
+ :returns dict: a dictionary of `ticker structures <https://docs.ccxt.com/#/?id=ticker-structure>`
1718
+ """
1719
+ method = self.safe_string(self.options, 'fetchTickers', 'fetchTickersV3')
1720
+ if method == 'fetchTickersV3':
1721
+ return self.fetch_tickers_v3(symbols, params)
1722
+ return self.fetch_tickers_v2(symbols, params)
1723
+
1724
+ def fetch_tickers_v2(self, symbols: Strings = None, params={}):
1725
+ self.load_markets()
1726
+ symbols = self.market_symbols(symbols)
1727
+ request: dict = {
1728
+ # 'currency': 'USD',
1729
+ }
1730
+ response = self.v2PublicGetExchangeRates(self.extend(request, params))
1731
+ #
1732
+ # {
1733
+ # "data":{
1734
+ # "currency":"USD",
1735
+ # "rates":{
1736
+ # "AED":"3.6731",
1737
+ # "AFN":"103.163942",
1738
+ # "ALL":"106.973038",
1739
+ # }
1740
+ # }
1741
+ # }
1742
+ #
1743
+ data = self.safe_dict(response, 'data', {})
1744
+ rates = self.safe_dict(data, 'rates', {})
1745
+ quoteId = self.safe_string(data, 'currency')
1746
+ result: dict = {}
1747
+ baseIds = list(rates.keys())
1748
+ delimiter = '-'
1749
+ for i in range(0, len(baseIds)):
1750
+ baseId = baseIds[i]
1751
+ marketId = baseId + delimiter + quoteId
1752
+ market = self.safe_market(marketId, None, delimiter)
1753
+ symbol = market['symbol']
1754
+ result[symbol] = self.parse_ticker(rates[baseId], market)
1755
+ return self.filter_by_array_tickers(result, 'symbol', symbols)
1756
+
1757
+ def fetch_tickers_v3(self, symbols: Strings = None, params={}):
1758
+ self.load_markets()
1759
+ symbols = self.market_symbols(symbols)
1760
+ request: dict = {}
1761
+ if symbols is not None:
1762
+ request['product_ids'] = self.market_ids(symbols)
1763
+ marketType = None
1764
+ marketType, params = self.handle_market_type_and_params('fetchTickers', self.get_market_from_symbols(symbols), params, 'default')
1765
+ if marketType is not None and marketType != 'default':
1766
+ request['product_type'] = 'FUTURE' if (marketType == 'swap') else 'SPOT'
1767
+ response = None
1768
+ usePrivate = False
1769
+ usePrivate, params = self.handle_option_and_params(params, 'fetchTickers', 'usePrivate', False)
1770
+ if usePrivate:
1771
+ response = self.v3PrivateGetBrokerageProducts(self.extend(request, params))
1772
+ else:
1773
+ response = self.v3PublicGetBrokerageMarketProducts(self.extend(request, params))
1774
+ #
1775
+ # {
1776
+ # "products": [
1777
+ # {
1778
+ # "product_id": "TONE-USD",
1779
+ # "price": "0.01523",
1780
+ # "price_percentage_change_24h": "1.94109772423025",
1781
+ # "volume_24h": "19773129",
1782
+ # "volume_percentage_change_24h": "437.0170530929949",
1783
+ # "base_increment": "1",
1784
+ # "quote_increment": "0.00001",
1785
+ # "quote_min_size": "1",
1786
+ # "quote_max_size": "10000000",
1787
+ # "base_min_size": "26.7187147229469674",
1788
+ # "base_max_size": "267187147.2294696735908216",
1789
+ # "base_name": "TE-FOOD",
1790
+ # "quote_name": "US Dollar",
1791
+ # "watched": False,
1792
+ # "is_disabled": False,
1793
+ # "new": False,
1794
+ # "status": "online",
1795
+ # "cancel_only": False,
1796
+ # "limit_only": False,
1797
+ # "post_only": False,
1798
+ # "trading_disabled": False,
1799
+ # "auction_mode": False,
1800
+ # "product_type": "SPOT",
1801
+ # "quote_currency_id": "USD",
1802
+ # "base_currency_id": "TONE",
1803
+ # "fcm_trading_session_details": null,
1804
+ # "mid_market_price": ""
1805
+ # },
1806
+ # ...
1807
+ # ],
1808
+ # "num_products": 549
1809
+ # }
1810
+ #
1811
+ data = self.safe_list(response, 'products', [])
1812
+ result: dict = {}
1813
+ for i in range(0, len(data)):
1814
+ entry = data[i]
1815
+ marketId = self.safe_string(entry, 'product_id')
1816
+ market = self.safe_market(marketId, None, '-')
1817
+ symbol = market['symbol']
1818
+ result[symbol] = self.parse_ticker(entry, market)
1819
+ return self.filter_by_array_tickers(result, 'symbol', symbols)
1820
+
1821
+ def fetch_ticker(self, symbol: str, params={}) -> Ticker:
1822
+ """
1823
+ fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
1824
+ :see: https://docs.cloud.coinbase.com/advanced-trade-api/reference/retailbrokerageapi_getmarkettrades
1825
+ :see: https://docs.cloud.coinbase.com/sign-in-with-coinbase/docs/api-prices#get-spot-price
1826
+ :see: https://docs.cloud.coinbase.com/sign-in-with-coinbase/docs/api-prices#get-buy-price
1827
+ :see: https://docs.cloud.coinbase.com/sign-in-with-coinbase/docs/api-prices#get-sell-price
1828
+ :param str symbol: unified symbol of the market to fetch the ticker for
1829
+ :param dict [params]: extra parameters specific to the exchange API endpoint
1830
+ :param boolean [params.usePrivate]: whether to use the private endpoint for fetching the ticker
1831
+ :returns dict: a `ticker structure <https://docs.ccxt.com/#/?id=ticker-structure>`
1832
+ """
1833
+ method = self.safe_string(self.options, 'fetchTicker', 'fetchTickerV3')
1834
+ if method == 'fetchTickerV3':
1835
+ return self.fetch_ticker_v3(symbol, params)
1836
+ return self.fetch_ticker_v2(symbol, params)
1837
+
1838
+ def fetch_ticker_v2(self, symbol: str, params={}):
1839
+ self.load_markets()
1840
+ market = self.market(symbol)
1841
+ request = self.extend({
1842
+ 'symbol': market['id'],
1843
+ }, params)
1844
+ spot = self.v2PublicGetPricesSymbolSpot(request)
1845
+ #
1846
+ # {"data":{"base":"BTC","currency":"USD","amount":"48691.23"}}
1847
+ #
1848
+ ask = self.v2PublicGetPricesSymbolBuy(request)
1849
+ #
1850
+ # {"data":{"base":"BTC","currency":"USD","amount":"48691.23"}}
1851
+ #
1852
+ bid = self.v2PublicGetPricesSymbolSell(request)
1853
+ #
1854
+ # {"data":{"base":"BTC","currency":"USD","amount":"48691.23"}}
1855
+ #
1856
+ spotData = self.safe_dict(spot, 'data', {})
1857
+ askData = self.safe_dict(ask, 'data', {})
1858
+ bidData = self.safe_dict(bid, 'data', {})
1859
+ bidAskLast: dict = {
1860
+ 'bid': self.safe_number(bidData, 'amount'),
1861
+ 'ask': self.safe_number(askData, 'amount'),
1862
+ 'price': self.safe_number(spotData, 'amount'),
1863
+ }
1864
+ return self.parse_ticker(bidAskLast, market)
1865
+
1866
+ def fetch_ticker_v3(self, symbol: str, params={}):
1867
+ self.load_markets()
1868
+ market = self.market(symbol)
1869
+ request: dict = {
1870
+ 'product_id': market['id'],
1871
+ 'limit': 1,
1872
+ }
1873
+ usePrivate = False
1874
+ usePrivate, params = self.handle_option_and_params(params, 'fetchTicker', 'usePrivate', False)
1875
+ response = None
1876
+ if usePrivate:
1877
+ response = self.v3PrivateGetBrokerageProductsProductIdTicker(self.extend(request, params))
1878
+ else:
1879
+ response = self.v3PublicGetBrokerageMarketProductsProductIdTicker(self.extend(request, params))
1880
+ #
1881
+ # {
1882
+ # "trades": [
1883
+ # {
1884
+ # "trade_id": "518078013",
1885
+ # "product_id": "BTC-USD",
1886
+ # "price": "28208.1",
1887
+ # "size": "0.00659179",
1888
+ # "time": "2023-04-04T23:05:34.492746Z",
1889
+ # "side": "BUY",
1890
+ # "bid": "",
1891
+ # "ask": ""
1892
+ # }
1893
+ # ],
1894
+ # "best_bid": "28208.61",
1895
+ # "best_ask": "28208.62"
1896
+ # }
1897
+ #
1898
+ data = self.safe_list(response, 'trades', [])
1899
+ ticker = self.parse_ticker(data[0], market)
1900
+ ticker['bid'] = self.safe_number(response, 'best_bid')
1901
+ ticker['ask'] = self.safe_number(response, 'best_ask')
1902
+ return ticker
1903
+
1904
+ def parse_ticker(self, ticker: dict, market: Market = None) -> Ticker:
1905
+ #
1906
+ # fetchTickerV2
1907
+ #
1908
+ # {
1909
+ # "bid": 20713.37,
1910
+ # "ask": 20924.65,
1911
+ # "price": 20809.83
1912
+ # }
1913
+ #
1914
+ # fetchTickerV3
1915
+ #
1916
+ # {
1917
+ # "trade_id": "10209805",
1918
+ # "product_id": "BTC-USDT",
1919
+ # "price": "19381.27",
1920
+ # "size": "0.1",
1921
+ # "time": "2023-01-13T20:35:41.865970Z",
1922
+ # "side": "BUY",
1923
+ # "bid": "",
1924
+ # "ask": ""
1925
+ # }
1926
+ #
1927
+ # fetchTickersV2
1928
+ #
1929
+ # "48691.23"
1930
+ #
1931
+ # fetchTickersV3
1932
+ #
1933
+ # [
1934
+ # {
1935
+ # "product_id": "TONE-USD",
1936
+ # "price": "0.01523",
1937
+ # "price_percentage_change_24h": "1.94109772423025",
1938
+ # "volume_24h": "19773129",
1939
+ # "volume_percentage_change_24h": "437.0170530929949",
1940
+ # "base_increment": "1",
1941
+ # "quote_increment": "0.00001",
1942
+ # "quote_min_size": "1",
1943
+ # "quote_max_size": "10000000",
1944
+ # "base_min_size": "26.7187147229469674",
1945
+ # "base_max_size": "267187147.2294696735908216",
1946
+ # "base_name": "TE-FOOD",
1947
+ # "quote_name": "US Dollar",
1948
+ # "watched": False,
1949
+ # "is_disabled": False,
1950
+ # "new": False,
1951
+ # "status": "online",
1952
+ # "cancel_only": False,
1953
+ # "limit_only": False,
1954
+ # "post_only": False,
1955
+ # "trading_disabled": False,
1956
+ # "auction_mode": False,
1957
+ # "product_type": "SPOT",
1958
+ # "quote_currency_id": "USD",
1959
+ # "base_currency_id": "TONE",
1960
+ # "fcm_trading_session_details": null,
1961
+ # "mid_market_price": ""
1962
+ # },
1963
+ # ...
1964
+ # ]
1965
+ #
1966
+ # fetchBidsAsks
1967
+ #
1968
+ # {
1969
+ # "product_id": "TRAC-EUR",
1970
+ # "bids": [
1971
+ # {
1972
+ # "price": "0.2384",
1973
+ # "size": "386.1"
1974
+ # }
1975
+ # ],
1976
+ # "asks": [
1977
+ # {
1978
+ # "price": "0.2406",
1979
+ # "size": "672"
1980
+ # }
1981
+ # ],
1982
+ # "time": "2023-06-30T07:15:24.656044Z"
1983
+ # }
1984
+ #
1985
+ bid = self.safe_number(ticker, 'bid')
1986
+ ask = self.safe_number(ticker, 'ask')
1987
+ bidVolume = None
1988
+ askVolume = None
1989
+ if ('bids' in ticker):
1990
+ bids = self.safe_list(ticker, 'bids', [])
1991
+ asks = self.safe_list(ticker, 'asks', [])
1992
+ bid = self.safe_number(bids[0], 'price')
1993
+ bidVolume = self.safe_number(bids[0], 'size')
1994
+ ask = self.safe_number(asks[0], 'price')
1995
+ askVolume = self.safe_number(asks[0], 'size')
1996
+ marketId = self.safe_string(ticker, 'product_id')
1997
+ last = self.safe_number(ticker, 'price')
1998
+ datetime = self.safe_string(ticker, 'time')
1999
+ return self.safe_ticker({
2000
+ 'symbol': self.safe_symbol(marketId, market),
2001
+ 'timestamp': self.parse8601(datetime),
2002
+ 'datetime': datetime,
2003
+ 'bid': bid,
2004
+ 'ask': ask,
2005
+ 'last': last,
2006
+ 'high': None,
2007
+ 'low': None,
2008
+ 'bidVolume': bidVolume,
2009
+ 'askVolume': askVolume,
2010
+ 'vwap': None,
2011
+ 'open': None,
2012
+ 'close': last,
2013
+ 'previousClose': None,
2014
+ 'change': None,
2015
+ 'percentage': self.safe_number(ticker, 'price_percentage_change_24h'),
2016
+ 'average': None,
2017
+ 'baseVolume': None,
2018
+ 'quoteVolume': None,
2019
+ 'info': ticker,
2020
+ }, market)
2021
+
2022
+ def parse_custom_balance(self, response, params={}):
2023
+ balances = self.safe_list_2(response, 'data', 'accounts', [])
2024
+ accounts = self.safe_list(params, 'type', self.options['accounts'])
2025
+ v3Accounts = self.safe_list(params, 'type', self.options['v3Accounts'])
2026
+ result: dict = {'info': response}
2027
+ for b in range(0, len(balances)):
2028
+ balance = balances[b]
2029
+ type = self.safe_string(balance, 'type')
2030
+ if self.in_array(type, accounts):
2031
+ value = self.safe_dict(balance, 'balance')
2032
+ if value is not None:
2033
+ currencyId = self.safe_string(value, 'currency')
2034
+ code = self.safe_currency_code(currencyId)
2035
+ total = self.safe_string(value, 'amount')
2036
+ free = total
2037
+ account = self.safe_dict(result, code)
2038
+ if account is None:
2039
+ account = self.account()
2040
+ account['free'] = free
2041
+ account['total'] = total
2042
+ else:
2043
+ account['free'] = Precise.string_add(account['free'], total)
2044
+ account['total'] = Precise.string_add(account['total'], total)
2045
+ result[code] = account
2046
+ elif self.in_array(type, v3Accounts):
2047
+ available = self.safe_dict(balance, 'available_balance')
2048
+ hold = self.safe_dict(balance, 'hold')
2049
+ if available is not None and hold is not None:
2050
+ currencyId = self.safe_string(available, 'currency')
2051
+ code = self.safe_currency_code(currencyId)
2052
+ used = self.safe_string(hold, 'value')
2053
+ free = self.safe_string(available, 'value')
2054
+ total = Precise.string_add(used, free)
2055
+ account = self.safe_dict(result, code)
2056
+ if account is None:
2057
+ account = self.account()
2058
+ account['free'] = free
2059
+ account['used'] = used
2060
+ account['total'] = total
2061
+ else:
2062
+ account['free'] = Precise.string_add(account['free'], free)
2063
+ account['used'] = Precise.string_add(account['used'], used)
2064
+ account['total'] = Precise.string_add(account['total'], total)
2065
+ result[code] = account
2066
+ return self.safe_balance(result)
2067
+
2068
+ def fetch_balance(self, params={}) -> Balances:
2069
+ """
2070
+ query for balance and get the amount of funds available for trading or funds locked in orders
2071
+ :see: https://docs.cloud.coinbase.com/advanced-trade-api/reference/retailbrokerageapi_getaccounts
2072
+ :see: https://docs.cloud.coinbase.com/sign-in-with-coinbase/docs/api-accounts#list-accounts
2073
+ :see: https://docs.cloud.coinbase.com/advanced-trade-api/reference/retailbrokerageapi_getfcmbalancesummary
2074
+ :param dict [params]: extra parameters specific to the exchange API endpoint
2075
+ :param boolean [params.v3]: default False, set True to use v3 api endpoint
2076
+ :param dict [params.type]: "spot"(default) or "swap" or "future"
2077
+ :returns dict: a `balance structure <https://docs.ccxt.com/#/?id=balance-structure>`
2078
+ """
2079
+ self.load_markets()
2080
+ request: dict = {}
2081
+ response = None
2082
+ isV3 = self.safe_bool(params, 'v3', False)
2083
+ params = self.omit(params, ['v3'])
2084
+ marketType = None
2085
+ marketType, params = self.handle_market_type_and_params('fetchBalance', None, params)
2086
+ method = self.safe_string(self.options, 'fetchBalance', 'v3PrivateGetBrokerageAccounts')
2087
+ if marketType == 'future':
2088
+ response = self.v3PrivateGetBrokerageCfmBalanceSummary(self.extend(request, params))
2089
+ elif (isV3) or (method == 'v3PrivateGetBrokerageAccounts'):
2090
+ request['limit'] = 250
2091
+ response = self.v3PrivateGetBrokerageAccounts(self.extend(request, params))
2092
+ else:
2093
+ request['limit'] = 100
2094
+ response = self.v2PrivateGetAccounts(self.extend(request, params))
2095
+ #
2096
+ # v2PrivateGetAccounts
2097
+ # {
2098
+ # "pagination":{
2099
+ # "ending_before":null,
2100
+ # "starting_after":null,
2101
+ # "previous_ending_before":null,
2102
+ # "next_starting_after":"6b17acd6-2e68-5eb0-9f45-72d67cef578b",
2103
+ # "limit":100,
2104
+ # "order":"desc",
2105
+ # "previous_uri":null,
2106
+ # "next_uri":"/v2/accounts?limit=100\u0026starting_after=6b17acd6-2e68-5eb0-9f45-72d67cef578b"
2107
+ # },
2108
+ # "data":[
2109
+ # {
2110
+ # "id":"94ad58bc-0f15-5309-b35a-a4c86d7bad60",
2111
+ # "name":"MINA Wallet",
2112
+ # "primary":false,
2113
+ # "type":"wallet",
2114
+ # "currency":{
2115
+ # "code":"MINA",
2116
+ # "name":"Mina",
2117
+ # "color":"#EA6B48",
2118
+ # "sort_index":397,
2119
+ # "exponent":9,
2120
+ # "type":"crypto",
2121
+ # "address_regex":"^(B62)[A-Za-z0-9]{52}$",
2122
+ # "asset_id":"a4ffc575-942c-5e26-b70c-cb3befdd4229",
2123
+ # "slug":"mina"
2124
+ # },
2125
+ # "balance":{"amount":"0.000000000","currency":"MINA"},
2126
+ # "created_at":"2022-03-25T00:36:16Z",
2127
+ # "updated_at":"2022-03-25T00:36:16Z",
2128
+ # "resource":"account",
2129
+ # "resource_path":"/v2/accounts/94ad58bc-0f15-5309-b35a-a4c86d7bad60",
2130
+ # "allow_deposits":true,
2131
+ # "allow_withdrawals":true
2132
+ # },
2133
+ # ]
2134
+ # }
2135
+ #
2136
+ # v3PrivateGetBrokerageAccounts
2137
+ # {
2138
+ # "accounts": [
2139
+ # {
2140
+ # "uuid": "11111111-1111-1111-1111-111111111111",
2141
+ # "name": "USDC Wallet",
2142
+ # "currency": "USDC",
2143
+ # "available_balance": {
2144
+ # "value": "0.0000000000000000",
2145
+ # "currency": "USDC"
2146
+ # },
2147
+ # "default": True,
2148
+ # "active": True,
2149
+ # "created_at": "2023-01-04T06:20:06.456Z",
2150
+ # "updated_at": "2023-01-04T06:20:07.181Z",
2151
+ # "deleted_at": null,
2152
+ # "type": "ACCOUNT_TYPE_CRYPTO",
2153
+ # "ready": False,
2154
+ # "hold": {
2155
+ # "value": "0.0000000000000000",
2156
+ # "currency": "USDC"
2157
+ # }
2158
+ # },
2159
+ # ...
2160
+ # ],
2161
+ # "has_next": False,
2162
+ # "cursor": "",
2163
+ # "size": 9
2164
+ # }
2165
+ #
2166
+ params['type'] = marketType
2167
+ return self.parse_custom_balance(response, params)
2168
+
2169
+ def fetch_ledger(self, code: Str = None, since: Int = None, limit: Int = None, params={}):
2170
+ """
2171
+ fetch the history of changes, actions done by the user or operations that altered balance of the user
2172
+ :see: https://docs.cloud.coinbase.com/sign-in-with-coinbase/docs/api-transactions#list-transactions
2173
+ :param str code: unified currency code, default is None
2174
+ :param int [since]: timestamp in ms of the earliest ledger entry, default is None
2175
+ :param int [limit]: max number of ledger entrys to return, default is None
2176
+ :param dict [params]: extra parameters specific to the exchange API endpoint
2177
+ :param boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
2178
+ :returns dict: a `ledger structure <https://docs.ccxt.com/#/?id=ledger-structure>`
2179
+ """
2180
+ self.load_markets()
2181
+ paginate = False
2182
+ paginate, params = self.handle_option_and_params(params, 'fetchLedger', 'paginate')
2183
+ if paginate:
2184
+ return self.fetch_paginated_call_cursor('fetchLedger', code, since, limit, params, 'next_starting_after', 'starting_after', None, 100)
2185
+ currency = None
2186
+ if code is not None:
2187
+ currency = self.currency(code)
2188
+ request = None
2189
+ request, params = self.prepare_account_request_with_currency_code(code, limit, params)
2190
+ # for pagination use parameter 'starting_after'
2191
+ # the value for the next page can be obtained from the result of the previous call in the 'pagination' field
2192
+ # eg: instance.last_json_response.pagination.next_starting_after
2193
+ response = self.v2PrivateGetAccountsAccountIdTransactions(self.extend(request, params))
2194
+ ledger = self.parse_ledger(response['data'], currency, since, limit)
2195
+ length = len(ledger)
2196
+ if length == 0:
2197
+ return ledger
2198
+ lastIndex = length - 1
2199
+ last = self.safe_dict(ledger, lastIndex)
2200
+ pagination = self.safe_dict(response, 'pagination', {})
2201
+ cursor = self.safe_string(pagination, 'next_starting_after')
2202
+ if (cursor is not None) and (cursor != ''):
2203
+ last['next_starting_after'] = cursor
2204
+ ledger[lastIndex] = last
2205
+ return ledger
2206
+
2207
+ def parse_ledger_entry_status(self, status):
2208
+ types: dict = {
2209
+ 'completed': 'ok',
2210
+ }
2211
+ return self.safe_string(types, status, status)
2212
+
2213
+ def parse_ledger_entry_type(self, type):
2214
+ types: dict = {
2215
+ 'buy': 'trade',
2216
+ 'sell': 'trade',
2217
+ 'fiat_deposit': 'transaction',
2218
+ 'fiat_withdrawal': 'transaction',
2219
+ 'exchange_deposit': 'transaction', # fiat withdrawal(from coinbase to coinbasepro)
2220
+ 'exchange_withdrawal': 'transaction', # fiat deposit(to coinbase from coinbasepro)
2221
+ 'send': 'transaction', # crypto deposit OR withdrawal
2222
+ 'pro_deposit': 'transaction', # crypto withdrawal(from coinbase to coinbasepro)
2223
+ 'pro_withdrawal': 'transaction', # crypto deposit(to coinbase from coinbasepro)
2224
+ }
2225
+ return self.safe_string(types, type, type)
2226
+
2227
+ def parse_ledger_entry(self, item: dict, currency: Currency = None):
2228
+ #
2229
+ # crypto deposit transaction
2230
+ #
2231
+ # {
2232
+ # "id": "34e4816b-4c8c-5323-a01c-35a9fa26e490",
2233
+ # "type": "send",
2234
+ # "status": "completed",
2235
+ # "amount": {amount: "28.31976528", currency: "BCH"},
2236
+ # "native_amount": {amount: "2799.65", currency: "GBP"},
2237
+ # "description": null,
2238
+ # "created_at": "2019-02-28T12:35:20Z",
2239
+ # "updated_at": "2019-02-28T12:43:24Z",
2240
+ # "resource": "transaction",
2241
+ # "resource_path": "/v2/accounts/c01d7364-edd7-5f3a-bd1d-de53d4cbb25e/transactions/34e4816b-4c8c-5323-a01c-35a9fa26e490",
2242
+ # "instant_exchange": False,
2243
+ # "network": {
2244
+ # "status": "confirmed",
2245
+ # "hash": "56222d865dae83774fccb2efbd9829cf08c75c94ce135bfe4276f3fb46d49701",
2246
+ # "transaction_url": "https://bch.btc.com/56222d865dae83774fccb2efbd9829cf08c75c94ce135bfe4276f3fb46d49701"
2247
+ # },
2248
+ # "from": {resource: "bitcoin_cash_network", currency: "BCH"},
2249
+ # "details": {title: 'Received Bitcoin Cash', subtitle: "From Bitcoin Cash address"}
2250
+ # }
2251
+ #
2252
+ # crypto withdrawal transaction
2253
+ #
2254
+ # {
2255
+ # "id": "459aad99-2c41-5698-ac71-b6b81a05196c",
2256
+ # "type": "send",
2257
+ # "status": "completed",
2258
+ # "amount": {amount: "-0.36775642", currency: "BTC"},
2259
+ # "native_amount": {amount: "-1111.65", currency: "GBP"},
2260
+ # "description": null,
2261
+ # "created_at": "2019-03-20T08:37:07Z",
2262
+ # "updated_at": "2019-03-20T08:49:33Z",
2263
+ # "resource": "transaction",
2264
+ # "resource_path": "/v2/accounts/c6afbd34-4bd0-501e-8616-4862c193cd84/transactions/459aad99-2c41-5698-ac71-b6b81a05196c",
2265
+ # "instant_exchange": False,
2266
+ # "network": {
2267
+ # "status": "confirmed",
2268
+ # "hash": "2732bbcf35c69217c47b36dce64933d103895277fe25738ffb9284092701e05b",
2269
+ # "transaction_url": "https://blockchain.info/tx/2732bbcf35c69217c47b36dce64933d103895277fe25738ffb9284092701e05b",
2270
+ # "transaction_fee": {amount: "0.00000000", currency: "BTC"},
2271
+ # "transaction_amount": {amount: "0.36775642", currency: "BTC"},
2272
+ # "confirmations": 15682
2273
+ # },
2274
+ # "to": {
2275
+ # "resource": "bitcoin_address",
2276
+ # "address": "1AHnhqbvbYx3rnZx8uC7NbFZaTe4tafFHX",
2277
+ # "currency": "BTC",
2278
+ # "address_info": {address: "1AHnhqbvbYx3rnZx8uC7NbFZaTe4tafFHX"}
2279
+ # },
2280
+ # "idem": "da0a2f14-a2af-4c5a-a37e-d4484caf582bsend",
2281
+ # "application": {
2282
+ # "id": "5756ab6e-836b-553b-8950-5e389451225d",
2283
+ # "resource": "application",
2284
+ # "resource_path": "/v2/applications/5756ab6e-836b-553b-8950-5e389451225d"
2285
+ # },
2286
+ # "details": {title: 'Sent Bitcoin', subtitle: "To Bitcoin address"}
2287
+ # }
2288
+ #
2289
+ # withdrawal transaction from coinbase to coinbasepro
2290
+ #
2291
+ # {
2292
+ # "id": "5b1b9fb8-5007-5393-b923-02903b973fdc",
2293
+ # "type": "pro_deposit",
2294
+ # "status": "completed",
2295
+ # "amount": {amount: "-0.00001111", currency: "BCH"},
2296
+ # "native_amount": {amount: "0.00", currency: "GBP"},
2297
+ # "description": null,
2298
+ # "created_at": "2019-02-28T13:31:58Z",
2299
+ # "updated_at": "2019-02-28T13:31:58Z",
2300
+ # "resource": "transaction",
2301
+ # "resource_path": "/v2/accounts/c01d7364-edd7-5f3a-bd1d-de53d4cbb25e/transactions/5b1b9fb8-5007-5393-b923-02903b973fdc",
2302
+ # "instant_exchange": False,
2303
+ # "application": {
2304
+ # "id": "5756ab6e-836b-553b-8950-5e389451225d",
2305
+ # "resource": "application",
2306
+ # "resource_path": "/v2/applications/5756ab6e-836b-553b-8950-5e389451225d"
2307
+ # },
2308
+ # "details": {title: 'Transferred Bitcoin Cash', subtitle: "To Coinbase Pro"}
2309
+ # }
2310
+ #
2311
+ # withdrawal transaction from coinbase to gdax
2312
+ #
2313
+ # {
2314
+ # "id": "badb7313-a9d3-5c07-abd0-00f8b44199b1",
2315
+ # "type": "exchange_deposit",
2316
+ # "status": "completed",
2317
+ # "amount": {amount: "-0.43704149", currency: "BCH"},
2318
+ # "native_amount": {amount: "-51.90", currency: "GBP"},
2319
+ # "description": null,
2320
+ # "created_at": "2019-03-19T10:30:40Z",
2321
+ # "updated_at": "2019-03-19T10:30:40Z",
2322
+ # "resource": "transaction",
2323
+ # "resource_path": "/v2/accounts/c01d7364-edd7-5f3a-bd1d-de53d4cbb25e/transactions/badb7313-a9d3-5c07-abd0-00f8b44199b1",
2324
+ # "instant_exchange": False,
2325
+ # "details": {title: 'Transferred Bitcoin Cash', subtitle: "To GDAX"}
2326
+ # }
2327
+ #
2328
+ # deposit transaction from gdax to coinbase
2329
+ #
2330
+ # {
2331
+ # "id": "9c4b642c-8688-58bf-8962-13cef64097de",
2332
+ # "type": "exchange_withdrawal",
2333
+ # "status": "completed",
2334
+ # "amount": {amount: "0.57729420", currency: "BTC"},
2335
+ # "native_amount": {amount: "4418.72", currency: "GBP"},
2336
+ # "description": null,
2337
+ # "created_at": "2018-02-17T11:33:33Z",
2338
+ # "updated_at": "2018-02-17T11:33:33Z",
2339
+ # "resource": "transaction",
2340
+ # "resource_path": "/v2/accounts/c6afbd34-4bd0-501e-8616-4862c193cd84/transactions/9c4b642c-8688-58bf-8962-13cef64097de",
2341
+ # "instant_exchange": False,
2342
+ # "details": {title: 'Transferred Bitcoin', subtitle: "From GDAX"}
2343
+ # }
2344
+ #
2345
+ # deposit transaction from coinbasepro to coinbase
2346
+ #
2347
+ # {
2348
+ # "id": "8d6dd0b9-3416-568a-889d-8f112fae9e81",
2349
+ # "type": "pro_withdrawal",
2350
+ # "status": "completed",
2351
+ # "amount": {amount: "0.40555386", currency: "BTC"},
2352
+ # "native_amount": {amount: "1140.27", currency: "GBP"},
2353
+ # "description": null,
2354
+ # "created_at": "2019-03-04T19:41:58Z",
2355
+ # "updated_at": "2019-03-04T19:41:58Z",
2356
+ # "resource": "transaction",
2357
+ # "resource_path": "/v2/accounts/c6afbd34-4bd0-501e-8616-4862c193cd84/transactions/8d6dd0b9-3416-568a-889d-8f112fae9e81",
2358
+ # "instant_exchange": False,
2359
+ # "application": {
2360
+ # "id": "5756ab6e-836b-553b-8950-5e389451225d",
2361
+ # "resource": "application",
2362
+ # "resource_path": "/v2/applications/5756ab6e-836b-553b-8950-5e389451225d"
2363
+ # },
2364
+ # "details": {title: 'Transferred Bitcoin', subtitle: "From Coinbase Pro"}
2365
+ # }
2366
+ #
2367
+ # sell trade
2368
+ #
2369
+ # {
2370
+ # "id": "a9409207-df64-585b-97ab-a50780d2149e",
2371
+ # "type": "sell",
2372
+ # "status": "completed",
2373
+ # "amount": {amount: "-9.09922880", currency: "BTC"},
2374
+ # "native_amount": {amount: "-7285.73", currency: "GBP"},
2375
+ # "description": null,
2376
+ # "created_at": "2017-03-27T15:38:34Z",
2377
+ # "updated_at": "2017-03-27T15:38:34Z",
2378
+ # "resource": "transaction",
2379
+ # "resource_path": "/v2/accounts/c6afbd34-4bd0-501e-8616-4862c193cd84/transactions/a9409207-df64-585b-97ab-a50780d2149e",
2380
+ # "instant_exchange": False,
2381
+ # "sell": {
2382
+ # "id": "e3550b4d-8ae6-5de3-95fe-1fb01ba83051",
2383
+ # "resource": "sell",
2384
+ # "resource_path": "/v2/accounts/c6afbd34-4bd0-501e-8616-4862c193cd84/sells/e3550b4d-8ae6-5de3-95fe-1fb01ba83051"
2385
+ # },
2386
+ # "details": {
2387
+ # "title": "Sold Bitcoin",
2388
+ # "subtitle": "Using EUR Wallet",
2389
+ # "payment_method_name": "EUR Wallet"
2390
+ # }
2391
+ # }
2392
+ #
2393
+ # buy trade
2394
+ #
2395
+ # {
2396
+ # "id": "63eeed67-9396-5912-86e9-73c4f10fe147",
2397
+ # "type": "buy",
2398
+ # "status": "completed",
2399
+ # "amount": {amount: "2.39605772", currency: "ETH"},
2400
+ # "native_amount": {amount: "98.31", currency: "GBP"},
2401
+ # "description": null,
2402
+ # "created_at": "2017-03-27T09:07:56Z",
2403
+ # "updated_at": "2017-03-27T09:07:57Z",
2404
+ # "resource": "transaction",
2405
+ # "resource_path": "/v2/accounts/8902f85d-4a69-5d74-82fe-8e390201bda7/transactions/63eeed67-9396-5912-86e9-73c4f10fe147",
2406
+ # "instant_exchange": False,
2407
+ # "buy": {
2408
+ # "id": "20b25b36-76c6-5353-aa57-b06a29a39d82",
2409
+ # "resource": "buy",
2410
+ # "resource_path": "/v2/accounts/8902f85d-4a69-5d74-82fe-8e390201bda7/buys/20b25b36-76c6-5353-aa57-b06a29a39d82"
2411
+ # },
2412
+ # "details": {
2413
+ # "title": "Bought Ethereum",
2414
+ # "subtitle": "Using EUR Wallet",
2415
+ # "payment_method_name": "EUR Wallet"
2416
+ # }
2417
+ # }
2418
+ #
2419
+ # fiat deposit transaction
2420
+ #
2421
+ # {
2422
+ # "id": "04ed4113-3732-5b0c-af86-b1d2146977d0",
2423
+ # "type": "fiat_deposit",
2424
+ # "status": "completed",
2425
+ # "amount": {amount: "114.02", currency: "EUR"},
2426
+ # "native_amount": {amount: "97.23", currency: "GBP"},
2427
+ # "description": null,
2428
+ # "created_at": "2017-02-09T07:01:21Z",
2429
+ # "updated_at": "2017-02-09T07:01:22Z",
2430
+ # "resource": "transaction",
2431
+ # "resource_path": "/v2/accounts/91cd2d36-3a91-55b6-a5d4-0124cf105483/transactions/04ed4113-3732-5b0c-af86-b1d2146977d0",
2432
+ # "instant_exchange": False,
2433
+ # "fiat_deposit": {
2434
+ # "id": "f34c19f3-b730-5e3d-9f72-96520448677a",
2435
+ # "resource": "fiat_deposit",
2436
+ # "resource_path": "/v2/accounts/91cd2d36-3a91-55b6-a5d4-0124cf105483/deposits/f34c19f3-b730-5e3d-9f72-96520448677a"
2437
+ # },
2438
+ # "details": {
2439
+ # "title": "Deposited funds",
2440
+ # "subtitle": "From SEPA Transfer(GB47 BARC 20..., reference CBADVI)",
2441
+ # "payment_method_name": "SEPA Transfer(GB47 BARC 20..., reference CBADVI)"
2442
+ # }
2443
+ # }
2444
+ #
2445
+ # fiat withdrawal transaction
2446
+ #
2447
+ # {
2448
+ # "id": "957d98e2-f80e-5e2f-a28e-02945aa93079",
2449
+ # "type": "fiat_withdrawal",
2450
+ # "status": "completed",
2451
+ # "amount": {amount: "-11000.00", currency: "EUR"},
2452
+ # "native_amount": {amount: "-9698.22", currency: "GBP"},
2453
+ # "description": null,
2454
+ # "created_at": "2017-12-06T13:19:19Z",
2455
+ # "updated_at": "2017-12-06T13:19:19Z",
2456
+ # "resource": "transaction",
2457
+ # "resource_path": "/v2/accounts/91cd2d36-3a91-55b6-a5d4-0124cf105483/transactions/957d98e2-f80e-5e2f-a28e-02945aa93079",
2458
+ # "instant_exchange": False,
2459
+ # "fiat_withdrawal": {
2460
+ # "id": "f4bf1fd9-ab3b-5de7-906d-ed3e23f7a4e7",
2461
+ # "resource": "fiat_withdrawal",
2462
+ # "resource_path": "/v2/accounts/91cd2d36-3a91-55b6-a5d4-0124cf105483/withdrawals/f4bf1fd9-ab3b-5de7-906d-ed3e23f7a4e7"
2463
+ # },
2464
+ # "details": {
2465
+ # "title": "Withdrew funds",
2466
+ # "subtitle": "To HSBC BANK PLC(GB74 MIDL...)",
2467
+ # "payment_method_name": "HSBC BANK PLC(GB74 MIDL...)"
2468
+ # }
2469
+ # }
2470
+ #
2471
+ amountInfo = self.safe_dict(item, 'amount', {})
2472
+ amount = self.safe_string(amountInfo, 'amount')
2473
+ direction = None
2474
+ if Precise.string_lt(amount, '0'):
2475
+ direction = 'out'
2476
+ amount = Precise.string_neg(amount)
2477
+ else:
2478
+ direction = 'in'
2479
+ currencyId = self.safe_string(amountInfo, 'currency')
2480
+ code = self.safe_currency_code(currencyId, currency)
2481
+ #
2482
+ # the address and txid do not belong to the unified ledger structure
2483
+ #
2484
+ # address = None
2485
+ # if item['to']:
2486
+ # address = self.safe_string(item['to'], 'address')
2487
+ # }
2488
+ # txid = None
2489
+ #
2490
+ fee = None
2491
+ networkInfo = self.safe_dict(item, 'network', {})
2492
+ # txid = network['hash'] # txid does not belong to the unified ledger structure
2493
+ feeInfo = self.safe_dict(networkInfo, 'transaction_fee')
2494
+ if feeInfo is not None:
2495
+ feeCurrencyId = self.safe_string(feeInfo, 'currency')
2496
+ feeCurrencyCode = self.safe_currency_code(feeCurrencyId, currency)
2497
+ feeAmount = self.safe_number(feeInfo, 'amount')
2498
+ fee = {
2499
+ 'cost': feeAmount,
2500
+ 'currency': feeCurrencyCode,
2501
+ }
2502
+ timestamp = self.parse8601(self.safe_string(item, 'created_at'))
2503
+ id = self.safe_string(item, 'id')
2504
+ type = self.parse_ledger_entry_type(self.safe_string(item, 'type'))
2505
+ status = self.parse_ledger_entry_status(self.safe_string(item, 'status'))
2506
+ path = self.safe_string(item, 'resource_path')
2507
+ accountId = None
2508
+ if path is not None:
2509
+ parts = path.split('/')
2510
+ numParts = len(parts)
2511
+ if numParts > 3:
2512
+ accountId = parts[3]
2513
+ return {
2514
+ 'info': item,
2515
+ 'id': id,
2516
+ 'timestamp': timestamp,
2517
+ 'datetime': self.iso8601(timestamp),
2518
+ 'direction': direction,
2519
+ 'account': accountId,
2520
+ 'referenceId': None,
2521
+ 'referenceAccount': None,
2522
+ 'type': type,
2523
+ 'currency': code,
2524
+ 'amount': self.parse_number(amount),
2525
+ 'before': None,
2526
+ 'after': None,
2527
+ 'status': status,
2528
+ 'fee': fee,
2529
+ }
2530
+
2531
+ def find_account_id(self, code, params={}):
2532
+ self.load_markets()
2533
+ self.load_accounts(False, params)
2534
+ for i in range(0, len(self.accounts)):
2535
+ account = self.accounts[i]
2536
+ if account['code'] == code:
2537
+ return account['id']
2538
+ return None
2539
+
2540
+ def prepare_account_request(self, limit: Int = None, params={}):
2541
+ accountId = self.safe_string_2(params, 'account_id', 'accountId')
2542
+ if accountId is None:
2543
+ raise ArgumentsRequired(self.id + ' prepareAccountRequest() method requires an account_id(or accountId) parameter')
2544
+ request: dict = {
2545
+ 'account_id': accountId,
2546
+ }
2547
+ if limit is not None:
2548
+ request['limit'] = limit
2549
+ return request
2550
+
2551
+ def prepare_account_request_with_currency_code(self, code: Str = None, limit: Int = None, params={}):
2552
+ accountId = self.safe_string_2(params, 'account_id', 'accountId')
2553
+ params = self.omit(params, ['account_id', 'accountId'])
2554
+ if accountId is None:
2555
+ if code is None:
2556
+ raise ArgumentsRequired(self.id + ' prepareAccountRequestWithCurrencyCode() method requires an account_id(or accountId) parameter OR a currency code argument')
2557
+ accountId = self.find_account_id(code, params)
2558
+ if accountId is None:
2559
+ raise ExchangeError(self.id + ' prepareAccountRequestWithCurrencyCode() could not find account id for ' + code)
2560
+ request: dict = {
2561
+ 'account_id': accountId,
2562
+ }
2563
+ if limit is not None:
2564
+ request['limit'] = limit
2565
+ return [request, params]
2566
+
2567
+ def create_market_buy_order_with_cost(self, symbol: str, cost: float, params={}):
2568
+ """
2569
+ create a market buy order by providing the symbol and cost
2570
+ :see: https://docs.cloud.coinbase.com/advanced-trade-api/reference/retailbrokerageapi_postorder
2571
+ :param str symbol: unified symbol of the market to create an order in
2572
+ :param float cost: how much you want to trade in units of the quote currency
2573
+ :param dict [params]: extra parameters specific to the exchange API endpoint
2574
+ :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
2575
+ """
2576
+ self.load_markets()
2577
+ market = self.market(symbol)
2578
+ if not market['spot']:
2579
+ raise NotSupported(self.id + ' createMarketBuyOrderWithCost() supports spot orders only')
2580
+ params['createMarketBuyOrderRequiresPrice'] = False
2581
+ return self.create_order(symbol, 'market', 'buy', cost, None, params)
2582
+
2583
+ def create_order(self, symbol: str, type: OrderType, side: OrderSide, amount: float, price: Num = None, params={}):
2584
+ """
2585
+ create a trade order
2586
+ :see: https://docs.cloud.coinbase.com/advanced-trade-api/reference/retailbrokerageapi_postorder
2587
+ :param str symbol: unified symbol of the market to create an order in
2588
+ :param str type: 'market' or 'limit'
2589
+ :param str side: 'buy' or 'sell'
2590
+ :param float amount: how much you want to trade in units of the base currency, quote currency for 'market' 'buy' orders
2591
+ :param float [price]: the price to fulfill the order, in units of the quote currency, ignored in market orders
2592
+ :param dict [params]: extra parameters specific to the exchange API endpoint
2593
+ :param float [params.stopPrice]: price to trigger stop orders
2594
+ :param float [params.triggerPrice]: price to trigger stop orders
2595
+ :param float [params.stopLossPrice]: price to trigger stop-loss orders
2596
+ :param float [params.takeProfitPrice]: price to trigger take-profit orders
2597
+ :param bool [params.postOnly]: True or False
2598
+ :param str [params.timeInForce]: 'GTC', 'IOC', 'GTD' or 'PO', 'FOK'
2599
+ :param str [params.stop_direction]: 'UNKNOWN_STOP_DIRECTION', 'STOP_DIRECTION_STOP_UP', 'STOP_DIRECTION_STOP_DOWN' the direction the stopPrice is triggered from
2600
+ :param str [params.end_time]: '2023-05-25T17:01:05.092Z' for 'GTD' orders
2601
+ :param float [params.cost]: *spot market buy only* the quote quantity that can be used alternative for the amount
2602
+ :param boolean [params.preview]: default to False, wether to use the test/preview endpoint or not
2603
+ :param float [params.leverage]: default to 1, the leverage to use for the order
2604
+ :param str [params.marginMode]: 'cross' or 'isolated'
2605
+ :param str [params.retail_portfolio_id]: portfolio uid
2606
+ :param boolean [params.is_max]: Used in conjunction with tradable_balance to indicate the user wants to use their entire tradable balance
2607
+ :param str [params.tradable_balance]: amount of tradable balance
2608
+ :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
2609
+ """
2610
+ self.load_markets()
2611
+ market = self.market(symbol)
2612
+ id = self.safe_string(self.options, 'brokerId', 'ccxt')
2613
+ request: dict = {
2614
+ 'client_order_id': id + '-' + self.uuid(),
2615
+ 'product_id': market['id'],
2616
+ 'side': side.upper(),
2617
+ }
2618
+ stopPrice = self.safe_number_n(params, ['stopPrice', 'stop_price', 'triggerPrice'])
2619
+ stopLossPrice = self.safe_number(params, 'stopLossPrice')
2620
+ takeProfitPrice = self.safe_number(params, 'takeProfitPrice')
2621
+ isStop = stopPrice is not None
2622
+ isStopLoss = stopLossPrice is not None
2623
+ isTakeProfit = takeProfitPrice is not None
2624
+ timeInForce = self.safe_string(params, 'timeInForce')
2625
+ postOnly = True if (timeInForce == 'PO') else self.safe_bool_2(params, 'postOnly', 'post_only', False)
2626
+ endTime = self.safe_string(params, 'end_time')
2627
+ stopDirection = self.safe_string(params, 'stop_direction')
2628
+ if type == 'limit':
2629
+ if isStop:
2630
+ if stopDirection is None:
2631
+ stopDirection = 'STOP_DIRECTION_STOP_DOWN' if (side == 'buy') else 'STOP_DIRECTION_STOP_UP'
2632
+ if (timeInForce == 'GTD') or (endTime is not None):
2633
+ if endTime is None:
2634
+ raise ExchangeError(self.id + ' createOrder() requires an end_time parameter for a GTD order')
2635
+ request['order_configuration'] = {
2636
+ 'stop_limit_stop_limit_gtd': {
2637
+ 'base_size': self.amount_to_precision(symbol, amount),
2638
+ 'limit_price': self.price_to_precision(symbol, price),
2639
+ 'stop_price': self.price_to_precision(symbol, stopPrice),
2640
+ 'stop_direction': stopDirection,
2641
+ 'end_time': endTime,
2642
+ },
2643
+ }
2644
+ else:
2645
+ request['order_configuration'] = {
2646
+ 'stop_limit_stop_limit_gtc': {
2647
+ 'base_size': self.amount_to_precision(symbol, amount),
2648
+ 'limit_price': self.price_to_precision(symbol, price),
2649
+ 'stop_price': self.price_to_precision(symbol, stopPrice),
2650
+ 'stop_direction': stopDirection,
2651
+ },
2652
+ }
2653
+ elif isStopLoss or isTakeProfit:
2654
+ triggerPrice = None
2655
+ if isStopLoss:
2656
+ if stopDirection is None:
2657
+ stopDirection = 'STOP_DIRECTION_STOP_UP' if (side == 'buy') else 'STOP_DIRECTION_STOP_DOWN'
2658
+ triggerPrice = self.price_to_precision(symbol, stopLossPrice)
2659
+ else:
2660
+ if stopDirection is None:
2661
+ stopDirection = 'STOP_DIRECTION_STOP_DOWN' if (side == 'buy') else 'STOP_DIRECTION_STOP_UP'
2662
+ triggerPrice = self.price_to_precision(symbol, takeProfitPrice)
2663
+ request['order_configuration'] = {
2664
+ 'stop_limit_stop_limit_gtc': {
2665
+ 'base_size': self.amount_to_precision(symbol, amount),
2666
+ 'limit_price': self.price_to_precision(symbol, price),
2667
+ 'stop_price': triggerPrice,
2668
+ 'stop_direction': stopDirection,
2669
+ },
2670
+ }
2671
+ else:
2672
+ if (timeInForce == 'GTD') or (endTime is not None):
2673
+ if endTime is None:
2674
+ raise ExchangeError(self.id + ' createOrder() requires an end_time parameter for a GTD order')
2675
+ request['order_configuration'] = {
2676
+ 'limit_limit_gtd': {
2677
+ 'base_size': self.amount_to_precision(symbol, amount),
2678
+ 'limit_price': self.price_to_precision(symbol, price),
2679
+ 'end_time': endTime,
2680
+ 'post_only': postOnly,
2681
+ },
2682
+ }
2683
+ elif timeInForce == 'IOC':
2684
+ request['order_configuration'] = {
2685
+ 'sor_limit_ioc': {
2686
+ 'base_size': self.amount_to_precision(symbol, amount),
2687
+ 'limit_price': self.price_to_precision(symbol, price),
2688
+ },
2689
+ }
2690
+ elif timeInForce == 'FOK':
2691
+ request['order_configuration'] = {
2692
+ 'limit_limit_fok': {
2693
+ 'base_size': self.amount_to_precision(symbol, amount),
2694
+ 'limit_price': self.price_to_precision(symbol, price),
2695
+ },
2696
+ }
2697
+ else:
2698
+ request['order_configuration'] = {
2699
+ 'limit_limit_gtc': {
2700
+ 'base_size': self.amount_to_precision(symbol, amount),
2701
+ 'limit_price': self.price_to_precision(symbol, price),
2702
+ 'post_only': postOnly,
2703
+ },
2704
+ }
2705
+ else:
2706
+ if isStop or isStopLoss or isTakeProfit:
2707
+ raise NotSupported(self.id + ' createOrder() only stop limit orders are supported')
2708
+ if market['spot'] and (side == 'buy'):
2709
+ total = None
2710
+ createMarketBuyOrderRequiresPrice = True
2711
+ createMarketBuyOrderRequiresPrice, params = self.handle_option_and_params(params, 'createOrder', 'createMarketBuyOrderRequiresPrice', True)
2712
+ cost = self.safe_number(params, 'cost')
2713
+ params = self.omit(params, 'cost')
2714
+ if cost is not None:
2715
+ total = self.cost_to_precision(symbol, cost)
2716
+ elif createMarketBuyOrderRequiresPrice:
2717
+ if price is None:
2718
+ raise InvalidOrder(self.id + ' createOrder() requires a price argument for market buy orders on spot markets to calculate the total amount to spend(amount * price), alternatively set the createMarketBuyOrderRequiresPrice option or param to False and pass the cost to spend in the amount argument')
2719
+ else:
2720
+ amountString = self.number_to_string(amount)
2721
+ priceString = self.number_to_string(price)
2722
+ costRequest = Precise.string_mul(amountString, priceString)
2723
+ total = self.cost_to_precision(symbol, costRequest)
2724
+ else:
2725
+ total = self.cost_to_precision(symbol, amount)
2726
+ request['order_configuration'] = {
2727
+ 'market_market_ioc': {
2728
+ 'quote_size': total,
2729
+ },
2730
+ }
2731
+ else:
2732
+ request['order_configuration'] = {
2733
+ 'market_market_ioc': {
2734
+ 'base_size': self.amount_to_precision(symbol, amount),
2735
+ },
2736
+ }
2737
+ marginMode = self.safe_string(params, 'marginMode')
2738
+ if marginMode is not None:
2739
+ if marginMode == 'isolated':
2740
+ request['margin_type'] = 'ISOLATED'
2741
+ elif marginMode == 'cross':
2742
+ request['margin_type'] = 'CROSS'
2743
+ params = self.omit(params, ['timeInForce', 'triggerPrice', 'stopLossPrice', 'takeProfitPrice', 'stopPrice', 'stop_price', 'stopDirection', 'stop_direction', 'clientOrderId', 'postOnly', 'post_only', 'end_time', 'marginMode'])
2744
+ preview = self.safe_bool_2(params, 'preview', 'test', False)
2745
+ response = None
2746
+ if preview:
2747
+ params = self.omit(params, ['preview', 'test'])
2748
+ request = self.omit(request, 'client_order_id')
2749
+ response = self.v3PrivatePostBrokerageOrdersPreview(self.extend(request, params))
2750
+ else:
2751
+ response = self.v3PrivatePostBrokerageOrders(self.extend(request, params))
2752
+ #
2753
+ # successful order
2754
+ #
2755
+ # {
2756
+ # "success": True,
2757
+ # "failure_reason": "UNKNOWN_FAILURE_REASON",
2758
+ # "order_id": "52cfe5e2-0b29-4c19-a245-a6a773de5030",
2759
+ # "success_response": {
2760
+ # "order_id": "52cfe5e2-0b29-4c19-a245-a6a773de5030",
2761
+ # "product_id": "LTC-BTC",
2762
+ # "side": "SELL",
2763
+ # "client_order_id": "4d760580-6fca-4094-a70b-ebcca8626288"
2764
+ # },
2765
+ # "order_configuration": null
2766
+ # }
2767
+ #
2768
+ # failed order
2769
+ #
2770
+ # {
2771
+ # "success": False,
2772
+ # "failure_reason": "UNKNOWN_FAILURE_REASON",
2773
+ # "order_id": "",
2774
+ # "error_response": {
2775
+ # "error": "UNSUPPORTED_ORDER_CONFIGURATION",
2776
+ # "message": "source is not enabled for trading",
2777
+ # "error_details": "",
2778
+ # "new_order_failure_reason": "UNSUPPORTED_ORDER_CONFIGURATION"
2779
+ # },
2780
+ # "order_configuration": {
2781
+ # "limit_limit_gtc": {
2782
+ # "base_size": "100",
2783
+ # "limit_price": "40000",
2784
+ # "post_only": False
2785
+ # }
2786
+ # }
2787
+ # }
2788
+ #
2789
+ success = self.safe_bool(response, 'success')
2790
+ if success is not True:
2791
+ errorResponse = self.safe_dict(response, 'error_response')
2792
+ errorTitle = self.safe_string(errorResponse, 'error')
2793
+ errorMessage = self.safe_string(errorResponse, 'message')
2794
+ if errorResponse is not None:
2795
+ self.throw_exactly_matched_exception(self.exceptions['exact'], errorTitle, errorMessage)
2796
+ self.throw_broadly_matched_exception(self.exceptions['broad'], errorTitle, errorMessage)
2797
+ raise ExchangeError(errorMessage)
2798
+ data = self.safe_dict(response, 'success_response', {})
2799
+ return self.parse_order(data, market)
2800
+
2801
+ def parse_order(self, order: dict, market: Market = None) -> Order:
2802
+ #
2803
+ # createOrder
2804
+ #
2805
+ # {
2806
+ # "order_id": "52cfe5e2-0b29-4c19-a245-a6a773de5030",
2807
+ # "product_id": "LTC-BTC",
2808
+ # "side": "SELL",
2809
+ # "client_order_id": "4d760580-6fca-4094-a70b-ebcca8626288"
2810
+ # }
2811
+ #
2812
+ # cancelOrder, cancelOrders
2813
+ #
2814
+ # {
2815
+ # "success": True,
2816
+ # "failure_reason": "UNKNOWN_CANCEL_FAILURE_REASON",
2817
+ # "order_id": "bb8851a3-4fda-4a2c-aa06-9048db0e0f0d"
2818
+ # }
2819
+ #
2820
+ # fetchOrder, fetchOrders, fetchOpenOrders, fetchClosedOrders, fetchCanceledOrders
2821
+ #
2822
+ # {
2823
+ # "order_id": "9bc1eb3b-5b46-4b71-9628-ae2ed0cca75b",
2824
+ # "product_id": "LTC-BTC",
2825
+ # "user_id": "1111111-1111-1111-1111-111111111111",
2826
+ # "order_configuration": {
2827
+ # "limit_limit_gtc": {
2828
+ # "base_size": "0.2",
2829
+ # "limit_price": "0.006",
2830
+ # "post_only": False
2831
+ # },
2832
+ # "stop_limit_stop_limit_gtc": {
2833
+ # "base_size": "48.54",
2834
+ # "limit_price": "6.998",
2835
+ # "stop_price": "7.0687",
2836
+ # "stop_direction": "STOP_DIRECTION_STOP_DOWN"
2837
+ # }
2838
+ # },
2839
+ # "side": "SELL",
2840
+ # "client_order_id": "e5fe8482-05bb-428f-ad4d-dbc8ce39239c",
2841
+ # "status": "OPEN",
2842
+ # "time_in_force": "GOOD_UNTIL_CANCELLED",
2843
+ # "created_time": "2023-01-16T23:37:23.947030Z",
2844
+ # "completion_percentage": "0",
2845
+ # "filled_size": "0",
2846
+ # "average_filled_price": "0",
2847
+ # "fee": "",
2848
+ # "number_of_fills": "0",
2849
+ # "filled_value": "0",
2850
+ # "pending_cancel": False,
2851
+ # "size_in_quote": False,
2852
+ # "total_fees": "0",
2853
+ # "size_inclusive_of_fees": False,
2854
+ # "total_value_after_fees": "0",
2855
+ # "trigger_status": "INVALID_ORDER_TYPE",
2856
+ # "order_type": "LIMIT",
2857
+ # "reject_reason": "REJECT_REASON_UNSPECIFIED",
2858
+ # "settled": False,
2859
+ # "product_type": "SPOT",
2860
+ # "reject_message": "",
2861
+ # "cancel_message": ""
2862
+ # }
2863
+ #
2864
+ marketId = self.safe_string(order, 'product_id')
2865
+ symbol = self.safe_symbol(marketId, market, '-')
2866
+ if symbol is not None:
2867
+ market = self.safe_market(symbol, market)
2868
+ orderConfiguration = self.safe_dict(order, 'order_configuration', {})
2869
+ limitGTC = self.safe_dict(orderConfiguration, 'limit_limit_gtc')
2870
+ limitGTD = self.safe_dict(orderConfiguration, 'limit_limit_gtd')
2871
+ limitIOC = self.safe_dict(orderConfiguration, 'sor_limit_ioc')
2872
+ stopLimitGTC = self.safe_dict(orderConfiguration, 'stop_limit_stop_limit_gtc')
2873
+ stopLimitGTD = self.safe_dict(orderConfiguration, 'stop_limit_stop_limit_gtd')
2874
+ marketIOC = self.safe_dict(orderConfiguration, 'market_market_ioc')
2875
+ isLimit = ((limitGTC is not None) or (limitGTD is not None) or (limitIOC is not None))
2876
+ isStop = ((stopLimitGTC is not None) or (stopLimitGTD is not None))
2877
+ price = None
2878
+ amount = None
2879
+ postOnly = None
2880
+ triggerPrice = None
2881
+ if isLimit:
2882
+ target = None
2883
+ if limitGTC is not None:
2884
+ target = limitGTC
2885
+ elif limitGTD is not None:
2886
+ target = limitGTD
2887
+ else:
2888
+ target = limitIOC
2889
+ price = self.safe_string(target, 'limit_price')
2890
+ amount = self.safe_string(target, 'base_size')
2891
+ postOnly = self.safe_bool(target, 'post_only')
2892
+ elif isStop:
2893
+ stopTarget = stopLimitGTC if (stopLimitGTC is not None) else stopLimitGTD
2894
+ price = self.safe_string(stopTarget, 'limit_price')
2895
+ amount = self.safe_string(stopTarget, 'base_size')
2896
+ postOnly = self.safe_bool(stopTarget, 'post_only')
2897
+ triggerPrice = self.safe_string(stopTarget, 'stop_price')
2898
+ else:
2899
+ amount = self.safe_string(marketIOC, 'base_size')
2900
+ datetime = self.safe_string(order, 'created_time')
2901
+ totalFees = self.safe_string(order, 'total_fees')
2902
+ currencyFee = None
2903
+ if (totalFees is not None) and (market is not None):
2904
+ currencyFee = market['quote']
2905
+ return self.safe_order({
2906
+ 'info': order,
2907
+ 'id': self.safe_string(order, 'order_id'),
2908
+ 'clientOrderId': self.safe_string(order, 'client_order_id'),
2909
+ 'timestamp': self.parse8601(datetime),
2910
+ 'datetime': datetime,
2911
+ 'lastTradeTimestamp': None,
2912
+ 'symbol': symbol,
2913
+ 'type': self.parse_order_type(self.safe_string(order, 'order_type')),
2914
+ 'timeInForce': self.parse_time_in_force(self.safe_string(order, 'time_in_force')),
2915
+ 'postOnly': postOnly,
2916
+ 'side': self.safe_string_lower(order, 'side'),
2917
+ 'price': price,
2918
+ 'stopPrice': triggerPrice,
2919
+ 'triggerPrice': triggerPrice,
2920
+ 'amount': amount,
2921
+ 'filled': self.safe_string(order, 'filled_size'),
2922
+ 'remaining': None,
2923
+ 'cost': None,
2924
+ 'average': self.safe_string(order, 'average_filled_price'),
2925
+ 'status': self.parse_order_status(self.safe_string(order, 'status')),
2926
+ 'fee': {
2927
+ 'cost': self.safe_string(order, 'total_fees'),
2928
+ 'currency': currencyFee,
2929
+ },
2930
+ 'trades': None,
2931
+ }, market)
2932
+
2933
+ def parse_order_status(self, status: Str):
2934
+ statuses: dict = {
2935
+ 'OPEN': 'open',
2936
+ 'FILLED': 'closed',
2937
+ 'CANCELLED': 'canceled',
2938
+ 'EXPIRED': 'canceled',
2939
+ 'FAILED': 'canceled',
2940
+ 'UNKNOWN_ORDER_STATUS': None,
2941
+ }
2942
+ return self.safe_string(statuses, status, status)
2943
+
2944
+ def parse_order_type(self, type: Str):
2945
+ if type == 'UNKNOWN_ORDER_TYPE':
2946
+ return None
2947
+ types: dict = {
2948
+ 'MARKET': 'market',
2949
+ 'LIMIT': 'limit',
2950
+ 'STOP': 'limit',
2951
+ 'STOP_LIMIT': 'limit',
2952
+ }
2953
+ return self.safe_string(types, type, type)
2954
+
2955
+ def parse_time_in_force(self, timeInForce: Str):
2956
+ timeInForces: dict = {
2957
+ 'GOOD_UNTIL_CANCELLED': 'GTC',
2958
+ 'GOOD_UNTIL_DATE_TIME': 'GTD',
2959
+ 'IMMEDIATE_OR_CANCEL': 'IOC',
2960
+ 'FILL_OR_KILL': 'FOK',
2961
+ 'UNKNOWN_TIME_IN_FORCE': None,
2962
+ }
2963
+ return self.safe_string(timeInForces, timeInForce, timeInForce)
2964
+
2965
+ def cancel_order(self, id: str, symbol: Str = None, params={}):
2966
+ """
2967
+ cancels an open order
2968
+ :see: https://docs.cloud.coinbase.com/advanced-trade-api/reference/retailbrokerageapi_cancelorders
2969
+ :param str id: order id
2970
+ :param str symbol: not used by coinbase cancelOrder()
2971
+ :param dict [params]: extra parameters specific to the exchange API endpoint
2972
+ :returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
2973
+ """
2974
+ self.load_markets()
2975
+ orders = self.cancel_orders([id], symbol, params)
2976
+ return self.safe_dict(orders, 0, {})
2977
+
2978
+ def cancel_orders(self, ids, symbol: Str = None, params={}):
2979
+ """
2980
+ cancel multiple orders
2981
+ :see: https://docs.cloud.coinbase.com/advanced-trade-api/reference/retailbrokerageapi_cancelorders
2982
+ :param str[] ids: order ids
2983
+ :param str symbol: not used by coinbase cancelOrders()
2984
+ :param dict [params]: extra parameters specific to the exchange API endpoint
2985
+ :returns dict: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
2986
+ """
2987
+ self.load_markets()
2988
+ market = None
2989
+ if symbol is not None:
2990
+ market = self.market(symbol)
2991
+ request: dict = {
2992
+ 'order_ids': ids,
2993
+ }
2994
+ response = self.v3PrivatePostBrokerageOrdersBatchCancel(self.extend(request, params))
2995
+ #
2996
+ # {
2997
+ # "results": [
2998
+ # {
2999
+ # "success": True,
3000
+ # "failure_reason": "UNKNOWN_CANCEL_FAILURE_REASON",
3001
+ # "order_id": "bb8851a3-4fda-4a2c-aa06-9048db0e0f0d"
3002
+ # }
3003
+ # ]
3004
+ # }
3005
+ #
3006
+ orders = self.safe_list(response, 'results', [])
3007
+ for i in range(0, len(orders)):
3008
+ success = self.safe_bool(orders[i], 'success')
3009
+ if success is not True:
3010
+ raise BadRequest(self.id + ' cancelOrders() has failed, check your arguments and parameters')
3011
+ return self.parse_orders(orders, market)
3012
+
3013
+ def edit_order(self, id: str, symbol: str, type: OrderType, side: OrderSide, amount: Num = None, price: Num = None, params={}):
3014
+ """
3015
+ edit a trade order
3016
+ :see: https://docs.cloud.coinbase.com/advanced-trade-api/reference/retailbrokerageapi_editorder
3017
+ :param str id: cancel order id
3018
+ :param str symbol: unified symbol of the market to create an order in
3019
+ :param str type: 'market' or 'limit'
3020
+ :param str side: 'buy' or 'sell'
3021
+ :param float amount: how much of currency you want to trade in units of base currency
3022
+ :param float [price]: the price at which the order is to be fullfilled, in units of the base currency, ignored in market orders
3023
+ :param dict [params]: extra parameters specific to the exchange API endpoint
3024
+ :param boolean [params.preview]: default to False, wether to use the test/preview endpoint or not
3025
+ :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
3026
+ """
3027
+ self.load_markets()
3028
+ market = self.market(symbol)
3029
+ request: dict = {
3030
+ 'order_id': id,
3031
+ }
3032
+ if amount is not None:
3033
+ request['size'] = self.amount_to_precision(symbol, amount)
3034
+ if price is not None:
3035
+ request['price'] = self.price_to_precision(symbol, price)
3036
+ preview = self.safe_bool_2(params, 'preview', 'test', False)
3037
+ response = None
3038
+ if preview:
3039
+ params = self.omit(params, ['preview', 'test'])
3040
+ response = self.v3PrivatePostBrokerageOrdersEditPreview(self.extend(request, params))
3041
+ else:
3042
+ response = self.v3PrivatePostBrokerageOrdersEdit(self.extend(request, params))
3043
+ #
3044
+ # {
3045
+ # "success": True,
3046
+ # "errors": {
3047
+ # "edit_failure_reason": "UNKNOWN_EDIT_ORDER_FAILURE_REASON",
3048
+ # "preview_failure_reason": "UNKNOWN_PREVIEW_FAILURE_REASON"
3049
+ # }
3050
+ # }
3051
+ #
3052
+ return self.parse_order(response, market)
3053
+
3054
+ def fetch_order(self, id: str, symbol: Str = None, params={}):
3055
+ """
3056
+ fetches information on an order made by the user
3057
+ :see: https://docs.cloud.coinbase.com/advanced-trade-api/reference/retailbrokerageapi_gethistoricalorder
3058
+ :param str id: the order id
3059
+ :param str symbol: unified market symbol that the order was made in
3060
+ :param dict [params]: extra parameters specific to the exchange API endpoint
3061
+ :returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
3062
+ """
3063
+ self.load_markets()
3064
+ market = None
3065
+ if symbol is not None:
3066
+ market = self.market(symbol)
3067
+ request: dict = {
3068
+ 'order_id': id,
3069
+ }
3070
+ response = self.v3PrivateGetBrokerageOrdersHistoricalOrderId(self.extend(request, params))
3071
+ #
3072
+ # {
3073
+ # "order": {
3074
+ # "order_id": "9bc1eb3b-5b46-4b71-9628-ae2ed0cca75b",
3075
+ # "product_id": "LTC-BTC",
3076
+ # "user_id": "1111111-1111-1111-1111-111111111111",
3077
+ # "order_configuration": {
3078
+ # "limit_limit_gtc": {
3079
+ # "base_size": "0.2",
3080
+ # "limit_price": "0.006",
3081
+ # "post_only": False
3082
+ # }
3083
+ # },
3084
+ # "side": "SELL",
3085
+ # "client_order_id": "e5fe8482-05bb-428f-ad4d-dbc8ce39239c",
3086
+ # "status": "OPEN",
3087
+ # "time_in_force": "GOOD_UNTIL_CANCELLED",
3088
+ # "created_time": "2023-01-16T23:37:23.947030Z",
3089
+ # "completion_percentage": "0",
3090
+ # "filled_size": "0",
3091
+ # "average_filled_price": "0",
3092
+ # "fee": "",
3093
+ # "number_of_fills": "0",
3094
+ # "filled_value": "0",
3095
+ # "pending_cancel": False,
3096
+ # "size_in_quote": False,
3097
+ # "total_fees": "0",
3098
+ # "size_inclusive_of_fees": False,
3099
+ # "total_value_after_fees": "0",
3100
+ # "trigger_status": "INVALID_ORDER_TYPE",
3101
+ # "order_type": "LIMIT",
3102
+ # "reject_reason": "REJECT_REASON_UNSPECIFIED",
3103
+ # "settled": False,
3104
+ # "product_type": "SPOT",
3105
+ # "reject_message": "",
3106
+ # "cancel_message": ""
3107
+ # }
3108
+ # }
3109
+ #
3110
+ order = self.safe_dict(response, 'order', {})
3111
+ return self.parse_order(order, market)
3112
+
3113
+ def fetch_orders(self, symbol: Str = None, since: Int = None, limit: Int = 100, params={}) -> List[Order]:
3114
+ """
3115
+ fetches information on multiple orders made by the user
3116
+ :see: https://docs.cloud.coinbase.com/advanced-trade-api/reference/retailbrokerageapi_gethistoricalorders
3117
+ :param str symbol: unified market symbol that the orders were made in
3118
+ :param int [since]: the earliest time in ms to fetch orders
3119
+ :param int [limit]: the maximum number of order structures to retrieve
3120
+ :param dict [params]: extra parameters specific to the exchange API endpoint
3121
+ :param int [params.until]: the latest time in ms to fetch trades for
3122
+ :param boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
3123
+ :returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
3124
+ """
3125
+ self.load_markets()
3126
+ paginate = False
3127
+ paginate, params = self.handle_option_and_params(params, 'fetchOrders', 'paginate')
3128
+ if paginate:
3129
+ return self.fetch_paginated_call_cursor('fetchOrders', symbol, since, limit, params, 'cursor', 'cursor', None, 1000)
3130
+ market = None
3131
+ if symbol is not None:
3132
+ market = self.market(symbol)
3133
+ request: dict = {}
3134
+ if market is not None:
3135
+ request['product_id'] = market['id']
3136
+ if limit is not None:
3137
+ request['limit'] = limit
3138
+ if since is not None:
3139
+ request['start_date'] = self.iso8601(since)
3140
+ until = self.safe_integer_n(params, ['until'])
3141
+ if until is not None:
3142
+ params = self.omit(params, ['until'])
3143
+ request['end_date'] = self.iso8601(until)
3144
+ response = self.v3PrivateGetBrokerageOrdersHistoricalBatch(self.extend(request, params))
3145
+ #
3146
+ # {
3147
+ # "orders": [
3148
+ # {
3149
+ # "order_id": "813a53c5-3e39-47bb-863d-2faf685d22d8",
3150
+ # "product_id": "BTC-USDT",
3151
+ # "user_id": "1111111-1111-1111-1111-111111111111",
3152
+ # "order_configuration": {
3153
+ # "market_market_ioc": {
3154
+ # "quote_size": "6.36"
3155
+ # }
3156
+ # },
3157
+ # "side": "BUY",
3158
+ # "client_order_id": "18eb9947-db49-4874-8e7b-39b8fe5f4317",
3159
+ # "status": "FILLED",
3160
+ # "time_in_force": "IMMEDIATE_OR_CANCEL",
3161
+ # "created_time": "2023-01-18T01:37:37.975552Z",
3162
+ # "completion_percentage": "100",
3163
+ # "filled_size": "0.000297920684505",
3164
+ # "average_filled_price": "21220.6399999973697697",
3165
+ # "fee": "",
3166
+ # "number_of_fills": "2",
3167
+ # "filled_value": "6.3220675944333996",
3168
+ # "pending_cancel": False,
3169
+ # "size_in_quote": True,
3170
+ # "total_fees": "0.0379324055666004",
3171
+ # "size_inclusive_of_fees": True,
3172
+ # "total_value_after_fees": "6.36",
3173
+ # "trigger_status": "INVALID_ORDER_TYPE",
3174
+ # "order_type": "MARKET",
3175
+ # "reject_reason": "REJECT_REASON_UNSPECIFIED",
3176
+ # "settled": True,
3177
+ # "product_type": "SPOT",
3178
+ # "reject_message": "",
3179
+ # "cancel_message": "Internal error"
3180
+ # },
3181
+ # ],
3182
+ # "sequence": "0",
3183
+ # "has_next": False,
3184
+ # "cursor": ""
3185
+ # }
3186
+ #
3187
+ orders = self.safe_list(response, 'orders', [])
3188
+ first = self.safe_dict(orders, 0)
3189
+ cursor = self.safe_string(response, 'cursor')
3190
+ if (cursor is not None) and (cursor != ''):
3191
+ first['cursor'] = cursor
3192
+ orders[0] = first
3193
+ return self.parse_orders(orders, market, since, limit)
3194
+
3195
+ def fetch_orders_by_status(self, status, symbol: Str = None, since: Int = None, limit: Int = None, params={}):
3196
+ self.load_markets()
3197
+ market = None
3198
+ if symbol is not None:
3199
+ market = self.market(symbol)
3200
+ request: dict = {
3201
+ 'order_status': status,
3202
+ }
3203
+ if market is not None:
3204
+ request['product_id'] = market['id']
3205
+ if limit is None:
3206
+ limit = 100
3207
+ request['limit'] = limit
3208
+ if since is not None:
3209
+ request['start_date'] = self.iso8601(since)
3210
+ until = self.safe_integer_n(params, ['until'])
3211
+ if until is not None:
3212
+ params = self.omit(params, ['until'])
3213
+ request['end_date'] = self.iso8601(until)
3214
+ response = self.v3PrivateGetBrokerageOrdersHistoricalBatch(self.extend(request, params))
3215
+ #
3216
+ # {
3217
+ # "orders": [
3218
+ # {
3219
+ # "order_id": "813a53c5-3e39-47bb-863d-2faf685d22d8",
3220
+ # "product_id": "BTC-USDT",
3221
+ # "user_id": "1111111-1111-1111-1111-111111111111",
3222
+ # "order_configuration": {
3223
+ # "market_market_ioc": {
3224
+ # "quote_size": "6.36"
3225
+ # }
3226
+ # },
3227
+ # "side": "BUY",
3228
+ # "client_order_id": "18eb9947-db49-4874-8e7b-39b8fe5f4317",
3229
+ # "status": "FILLED",
3230
+ # "time_in_force": "IMMEDIATE_OR_CANCEL",
3231
+ # "created_time": "2023-01-18T01:37:37.975552Z",
3232
+ # "completion_percentage": "100",
3233
+ # "filled_size": "0.000297920684505",
3234
+ # "average_filled_price": "21220.6399999973697697",
3235
+ # "fee": "",
3236
+ # "number_of_fills": "2",
3237
+ # "filled_value": "6.3220675944333996",
3238
+ # "pending_cancel": False,
3239
+ # "size_in_quote": True,
3240
+ # "total_fees": "0.0379324055666004",
3241
+ # "size_inclusive_of_fees": True,
3242
+ # "total_value_after_fees": "6.36",
3243
+ # "trigger_status": "INVALID_ORDER_TYPE",
3244
+ # "order_type": "MARKET",
3245
+ # "reject_reason": "REJECT_REASON_UNSPECIFIED",
3246
+ # "settled": True,
3247
+ # "product_type": "SPOT",
3248
+ # "reject_message": "",
3249
+ # "cancel_message": "Internal error"
3250
+ # },
3251
+ # ],
3252
+ # "sequence": "0",
3253
+ # "has_next": False,
3254
+ # "cursor": ""
3255
+ # }
3256
+ #
3257
+ orders = self.safe_list(response, 'orders', [])
3258
+ first = self.safe_dict(orders, 0)
3259
+ cursor = self.safe_string(response, 'cursor')
3260
+ if (cursor is not None) and (cursor != ''):
3261
+ first['cursor'] = cursor
3262
+ orders[0] = first
3263
+ return self.parse_orders(orders, market, since, limit)
3264
+
3265
+ def fetch_open_orders(self, symbol: Str = None, since: Int = None, limit: Int = None, params={}) -> List[Order]:
3266
+ """
3267
+ fetches information on all currently open orders
3268
+ :see: https://docs.cloud.coinbase.com/advanced-trade-api/reference/retailbrokerageapi_gethistoricalorders
3269
+ :param str symbol: unified market symbol of the orders
3270
+ :param int [since]: timestamp in ms of the earliest order, default is None
3271
+ :param int [limit]: the maximum number of open order structures to retrieve
3272
+ :param dict [params]: extra parameters specific to the exchange API endpoint
3273
+ :param boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
3274
+ :param int [params.until]: the latest time in ms to fetch trades for
3275
+ :returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
3276
+ """
3277
+ self.load_markets()
3278
+ paginate = False
3279
+ paginate, params = self.handle_option_and_params(params, 'fetchOpenOrders', 'paginate')
3280
+ if paginate:
3281
+ return self.fetch_paginated_call_cursor('fetchOpenOrders', symbol, since, limit, params, 'cursor', 'cursor', None, 100)
3282
+ return self.fetch_orders_by_status('OPEN', symbol, since, limit, params)
3283
+
3284
+ def fetch_closed_orders(self, symbol: Str = None, since: Int = None, limit: Int = None, params={}) -> List[Order]:
3285
+ """
3286
+ fetches information on multiple closed orders made by the user
3287
+ :see: https://docs.cloud.coinbase.com/advanced-trade-api/reference/retailbrokerageapi_gethistoricalorders
3288
+ :param str symbol: unified market symbol of the orders
3289
+ :param int [since]: timestamp in ms of the earliest order, default is None
3290
+ :param int [limit]: the maximum number of closed order structures to retrieve
3291
+ :param dict [params]: extra parameters specific to the exchange API endpoint
3292
+ :param boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
3293
+ :param int [params.until]: the latest time in ms to fetch trades for
3294
+ :returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
3295
+ """
3296
+ self.load_markets()
3297
+ paginate = False
3298
+ paginate, params = self.handle_option_and_params(params, 'fetchClosedOrders', 'paginate')
3299
+ if paginate:
3300
+ return self.fetch_paginated_call_cursor('fetchClosedOrders', symbol, since, limit, params, 'cursor', 'cursor', None, 100)
3301
+ return self.fetch_orders_by_status('FILLED', symbol, since, limit, params)
3302
+
3303
+ def fetch_canceled_orders(self, symbol: Str = None, since: Int = None, limit: Int = None, params={}):
3304
+ """
3305
+ fetches information on multiple canceled orders made by the user
3306
+ :see: https://docs.cloud.coinbase.com/advanced-trade-api/reference/retailbrokerageapi_gethistoricalorders
3307
+ :param str symbol: unified market symbol of the orders
3308
+ :param int [since]: timestamp in ms of the earliest order, default is None
3309
+ :param int [limit]: the maximum number of canceled order structures to retrieve
3310
+ :param dict [params]: extra parameters specific to the exchange API endpoint
3311
+ :returns dict: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
3312
+ """
3313
+ return self.fetch_orders_by_status('CANCELLED', symbol, since, limit, params)
3314
+
3315
+ def fetch_ohlcv(self, symbol: str, timeframe='1m', since: Int = None, limit: Int = None, params={}) -> List[list]:
3316
+ """
3317
+ fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
3318
+ :see: https://docs.cloud.coinbase.com/advanced-trade-api/reference/retailbrokerageapi_getpubliccandles
3319
+ :param str symbol: unified symbol of the market to fetch OHLCV data for
3320
+ :param str timeframe: the length of time each candle represents
3321
+ :param int [since]: timestamp in ms of the earliest candle to fetch
3322
+ :param int [limit]: the maximum amount of candles to fetch, not used by coinbase
3323
+ :param dict [params]: extra parameters specific to the exchange API endpoint
3324
+ :param int [params.until]: the latest time in ms to fetch trades for
3325
+ :param boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
3326
+ :param boolean [params.usePrivate]: default False, when True will use the private endpoint to fetch the candles
3327
+ :returns int[][]: A list of candles ordered, open, high, low, close, volume
3328
+ """
3329
+ self.load_markets()
3330
+ maxLimit = 300
3331
+ limit = maxLimit if (limit is None) else min(limit, maxLimit)
3332
+ paginate = False
3333
+ paginate, params = self.handle_option_and_params(params, 'fetchOHLCV', 'paginate', False)
3334
+ if paginate:
3335
+ return self.fetch_paginated_call_deterministic('fetchOHLCV', symbol, since, limit, timeframe, params, maxLimit - 1)
3336
+ market = self.market(symbol)
3337
+ request: dict = {
3338
+ 'product_id': market['id'],
3339
+ 'granularity': self.safe_string(self.timeframes, timeframe, timeframe),
3340
+ }
3341
+ until = self.safe_integer_n(params, ['until', 'end'])
3342
+ params = self.omit(params, ['until'])
3343
+ duration = self.parse_timeframe(timeframe)
3344
+ requestedDuration = limit * duration
3345
+ sinceString = None
3346
+ if since is not None:
3347
+ sinceString = self.number_to_string(self.parse_to_int(since / 1000))
3348
+ else:
3349
+ now = str(self.seconds())
3350
+ sinceString = Precise.string_sub(now, str(requestedDuration))
3351
+ request['start'] = sinceString
3352
+ if until is not None:
3353
+ request['end'] = self.number_to_string(self.parse_to_int(until / 1000))
3354
+ else:
3355
+ # 300 candles max
3356
+ request['end'] = Precise.string_add(sinceString, str(requestedDuration))
3357
+ response = None
3358
+ usePrivate = False
3359
+ usePrivate, params = self.handle_option_and_params(params, 'fetchOHLCV', 'usePrivate', False)
3360
+ if usePrivate:
3361
+ response = self.v3PrivateGetBrokerageProductsProductIdCandles(self.extend(request, params))
3362
+ else:
3363
+ response = self.v3PublicGetBrokerageMarketProductsProductIdCandles(self.extend(request, params))
3364
+ #
3365
+ # {
3366
+ # "candles": [
3367
+ # {
3368
+ # "start": "1673391780",
3369
+ # "low": "17414.36",
3370
+ # "high": "17417.99",
3371
+ # "open": "17417.74",
3372
+ # "close": "17417.38",
3373
+ # "volume": "1.87780853"
3374
+ # },
3375
+ # ]
3376
+ # }
3377
+ #
3378
+ candles = self.safe_list(response, 'candles', [])
3379
+ return self.parse_ohlcvs(candles, market, timeframe, since, limit)
3380
+
3381
+ def parse_ohlcv(self, ohlcv, market: Market = None) -> list:
3382
+ #
3383
+ # [
3384
+ # {
3385
+ # "start": "1673391780",
3386
+ # "low": "17414.36",
3387
+ # "high": "17417.99",
3388
+ # "open": "17417.74",
3389
+ # "close": "17417.38",
3390
+ # "volume": "1.87780853"
3391
+ # },
3392
+ # ]
3393
+ #
3394
+ return [
3395
+ self.safe_timestamp(ohlcv, 'start'),
3396
+ self.safe_number(ohlcv, 'open'),
3397
+ self.safe_number(ohlcv, 'high'),
3398
+ self.safe_number(ohlcv, 'low'),
3399
+ self.safe_number(ohlcv, 'close'),
3400
+ self.safe_number(ohlcv, 'volume'),
3401
+ ]
3402
+
3403
+ def fetch_trades(self, symbol: str, since: Int = None, limit: Int = None, params={}) -> List[Trade]:
3404
+ """
3405
+ get the list of most recent trades for a particular symbol
3406
+ :see: https://docs.cloud.coinbase.com/advanced-trade-api/reference/retailbrokerageapi_getpublicmarkettrades
3407
+ :param str symbol: unified market symbol of the trades
3408
+ :param int [since]: not used by coinbase fetchTrades
3409
+ :param int [limit]: the maximum number of trade structures to fetch
3410
+ :param dict [params]: extra parameters specific to the exchange API endpoint
3411
+ :param boolean [params.usePrivate]: default False, when True will use the private endpoint to fetch the trades
3412
+ :returns Trade[]: a list of `trade structures <https://docs.ccxt.com/#/?id=public-trades>`
3413
+ """
3414
+ self.load_markets()
3415
+ market = self.market(symbol)
3416
+ request: dict = {
3417
+ 'product_id': market['id'],
3418
+ }
3419
+ if since is not None:
3420
+ request['start'] = self.number_to_string(self.parse_to_int(since / 1000))
3421
+ if limit is not None:
3422
+ request['limit'] = min(limit, 1000)
3423
+ until = None
3424
+ until, params = self.handle_option_and_params(params, 'fetchTrades', 'until')
3425
+ if until is not None:
3426
+ request['end'] = self.number_to_string(self.parse_to_int(until / 1000))
3427
+ elif since is not None:
3428
+ raise ArgumentsRequired(self.id + ' fetchTrades() requires a `until` parameter when you use `since` argument')
3429
+ response = None
3430
+ usePrivate = False
3431
+ usePrivate, params = self.handle_option_and_params(params, 'fetchTrades', 'usePrivate', False)
3432
+ if usePrivate:
3433
+ response = self.v3PrivateGetBrokerageProductsProductIdTicker(self.extend(request, params))
3434
+ else:
3435
+ response = self.v3PublicGetBrokerageMarketProductsProductIdTicker(self.extend(request, params))
3436
+ #
3437
+ # {
3438
+ # "trades": [
3439
+ # {
3440
+ # "trade_id": "10092327",
3441
+ # "product_id": "BTC-USDT",
3442
+ # "price": "17488.12",
3443
+ # "size": "0.0000623",
3444
+ # "time": "2023-01-11T00:52:37.557001Z",
3445
+ # "side": "BUY",
3446
+ # "bid": "",
3447
+ # "ask": ""
3448
+ # },
3449
+ # ]
3450
+ # }
3451
+ #
3452
+ trades = self.safe_list(response, 'trades', [])
3453
+ return self.parse_trades(trades, market, since, limit)
3454
+
3455
+ def fetch_my_trades(self, symbol: Str = None, since: Int = None, limit: Int = None, params={}):
3456
+ """
3457
+ fetch all trades made by the user
3458
+ :see: https://docs.cloud.coinbase.com/advanced-trade-api/reference/retailbrokerageapi_getfills
3459
+ :param str symbol: unified market symbol of the trades
3460
+ :param int [since]: timestamp in ms of the earliest order, default is None
3461
+ :param int [limit]: the maximum number of trade structures to fetch
3462
+ :param dict [params]: extra parameters specific to the exchange API endpoint
3463
+ :param int [params.until]: the latest time in ms to fetch trades for
3464
+ :param boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
3465
+ :returns Trade[]: a list of `trade structures <https://docs.ccxt.com/#/?id=trade-structure>`
3466
+ """
3467
+ self.load_markets()
3468
+ paginate = False
3469
+ paginate, params = self.handle_option_and_params(params, 'fetchMyTrades', 'paginate')
3470
+ if paginate:
3471
+ return self.fetch_paginated_call_cursor('fetchMyTrades', symbol, since, limit, params, 'cursor', 'cursor', None, 100)
3472
+ market = None
3473
+ if symbol is not None:
3474
+ market = self.market(symbol)
3475
+ request: dict = {}
3476
+ if market is not None:
3477
+ request['product_id'] = market['id']
3478
+ if limit is not None:
3479
+ request['limit'] = limit
3480
+ if since is not None:
3481
+ request['start_sequence_timestamp'] = self.iso8601(since)
3482
+ until = self.safe_integer_n(params, ['until'])
3483
+ if until is not None:
3484
+ params = self.omit(params, ['until'])
3485
+ request['end_sequence_timestamp'] = self.iso8601(until)
3486
+ response = self.v3PrivateGetBrokerageOrdersHistoricalFills(self.extend(request, params))
3487
+ #
3488
+ # {
3489
+ # "fills": [
3490
+ # {
3491
+ # "entry_id": "b88b82cc89e326a2778874795102cbafd08dd979a2a7a3c69603fc4c23c2e010",
3492
+ # "trade_id": "cdc39e45-bbd3-44ec-bf02-61742dfb16a1",
3493
+ # "order_id": "813a53c5-3e39-47bb-863d-2faf685d22d8",
3494
+ # "trade_time": "2023-01-18T01:37:38.091377090Z",
3495
+ # "trade_type": "FILL",
3496
+ # "price": "21220.64",
3497
+ # "size": "0.0046830664333996",
3498
+ # "commission": "0.0000280983986004",
3499
+ # "product_id": "BTC-USDT",
3500
+ # "sequence_timestamp": "2023-01-18T01:37:38.092520Z",
3501
+ # "liquidity_indicator": "UNKNOWN_LIQUIDITY_INDICATOR",
3502
+ # "size_in_quote": True,
3503
+ # "user_id": "1111111-1111-1111-1111-111111111111",
3504
+ # "side": "BUY"
3505
+ # },
3506
+ # ],
3507
+ # "cursor": ""
3508
+ # }
3509
+ #
3510
+ trades = self.safe_list(response, 'fills', [])
3511
+ first = self.safe_dict(trades, 0)
3512
+ cursor = self.safe_string(response, 'cursor')
3513
+ if (cursor is not None) and (cursor != ''):
3514
+ first['cursor'] = cursor
3515
+ trades[0] = first
3516
+ return self.parse_trades(trades, market, since, limit)
3517
+
3518
+ def fetch_order_book(self, symbol: str, limit: Int = None, params={}) -> OrderBook:
3519
+ """
3520
+ fetches information on open orders with bid(buy) and ask(sell) prices, volumes and other data
3521
+ :see: https://docs.cloud.coinbase.com/advanced-trade-api/reference/retailbrokerageapi_getpublicproductbook
3522
+ :param str symbol: unified symbol of the market to fetch the order book for
3523
+ :param int [limit]: the maximum amount of order book entries to return
3524
+ :param dict [params]: extra parameters specific to the exchange API endpoint
3525
+ :param boolean [params.usePrivate]: default False, when True will use the private endpoint to fetch the order book
3526
+ :returns dict: A dictionary of `order book structures <https://docs.ccxt.com/#/?id=order-book-structure>` indexed by market symbols
3527
+ """
3528
+ self.load_markets()
3529
+ market = self.market(symbol)
3530
+ request: dict = {
3531
+ 'product_id': market['id'],
3532
+ }
3533
+ if limit is not None:
3534
+ request['limit'] = limit
3535
+ response = None
3536
+ usePrivate = False
3537
+ usePrivate, params = self.handle_option_and_params(params, 'fetchOrderBook', 'usePrivate', False)
3538
+ if usePrivate:
3539
+ response = self.v3PrivateGetBrokerageProductBook(self.extend(request, params))
3540
+ else:
3541
+ response = self.v3PublicGetBrokerageMarketProductBook(self.extend(request, params))
3542
+ #
3543
+ # {
3544
+ # "pricebook": {
3545
+ # "product_id": "BTC-USDT",
3546
+ # "bids": [
3547
+ # {
3548
+ # "price": "30757.85",
3549
+ # "size": "0.115"
3550
+ # },
3551
+ # ],
3552
+ # "asks": [
3553
+ # {
3554
+ # "price": "30759.07",
3555
+ # "size": "0.04877659"
3556
+ # },
3557
+ # ],
3558
+ # "time": "2023-06-30T04:02:40.533606Z"
3559
+ # }
3560
+ # }
3561
+ #
3562
+ data = self.safe_dict(response, 'pricebook', {})
3563
+ time = self.safe_string(data, 'time')
3564
+ timestamp = self.parse8601(time)
3565
+ return self.parse_order_book(data, symbol, timestamp, 'bids', 'asks', 'price', 'size')
3566
+
3567
+ def fetch_bids_asks(self, symbols: Strings = None, params={}):
3568
+ """
3569
+ fetches the bid and ask price and volume for multiple markets
3570
+ :see: https://docs.cloud.coinbase.com/advanced-trade-api/reference/retailbrokerageapi_getbestbidask
3571
+ :param str[] [symbols]: unified symbols of the markets to fetch the bids and asks for, all markets are returned if not assigned
3572
+ :param dict [params]: extra parameters specific to the exchange API endpoint
3573
+ :returns dict: a dictionary of `ticker structures <https://docs.ccxt.com/#/?id=ticker-structure>`
3574
+ """
3575
+ self.load_markets()
3576
+ symbols = self.market_symbols(symbols)
3577
+ request: dict = {}
3578
+ if symbols is not None:
3579
+ request['product_ids'] = self.market_ids(symbols)
3580
+ response = self.v3PrivateGetBrokerageBestBidAsk(self.extend(request, params))
3581
+ #
3582
+ # {
3583
+ # "pricebooks": [
3584
+ # {
3585
+ # "product_id": "TRAC-EUR",
3586
+ # "bids": [
3587
+ # {
3588
+ # "price": "0.2384",
3589
+ # "size": "386.1"
3590
+ # }
3591
+ # ],
3592
+ # "asks": [
3593
+ # {
3594
+ # "price": "0.2406",
3595
+ # "size": "672"
3596
+ # }
3597
+ # ],
3598
+ # "time": "2023-06-30T07:15:24.656044Z"
3599
+ # },
3600
+ # ]
3601
+ # }
3602
+ #
3603
+ tickers = self.safe_list(response, 'pricebooks', [])
3604
+ return self.parse_tickers(tickers, symbols)
3605
+
3606
+ def withdraw(self, code: str, amount: float, address: str, tag=None, params={}):
3607
+ """
3608
+ make a withdrawal
3609
+ :see: https://docs.cloud.coinbase.com/sign-in-with-coinbase/docs/api-transactions#send-money
3610
+ :param str code: unified currency code
3611
+ :param float amount: the amount to withdraw
3612
+ :param str address: the address to withdraw to
3613
+ :param str [tag]: an optional tag for the withdrawal
3614
+ :param dict [params]: extra parameters specific to the exchange API endpoint
3615
+ :returns dict: a `transaction structure <https://docs.ccxt.com/#/?id=transaction-structure>`
3616
+ """
3617
+ tag, params = self.handle_withdraw_tag_and_params(tag, params)
3618
+ self.check_address(address)
3619
+ self.load_markets()
3620
+ currency = self.currency(code)
3621
+ accountId = self.safe_string_2(params, 'account_id', 'accountId')
3622
+ params = self.omit(params, ['account_id', 'accountId'])
3623
+ if accountId is None:
3624
+ if code is None:
3625
+ raise ArgumentsRequired(self.id + ' withdraw() requires an account_id(or accountId) parameter OR a currency code argument')
3626
+ accountId = self.find_account_id(code, params)
3627
+ if accountId is None:
3628
+ raise ExchangeError(self.id + ' withdraw() could not find account id for ' + code)
3629
+ request: dict = {
3630
+ 'account_id': accountId,
3631
+ 'type': 'send',
3632
+ 'to': address,
3633
+ 'amount': amount,
3634
+ 'currency': currency['id'],
3635
+ }
3636
+ if tag is not None:
3637
+ request['destination_tag'] = tag
3638
+ response = self.v2PrivatePostAccountsAccountIdTransactions(self.extend(request, params))
3639
+ #
3640
+ # {
3641
+ # "data": {
3642
+ # "id": "a1794ecf-5693-55fa-70cf-ef731748ed82",
3643
+ # "type": "send",
3644
+ # "status": "pending",
3645
+ # "amount": {
3646
+ # "amount": "-14.008308",
3647
+ # "currency": "USDC"
3648
+ # },
3649
+ # "native_amount": {
3650
+ # "amount": "-18.74",
3651
+ # "currency": "CAD"
3652
+ # },
3653
+ # "description": null,
3654
+ # "created_at": "2024-01-12T01:27:31Z",
3655
+ # "updated_at": "2024-01-12T01:27:31Z",
3656
+ # "resource": "transaction",
3657
+ # "resource_path": "/v2/accounts/a34bgfad-ed67-538b-bffc-730c98c10da0/transactions/a1794ecf-5693-55fa-70cf-ef731748ed82",
3658
+ # "instant_exchange": False,
3659
+ # "network": {
3660
+ # "status": "pending",
3661
+ # "status_description": "Pending(est. less than 10 minutes)",
3662
+ # "transaction_fee": {
3663
+ # "amount": "4.008308",
3664
+ # "currency": "USDC"
3665
+ # },
3666
+ # "transaction_amount": {
3667
+ # "amount": "10.000000",
3668
+ # "currency": "USDC"
3669
+ # },
3670
+ # "confirmations": 0
3671
+ # },
3672
+ # "to": {
3673
+ # "resource": "ethereum_address",
3674
+ # "address": "0x9...",
3675
+ # "currency": "USDC",
3676
+ # "address_info": {
3677
+ # "address": "0x9..."
3678
+ # }
3679
+ # },
3680
+ # "idem": "748d8591-dg9a-7831-a45b-crd61dg78762",
3681
+ # "details": {
3682
+ # "title": "Sent USDC",
3683
+ # "subtitle": "To USDC address on Ethereum network",
3684
+ # "header": "Sent 14.008308 USDC($18.74)",
3685
+ # "health": "warning"
3686
+ # },
3687
+ # "hide_native_amount": False
3688
+ # }
3689
+ # }
3690
+ #
3691
+ data = self.safe_dict(response, 'data', {})
3692
+ return self.parse_transaction(data, currency)
3693
+
3694
+ def fetch_deposit_addresses_by_network(self, code: str, params={}):
3695
+ """
3696
+ fetch the deposit address for a currency associated with self account
3697
+ :see: https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_postcoinbaseaccountaddresses
3698
+ :param str code: unified currency code
3699
+ :param dict [params]: extra parameters specific to the exchange API endpoint
3700
+ :returns dict: an `address structure <https://docs.ccxt.com/#/?id=address-structure>`
3701
+ """
3702
+ self.load_markets()
3703
+ currency = self.currency(code)
3704
+ request = None
3705
+ request, params = self.prepare_account_request_with_currency_code(currency['code'])
3706
+ response = self.v2PrivateGetAccountsAccountIdAddresses(self.extend(request, params))
3707
+ #
3708
+ # {
3709
+ # pagination: {
3710
+ # ending_before: null,
3711
+ # starting_after: null,
3712
+ # previous_ending_before: null,
3713
+ # next_starting_after: null,
3714
+ # limit: '25',
3715
+ # order: 'desc',
3716
+ # previous_uri: null,
3717
+ # next_uri: null
3718
+ # },
3719
+ # data: [
3720
+ # {
3721
+ # id: '64ceb5f1-5fa2-5310-a4ff-9fd46271003d',
3722
+ # address: '5xjPKeAXpnhA2kHyinvdVeui6RXVdEa3B2J3SCAwiKnk',
3723
+ # address_info: {address: '5xjPKeAXpnhA2kHyinvdVeui6RXVdEa3B2J3SCAwiKnk'},
3724
+ # name: null,
3725
+ # created_at: '2023-05-29T21:12:12Z',
3726
+ # updated_at: '2023-05-29T21:12:12Z',
3727
+ # network: 'solana',
3728
+ # uri_scheme: 'solana',
3729
+ # resource: 'address',
3730
+ # resource_path: '/v2/accounts/a7b3d387-bfb8-5ce7-b8da-1f507e81cf25/addresses/64ceb5f1-5fa2-5310-a4ff-9fd46271003d',
3731
+ # warnings: [
3732
+ # {
3733
+ # type: 'correct_address_warning',
3734
+ # title: 'This is an ERC20 USDC address.',
3735
+ # details: 'Only send ERC20 USD Coin(USDC) to self address.',
3736
+ # image_url: 'https://www.coinbase.com/assets/addresses/global-receive-warning-a3d91807e61c717e5a38d270965003dcc025ca8a3cea40ec3d7835b7c86087fa.png',
3737
+ # options: [{text: 'I understand', style: 'primary', id: 'dismiss'}]
3738
+ # }
3739
+ # ],
3740
+ # qr_code_image_url: 'https://static-assets.coinbase.com/p2p/l2/asset_network_combinations/v5/usdc-solana.png',
3741
+ # address_label: 'USDC address(Solana)',
3742
+ # default_receive: True,
3743
+ # deposit_uri: 'solana:5xjPKeAXpnhA2kHyinvdVeui6RXVdEa3B2J3SCAwiKnk?spl-token=EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v',
3744
+ # callback_url: null,
3745
+ # share_address_copy: {
3746
+ # line1: '5xjPKeAXpnhA2kHyinvdVeui6RXVdEa3B2J3SCAwiKnk',
3747
+ # line2: 'This address can only receive USDC-SPL from Solana network. Don’t send USDC from other networks, other SPL tokens or NFTs, or it may result in a loss of funds.'
3748
+ # },
3749
+ # receive_subtitle: 'ERC-20',
3750
+ # inline_warning: {
3751
+ # text: 'This address can only receive USDC-SPL from Solana network. Don’t send USDC from other networks, other SPL tokens or NFTs, or it may result in a loss of funds.',
3752
+ # tooltip: {
3753
+ # title: 'USDC(Solana)',
3754
+ # subtitle: 'This address can only receive USDC-SPL from Solana network.'
3755
+ # }
3756
+ # }
3757
+ # },
3758
+ # ...
3759
+ # ]
3760
+ # }
3761
+ #
3762
+ data = self.safe_list(response, 'data', [])
3763
+ addressStructures = self.parse_deposit_addresses(data, None, False)
3764
+ return self.index_by(addressStructures, 'network')
3765
+
3766
+ def parse_deposit_address(self, depositAddress, currency: Currency = None):
3767
+ #
3768
+ # {
3769
+ # id: '64ceb5f1-5fa2-5310-a4ff-9fd46271003d',
3770
+ # address: '5xjPKeAXpnhA2kHyinvdVeui6RXVdEa3B2J3SCAwiKnk',
3771
+ # address_info: {
3772
+ # address: 'GCF74576I7AQ56SLMKBQAP255EGUOWCRVII3S44KEXVNJEOIFVBDMXVL',
3773
+ # destination_tag: '3722061866'
3774
+ # },
3775
+ # name: null,
3776
+ # created_at: '2023-05-29T21:12:12Z',
3777
+ # updated_at: '2023-05-29T21:12:12Z',
3778
+ # network: 'solana',
3779
+ # uri_scheme: 'solana',
3780
+ # resource: 'address',
3781
+ # resource_path: '/v2/accounts/a7b3d387-bfb8-5ce7-b8da-1f507e81cf25/addresses/64ceb5f1-5fa2-5310-a4ff-9fd46271003d',
3782
+ # warnings: [
3783
+ # {
3784
+ # type: 'correct_address_warning',
3785
+ # title: 'This is an ERC20 USDC address.',
3786
+ # details: 'Only send ERC20 USD Coin(USDC) to self address.',
3787
+ # image_url: 'https://www.coinbase.com/assets/addresses/global-receive-warning-a3d91807e61c717e5a38d270965003dcc025ca8a3cea40ec3d7835b7c86087fa.png',
3788
+ # options: [{text: 'I understand', style: 'primary', id: 'dismiss'}]
3789
+ # }
3790
+ # ],
3791
+ # qr_code_image_url: 'https://static-assets.coinbase.com/p2p/l2/asset_network_combinations/v5/usdc-solana.png',
3792
+ # address_label: 'USDC address(Solana)',
3793
+ # default_receive: True,
3794
+ # deposit_uri: 'solana:5xjPKeAXpnhA2kHyinvdVeui6RXVdEa3B2J3SCAwiKnk?spl-token=EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v',
3795
+ # callback_url: null,
3796
+ # share_address_copy: {
3797
+ # line1: '5xjPKeAXpnhA2kHyinvdVeui6RXVdEa3B2J3SCAwiKnk',
3798
+ # line2: 'This address can only receive USDC-SPL from Solana network. Don’t send USDC from other networks, other SPL tokens or NFTs, or it may result in a loss of funds.'
3799
+ # },
3800
+ # receive_subtitle: 'ERC-20',
3801
+ # inline_warning: {
3802
+ # text: 'This address can only receive USDC-SPL from Solana network. Don’t send USDC from other networks, other SPL tokens or NFTs, or it may result in a loss of funds.',
3803
+ # tooltip: {
3804
+ # title: 'USDC(Solana)',
3805
+ # subtitle: 'This address can only receive USDC-SPL from Solana network.'
3806
+ # }
3807
+ # }
3808
+ # }
3809
+ #
3810
+ address = self.safe_string(depositAddress, 'address')
3811
+ self.check_address(address)
3812
+ networkId = self.safe_string(depositAddress, 'network')
3813
+ code = self.safe_currency_code(None, currency)
3814
+ addressLabel = self.safe_string(depositAddress, 'address_label')
3815
+ splitAddressLabel = addressLabel.split(' ')
3816
+ marketId = self.safe_string(splitAddressLabel, 0)
3817
+ addressInfo = self.safe_dict(depositAddress, 'address_info')
3818
+ return {
3819
+ 'info': depositAddress,
3820
+ 'currency': self.safe_currency_code(marketId, currency),
3821
+ 'address': address,
3822
+ 'tag': self.safe_string(addressInfo, 'destination_tag'),
3823
+ 'network': self.network_id_to_code(networkId, code),
3824
+ }
3825
+
3826
+ def deposit(self, code: str, amount: float, id: str, params={}):
3827
+ """
3828
+ make a deposit
3829
+ :see: https://docs.cloud.coinbase.com/sign-in-with-coinbase/docs/api-deposits#deposit-funds
3830
+ :param str code: unified currency code
3831
+ :param float amount: the amount to deposit
3832
+ :param str id: the payment method id to be used for the deposit, can be retrieved from v2PrivateGetPaymentMethods
3833
+ :param dict [params]: extra parameters specific to the exchange API endpoint
3834
+ :param str [params.accountId]: the id of the account to deposit into
3835
+ :returns dict: a `transaction structure <https://docs.ccxt.com/#/?id=transaction-structure>`
3836
+ """
3837
+ self.load_markets()
3838
+ accountId = self.safe_string_2(params, 'account_id', 'accountId')
3839
+ params = self.omit(params, ['account_id', 'accountId'])
3840
+ if accountId is None:
3841
+ if code is None:
3842
+ raise ArgumentsRequired(self.id + ' deposit() requires an account_id(or accountId) parameter OR a currency code argument')
3843
+ accountId = self.find_account_id(code, params)
3844
+ if accountId is None:
3845
+ raise ExchangeError(self.id + ' deposit() could not find account id for ' + code)
3846
+ request: dict = {
3847
+ 'account_id': accountId,
3848
+ 'amount': self.number_to_string(amount),
3849
+ 'currency': code.upper(), # need to use code in case depositing USD etc.
3850
+ 'payment_method': id,
3851
+ }
3852
+ response = self.v2PrivatePostAccountsAccountIdDeposits(self.extend(request, params))
3853
+ #
3854
+ # {
3855
+ # "data": {
3856
+ # "id": "67e0eaec-07d7-54c4-a72c-2e92826897df",
3857
+ # "status": "created",
3858
+ # "payment_method": {
3859
+ # "id": "83562370-3e5c-51db-87da-752af5ab9559",
3860
+ # "resource": "payment_method",
3861
+ # "resource_path": "/v2/payment-methods/83562370-3e5c-51db-87da-752af5ab9559"
3862
+ # },
3863
+ # "transaction": {
3864
+ # "id": "441b9494-b3f0-5b98-b9b0-4d82c21c252a",
3865
+ # "resource": "transaction",
3866
+ # "resource_path": "/v2/accounts/2bbf394c-193b-5b2a-9155-3b4732659ede/transactions/441b9494-b3f0-5b98-b9b0-4d82c21c252a"
3867
+ # },
3868
+ # "amount": {
3869
+ # "amount": "10.00",
3870
+ # "currency": "USD"
3871
+ # },
3872
+ # "subtotal": {
3873
+ # "amount": "10.00",
3874
+ # "currency": "USD"
3875
+ # },
3876
+ # "created_at": "2015-01-31T20:49:02Z",
3877
+ # "updated_at": "2015-02-11T16:54:02-08:00",
3878
+ # "resource": "deposit",
3879
+ # "resource_path": "/v2/accounts/2bbf394c-193b-5b2a-9155-3b4732659ede/deposits/67e0eaec-07d7-54c4-a72c-2e92826897df",
3880
+ # "committed": True,
3881
+ # "fee": {
3882
+ # "amount": "0.00",
3883
+ # "currency": "USD"
3884
+ # },
3885
+ # "payout_at": "2015-02-18T16:54:00-08:00"
3886
+ # }
3887
+ # }
3888
+ #
3889
+ data = self.safe_dict(response, 'data', {})
3890
+ return self.parse_transaction(data)
3891
+
3892
+ def fetch_deposit(self, id: str, code: Str = None, params={}):
3893
+ """
3894
+ fetch information on a deposit, fiat only, for crypto transactions use fetchLedger
3895
+ :see: https://docs.cloud.coinbase.com/sign-in-with-coinbase/docs/api-deposits#show-deposit
3896
+ :param str id: deposit id
3897
+ :param str [code]: unified currency code
3898
+ :param dict [params]: extra parameters specific to the exchange API endpoint
3899
+ :param str [params.accountId]: the id of the account that the funds were deposited into
3900
+ :returns dict: a `transaction structure <https://docs.ccxt.com/#/?id=transaction-structure>`
3901
+ """
3902
+ self.load_markets()
3903
+ accountId = self.safe_string_2(params, 'account_id', 'accountId')
3904
+ params = self.omit(params, ['account_id', 'accountId'])
3905
+ if accountId is None:
3906
+ if code is None:
3907
+ raise ArgumentsRequired(self.id + ' fetchDeposit() requires an account_id(or accountId) parameter OR a currency code argument')
3908
+ accountId = self.find_account_id(code, params)
3909
+ if accountId is None:
3910
+ raise ExchangeError(self.id + ' fetchDeposit() could not find account id for ' + code)
3911
+ request: dict = {
3912
+ 'account_id': accountId,
3913
+ 'deposit_id': id,
3914
+ }
3915
+ response = self.v2PrivateGetAccountsAccountIdDepositsDepositId(self.extend(request, params))
3916
+ #
3917
+ # {
3918
+ # "data": {
3919
+ # "id": "67e0eaec-07d7-54c4-a72c-2e92826897df",
3920
+ # "status": "completed",
3921
+ # "payment_method": {
3922
+ # "id": "83562370-3e5c-51db-87da-752af5ab9559",
3923
+ # "resource": "payment_method",
3924
+ # "resource_path": "/v2/payment-methods/83562370-3e5c-51db-87da-752af5ab9559"
3925
+ # },
3926
+ # "transaction": {
3927
+ # "id": "441b9494-b3f0-5b98-b9b0-4d82c21c252a",
3928
+ # "resource": "transaction",
3929
+ # "resource_path": "/v2/accounts/2bbf394c-193b-5b2a-9155-3b4732659ede/transactions/441b9494-b3f0-5b98-b9b0-4d82c21c252a"
3930
+ # },
3931
+ # "amount": {
3932
+ # "amount": "10.00",
3933
+ # "currency": "USD"
3934
+ # },
3935
+ # "subtotal": {
3936
+ # "amount": "10.00",
3937
+ # "currency": "USD"
3938
+ # },
3939
+ # "created_at": "2015-01-31T20:49:02Z",
3940
+ # "updated_at": "2015-02-11T16:54:02-08:00",
3941
+ # "resource": "deposit",
3942
+ # "resource_path": "/v2/accounts/2bbf394c-193b-5b2a-9155-3b4732659ede/deposits/67e0eaec-07d7-54c4-a72c-2e92826897df",
3943
+ # "committed": True,
3944
+ # "fee": {
3945
+ # "amount": "0.00",
3946
+ # "currency": "USD"
3947
+ # },
3948
+ # "payout_at": "2015-02-18T16:54:00-08:00"
3949
+ # }
3950
+ # }
3951
+ #
3952
+ data = self.safe_dict(response, 'data', {})
3953
+ return self.parse_transaction(data)
3954
+
3955
+ def fetch_convert_quote(self, fromCode: str, toCode: str, amount: Num = None, params={}) -> Conversion:
3956
+ """
3957
+ fetch a quote for converting from one currency to another
3958
+ :see: https://docs.cloud.coinbase.com/advanced-trade-api/reference/retailbrokerageapi_createconvertquote
3959
+ :param str fromCode: the currency that you want to sell and convert from
3960
+ :param str toCode: the currency that you want to buy and convert into
3961
+ :param float [amount]: how much you want to trade in units of the from currency
3962
+ :param dict [params]: extra parameters specific to the exchange API endpoint
3963
+ :param dict [params.trade_incentive_metadata]: an object to fill in user incentive data
3964
+ :param str [params.trade_incentive_metadata.user_incentive_id]: the id of the incentive
3965
+ :param str [params.trade_incentive_metadata.code_val]: the code value of the incentive
3966
+ :returns dict: a `conversion structure <https://docs.ccxt.com/#/?id=conversion-structure>`
3967
+ """
3968
+ self.load_markets()
3969
+ request: dict = {
3970
+ 'from_account': fromCode,
3971
+ 'to_account': toCode,
3972
+ 'amount': self.number_to_string(amount),
3973
+ }
3974
+ response = self.v3PrivatePostBrokerageConvertQuote(self.extend(request, params))
3975
+ data = self.safe_dict(response, 'trade', {})
3976
+ return self.parse_conversion(data)
3977
+
3978
+ def create_convert_trade(self, id: str, fromCode: str, toCode: str, amount: Num = None, params={}) -> Conversion:
3979
+ """
3980
+ convert from one currency to another
3981
+ :see: https://docs.cloud.coinbase.com/advanced-trade-api/reference/retailbrokerageapi_commitconverttrade
3982
+ :param str id: the id of the trade that you want to make
3983
+ :param str fromCode: the currency that you want to sell and convert from
3984
+ :param str toCode: the currency that you want to buy and convert into
3985
+ :param float [amount]: how much you want to trade in units of the from currency
3986
+ :param dict [params]: extra parameters specific to the exchange API endpoint
3987
+ :returns dict: a `conversion structure <https://docs.ccxt.com/#/?id=conversion-structure>`
3988
+ """
3989
+ self.load_markets()
3990
+ request: dict = {
3991
+ 'trade_id': id,
3992
+ 'from_account': fromCode,
3993
+ 'to_account': toCode,
3994
+ }
3995
+ response = self.v3PrivatePostBrokerageConvertTradeTradeId(self.extend(request, params))
3996
+ data = self.safe_dict(response, 'trade', {})
3997
+ return self.parse_conversion(data)
3998
+
3999
+ def fetch_convert_trade(self, id: str, code: Str = None, params={}) -> Conversion:
4000
+ """
4001
+ fetch the data for a conversion trade
4002
+ :see: https://docs.cloud.coinbase.com/advanced-trade-api/reference/retailbrokerageapi_getconverttrade
4003
+ :param str id: the id of the trade that you want to commit
4004
+ :param str code: the unified currency code that was converted from
4005
+ :param dict [params]: extra parameters specific to the exchange API endpoint
4006
+ :param strng params['toCode']: the unified currency code that was converted into
4007
+ :returns dict: a `conversion structure <https://docs.ccxt.com/#/?id=conversion-structure>`
4008
+ """
4009
+ self.load_markets()
4010
+ if code is None:
4011
+ raise ArgumentsRequired(self.id + ' fetchConvertTrade() requires a code argument')
4012
+ toCode = self.safe_string(params, 'toCode')
4013
+ if toCode is None:
4014
+ raise ArgumentsRequired(self.id + ' fetchConvertTrade() requires a toCode parameter')
4015
+ params = self.omit(params, 'toCode')
4016
+ request: dict = {
4017
+ 'trade_id': id,
4018
+ 'from_account': code,
4019
+ 'to_account': toCode,
4020
+ }
4021
+ response = self.v3PrivateGetBrokerageConvertTradeTradeId(self.extend(request, params))
4022
+ data = self.safe_dict(response, 'trade', {})
4023
+ return self.parse_conversion(data)
4024
+
4025
+ def parse_conversion(self, conversion: dict, fromCurrency: Currency = None, toCurrency: Currency = None) -> Conversion:
4026
+ fromCoin = self.safe_string(conversion, 'source_currency')
4027
+ fromCode = self.safe_currency_code(fromCoin, fromCurrency)
4028
+ to = self.safe_string(conversion, 'target_currency')
4029
+ toCode = self.safe_currency_code(to, toCurrency)
4030
+ fromAmountStructure = self.safe_dict(conversion, 'user_entered_amount')
4031
+ feeStructure = self.safe_dict(conversion, 'total_fee')
4032
+ feeAmountStructure = self.safe_dict(feeStructure, 'amount')
4033
+ return {
4034
+ 'info': conversion,
4035
+ 'timestamp': None,
4036
+ 'datetime': None,
4037
+ 'id': self.safe_string(conversion, 'id'),
4038
+ 'fromCurrency': fromCode,
4039
+ 'fromAmount': self.safe_number(fromAmountStructure, 'value'),
4040
+ 'toCurrency': toCode,
4041
+ 'toAmount': None,
4042
+ 'price': None,
4043
+ 'fee': self.safe_number(feeAmountStructure, 'value'),
4044
+ }
4045
+
4046
+ def close_position(self, symbol: str, side: OrderSide = None, params={}) -> Order:
4047
+ """
4048
+ *futures only* closes open positions for a market
4049
+ :see: https://coinbase-api.github.io/docs/#/en-us/swapV2/trade-api.html#One-Click%20Close%20All%20Positions
4050
+ :param str symbol: Unified CCXT market symbol
4051
+ :param str [side]: not used by coinbase
4052
+ :param dict [params]: extra parameters specific to the coinbase api endpoint
4053
+ * @param {str} params.clientOrderId *mandatory* the client order id of the position to close
4054
+ :param float [params.size]: the size of the position to close, optional
4055
+ :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
4056
+ """
4057
+ self.load_markets()
4058
+ market = self.market(symbol)
4059
+ if not market['future']:
4060
+ raise NotSupported(self.id + ' closePosition() only supported for futures markets')
4061
+ clientOrderId = self.safe_string_2(params, 'client_order_id', 'clientOrderId')
4062
+ params = self.omit(params, 'clientOrderId')
4063
+ request: dict = {
4064
+ 'product_id': market['id'],
4065
+ }
4066
+ if clientOrderId is None:
4067
+ raise ArgumentsRequired(self.id + ' closePosition() requires a clientOrderId parameter')
4068
+ request['client_order_id'] = clientOrderId
4069
+ response = self.v3PrivatePostBrokerageOrdersClosePosition(self.extend(request, params))
4070
+ order = self.safe_dict(response, 'success_response', {})
4071
+ return self.parse_order(order)
4072
+
4073
+ def fetch_positions(self, symbols: Strings = None, params={}):
4074
+ """
4075
+ fetch all open positions
4076
+ :see: https://docs.cloud.coinbase.com/advanced-trade-api/reference/retailbrokerageapi_getfcmpositions
4077
+ :see: https://docs.cloud.coinbase.com/advanced-trade-api/reference/retailbrokerageapi_getintxpositions
4078
+ :param str[] [symbols]: list of unified market symbols
4079
+ :param dict [params]: extra parameters specific to the exchange API endpoint
4080
+ :param str [params.portfolio]: the portfolio UUID to fetch positions for
4081
+ :returns dict[]: a list of `position structure <https://docs.ccxt.com/#/?id=position-structure>`
4082
+ """
4083
+ self.load_markets()
4084
+ symbols = self.market_symbols(symbols)
4085
+ market = None
4086
+ if symbols is not None:
4087
+ market = self.market(symbols[0])
4088
+ type = None
4089
+ type, params = self.handle_market_type_and_params('fetchPositions', market, params)
4090
+ response = None
4091
+ if type == 'future':
4092
+ response = self.v3PrivateGetBrokerageCfmPositions(params)
4093
+ else:
4094
+ portfolio = None
4095
+ portfolio, params = self.handle_option_and_params(params, 'fetchPositions', 'portfolio')
4096
+ if portfolio is None:
4097
+ 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()')
4098
+ request: dict = {
4099
+ 'portfolio_uuid': portfolio,
4100
+ }
4101
+ response = self.v3PrivateGetBrokerageIntxPositionsPortfolioUuid(self.extend(request, params))
4102
+ positions = self.safe_list(response, 'positions', [])
4103
+ return self.parse_positions(positions, symbols)
4104
+
4105
+ def fetch_position(self, symbol: str, params={}):
4106
+ """
4107
+ fetch data on a single open contract trade position
4108
+ :see: https://docs.cloud.coinbase.com/advanced-trade-api/reference/retailbrokerageapi_getintxposition
4109
+ :see: https://docs.cloud.coinbase.com/advanced-trade-api/reference/retailbrokerageapi_getfcmposition
4110
+ :param str symbol: unified market symbol of the market the position is held in, default is None
4111
+ :param dict [params]: extra parameters specific to the exchange API endpoint
4112
+ :param str [params.product_id]: *futures only* the product id of the position to fetch, required for futures markets only
4113
+ :param str [params.portfolio]: *perpetual/swaps only* the portfolio UUID to fetch the position for, required for perpetual/swaps markets only
4114
+ :returns dict: a `position structure <https://docs.ccxt.com/#/?id=position-structure>`
4115
+ """
4116
+ self.load_markets()
4117
+ market = self.market(symbol)
4118
+ response = None
4119
+ if market['future']:
4120
+ productId = self.safe_string(market, 'product_id')
4121
+ if productId is None:
4122
+ raise ArgumentsRequired(self.id + ' fetchPosition() requires a "product_id" in params')
4123
+ futureRequest: dict = {
4124
+ 'product_id': productId,
4125
+ }
4126
+ response = self.v3PrivateGetBrokerageCfmPositionsProductId(self.extend(futureRequest, params))
4127
+ else:
4128
+ portfolio = None
4129
+ portfolio, params = self.handle_option_and_params(params, 'fetchPositions', 'portfolio')
4130
+ if portfolio is None:
4131
+ 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()')
4132
+ request: dict = {
4133
+ 'symbol': market['id'],
4134
+ 'portfolio_uuid': portfolio,
4135
+ }
4136
+ response = self.v3PrivateGetBrokerageIntxPositionsPortfolioUuidSymbol(self.extend(request, params))
4137
+ position = self.safe_dict(response, 'position', {})
4138
+ return self.parse_position(position, market)
4139
+
4140
+ def parse_position(self, position: dict, market: Market = None):
4141
+ #
4142
+ # {
4143
+ # "product_id": "1r4njf84-0-0",
4144
+ # "product_uuid": "cd34c18b-3665-4ed8-9305-3db277c49fc5",
4145
+ # "symbol": "ADA-PERP-INTX",
4146
+ # "vwap": {
4147
+ # "value": "0.6171",
4148
+ # "currency": "USDC"
4149
+ # },
4150
+ # "position_side": "POSITION_SIDE_LONG",
4151
+ # "net_size": "20",
4152
+ # "buy_order_size": "0",
4153
+ # "sell_order_size": "0",
4154
+ # "im_contribution": "0.1",
4155
+ # "unrealized_pnl": {
4156
+ # "value": "0.074",
4157
+ # "currency": "USDC"
4158
+ # },
4159
+ # "mark_price": {
4160
+ # "value": "0.6208",
4161
+ # "currency": "USDC"
4162
+ # },
4163
+ # "liquidation_price": {
4164
+ # "value": "0",
4165
+ # "currency": "USDC"
4166
+ # },
4167
+ # "leverage": "1",
4168
+ # "im_notional": {
4169
+ # "value": "12.342",
4170
+ # "currency": "USDC"
4171
+ # },
4172
+ # "mm_notional": {
4173
+ # "value": "0.814572",
4174
+ # "currency": "USDC"
4175
+ # },
4176
+ # "position_notional": {
4177
+ # "value": "12.342",
4178
+ # "currency": "USDC"
4179
+ # },
4180
+ # "margin_type": "MARGIN_TYPE_CROSS",
4181
+ # "liquidation_buffer": "19.677828",
4182
+ # "liquidation_percentage": "4689.3506",
4183
+ # "portfolio_summary": {
4184
+ # "portfolio_uuid": "018ebd63-1f6d-7c8e-ada9-0761c5a2235f",
4185
+ # "collateral": "20.4184",
4186
+ # "position_notional": "12.342",
4187
+ # "open_position_notional": "12.342",
4188
+ # "pending_fees": "0",
4189
+ # "borrow": "0",
4190
+ # "accrued_interest": "0",
4191
+ # "rolling_debt": "0",
4192
+ # "portfolio_initial_margin": "0.1",
4193
+ # "portfolio_im_notional": {
4194
+ # "value": "12.342",
4195
+ # "currency": "USDC"
4196
+ # },
4197
+ # "portfolio_maintenance_margin": "0.066",
4198
+ # "portfolio_mm_notional": {
4199
+ # "value": "0.814572",
4200
+ # "currency": "USDC"
4201
+ # },
4202
+ # "liquidation_percentage": "4689.3506",
4203
+ # "liquidation_buffer": "19.677828",
4204
+ # "margin_type": "MARGIN_TYPE_CROSS",
4205
+ # "margin_flags": "PORTFOLIO_MARGIN_FLAGS_UNSPECIFIED",
4206
+ # "liquidation_status": "PORTFOLIO_LIQUIDATION_STATUS_NOT_LIQUIDATING",
4207
+ # "unrealized_pnl": {
4208
+ # "value": "0.074",
4209
+ # "currency": "USDC"
4210
+ # },
4211
+ # "buying_power": {
4212
+ # "value": "8.1504",
4213
+ # "currency": "USDC"
4214
+ # },
4215
+ # "total_balance": {
4216
+ # "value": "20.4924",
4217
+ # "currency": "USDC"
4218
+ # },
4219
+ # "max_withdrawal": {
4220
+ # "value": "8.0764",
4221
+ # "currency": "USDC"
4222
+ # }
4223
+ # },
4224
+ # "entry_vwap": {
4225
+ # "value": "0.6091",
4226
+ # "currency": "USDC"
4227
+ # }
4228
+ # }
4229
+ #
4230
+ marketId = self.safe_string(position, 'symbol', '')
4231
+ market = self.safe_market(marketId, market)
4232
+ rawMargin = self.safe_string(position, 'margin_type')
4233
+ marginMode = None
4234
+ if rawMargin is not None:
4235
+ marginMode = 'cross' if (rawMargin == 'MARGIN_TYPE_CROSS') else 'isolated'
4236
+ notionalObject = self.safe_dict(position, 'position_notional', {})
4237
+ positionSide = self.safe_string(position, 'position_side')
4238
+ side = 'long' if (positionSide == 'POSITION_SIDE_LONG') else 'short'
4239
+ unrealizedPNLObject = self.safe_dict(position, 'unrealized_pnl', {})
4240
+ liquidationPriceObject = self.safe_dict(position, 'liquidation_price', {})
4241
+ liquidationPrice = self.safe_number(liquidationPriceObject, 'value')
4242
+ vwapObject = self.safe_dict(position, 'vwap', {})
4243
+ summaryObject = self.safe_dict(position, 'portfolio_summary', {})
4244
+ return self.safe_position({
4245
+ 'info': position,
4246
+ 'id': self.safe_string(position, 'product_id'),
4247
+ 'symbol': self.safe_symbol(marketId, market),
4248
+ 'notional': self.safe_number(notionalObject, 'value'),
4249
+ 'marginMode': marginMode,
4250
+ 'liquidationPrice': liquidationPrice,
4251
+ 'entryPrice': self.safe_number(vwapObject, 'value'),
4252
+ 'unrealizedPnl': self.safe_number(unrealizedPNLObject, 'value'),
4253
+ 'realizedPnl': None,
4254
+ 'percentage': None,
4255
+ 'contracts': self.safe_number(position, 'net_size'),
4256
+ 'contractSize': market['contractSize'],
4257
+ 'markPrice': None,
4258
+ 'lastPrice': None,
4259
+ 'side': side,
4260
+ 'hedged': None,
4261
+ 'timestamp': None,
4262
+ 'datetime': None,
4263
+ 'lastUpdateTimestamp': None,
4264
+ 'maintenanceMargin': None,
4265
+ 'maintenanceMarginPercentage': None,
4266
+ 'collateral': self.safe_number(summaryObject, 'collateral'),
4267
+ 'initialMargin': None,
4268
+ 'initialMarginPercentage': None,
4269
+ 'leverage': self.safe_number(position, 'leverage'),
4270
+ 'marginRatio': None,
4271
+ 'stopLossPrice': None,
4272
+ 'takeProfitPrice': None,
4273
+ })
4274
+
4275
+ def fetch_trading_fees(self, params={}) -> TradingFees:
4276
+ """
4277
+ :see: https://docs.cdp.coinbase.com/advanced-trade/reference/retailbrokerageapi_gettransactionsummary/
4278
+ fetch the trading fees for multiple markets
4279
+ :param dict [params]: extra parameters specific to the exchange API endpoint
4280
+ :param str [params.type]: 'spot' or 'swap'
4281
+ :returns dict: a dictionary of `fee structures <https://docs.ccxt.com/#/?id=fee-structure>` indexed by market symbols
4282
+ """
4283
+ self.load_markets()
4284
+ type = None
4285
+ type, params = self.handle_market_type_and_params('fetchTradingFees', None, params)
4286
+ isSpot = (type == 'spot')
4287
+ productType = 'SPOT' if isSpot else 'FUTURE'
4288
+ request: dict = {
4289
+ 'product_type': productType,
4290
+ }
4291
+ response = self.v3PrivateGetBrokerageTransactionSummary(self.extend(request, params))
4292
+ #
4293
+ # {
4294
+ # total_volume: '0',
4295
+ # total_fees: '0',
4296
+ # fee_tier: {
4297
+ # pricing_tier: 'Advanced 1',
4298
+ # usd_from: '0',
4299
+ # usd_to: '1000',
4300
+ # taker_fee_rate: '0.008',
4301
+ # maker_fee_rate: '0.006',
4302
+ # aop_from: '',
4303
+ # aop_to: ''
4304
+ # },
4305
+ # margin_rate: null,
4306
+ # goods_and_services_tax: null,
4307
+ # advanced_trade_only_volume: '0',
4308
+ # advanced_trade_only_fees: '0',
4309
+ # coinbase_pro_volume: '0',
4310
+ # coinbase_pro_fees: '0',
4311
+ # total_balance: '',
4312
+ # has_promo_fee: False
4313
+ # }
4314
+ #
4315
+ data = self.safe_dict(response, 'fee_tier', {})
4316
+ taker_fee = self.safe_number(data, 'taker_fee_rate')
4317
+ marker_fee = self.safe_number(data, 'maker_fee_rate')
4318
+ result: dict = {}
4319
+ for i in range(0, len(self.symbols)):
4320
+ symbol = self.symbols[i]
4321
+ market = self.market(symbol)
4322
+ if (isSpot and market['spot']) or (not isSpot and not market['spot']):
4323
+ result[symbol] = {
4324
+ 'info': response,
4325
+ 'symbol': symbol,
4326
+ 'maker': taker_fee,
4327
+ 'taker': marker_fee,
4328
+ 'percentage': True,
4329
+ }
4330
+ return result
4331
+
4332
+ def create_auth_token(self, seconds: Int, method: Str = None, url: Str = None):
4333
+ # it may not work for v2
4334
+ uri = None
4335
+ if url is not None:
4336
+ uri = method + ' ' + url.replace('https://', '')
4337
+ quesPos = uri.find('?')
4338
+ # Due to we use mb_strpos, quesPos could be False in php. In that case, the quesPos >= 0 is True
4339
+ # Also it's not possible that the question mark is first character, only check > 0 here.
4340
+ if quesPos > 0:
4341
+ uri = uri[0:quesPos]
4342
+ nonce = self.random_bytes(16)
4343
+ request: dict = {
4344
+ 'aud': ['retail_rest_api_proxy'],
4345
+ 'iss': 'coinbase-cloud',
4346
+ 'nbf': seconds,
4347
+ 'exp': seconds + 120,
4348
+ 'sub': self.apiKey,
4349
+ 'iat': seconds,
4350
+ }
4351
+ if uri is not None:
4352
+ request['uri'] = uri
4353
+ token = self.jwt(request, self.encode(self.secret), 'sha256', False, {'kid': self.apiKey, 'nonce': nonce, 'alg': 'ES256'})
4354
+ return token
4355
+
4356
+ def sign(self, path, api=[], method='GET', params={}, headers=None, body=None):
4357
+ version = api[0]
4358
+ signed = api[1] == 'private'
4359
+ isV3 = version == 'v3'
4360
+ pathPart = 'api/v3' if (isV3) else 'v2'
4361
+ fullPath = '/' + pathPart + '/' + self.implode_params(path, params)
4362
+ query = self.omit(params, self.extract_params(path))
4363
+ savedPath = fullPath
4364
+ if method == 'GET':
4365
+ if query:
4366
+ fullPath += '?' + self.urlencode_with_array_repeat(query)
4367
+ url = self.urls['api']['rest'] + fullPath
4368
+ if signed:
4369
+ authorization = self.safe_string(self.headers, 'Authorization')
4370
+ authorizationString = None
4371
+ if authorization is not None:
4372
+ authorizationString = authorization
4373
+ elif self.token and not self.check_required_credentials(False):
4374
+ authorizationString = 'Bearer ' + self.token
4375
+ else:
4376
+ self.check_required_credentials()
4377
+ seconds = self.seconds()
4378
+ payload = ''
4379
+ if method != 'GET':
4380
+ if query:
4381
+ body = self.json(query)
4382
+ payload = body
4383
+ else:
4384
+ if not isV3:
4385
+ if query:
4386
+ payload += '?' + self.urlencode(query)
4387
+ # v3: 'GET' doesn't need payload in the signature. inside url is enough
4388
+ # https://docs.cloud.coinbase.com/advanced-trade-api/docs/auth#example-request
4389
+ # v2: 'GET' require payload in the signature
4390
+ # https://docs.cloud.coinbase.com/sign-in-with-coinbase/docs/api-key-authentication
4391
+ isCloudAPiKey = (self.apiKey.find('organizations/') >= 0) or (self.secret.startswith('-----BEGIN'))
4392
+ if isCloudAPiKey:
4393
+ if self.apiKey.startswith('-----BEGIN'):
4394
+ raise ArgumentsRequired(self.id + ' apiKey should contain the name(eg: organizations/3b910e93....) and not the public key')
4395
+ # # it may not work for v2
4396
+ # uri = method + ' ' + url.replace('https://', '')
4397
+ # quesPos = uri.find('?')
4398
+ # # Due to we use mb_strpos, quesPos could be False in php. In that case, the quesPos >= 0 is True
4399
+ # # Also it's not possible that the question mark is first character, only check > 0 here.
4400
+ # if quesPos > 0:
4401
+ # uri = uri[0:quesPos]
4402
+ # }
4403
+ # nonce = self.random_bytes(16)
4404
+ # request: Dict = {
4405
+ # 'aud': ['retail_rest_api_proxy'],
4406
+ # 'iss': 'coinbase-cloud',
4407
+ # 'nbf': seconds,
4408
+ # 'exp': seconds + 120,
4409
+ # 'sub': self.apiKey,
4410
+ # 'uri': uri,
4411
+ # 'iat': seconds,
4412
+ # }
4413
+ token = self.create_auth_token(seconds, method, url)
4414
+ # token = self.jwt(request, self.encode(self.secret), 'sha256', False, {'kid': self.apiKey, 'nonce': nonce, 'alg': 'ES256'})
4415
+ authorizationString = 'Bearer ' + token
4416
+ else:
4417
+ timestampString = str(self.seconds())
4418
+ auth = timestampString + method + savedPath + payload
4419
+ signature = self.hmac(self.encode(auth), self.encode(self.secret), hashlib.sha256)
4420
+ headers = {
4421
+ 'CB-ACCESS-KEY': self.apiKey,
4422
+ 'CB-ACCESS-SIGN': signature,
4423
+ 'CB-ACCESS-TIMESTAMP': timestampString,
4424
+ 'Content-Type': 'application/json',
4425
+ }
4426
+ if authorizationString is not None:
4427
+ headers = {
4428
+ 'Authorization': authorizationString,
4429
+ 'Content-Type': 'application/json',
4430
+ }
4431
+ if method != 'GET':
4432
+ if query:
4433
+ body = self.json(query)
4434
+ return {'url': url, 'method': method, 'body': body, 'headers': headers}
4435
+
4436
+ def handle_errors(self, code: int, reason: str, url: str, method: str, headers: dict, body: str, response, requestHeaders, requestBody):
4437
+ if response is None:
4438
+ return None # fallback to default error handler
4439
+ feedback = self.id + ' ' + body
4440
+ #
4441
+ # {"error": "invalid_request", "error_description": "The request is missing a required parameter, includes an unsupported parameter value, or is otherwise malformed."}
4442
+ #
4443
+ # or
4444
+ #
4445
+ # {
4446
+ # "errors": [
4447
+ # {
4448
+ # "id": "not_found",
4449
+ # "message": "Not found"
4450
+ # }
4451
+ # ]
4452
+ # }
4453
+ #
4454
+ errorCode = self.safe_string(response, 'error')
4455
+ if errorCode is not None:
4456
+ errorMessage = self.safe_string(response, 'error_description')
4457
+ self.throw_exactly_matched_exception(self.exceptions['exact'], errorCode, feedback)
4458
+ self.throw_broadly_matched_exception(self.exceptions['broad'], errorMessage, feedback)
4459
+ raise ExchangeError(feedback)
4460
+ errors = self.safe_list(response, 'errors')
4461
+ if errors is not None:
4462
+ if isinstance(errors, list):
4463
+ numErrors = len(errors)
4464
+ if numErrors > 0:
4465
+ errorCode = self.safe_string(errors[0], 'id')
4466
+ errorMessage = self.safe_string(errors[0], 'message')
4467
+ if errorCode is not None:
4468
+ self.throw_exactly_matched_exception(self.exceptions['exact'], errorCode, feedback)
4469
+ self.throw_broadly_matched_exception(self.exceptions['broad'], errorMessage, feedback)
4470
+ raise ExchangeError(feedback)
4471
+ advancedTrade = self.options['advanced']
4472
+ if not ('data' in response) and (not advancedTrade):
4473
+ raise ExchangeError(self.id + ' failed due to a malformed response ' + self.json(response))
4474
+ return None