Samples
The JavaScript and Python tabs assume you already have an access token (accessToken in JavaScript, access_token in Python) from the Authentication guide.
All Spot Prices
Fetches all available spot prices for all ports and fuel grades:
- GraphQL
- JavaScript
- Python
query allSpotPrices {
latestSpotPrices {
port {
id
name
countryName
}
fuelGrade {
id
description
}
latestPrices {
publishedDate
price
}
}
}
const response = await fetch("https://api.tideform.io/graphql", {
method: "POST",
headers: {
Authorization: `Bearer ${accessToken}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
query: `query allSpotPrices {
latestSpotPrices {
port { id name countryName }
fuelGrade { id description }
latestPrices { publishedDate price }
}
}`,
}),
});
const { data } = await response.json();
import requests
response = requests.post(
"https://api.tideform.io/graphql",
json={
"query": """
query allSpotPrices {
latestSpotPrices {
port { id name countryName }
fuelGrade { id description }
latestPrices { publishedDate price }
}
}
"""
},
headers={"Authorization": f"Bearer {access_token}"},
)
data = response.json()["data"]
Filter By Fuel Grade
Use fuel grade IDs such as mgo or vlsfo (see Fuel Grades for the full list; biofuel returns all three biofuel blends).
- GraphQL
- JavaScript
- Python
query allSpotPricesByFuelGrade {
latestSpotPrices(input: { fuelGradeIds: ["mgo", "vlsfo"] }) {
port {
id
name
countryName
}
fuelGrade {
id
description
}
latestPrices {
publishedDate
price
}
}
}
const response = await fetch("https://api.tideform.io/graphql", {
method: "POST",
headers: {
Authorization: `Bearer ${accessToken}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
query: `query allSpotPricesByFuelGrade {
latestSpotPrices(input: { fuelGradeIds: ["mgo", "vlsfo"] }) {
port { id name countryName }
fuelGrade { id description }
latestPrices { publishedDate price }
}
}`,
}),
});
const { data } = await response.json();
import requests
response = requests.post(
"https://api.tideform.io/graphql",
json={
"query": """
query allSpotPricesByFuelGrade {
latestSpotPrices(input: { fuelGradeIds: ["mgo", "vlsfo"] }) {
port { id name countryName }
fuelGrade { id description }
latestPrices { publishedDate price }
}
}
"""
},
headers={"Authorization": f"Bearer {access_token}"},
)
data = response.json()["data"]
Filter By Port
- GraphQL
- JavaScript
- Python
query allSpotPricesByPort {
latestSpotPrices(input: { portIds: ["sgsin", "nlrtm", "aefjr"] }) {
port {
id
name
countryName
}
fuelGrade {
id
description
}
latestPrices {
publishedDate
price
}
}
}
const response = await fetch("https://api.tideform.io/graphql", {
method: "POST",
headers: {
Authorization: `Bearer ${accessToken}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
query: `query allSpotPricesByPort {
latestSpotPrices(input: { portIds: ["sgsin", "nlrtm", "aefjr"] }) {
port { id name countryName }
fuelGrade { id description }
latestPrices { publishedDate price }
}
}`,
}),
});
const { data } = await response.json();
import requests
response = requests.post(
"https://api.tideform.io/graphql",
json={
"query": """
query allSpotPricesByPort {
latestSpotPrices(input: { portIds: ["sgsin", "nlrtm", "aefjr"] }) {
port { id name countryName }
fuelGrade { id description }
latestPrices { publishedDate price }
}
}
"""
},
headers={"Authorization": f"Bearer {access_token}"},
)
data = response.json()["data"]
Filter By Fuel Grade And Port
- GraphQL
- JavaScript
- Python
query spotPricesByFuelGradeAndPort {
latestSpotPrices(
input: {
fuelGradeIds: ["mgo", "vlsfo"]
portIds: ["sgsin", "nlrtm", "aefjr"]
}
) {
port {
id
name
countryName
}
fuelGrade {
id
description
}
latestPrices {
publishedDate
price
}
}
}
const response = await fetch("https://api.tideform.io/graphql", {
method: "POST",
headers: {
Authorization: `Bearer ${accessToken}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
query: `query spotPricesByFuelGradeAndPort {
latestSpotPrices(
input: {
fuelGradeIds: ["mgo", "vlsfo"]
portIds: ["sgsin", "nlrtm", "aefjr"]
}
) {
port { id name countryName }
fuelGrade { id description }
latestPrices { publishedDate price }
}
}`,
}),
});
const { data } = await response.json();
import requests
response = requests.post(
"https://api.tideform.io/graphql",
json={
"query": """
query spotPricesByFuelGradeAndPort {
latestSpotPrices(
input: {
fuelGradeIds: ["mgo", "vlsfo"]
portIds: ["sgsin", "nlrtm", "aefjr"]
}
) {
port { id name countryName }
fuelGrade { id description }
latestPrices { publishedDate price }
}
}
"""
},
headers={"Authorization": f"Bearer {access_token}"},
)
data = response.json()["data"]
Additional Fields
A few extra fields are worth knowing about - add any of these to the queries above.
Port location and time zone details, on any port selection:
port {
id
name
coordinates {
latitude
longitude
}
timeZone {
name
offset
}
}
Confidence band, the 68% confidence interval around the price (only populated for ports and fuel grades where one is calculated, null otherwise):
latestPrices {
publishedDate
price
band68Lower
band68Upper
}
Listing Ports
Use the ports query to list ports, with pagination:
- GraphQL
- JavaScript
- Python
query ports {
ports(first: 10) {
totalCount
pageInfo {
startCursor
hasPreviousPage
hasNextPage
endCursor
}
edges {
cursor
node {
id
name
country
timeZone {
name
offset
}
}
}
}
}
const response = await fetch("https://api.tideform.io/graphql", {
method: "POST",
headers: {
Authorization: `Bearer ${accessToken}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
query: `query ports {
ports(first: 10) {
totalCount
pageInfo { startCursor hasPreviousPage hasNextPage endCursor }
edges {
cursor
node { id name country timeZone { name offset } }
}
}
}`,
}),
});
const { data } = await response.json();
import requests
response = requests.post(
"https://api.tideform.io/graphql",
json={
"query": """
query ports {
ports(first: 10) {
totalCount
pageInfo { startCursor hasPreviousPage hasNextPage endCursor }
edges {
cursor
node { id name country timeZone { name offset } }
}
}
}
"""
},
headers={"Authorization": f"Bearer {access_token}"},
)
data = response.json()["data"]
To retrieve the next page when hasNextPage is true, pass the previous page's endCursor in the after parameter. Without a search, cursors are port IDs, so you can also start after a known port as below. With filter.search, results are sorted by how closely they match and the cursors are positions ("1", "2", ...), so always use endCursor from the previous page:
query ports {
ports(first: 10, after: "grpir") {
totalCount
pageInfo {
startCursor
hasPreviousPage
hasNextPage
endCursor
}
edges {
cursor
node {
id
name
country
timeZone {
name
offset
}
}
}
}
}