datawookie/binance

Payment movements (Funding)

laresbernardo opened this issue · 21 comments

Is there a way to fetch "Pay" movements? I use this functionality for internal transactions to other Binance users from the "Funding" tab. Attached screenshots.

AEB2D9A5-719F-4B6F-AF56-D1BE562524FB_1_201_a
0D4A02BE-044A-4AEF-9886-256F7C33009D_1_201_a

Please have a look at the API documentation and see if there's an endpoint to support this. If there is then it should be a simple matter to wrap it. If not then we'll need to see if we can reverse-engineer from the website.

I looked around and there's a place where MAIN_FUNDING is an option to set the type parameter but it actually doesn't return these values.
Maybe this could be it: /sapi/v1/asset/get-funding-asset
And this for historical values? Not sure: /sapi/v1/capital/withdraw/history

Hi @laresbernardo, what about this: https://developers.binance.com/docs/binance-pay/introduction?

That seems to have some documentation for the Binance Pay API. However, I am not using this service so I don't have any data in my account to test. Perhaps you can try out some of those endpoints?

Okay, I think I might have a start. Can you please try each of the following and let me know if any of them return non-empty results?

  binance:::POST(
    "/sapi/v1/asset/get-funding-asset",
    query = list(
      asset = "Binance Pay"
    ),
    simplifyVector = FALSE,
    security_type = "USER_DATA"
  )
  binance:::POST(
    "/sapi/v1/asset/get-funding-asset",
    query = list(
      asset = "USDT"
    ),
    simplifyVector = FALSE,
    security_type = "USER_DATA"
  )
  binance:::POST(
    "/sapi/v1/asset/get-funding-asset",
    simplifyVector = FALSE,
    security_type = "USER_DATA"
  )

You'll need to load {binance} first and authenticate yourself.

I think this is the way to go. This is what I get (I only have USDT for now):

> binance:::POST(
+   "/sapi/v1/asset/get-funding-asset",
+   query = list(
+     asset = "Binance Pay"
+   ),
+   simplifyVector = FALSE,
+   security_type = "USER_DATA"
+ )
list()
> binance:::POST(
+   "/sapi/v1/asset/get-funding-asset",
+   query = list(
+     asset = "USDT"
+   ),
+   simplifyVector = FALSE,
+   security_type = "USER_DATA"
+ )
[[1]]
[[1]]$asset
[1] "USDT"

[[1]]$free
[1] "6641.03"

[[1]]$locked
[1] "0"

[[1]]$freeze
[1] "0"

[[1]]$withdrawing
[1] "0"

[[1]]$btcValuation
[1] "0"
> binance:::POST(
+   "/sapi/v1/asset/get-funding-asset",
+   simplifyVector = FALSE,
+   security_type = "USER_DATA"
+ )
[[1]]
[[1]]$asset
[1] "USDT"

[[1]]$free
[1] "6641.03"

[[1]]$locked
[1] "0"

[[1]]$freeze
[1] "0"

[[1]]$withdrawing
[1] "0"

[[1]]$btcValuation
[1] "0"

So with the 3rd one we get the current balance for any asset (with no transactions data)

Okay, @laresbernardo, how about this?

  • Balance of all assets in funding account:
> wallet_get_funding_asset()
  asset       free locked freeze withdrawing btc_valuation
1 USDT  0.296           0      0           0             0
2 ETH   0.00000653      0      0           0             0
  • Balance of specific assets in funding account:
> wallet_get_funding_asset("USDT")
  asset  free locked freeze withdrawing btc_valuation
1 USDT  0.296      0      0           0             0
> wallet_get_funding_asset("ETH")
  asset       free locked freeze withdrawing btc_valuation
1 ETH   0.00000653      0      0           0             0
  • History of transfers from main (spot) to funding account:
> wallet_asset_transfer()
  timestamp           asset amount     type         from  to      status        tran_id
