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