<jupyter_start><jupyter_text>Market Rates API Example  SetupInstall the Signal Ocean SDK:```pip install signal-ocean```Set your subscription key acquired here: https://apis.signalocean.com/profile<jupyter_code>signal_ocean_api_key = '' #replace with your subscription key<jupyter_output><empty_output><jupyter_text>Market Rates APIThe Market Rates API retrieves available routes and market rates. First create connection towardsMarket Rates API in order to find available routes by vessel class:<jupyter_code>from signal_ocean import Connection, MarketRatesAPI
from datetime import date

connection = Connection(api_key=signal_ocean_api_key)
mr_api = MarketRatesAPI(connection)<jupyter_output><empty_output><jupyter_text>Get the available vessel classesRetrieve the vessel classes for which we can get routes or market rates:<jupyter_code>vessel_classes = mr_api.get_vessel_classes()
print(vessel_classes)<jupyter_output>(VesselClass(id=60, vessel_type_id=6, from_size=70001, to_size=250000, name='VLGC', vessel_type='LPG', defining_size='CubicSize', size='cbm'), VesselClass(id=61, vessel_type_id=6, from_size=28001, to_size=70000, name='Midsize/LGC', vessel_type='LPG', defining_size='CubicSize', size='cbm'), VesselClass(id=62, vessel_type_id=6, from_size=10001, to_size=28000, name='Handy', vessel_type='LPG', defining_size='CubicSize', size='cbm'), VesselClass(id=63, vessel_type_id=6, from_size=0, to_size=10000, name='Small', vessel_type='LPG', defining_size='CubicSize', size='cbm'), VesselClass(id=69, vessel_type_id=3, from_size=220000, to_size=550000, name='VLOC', vessel_type='Dry', defining_size='DeadWeight', size='kt'), VesselClass(id=70, vessel_type_id=3, from_size=120000, to_size=219999, name='Capesize', vessel_type='Dry', defining_size='DeadWeight', size='kt'), VesselClass(id=72, vessel_type_id=3, from_size=85000, to_size=119999, name='Post Panamax Dry', vessel_type='Dry', defining_size='DeadWeight[...]<jupyter_text>Get routes for a vessel classBased on the vessel classes that we got above we can request available routes for VLCC vessels<jupyter_code>vlcc_vessel_class = next(vc for vc in vessel_classes if vc.name=='VLCC')
vlcc_routes = mr_api.get_routes(vessel_class_id=vlcc_vessel_class.id)
print(vlcc_routes)<jupyter_output>(Route(id='R5', description='VLCC - AG_FarEast', unit='WS', vessel_class_id=84, is_clean=False), Route(id='R6', description='VLCC - AG_Spore', unit='WS', vessel_class_id=84, is_clean=False), Route(id='R7', description='VLCC - AG_USG', unit='WS', vessel_class_id=84, is_clean=False), Route(id='R8', description='VLCC - WAfr_East', unit='WS', vessel_class_id=84, is_clean=False))<jupyter_text>Get the market ratesNow we can request the market rate on a given date for one of the routes we got in previous step orfor all routes matching this vessel class<jupyter_code>mr_api.get_market_rates(date(2020, 1, 2), route_id=vlcc_routes[0].id)
mr_api.get_market_rates(date(2020, 1, 2), vessel_class_id=vlcc_vessel_class.id)<jupyter_output><empty_output><jupyter_text>We can also see how market rates evolve on the routes of a certain vessel class for a given time period.Below we plot the VLCC market rates in WS from October through December 2020.<jupyter_code>import pandas as pd
import warnings
warnings.filterwarnings('ignore')

vlcc_rates = mr_api.get_market_rates(start_date=date(2020, 10, 1),
                                end_date=date(2020, 12, 31),
                                vessel_class_id=vlcc_vessel_class.id)
df = pd.DataFrame([vars(vr) for vr in vlcc_rates])
df.set_index('rate_date', inplace=True)
df.groupby('route_id')['rate_value'].plot(legend=True);<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11856516976998904, 'fraction_numerical': 0.03751369112814896, 'mean_word_length': 8.295165394402035, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '270552', 'license': 'Apache-2.0', 'n_tokens_mistral': 1363, 'n_tokens_neox': 1238, 'n_words': 281, 'path': 'docs/examples/jupyter/MarketRatesAPI/MarketRatesAPI.ipynb', 'repo_name': 'SignalOceanSdk/SignalSDK', 'size': '3652'}