
ํ์ด์ฌ์์ json ํ์ผ์ ์ฝ๊ณ ํ์ฑ ํ ๋๋ฆ์ ํํฐ๋ง์ ๊ฑฐ์ณ ๋ณด๊ณ ์ถ์ ์ ๋ณด๋ฅผ ์ถ๋ ฅํ๋ ๊ฐ๋จํ ์์ ๋ค. ํ์ด์ฌ์์๋ json์ js์ ๊ฐ์ด ํธํ๊ฒ ์ฌ์ฉํ ์ ์์ผ๋ฉฐ, ๋ณ๋์ ์ถ๊ฐ ํจํค์ง ์์ด json์ ์ฝ๊ณ ์ธ์ ์๋๋ก ์ง์ํ๋ค.
๋ณดํต json์ ํ์ด์ฌ์ ๋ฆฌ์คํธ, ํํ, ๋์ ๋๋ฆฌ๋ก ๋ณํํด์ ํ๋ก๊ทธ๋จ์ ๋ฐ์ํ๋ ๊ฒ์ด ์ผ๋ฐ์ ์ด๋ค.
์๋๋ json ํ์ผ์ open ํ loadํจ์๋ฅผ ํตํด json_data๋ก ์ฝ๊ณ ํ์ํ ๋ฐ์ดํฐ๋ค์ ๋ฆฌ์คํธ์ ๋ฐ๋ก ๋ด์์ count์ ๋ฐ์ดํฐ ๋ชจ๋ ์ถ๋ ฅํ๋ ์์ ์ด๋ค.
import json
with open("ETHUSDT.json", "r") as f:
json_data = json.load(f)
# print(json.dumps(json_data))
buy_arr = []
sell_arr = []
for json_obj in json_data:
if "SELL" in json_obj["side"] and ("SEOA" in json_obj["clientOrderId"] or "C2O" in json_obj["clientOrderId"] or "REFILL" in json_obj["clientOrderId"]):
sell_arr.append((json_obj["price"], json_obj["side"], json_obj["clientOrderId"]))
if "BUY" in json_obj["side"] and ("SEOA" in json_obj["clientOrderId"] or "C2O" in json_obj["clientOrderId"] or "REFILL" in json_obj["clientOrderId"]):
buy_arr.append((json_obj["price"], json_obj["side"], json_obj["clientOrderId"]))
sub_arr = []
for json_obj in json_data:
if "SUB" in json_obj["clientOrderId"]:
sub_arr.append((json_obj["price"], json_obj["side"], json_obj["clientOrderId"]))
#buy_jes_arr.sort(key = lambda x:x[0], reverse=True)
print("Total count = ", len(json_data))
print("JES_BUY count = ", len(buy__arr))
print("JES_SELL count = ", len(sell_arr))
print("SUB count = ", len(sub_arr))
print("---- DATA ----")
print("BUY: ", buy_arr)
print("SELL: ", sell_arr)
print("SUB:", sub_arr)
์๋๋ jsonํ์ผ์ ๋ด์ฉ์ด๋ค. Array ๋ด ๊ฐ์ฒด๊ฐ 200๊ฐ๊ฐ ๋๊ธฐ ๋๋ฌธ์ ์ผ๋ถ๋ง ๊ฐ์ ธ์๋ค.
[
{
"time": "1684375756476",
"updateTime": "1684375756499",
"orderId": "1423041418184758528",
"clientOrderId": "SELL-755933-1020003-100-O-SEOA-OT",
"symbol": "ETHUSDT",
"price": "1823.35",
"orderType": "LIMIT",
"side": "SELL",
},
{
"time": "1684375756467",
"updateTime": "1684375756769",
"orderId": "1423041418159521024",
"clientOrderId": "BUY-755933-1020003-1-O-SEOA",
"symbol": "ETHUSDT",
"price": "1820.85",
"orderType": "LIMIT",
"side": "BUY",
},
{
"time": "1684375750347",
"updateTime": "1684375753853",
"orderId": "1423041366687094016",
"clientOrderId": "BUY-749778-1020003-1-O-SUB",
"symbol": "ETHUSDT",
"price": "1819.25",
"orderType": "LIMIT",
"side": "BUY",
},
{
"time": "1684375750326",
"updateTime": "1684375750349",
"orderId": "1423041366645079296",
"clientOrderId": "SELL-749778-1020003-100-O-REFILL-OT",
"symbol": "ETHUSDT",
"price": "1819.05",
"orderType": "LIMIT",
"side": "BUY"
}
...
]
'ํ๋ก๊ทธ๋๋ฐ ์ธ์ด > Python' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
| ํ์ด์ฌ ํํ์ ๋ชจ๋ ๊ฒ (1) | 2023.12.03 |
|---|---|
| ํ์ด์ฌ ๋ฆฌ์คํธ(list)์ ๋ชจ๋ ๊ฒ (1) | 2023.12.02 |
| ํ์ด์ฌ ๋ฌธ์์ด(string)์ ๋ชจ๋ ๊ฒ (1) | 2023.12.01 |
| ํจํค์ง์ __init__ํ์ผ (1) | 2023.05.31 |
| ํ์ด์ฌ์ ์์ ๊ฐ์ฒด์งํฅ ์ธ์ด๋ค? (2) | 2023.05.28 |
๋๊ธ