autocomplete[name] = new google.maps.places.Autocomplete(document.getElementById(name) ,
{
types: ['geocode'] ,
componentRestrictions: {country: 'SG'}
});
This code is working in laptop, but in mobile phone, it is not using componentRestrictions to SG or Singapore only. It is showing result for whole world.
Related
I'm using Binance futures rest API for algorithmic trading. after creating a buy or sell order, I'm also creating "take profit" and "stop-loss" orders, when I look at the Binance app. it looks like regular SL/TP orders but when I close positions manually, or when any SL/TP orders executed SL/TP orders still waiting in my open orders.
But when I create SL/TP orders with the Binance app and close position (for any reason) open orders also close for the same symbol.
Here is the endpoint and parameters for creating SL/TP orders;
https://fapi.binance.com/fapi/v1/order?symbol=ETHUSDT&side=BUY&type=TAKE_PROFIT_MARKET×tamp=12123123&closePosition=true&stopPrice=4100&workingType=MARK_PRICE&priceProtect=true
this one create a TP order for the ETHUSDT symbol but I don't know why that order doesn't cancel when the position closed.
is there any missing parameter for creating SL/TP orders?
I'm have a related issue. For your specific problem what I have noticed is that when you submit, for example, a market long position. You can follow up with a TP and SL order by setting them as TAKE_PROFIT_MARKET and STOP_MARKET respectively.
For this to work you must by in 'one-way' mode (as opposed to 'hedge' mode).
Then set the value of 'timeInForce' to 'GTE_GTC' - I couldnt see this value in the documentation but I did see that when you set an order via the UI with a TP/SL this is what is shown. Also set 'reduceOnly' to True.
Then when you close the original market order both these 'pending' orders will be removed.
Just tested that you can in fact submit all these orders in a batch (list of json) to:
POST /fapi/v1/batchOrders
batch_payload = [
{
'newClientOrderId': '467fba09-a286-43c3-a79a-32efec4be80e',
'symbol': 'ETHUSDT',
'type': 'MARKET',
'quantity': '9.059',
'side': 'SELL'
},
{
'newClientOrderId': '6925e0cb-2d86-42af-875c-877da7b5fda5',
'symbol': 'ETHUSDT',
'type': 'STOP_MARKET',
'quantity': '9.059',
'side': 'BUY',
'stopPrice': '3037.9',
'timeInForce': 'GTE_GTC',
'reduceOnly': 'True'
},
{
'newClientOrderId': '121637a9-e15a-4f44-b62d-d424fb4870e0',
'symbol': 'ETHUSDT',
'type': 'TAKE_PROFIT_MARKET',
'quantity': '9.059',
'side': 'BUY',
'stopPrice': '2748.58',
'timeInForce': 'GTE_GTC',
'reduceOnly': 'True'
}
]
By default Binance doesn't close the TAKE_PROFIT_MARKET or STOP_MARKET after position is closed.. you need to manually close those orders, you can pull the current opened orders and filter them based on the positionSide (SELL / LONG / BOTH) and origType (TAKE_PROFIT_MARKET / STOP_MARKET) and you can get the orderId for those orders and batch cancel them or cancel them one by one
const position = 'LONG' // LONG, SHORT, BOTH
axios
.get('https://fapi.binance.com/fapi/v1/openOrders', {
params: {
symbol: 'BTCUSDT'
}
})
.then(({ data }) => {
const orderIds = data
.filter(
({ positionSide, origType }) =>
positionSide === position &&
['TAKE_PROFIT_MARKET', 'STOP_MARKET'].includes(origType)
)
.map(({ orderId }) => orderId)
// Use batch cancel or cancel order one by one
console.log('orderIds', orderIds)
})
I'm using the flutter_google_places widget to search for cities.
I've tried the AutoComplete example given with the widget and it works perfectly. But when I type "Paris" for example, I get many results of places in Paris (Paris, Paris Airport, Paris Expo, etc.).
I only need cities within my App. So for example, when typing "Paris", I would only want "Paris (France), Paris (Texas), Paris (Tennessee), etc.
I haven't found how to apply the "cities" filter.
Here is the equivalent in Javascript :
var input = document.getElementById('searchField');
var options = {
types: ['(cities)']
};
autocomplete = new google.maps.places.Autocomplete(input, options);
Any idea?
If you are using this example: https://github.com/fluttercommunity/flutter_google_places/blob/master/example/lib/main.dart
Should do
CustomSearchScaffold()
: super(
apiKey: kGoogleApiKey,
sessionToken: Uuid().generateV4(),
language: "en",
components: [Component(Component.country, "uk")],
types: ["(cities)"], // or cities
);
I am beginner and following a tutorial to make a review products application and rather than just copy pasting the code trying to do some experiment with it to get more depth knowledge. I have two questions regarding my app
1) I added some more functionality to my app and wrote some code in includes.js and reviews.html to show average rating and total review of a product .How i can show average rating and number of reviews for the product thats been clicked?
2) I added product categories list to show in side bar(e.g Electronics , Fashion, Books) through chrome console by adding them manually e.g like this
Categories.insert({name:'Eelctronics',slug:'electronics'});
So i have deployed this app on free meteor hosting and every time some one run this app he has to write this above code manually in chrome console to get list of categories.Even if some one clone my project from gitHub also can not see list of categories in left side bar and he also have to write the same code in console.So what is the solution for it how i can show list of categories in my side bar with out writing above code in console?
You can check gitHub repository for source code.
1) Show average rating and review count
<p>Average Rating: <img class="stars" src="/img/star{{averageRating}}.png"> ({{countReviews}})</p>
I've moved this code into reviews.helpers section
Template.reviews.helpers({
'reviews': function () {
return Reviews.find({productId: Router.current().data()._id})
},
countReviews: function(){
return Reviews.find({productId: Router.current().data()._id}).count();
},
averageRating: function() {
var reviews = Reviews.find({productId: Router.current().data()._id}); //get all reviews for productId
//var ratings = reviews.map(function(player){return player.score;}); // get just the ratings, or use _.pluck
var ratings = _.pluck(reviews, 'ratings'); // get just the ratings i.e. [1, 5, 3, 2, 5]
var sum = ratings.reduce(function(pv, cv){return pv + cv;}, 0); //sum ratings i.e. 14
var avg = sum / ratings.length; // i.e. 2.8
return Math.round(2.8); // round avg to ensure only integer values are returned
},
})
2) Seed database
Docs Add a Meteor.startup block to seed database
// On server startup, if the database is empty, create some initial data.
if (Meteor.isServer) {
Meteor.startup(function () {
if (Categories.find().count() === 0) {
Categories.insert({name:'Electronics',slug:'electronics'});
Categories.insert({name:'Fashion',slug:'fashion'});
Categories.insert({name:'Books',slug:'books'});
}
});
}
I am working on a certain problem where given a URL I need to map it to a country. Even if I can reliably answer the question "Is this particular URL relevant to United States?" that should be sufficient.
I am happy to have false negatives but never a false positive.
Currently I am considering the following approach.
See if the domain name of the URL is in top 1000 .com domains on Alexa for USA.
Check if the the link was shared by US users on Facebook or twitter.
Has anyone solved this kind of problem before ?
You can use http://dev.maxmind.com/geoip/geoip2/geolite2/ but you need to get the IP address from your URLs domain before you can access the GeoIP database with this address.
There are a lot of interfaces to the GeoIP dataset for different languages: http://dev.maxmind.com/geoip/geoip2/downloadable/#MaxMind_APIs
Have a look at a sample NodeJS project here:
https://github.com/tobilg/GeoLocateURL
You can also try out the userinfo.io API or javascript library which is free and gets its data from a merge of several geolocation databases for more accuracy.
<script type="text/javascript" href="//cdnjs.cloudflare.com/ajax/libs/userinfo/1.0.0/userinfo.min.js"></script>
<script type="text/javascript">
UserInfo.getInfo(function(data) {
// the "data" object contains the info
}, function(err) {
// the "err" object contains useful information in case of an error
});
</script>
The response will look like:
{
request_date: "2014-09-18T04:11:25.154Z",
ip_address: "192.77.237.95",
position: {
latitude: 37.7758,
longitude: -122.4128,
accuracy: 3 // This is the accuracy radius, in kilometers
},
continent: {
name: "North America",
code: "NA",
},
country: {
name: "United States",
code: "US",
},
city: {
name: "San Francisco",
code: "94103"
}
}
I have seen few examples of using geoip in node.js such as https://github.com/kuno/GeoIP.git and https://github.com/wadey/node-geoip. However what i want is to display the map showing geoip for the particular loged in user.How can it be implemented.
You can get a geolocation database (such as from http://www.maxmind.com) and store it in mongo. Each record contains an IP range (start/end) and the latitude/longitude associated with that IP range. IPs are represented as integers. You could create an index on the start field, and do a query on mongo to find the record with the largest value of start which is smaller than the IP of your client user, and look up the corresponding lat/lon.
As for plotting a map with this lat/lon, it's very easy to create a google map which is centered on a particular location: (View source at: http://code.google.com/apis/maps/documentation/javascript/v2/examples/map-simple.html)
There are a lot of different ways of storing/querying geolocation data, but this is just one possible approach using mongo that might work. Hope this helps.
The best module for GeoIP is https://github.com/kuno/GeoIP in my opinion (I actually used this module for a project and it worked perfectly for me). You have to download the database from Maxmind and also install some OS specific libraries and then compile the module.
There is no need to put the database into MongoDB unless you want to replicate easily across multiple servers. You can just put your database into a file and provide the path in the Node.js module.
Here is an example:
// Open the GeoLiteCity.dat file first.
var City = geoip.City;
var city = new City('/path/to/GeoLiteCity.dat');
console.log(city); // this contains country, city, lat, long, continent, postal code etc
I've just published an NPM module for the IPLocate.io API which I created, which lets you find the location (city, country and coordinates) based on an IP address.
Super easy, no databases to download, and 1,500 free requests per day.
Install
npm install node-iplocate
Usage
const iplocate = require("node-iplocate");
iplocate("8.8.8.8").then(function(results) {
console.log("IP Address: " + results.ip);
// IP Address: 8.8.8.8
console.log("Country: " + results.country + " (" + results.country_code + ")");
// Country: United States (US)
console.log("Continent: " + results.continent);
// Continent: North America
console.log("Organisation: " + results.org + " (" + results.asn + ")");
// Organisation: Google LLC (AS15169)
console.log(JSON.stringify(results, null, 2));
/*
{
"ip": "8.8.8.8",
"country": "United States",
"country_code": "US",
"city": null,
"continent": "North America",
"latitude": 37.751,
"longitude": -97.822,
"time_zone": null,
"postal_code": null,
"org": "Google LLC",
"asn": "AS15169"
}
*/
});
// Or with callbacks
iplocate("8.8.8.8", null, function(err, results) {
// ...
console.log(JSON.stringify(results, null, 2));
});
// Provide an API key from IPLocate.io
iplocate("8.8.8.8", { api_key: "abcdef" }).then(function(results) {
// ...
});
Python Implementation:
#!/usr/bin/python
#coding: utf-8
import os
import pygeoip
gi = pygeoip.GeoIP('GeoIP.dat')
gic = pygeoip.GeoIP('GeoIPCity.dat')
fl = file(r'apache-unique.log')
lines = fl.readlines()
for line in lines:
print gi.country_code_by_addr(line)
print gic.record_by_addr(line)
os.system('pause')
extending mpobrien's answer-
I found this to be easier and faster approach.
Download the binary db at maxmind
http://dev.maxmind.com/geoip/geoip2/geolite2/
http://geolite.maxmind.com/download/geoip/database/GeoLite2-Country.mmdb.gz
Use node-maxmind-db
https://github.com/PaddeK/node-maxmind-db
var mmdbreader = require('maxmind-db-reader');
// open database
var countries = mmdbreader.openSync('./countries.mmdb');
// get geodata
app.get('/api/v1/ip/', function(req, res) {
var ip = req.headers['x-forwarded-for'] || req.connection.remoteAddress;
countries.getGeoData(ip, function(err, geodata) {
if(!err && geodata.location) return res.json({success: true, location: geodata.location});
return res.json({success: false, location: null, error: err});
});
});
Then you will have user location based on his ip address which you can display on map.
Benefits-
The bindary data file is small and easy to update. No db import export.
Just swap the file and reload the data. ie- mmdbreader.openSync()