# Status

Get the past, present, or future status for a stock market. The endpoint will respond with "open" for trading days or "closed" for weekends or market holidays.

## Endpoint
```
https://api.marketdata.app/v1/markets/status/
```
#### Method
```
GET
```
## Request Example

### HTTP

**GET** [https://api.marketdata.app/v1/markets/status/?from=2020-01-01&to=2020-12-31](https://api.marketdata.app/v1/markets/status/?from=2020-01-01&to=2020-12-31)

**GET** [https://api.marketdata.app/v1/markets/status/?date=yesterday](https://api.marketdata.app/v1/markets/status/?date=yesterday)

### JavaScript

```js title="app.js"
import { MarketDataClient } from "@marketdata/sdk";

const client = new MarketDataClient();

try {
  const days = await client.markets.status({ from: "2020-01-01", to: "2020-12-31" });
  for (const d of days) {
    console.log(`date=${d.date} status=${d.status}`);
  }

  const yesterday = await client.markets.status({ date: "yesterday" });
  console.log(yesterday[0]);
} catch (error) {
  console.error(error);
}
```

### TypeScript

```typescript title="app.ts"
import { MarketDataClient } from "@marketdata/sdk";
import type { MarketStatusResponse } from "@marketdata/sdk";

const client = new MarketDataClient();

try {
  const days: MarketStatusResponse = await client.markets.status({ from: "2020-01-01", to: "2020-12-31" });
  for (const d of days) {
    console.log(`date=${d.date} status=${d.status}`);
  }

  const yesterday: MarketStatusResponse = await client.markets.status({ date: "yesterday" });
  console.log(yesterday[0]);
} catch (error) {
  console.error(error);
}
```

### Python

```python title="app.py"
from marketdata import MarketDataClient

client = MarketDataClient()
status1 = client.markets.status(from_date="2020-01-01", to_date="2020-12-31")
status2 = client.markets.status(date="yesterday")

print(status1)
print(status2)
```

### Go

```go title="marketstatus.go"

import (
  "fmt"

  api "github.com/MarketDataApp/sdk-go"
)

func ExampleMarketStatus() {
	msr, err := api.MarketStatus().From("2020-01-01").To("2020-12-31").Get()
	if err != nil {
		fmt.Print(err)
		return
	}

	for _, report := range msr {
		fmt.Println(report)
	}
}

func ExampleMarketStatus_relativeDates() {
	msr, err := api.MarketStatus().Date("yesterday").Get()
	if err != nil {
		fmt.Print(err)
		return
	}

	for _, report := range msr {
		fmt.Println(report)
	}
}
```

### PHP

```php title="marketStatus.php"
use MarketDataApp\Client;

$client = new Client();

// Get market status for a date range
$statuses = $client->markets->status(
    country: "US",
    from: "2020-01-01",
    to: "2020-12-31"
);

// Display formatted market statuses
echo $statuses;

// Get market status for yesterday
$yesterday = $client->markets->status(
    country: "US",
    date: "yesterday"
);
echo $yesterday;
```

### Java

```java title="MarketStatusApp.java"
import com.marketdata.sdk.MarketDataClient;
import com.marketdata.sdk.markets.MarketStatusRequest;
import java.time.LocalDate;

public class MarketStatusApp {
  public static void main(String[] args) {
    try (MarketDataClient client = new MarketDataClient()) {
      client.markets()
          .status(MarketStatusRequest.builder()
              .from(LocalDate.of(2020, 1, 1))
              .to(LocalDate.of(2020, 12, 31))
              .build())
          .values()
          .forEach(System.out::println);

      client.markets()
          .status(MarketStatusRequest.of())
          .values()
          .forEach(System.out::println);
    }
  }
}
```

### Kotlin

```kotlin title="MarketStatusApp.kt"
import com.marketdata.sdk.MarketDataClient
import com.marketdata.sdk.markets.MarketStatusRequest
import java.time.LocalDate

fun main() {
    MarketDataClient().use { client ->
        client.markets()
            .status(
                MarketStatusRequest.builder()
                    .from(LocalDate.of(2020, 1, 1))
                    .to(LocalDate.of(2020, 12, 31))
                    .build()
            )
            .values()
            .forEach(::println)

        client.markets()
            .status(MarketStatusRequest.of())
            .values()
            .forEach(::println)
    }
}
```

## Response Example

```json
{
  "s": "ok",
  "date": [1680580800],
  "status": ["open"]
}
```

## Request Parameters

### Required

- There are no required parameters for `status`. If no parameter is given, the request will return the market status in the United States for the current day.

### Optional

- **country** `string`

  Use to specify the country. Use the two digit ISO 3166 country code. If no country is specified, `US` will be assumed. Only countries that Market Data supports for stock price data are available (currently only the United States).

- **date** `date`

  Consult whether the market was open or closed on the specified date. Accepted timestamp inputs: ISO 8601, unix, spreadsheet, relative date strings.

- **from** `date`

  The earliest date (inclusive). If you use countback, from is not required. Accepted timestamp inputs: ISO 8601, unix, spreadsheet, relative date strings.

- **to** `date`

  The last date (inclusive). Accepted timestamp inputs: ISO 8601, unix, spreadsheet, relative date strings.

- **countback** `number`

  Countback will fetch a number of dates before `to` If you use from, countback is not required.

## Response Attributes

### Success

- **s** `string`

  ll always be `ok` when there is data for the dates requested.

- **date** `array[dates]`

  The date.

- **status** `array[string]`

  The market status. This will always be `open` or `closed` or `null`. Half days or partial trading days are reported as `open`. Requests for days further in the past or further in the future than our data will be returned as `null`.

### No Data

- **s** `string`

  Status will be `no_data` if no data is found for the request.

### Error

- **s** `string`

  Status will be `error` if the request produces an error response.

- **errmsg** `string`
  An error message.
