Get the lane historic
By following this tutorial, you'll be able to benchmark freight rates using our API by varying the date parameter and retrieving the historical rates for each week.
Step 1: Prepare your payload
To request the rate history for a specific lane, you need to construct a payload. The payload should include all the necessary information for the benchmarking request, such as the pickup, the delivery, and other characteristics details. However, the key parameter that you will need to modify is the date.
# Define the payload
payload = {
"pickup": {
"latitude": 45.7580407,
"longitude": 4.7525578
},
"delivery": {
"latitude": 50.6310857,
"longitude": 2.8911826
},
"schedule": {
"etd": '' # This will be modified in the loop
},
}
Step 2: Determine the desired time frame
Decide on the time frame for which you want to benchmark the rates. For example, if you want to benchmark rates since the beginning of 2023, you will need to retrieve the weekly prices for each week since then.
import datetime
# Step 2: Determine the desired time frame
start_date = datetime(2023, 1, 1)
end_date = datetime(2023, 4, 30)
Step 3: Loop through the dates
In your code, set up a loop that iterates through each week within your desired time frame. Start with the initial date (e.g., the first week of 2023) and increment it by one week for each iteration.
Step 4: Modify the payload
For each iteration of the loop, update the date in your payload to reflect the current week you are querying. Keep all other parameters in the payload the same.
Step 5: Make the API request
Using the modified payload, send a request to our API to retrieve the rate history for the specific lane. The API will return the benchmarked rates for the lane for each date.
import timedelta
# Steps 3: Loop through the dates
all_responses = []
current_date = start_date
while current_date <= end_date:
# Step 4: Modify the payload
payload_current = payload.copy()
payload_current['date'] = current_date.strftime('%Y-%m-%d')
# Step 5: Query the Benchmarking API and retrieve it in the response list
response = requests.post(url, json=payload_current, headers=headers)
all_responses += response
# Increment the date by one week
current_date += timedelta(weeks=1)
Step 6: Store or process the data
Capture the returned rate history data for each week, and store it or process it as per your requirements. You can analyze the data, compare rates over different weeks, or use it for any other purposes you need.
Updated over 1 year ago