Binance::API: can't connect to the exchange - perl

I'm an algo-trader and Perl fan.
I want to create a client which connects to Binance Future Testnet and i decided to exploit the Binance API module developed for Perl.
Once the Binance::API module was installed (no errors or warnings occurred there) i dived into my script first lines of code as follows:
#!/bin/perl
use Binance::API;
#API di Binance-Testnet
my $api = Binance::API->new(
apiKey => 'my api',
secretKey => 'my secret key',
);
$api->account();
$api->exchange_info();
API KEY and SECRET KEY are taken from my Binance Future Testnet Account (freely available for all users), succesfully used via tradingview and its Pine script tool.
Unfortunatly i got the following error:
[Binance::API::Request::_exec] Unsuccessful request.
Status => 401,
Content => {"code":-2015,"msg":"Invalid API-key, IP, or permissions for action."} at C:/Strawberry/perl/site/lib/Binance/API/Request.pm line 107.
[Binance::API::Request::_exec] Unsuccessful request.
Status => 404,
Content => <html><body><h2>404 Not found</h2></body></html> at C:/Strawberry/perl/site/lib/Binance/API/Request.pm line 107.
Any idea on what went wrong with this? I don't want to use Python or C++ as I love Perl and its versatility.

If you look at Binance::API source code, you can see this module developed for Spot market. not Futures.
https://github.com/taskula/binance-perl-api/blob/master/lib/Binance/Constants.pm
BEGIN {
%constants = (
BASE_URL => $ENV{BINANCE_API_BASE_URL} || 'https://api.binance.com', #this endpoint is for spot
DEBUG => $ENV{BINANCE_API_DEBUG} || 0,
);
}
for Spot Testnet you can get API KEY from here:
https://binance-docs.github.io/apidocs/spot/en/#enabling-accounts

I think you may get confused with spot and futures. There are 4 different base URL for different markets:
Spot Production site: https://api.binance.com
Spot Testnet site: https://testnet.binance.vision
Futures Production site: https://fapi.binance.com
Futures Testnet site: https://testnet.binancefuture.com

Related

Sudden Axios Error not properly sending parameters

April 26 2022 The system that we are working is suddenly not working, I found out that the request data from frontend to backend suddenly became weird.
The regular request
array ( 'email' => 'xxxxx+1#gmail.com', 'password' => 12341234, )
When running Axios:
When I tried to use Ajax, the request is the normal one. However we are using axios for the majority of the project. Is someone else having the same error?
using the script: https://unpkg.com/axios/dist/axios.min.js

AWS CDK: Api Key ignored when testing api gateway locally?

