Skip to content

Commit

Permalink
feat: core.order add order memo param, fix test response
Browse files Browse the repository at this point in the history
  • Loading branch information
zjkung1123 committed May 17, 2024
1 parent 453f1be commit 8f79308
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 30 deletions.
64 changes: 42 additions & 22 deletions fugle_trade/order.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
"""
Define Order Objects
"""

import typing
from fugle_trade.constant import (
Action,
APCode,
Trade,
PriceFlag,
BSFlag
)

class OrderObject():
from fugle_trade.constant import Action, APCode, Trade, PriceFlag, BSFlag


class OrderObject:
ap_code: APCode
bs_flag: BSFlag
price_flag: PriceFlag
Expand All @@ -19,18 +15,20 @@ class OrderObject():
price: float
stock_no: str
quantity: int
memo: str

def __init__(
self,
buy_sell: Action,
price: float,
stock_no: str,
quantity: int,
ap_code: APCode = APCode.Common,
bs_flag: BSFlag = BSFlag.ROD,
price_flag: PriceFlag = PriceFlag.Limit,
trade: Trade = Trade.Cash,
):
self,
buy_sell: Action,
price: float,
stock_no: str,
quantity: int,
ap_code: APCode = APCode.Common,
bs_flag: BSFlag = BSFlag.ROD,
price_flag: PriceFlag = PriceFlag.Limit,
trade: Trade = Trade.Cash,
memo: str = "",
):

if type(buy_sell) is not Action:
raise TypeError("Please use fugleTrade.constant Action")
Expand All @@ -50,8 +48,14 @@ def __init__(
if quantity < 1 or quantity > 1000:
raise TypeError("quantity must within range 1 ~ 999")
elif ap_code == APCode.Emg:
if quantity < 1 or quantity > 499000 or (quantity > 1000 and quantity % 1000 != 0):
raise TypeError("quantity must within range 1 ~ 499000, or multiply of 1000")
if (
quantity < 1
or quantity > 499000
or (quantity > 1000 and quantity % 1000 != 0)
):
raise TypeError(
"quantity must within range 1 ~ 499000, or multiply of 1000"
)

if type(ap_code) is not APCode:
raise TypeError("Please use fugleTrade.constant APCode")
Expand All @@ -65,6 +69,9 @@ def __init__(
if type(trade) is not Trade:
raise TypeError("Please use fugleTrade.constant Trade")

if len(memo) > 50:
memo = memo[:50]

self.ap_code = ap_code
self.price_flag = price_flag
self.bs_flag = bs_flag
Expand All @@ -73,6 +80,19 @@ def __init__(
self.price = price
self.stock_no = stock_no
self.quantity = quantity
self.memo = memo

def __str__(self):
return "ap_code: %s, price_flag: %s, bs_flag: %s, trade: %s, buy_sell: %s, price: %s, stock_no: %s, quantity: %s" % (self.ap_code, self.price_flag, self.bs_flag, self.trade, self.buy_sell, self.price, self.stock_no, self.quantity)
return (
"ap_code: %s, price_flag: %s, bs_flag: %s, trade: %s, buy_sell: %s, price: %s, stock_no: %s, quantity: %s"
% (
self.ap_code,
self.price_flag,
self.bs_flag,
self.trade,
self.buy_sell,
self.price,
self.stock_no,
self.quantity,
)
)
3 changes: 2 additions & 1 deletion fugle_trade/sdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Expose as a single library for user to use
"""

from fugle_trade_core.fugle_trade_core import CoreSDK
from fugle_trade.constant import APCode, PriceFlag
from fugle_trade.order import OrderObject
Expand Down Expand Up @@ -75,7 +76,7 @@ def reset_password(self):

def place_order(self, order_object: OrderObject):
"""place order"""
return loads(self.__core.order(order_object))["data"]
return loads(self.__core.order(order_object, order_object.memo))["data"]

def delete_order(self, order_result):
"""delete_order"""
Expand Down
6 changes: 4 additions & 2 deletions tests/fugle_trade_core/fixtures/response-inventories.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
"valueNow": "3148",
"makeA": "725",
"makeAPer": "30.21",
"priceEvn": "25.78"
"priceEvn": "25.78",
"memo": ""
},
{
"tDate": "20200807",
Expand All @@ -47,7 +48,8 @@
"valueNow": "4387",
"makeA": "762",
"makeAPer": "21.16",
"priceEvn": "27.67"
"priceEvn": "27.67",
"memo": ""
}
],
"stkNo": "0056",
Expand Down
6 changes: 4 additions & 2 deletions tests/fugle_trade_core/fixtures/response-orders-history.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
"cel_qty_share": 0,
"celable": 1,
"avg_price": 0,
"bs_flag": "R"
"bs_flag": "R",
"memo": ""
},
{
"ack_date": "20220314",
Expand All @@ -43,7 +44,8 @@
"cel_qty_share": 0,
"celable": "2",
"avg_price": 0,
"bs_flag": "R"
"bs_flag": "R",
"memo": ""
}
]
}
Expand Down
6 changes: 4 additions & 2 deletions tests/fugle_trade_core/fixtures/response-orders.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
"err_code": "00000000",
"err_msg": "",
"avg_price": 0,
"bs_flag": "R"
"bs_flag": "R",
"memo": ""
},
{
"work_date": "20220222",
Expand All @@ -49,7 +50,8 @@
"err_code": "00000000",
"err_msg": "",
"avg_price": 0,
"bs_flag": "R"
"bs_flag": "R",
"memo": ""
}
]
}
Expand Down
3 changes: 2 additions & 1 deletion tests/fugle_trade_core/fixtures/response-transactions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
"payn": "-30042",
"make": "0",
"makePer": "0.00",
"cDate": "20220222"
"cDate": "20220222",
"memo": ""
}
],
"tDate": "20220222",
Expand Down

0 comments on commit 8f79308

Please sign in to comment.