53 lines
1.2 KiB
Python
53 lines
1.2 KiB
Python
import requests
|
||
|
||
# 服务器地址
|
||
URL = "http://trader.biggerfish.tech:9527/yu"
|
||
|
||
def buy(code: str, price: float, amount: int) -> dict:
|
||
"""买入股票
|
||
|
||
Args:
|
||
code: 股票代码,例如 "601988.SH"
|
||
price: 买入价格
|
||
amount: 买入数量
|
||
|
||
Returns:
|
||
dict: 交易结果
|
||
"""
|
||
data = {
|
||
"code": code,
|
||
"price": str(price),
|
||
"amount": str(amount)
|
||
}
|
||
response = requests.post(f"{URL}/buy", json=data)
|
||
return response.json()
|
||
|
||
def sell(code: str, price: float, amount: int) -> dict:
|
||
"""卖出股票
|
||
|
||
Args:
|
||
code: 股票代码,例如 "601988.SH"
|
||
price: 卖出价格
|
||
amount: 卖出数量
|
||
|
||
Returns:
|
||
dict: 交易结果
|
||
"""
|
||
data = {
|
||
"code": code,
|
||
"price": str(price),
|
||
"amount": str(amount)
|
||
}
|
||
response = requests.post(f"{URL}/sell", json=data)
|
||
return response.json()
|
||
|
||
|
||
if __name__ == "__main__":
|
||
# 示例:买入中国银行1000股,价格3.45
|
||
result = buy("601988.SH", 3.45, 1000)
|
||
print("买入结果:", result)
|
||
|
||
# 示例:卖出中国银行1000股,价格3.48
|
||
result = sell("601988.SH", 3.48, 1000)
|
||
print("卖出结果:", result)
|
||
|