I'm currently developping an API with aws-cdk and I'm testing it locally with aws-sam-cli and docker. I wanted to add the requirement of an API Key to call the API.
Here is the code inside my stack:
const api = new apigw.RestApi(this, "MyAPI", {
restApiName: "My API",
description: "BLABLABLA API",
});
const myLambdaIntegration = new apigw.LambdaIntegration(myLambda, {
proxy: false,
});
// Endpoints of the API
api.root.addResource("test").addMethod("GET", myLambdaIntegration, {
apiKeyRequired: true,
});
Then I build this stack and synth it (npm run build ; cdk synth --no-staging myStack > template.yaml
And try to test it locally
sam local start-api
When I request my api without any API KEY, the API returns me the result of my lambda. 😭
I expected it to return me an error like {"message":"Missing Authentication Token"}
Does anyone have an idea of what is going on?
I suspect it's because authorizations are ignored locally but didn't find anything about that...
Thanks in advance! 😁
Edit: After deploying this stack, the API correctly asks me for a token.

Ruby gem facebook_ads exception_with_response: 400 Bad Request

I'm trying to query the Facebook Marketing API Insights using the facebook_ads Ruby gem. https://github.com/tophatter/facebook-ruby-ads-sdk
I created an app and have Editor permissions on the relevant pages for my company.
Next, I generated a user access token from this page after selecting ads_management permissions.
Next, I followed the instructions on this page to get a permanent page access token.
With the code below I get this error:
/var/lib/gems/2.3.0/gems/rest-client-/var/lib/gems/2.3.0/gems/rest-client-2.0.2/lib/restclient/abstract_response.rb:223:in exception_with_response': 400 Bad Request (RestClient::BadRequest)
from /var/lib/gems/2.3.0/gems/rest-client-2.0.2/lib/restclient/abstract_response.rb:103:inreturn!'
from /var/lib/gems/2.3.0/gems/rest-client-2.0.2/lib/restclient/request.rb:809:in process_result'
from /var/lib/gems/2.3.0/gems/rest-client-2.0.2/lib/restclient/request.rb:725:inblock in transmit'
from /usr/lib/ruby/2.3.0/net/http.rb:853:in start'
from /var/lib/gems/2.3.0/gems/rest-client-2.0.2/lib/restclient/request.rb:715:intransmit'
from /var/lib/gems/2.3.0/gems/rest-client-2.0.2/lib/restclient/request.rb:145:in execute'
from /var/lib/gems/2.3.0/gems/rest-client-2.0.2/lib/restclient/request.rb:52:inexecute'
from /var/lib/gems/2.3.0/gems/rest-client-2.0.2/lib/restclient.rb:67:in get'
from /var/lib/gems/2.3.0/gems/facebook_ads-0.6.6/lib/facebook_ads/base.rb:15:inget'
from /var/lib/gems/2.3.0/gems/facebook_ads-0.6.6/lib/facebook_ads/ad_account.rb:10:in `all'
I have also tried this code with my temporary user access code but get the same result.
Here is my code
#!/usr/bin/ruby
require 'facebook_ads'
MY_PAGE_PERMANENT_ACCESS_CODE = 'my access code'
APP_SECRET = 'my app secret'
FacebookAds.access_token = MY_PAGE_PERMANENT_ACCESS_CODE
FacebookAds.app_secret = APP_SECRET
accounts = FacebookAds::AdAccount.all
It turns out that I was using the page permanent access token which was out of scope for the API call. I needed to use my temporary user access code.
E, [2019-01-19T00:08:49.366067 #19868] ERROR -- : GET /me/adaccounts
OAuthException / 100: (#100) Tried accessing nonexisting field
(adaccounts) on node type (Page) RestClient::BadRequest: 400 Bad
Request
In the pry console for the gem I ran this command to set the account variable:
pry(main)> account = FacebookAds::AdAccount.find('act_MY_ACCOUNT_ID')
and I get this error:
E, [2019-01-19T00:12:24.760545 #20188] ERROR -- : GET /me/adaccounts
OAuthException / 2635: (#2635) You are calling a deprecated version of
the Ads API. Please update to the latest version: v3.2.
RestClient::BadRequest: 400 Bad Request
So, I ran this command:
pry(main)> FacebookAds.base_uri = 'https://graph.facebook.com/v3.2'
"https://graph.facebook.com/v3.2"
Then pry(main)> account = FacebookAds::AdAccount.find('act_MY_ACCOUNT_ID') again.
Finally, I ran:
pry(main)> account.ad_insights
but the result is an empty array when I know this should not be blank. I'm going to skip the gem and use Ruby net/http to query the API directly.

Simple SMPP Perl Script

I need your help/advices on my very short script I wrote in Perl in order to send SMS via SMPP protocol.
I got a SMS gateway which is perfectly working (sending SMS via HTML request or via web interface works), let's say this gateway has IP 192.168.1.15.
Its SMPP service is listening to TCP 2775 (I can successfully telnet to 2775, so I guess SMPP service is working on my SMS gateway)
my $smpp = Net::SMPP->new_transmitter(192.168.1.15,
port=>2775,
system_id =>"administrator",
password =>"passwdexample") or die;
$resp_pdu = $smpp->submit_sm(destination_addr => '+400123456789',
short_message => 'test message') or die;
die "Response indicated error: " . $Resp_PDU->explain_status() if $resp_pdu->status;
When I run the script, here the error I got :
Response indicated error: Incorrect BIND Status for given command (ESME_RINVBNDS TS=0x00000004) at C:\temp\smpptest.pl line .
Unfortunately, I haven't find so much help on internet, but according to this link : SMPP Errors Codes It says :
You must bind first before any other request is handled.
However, my bind is done with new_transmitter, and I don't get any errors at this point, so I don't understand how it cannot bind the TCP session (my credentials are corrects, I tried that in a telnet session).
That's the first time I use such a plugin, so maybe I'm missing something, and maybe someone has already met this error !
Many thanks for your help :-)
Try to quote the IP address:
Net::SMPP->new_transmitter("192.168.1.15", ...);

How to solve Android GCM 401 Error?

Have setup a project at Google Code APis console and have a server key at "Key for server apps (with IP locking)". I'am trying to send a push notification to GCM device using "API key" and one registration ID that I have stored at database.
For server side I'am using Zend_Mobile_Push_Gcm and have something like this:
$token = 'REGISTRATION ID';
$apiKey = 'API KEY';
//Send test push
$message = new Zend_Mobile_Push_Message_Gcm();
$message->setId(time());
$message->addToken($token);
$message->setData(array('foo' => 'bar', 'bar'=>'foo'));
$gcm = new Zend_Mobile_Push_Gcm();
$gcm->setApiKey($apiKey);
try {
$response = $gcm->send($message);
} catch (Zend_Mobile_Push_Exception $e) {
die($e->getMessage());
}
On the app side, I have used the GCM demo, that is currently registering it's registration ID on a server service.
I'am not able to send the push, always get a 401 error. Have gone through troubleshooting and tried my API KEY and Registration ID with the CLI test line at http://developer.android.com/guide/google/gcm/gcm.html#auth_error but with no success.
Any help would be appreciated.
I realise this was posted a while ago but be sure to use your server API key and not your android API key.
I had the same issue when trying to use my Android API key from PHP with Zend.