1 2021-11-12 06:05:29 ETH   0.00000653 MAIN_FUNDING MAIN  FUNDING CONFIRMED 85849274369
2 2021-11-12 06:04:41 USDT  0.29552403 MAIN_FUNDING MAIN  FUNDING CONFIRMED 85849183193
  • History of transfers from funding to main (spot) account:
> wallet_asset_transfer(type = "FUNDING_MAIN")
  timestamp           asset amount     type         from    to    status        tran_id
1 2021-11-12 06:33:07 ETH   0.00000653 FUNDING_MAIN FUNDING MAIN  CONFIRMED 85852543029

If this is what you are after then I'll push the changes.

Makes total sense. But if I "pay" or transfer from my wallet to yours, how will we see this transaction? This case I'm not transferring from spot to funding account but from my funding to you funding. So, not 100% there yet I think...

@laresbernardo isn't that what you get with wallet_withdrawal_history(coin = "USDT") though? Because that shows me the transactions from my wallet into others.

No. wallet_withdrawal_history() does not retrieve funding movements. In my case I do 3-4 transactions daily and this is the only one I get, which was a transaction to another wallet in another platform:

> data.frame(wallet_withdrawal_history(coin = "USDT"))
                                id amount transaction_fee coin status                            address
1 5929c06bd65c41faa2c821d1ddd4c6c5   1999               1 USDT      6 TJsxmHoMX3xk4ejPABGDEa79X1dkcHCPzS
                                                             tx_id          apply_time network
1 596428b41e3618a89b4ea154828b92f1871b0ca8a5bcc9d61b0f27ba01c85c1e 2021-09-07 15:00:24     TRX
  transfer_type info confirm_no
1             0              50

You're going to need to give me more information to work with here because I don't actually understand what transactions you are now looking for. I gather that these are transactions from your funding account to other accounts then? But the results from wallet_withdrawal_history() are only showing transactions from your spot account?

That's correct. I'm transferring USDT from my Binance account to another user's account, from my Funding tab, using Binance Pay. The transactions can be found in Payment History (as shown in the screenshots above). Feel free to test, sending 0.05 USDT to my account and I can happily send them back. Same user as github. Let me know how else can I help.

@laresbernardo these are the options that I have for identifying the recipient. The Pay ID appears to be numeric, so your GitHub user doesn't work there. Suggestions? Very happy to send you 0.05 USDT. Just need to know where to send it!

image

I usually use my gmail which is the same user. So laresbernardo @gmail should work. My PayID is 218749576. Thanks!

Cool. Just sent you 0.05 USDT. If you send it back then I'll have two transactions to play with!

Note to self: history can be found at https://www.binance.com/en/my/wallet/account/payment/history.

Just sent 0.06 USDT back so you have different amounts.

Damn! That's generous. ;)

Sadly I don't think that this functionality is currently supported in the API.

The closest I could get was this:

require(httr)

cookies = c(
  'logined' = 'y',
  'p20t' = 'web.212997035.E5366C9D372A18E7FD550752F7F3C686'
)

headers = c(
  `User-Agent` = 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:94.0) Gecko/20100101 Firefox/94.0',
  `content-type` = 'application/json',
  `clienttype` = 'web',
  `csrftoken` = '9588567e1833d0d0ca8c9525a9f8a7f0'
)

data = '{"page":1,"rows":10,"transactionType":"C2C"}'

res <- httr::POST(
  url = 'https://www.binance.com/bapi/pay/v1/private/binance-pay/transaction/list',
  httr::add_headers(.headers=headers),
  httr::set_cookies(.cookies = cookies),
  body = data
)
print(content(res))

That was reverse-engineered from the website. Unfortunately, since it's not possible to generate some of the cookies/headers, I don't see how we can use this in the package.

If you can find the endpoint for accessing these data, please let me know. Perhaps try contacting one of the support forums?

That's pretty clever. I got the following error though:

$code
[1] "100001005"

$message
[1] "Need to log in to access"

$success
[1] FALSE

I did authenticate but maybe using httr and binance simultaneously crashed something?

Yes, that's because the csrftoken was obfuscated!

Это до сих пор актуально)

еще актуально)