1 Star 0 Fork 0

damone/FastBinaryEncoding

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
serialization_json.py 937 Bytes
一键复制 编辑 原始数据 按行查看 历史
Ivan Shynkarenka 提交于 2018-10-20 01:25 +08:00 . Ruby json
import proto
from proto import proto
def main():
# Create a new account with some orders
account = proto.Account(1, "Test", proto.State.good, proto.Balance("USD", 1000.0), proto.Balance("EUR", 100.0))
account.orders.append(proto.Order(1, "EURUSD", proto.OrderSide.buy, proto.OrderType.market, 1.23456, 1000.0))
account.orders.append(proto.Order(2, "EURUSD", proto.OrderSide.sell, proto.OrderType.limit, 1.0, 100.0))
account.orders.append(proto.Order(3, "EURUSD", proto.OrderSide.buy, proto.OrderType.stop, 1.5, 10.0))
# Serialize the account to the JSON string
json = account.to_json()
# Show the serialized JSON and its size
print("JSON: {}".format(json))
print("JSON size: {}".format(len(json)))
# Deserialize the account from the JSON string
account = proto.Account.from_json(json)
# Show account content
print()
print(account)
if __name__ == "__main__":
main()
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/damone/FastBinaryEncoding.git
git@gitee.com:damone/FastBinaryEncoding.git
damone
FastBinaryEncoding
FastBinaryEncoding
master

搜索帮助