Skip to content

Commit 9e346ce

Browse files
authored
Merge pull request #3 from Patch-Code-Prosperity/Cfomodz-utils-1
Update and rename api_utilities.py to utilities.py
2 parents 8938576 + 1c0959f commit 9e346ce

File tree

2 files changed

+26
-57
lines changed

2 files changed

+26
-57
lines changed

api_utilities.py

Lines changed: 0 additions & 57 deletions
This file was deleted.

utilities.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# utilities.py
2+
3+
import datetime
4+
5+
def clean_params(params):
6+
"""Remove None values from a dictionary of parameters."""
7+
return {k: v for k, v in params.items() if v is not None}
8+
9+
def convert_time(dt=None, format_type="8601"):
10+
"""Convert datetime objects into a string format according to a specified type."""
11+
if dt is None:
12+
return None
13+
14+
formats = {
15+
"8601": lambda x: x.isoformat()[:-3] + 'Z', # ISO8601 format
16+
"epoch": lambda x: int(x.timestamp() * 1000), # Epoch time in milliseconds
17+
"YYYY-MM-DD": lambda x: x.strftime("%Y-%m-%d") # Custom Schwab Options date format
18+
}
19+
formatter = formats.get(format_type, str)
20+
return formatter(dt)
21+
22+
def format_list(items):
23+
"""Convert a list of items into a comma-separated string or return single item as string."""
24+
if items is None:
25+
return None
26+
return ",".join(items) if isinstance(items, list) else str(items)

0 commit comments

Comments
 (0)