Skip to content

Commit

Permalink
Merge pull request #54 from amashita/53
Browse files Browse the repository at this point in the history
  • Loading branch information
amashita committed Dec 12, 2020
2 parents 7a10132 + d68b2b2 commit 2629a8a
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 41 deletions.
2 changes: 1 addition & 1 deletion gmocoin/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!python3
__version__ = '0.0.3'
__version__ = '0.0.4'
10 changes: 5 additions & 5 deletions gmocoin/common/dto.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
from typing import List
from enum import Enum
from marshmallow import Schema, fields, post_load
# from datetime import datetime
from datetime import datetime
from pytz import timezone


class Status(Enum):
Expand Down Expand Up @@ -130,7 +131,7 @@ class BaseResponse:
"""
ベースレスポンスクラスです。
"""
def __init__(self, status: int, responsetime: str) -> None:
def __init__(self, status: int, responsetime: datetime) -> None:
"""
コンストラクタです。
Expand All @@ -141,7 +142,7 @@ def __init__(self, status: int, responsetime: str) -> None:
レスポンスタイムを設定します。
"""
self.status = status
self.responsetime = responsetime
self.responsetime = responsetime.astimezone(timezone('Asia/Tokyo'))


class BaseResponseSchema(BaseSchema):
Expand All @@ -150,8 +151,7 @@ class BaseResponseSchema(BaseSchema):
"""
__model__ = BaseResponse
status = fields.Int(data_key='status')
# responsetime = fields.DateTime(format='%Y-%m-%dT%H:%M:%S.%fZ', data_key='responsetime')
responsetime = fields.Str(data_key='responsetime')
responsetime = fields.DateTime(format='%Y-%m-%dT%H:%M:%S.%fZ', data_key='responsetime')


class Message:
Expand Down
19 changes: 10 additions & 9 deletions gmocoin/private/dto.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from marshmallow_enum import EnumField
from enum import Enum
from datetime import datetime
from pytz import timezone
from typing import List
from decimal import Decimal

Expand Down Expand Up @@ -50,7 +51,7 @@ class GetMarginRes(BaseResponse):
"""
余力情報レスポンスクラスです。
"""
def __init__(self, status: int, responsetime: str, data: GetMarginData) -> None:
def __init__(self, status: int, responsetime: datetime, data: GetMarginData) -> None:
"""
コンストラクタです。
Expand Down Expand Up @@ -113,7 +114,7 @@ class GetAssetsRes(BaseResponse):
"""
資産残高レスポンスクラスです。
"""
def __init__(self, status: int, responsetime: str, data: GetAssetsData) -> None:
def __init__(self, status: int, responsetime: datetime, data: GetAssetsData) -> None:
"""
コンストラクタです。
Expand Down Expand Up @@ -170,7 +171,7 @@ class ActiveOrder:
"""
def __init__(self, root_order_id: int, order_id: int, symbol: Symbol, side: SalesSide, order_type: OrderType,
execution_type: ExecutionType, settle_type: SettleType, size: Decimal, executed_size: Decimal,
price: Decimal, losscut_price: Decimal, status: OrderStatus, time_in_force: TimeInForce, timestamp: str) -> None:
price: Decimal, losscut_price: Decimal, status: OrderStatus, time_in_force: TimeInForce, timestamp: datetime) -> None:
"""
コンストラクタです。
Expand Down Expand Up @@ -218,7 +219,7 @@ def __init__(self, root_order_id: int, order_id: int, symbol: Symbol, side: Sale
self.losscut_price = losscut_price
self.status = status
self.time_in_force = time_in_force
self.timestamp = timestamp
self.timestamp = timestamp.astimezone(timezone('Asia/Tokyo'))


class ActiveOrderSchema(BaseSchema):
Expand All @@ -239,7 +240,7 @@ class ActiveOrderSchema(BaseSchema):
losscut_price = fields.Decimal(data_key='losscutPrice')
status = EnumField(OrderStatus, data_key='status')
time_in_force = EnumField(TimeInForce, data_key='timeInForce')
timestamp = fields.Str(data_key='timestamp')
timestamp = fields.DateTime(format='%Y-%m-%dT%H:%M:%S.%fZ', data_key='timestamp')


class GetActiveOrdersData:
Expand Down Expand Up @@ -273,7 +274,7 @@ class GetActiveOrdersRes(BaseResponse):
"""
有効注文一覧レスポンスクラスです。
"""
def __init__(self, status: int, responsetime: str, data: GetActiveOrdersData) -> None:
def __init__(self, status: int, responsetime: datetime, data: GetActiveOrdersData) -> None:
"""
コンストラクタです。
Expand Down Expand Up @@ -398,7 +399,7 @@ class PostOrderRes(BaseResponse):
"""
新規注文レスポンスクラスです。
"""
def __init__(self, status: int, responsetime: str, data: int) -> None:
def __init__(self, status: int, responsetime: datetime, data: int) -> None:
"""
コンストラクタです。
Expand Down Expand Up @@ -426,7 +427,7 @@ class PostCloseOrderRes(BaseResponse):
"""
決済注文レスポンスクラスです。
"""
def __init__(self, status: int, responsetime: str, data: int) -> None:
def __init__(self, status: int, responsetime: datetime, data: int) -> None:
"""
コンストラクタです。
Expand Down Expand Up @@ -454,7 +455,7 @@ class PostCloseBulkOrderRes(BaseResponse):
"""
一括決済注文レスポンスクラスです。
"""
def __init__(self, status: int, responsetime: str, data: int) -> None:
def __init__(self, status: int, responsetime: datetime, data: int) -> None:
"""
コンストラクタです。
Expand Down
22 changes: 12 additions & 10 deletions gmocoin/public/dto.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from marshmallow_enum import EnumField
from enum import Enum
from datetime import datetime
from pytz import timezone
from typing import List
from decimal import Decimal

Expand Down Expand Up @@ -36,7 +37,7 @@ class GetStatusRes(BaseResponse):
"""
取引所稼動状態レスポンスクラスです。
"""
def __init__(self, status: int, responsetime: str, data: GetStatusData) -> None:
def __init__(self, status: int, responsetime: datetime, data: GetStatusData) -> None:
"""
コンストラクタです。
Expand Down Expand Up @@ -65,7 +66,7 @@ class GetTickerData:
"""
銘柄最新レートデータクラスです。
"""
def __init__(self, symbol: Symbol, timestamp: str, volume: Decimal, ask: Decimal, bid: Decimal, high: Decimal, last: Decimal, low: Decimal) -> None:
def __init__(self, symbol: Symbol, timestamp: datetime, volume: Decimal, ask: Decimal, bid: Decimal, high: Decimal, last: Decimal, low: Decimal) -> None:
"""
コンストラクタです。
Expand All @@ -85,7 +86,7 @@ def __init__(self, symbol: Symbol, timestamp: str, volume: Decimal, ask: Decimal
self.last = last
self.low = low
self.symbol = symbol
self.timestamp = timestamp
self.timestamp = timestamp.astimezone(timezone('Asia/Tokyo'))
self.volume = volume


Expand All @@ -100,7 +101,7 @@ class GetTickerDataSchema(BaseSchema):
last = fields.Decimal(data_key='last')
low = fields.Decimal(data_key='low')
symbol = EnumField(Symbol, data_key='symbol')
timestamp = fields.Str(data_key='timestamp')
timestamp = fields.DateTime(format='%Y-%m-%dT%H:%M:%S.%fZ', data_key='timestamp')
volume = fields.Decimal(data_key='volume')

@pre_load
Expand All @@ -124,7 +125,7 @@ class GetTickerRes(BaseResponse):
"""
銘柄最新レートレスポンスクラスです。
"""
def __init__(self, status: int, responsetime: str, data: GetTickerData) -> None:
def __init__(self, status: int, responsetime: datetime, data: GetTickerData) -> None:
"""
コンストラクタです。
Expand Down Expand Up @@ -209,7 +210,7 @@ class GetOrderBooksRes(BaseResponse):
"""
銘柄板レスポンスクラスです。
"""
def __init__(self, status: int, responsetime: str, data: GetOrderBooksData) -> None:
def __init__(self, status: int, responsetime: datetime, data: GetOrderBooksData) -> None:
"""
コンストラクタです。
Expand Down Expand Up @@ -264,7 +265,7 @@ class Trade:
"""
取引データクラスです。
"""
def __init__(self, price: Decimal, side: SalesSide, size: Decimal, timestamp: str) -> None:
def __init__(self, price: Decimal, side: SalesSide, size: Decimal, timestamp: datetime) -> None:
"""
コンストラクタです。
Expand All @@ -281,7 +282,7 @@ def __init__(self, price: Decimal, side: SalesSide, size: Decimal, timestamp: st
self.price = price
self.side = side
self.size = size
self.timestamp = timestamp
self.timestamp = timestamp.astimezone(timezone('Asia/Tokyo'))


class TradeSchema(BaseSchema):
Expand All @@ -292,7 +293,8 @@ class TradeSchema(BaseSchema):
price = fields.Decimal(data_key='price')
side = EnumField(SalesSide, data_key='side')
size = fields.Decimal(data_key='size')
timestamp = fields.Str(data_key='timestamp')
timestamp = fields.DateTime(format='%Y-%m-%dT%H:%M:%S.%fZ', data_key='timestamp')



class GetTradesData:
Expand Down Expand Up @@ -326,7 +328,7 @@ class GetTradesRes(BaseResponse):
"""
取引履歴レスポンスクラスです。
"""
def __init__(self, status: int, responsetime: str, data: GetOrderBooksData) -> None:
def __init__(self, status: int, responsetime: datetime, data: GetOrderBooksData) -> None:
"""
コンストラクタです。
Expand Down
21 changes: 11 additions & 10 deletions tests/test_private_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import time
import json
from decimal import Decimal
from datetime import datetime

from gmocoin.private.api import Client
from gmocoin.common.dto import AssetSymbol, Symbol, SalesSide, OrderType, ExecutionType, SettleType, \
Expand All @@ -24,7 +25,7 @@ def test_get_margin(self):
res = client.get_margin()

assert type(res.status) is int
assert type(res.responsetime) is str
assert type(res.responsetime) is datetime
assert type(res.data.actual_profit_loss) is Decimal
assert type(res.data.available_amount) is Decimal
assert type(res.data.margin) is Decimal
Expand All @@ -43,7 +44,7 @@ def test_get_assets(self):
res = client.get_assets()

assert type(res.status) is int
assert type(res.responsetime) is str
assert type(res.responsetime) is datetime
for d in res.data:
assert type(d.amount) is Decimal
assert type(d.available) is Decimal
Expand Down Expand Up @@ -73,7 +74,7 @@ def test_get_active_orders(self):
res = client.get_active_orders(symbol=Symbol.BTC_JPY)

assert type(res.status) is int
assert type(res.responsetime) is str
assert type(res.responsetime) is datetime
assert type(res.data.pagination.current_page) is int
assert type(res.data.pagination.count) is int
for o in res.data.active_orders:
Expand All @@ -90,7 +91,7 @@ def test_get_active_orders(self):
assert type(o.losscut_price) is Decimal
assert type(o.status) is OrderStatus
assert type(o.time_in_force) is TimeInForce
assert type(o.timestamp) is str
assert type(o.timestamp) is datetime

print(res.status)
print(res.responsetime)
Expand Down Expand Up @@ -122,7 +123,7 @@ def test_get_position_summary(self):
res = client.get_position_summary(symbol=Symbol.XRP_JPY)

assert type(res.status) is int
assert type(res.responsetime) is str
assert type(res.responsetime) is datetime
if res.data.position_summarys is not None:
for p in res.data.position_summarys:
assert type(p.average_position_rate) is Decimal
Expand Down Expand Up @@ -157,7 +158,7 @@ def test_order_change_and_cancel(self):
order_id = res.data

assert type(res.status) is int
assert type(res.responsetime) is str
assert type(res.responsetime) is datetime
assert type(res.data) is int
print(res.status)
print(res.responsetime)
Expand All @@ -166,14 +167,14 @@ def test_order_change_and_cancel(self):
time.sleep(TestConst.API_CALL_INTERVAL)
res = client.change_order(res.data, price='1510000', losscut_price='1000000')
assert type(res.status) is int
assert type(res.responsetime) is str
assert type(res.responsetime) is datetime
print(res.status)
print(res.responsetime)

time.sleep(TestConst.API_CALL_INTERVAL)
res = client.cancel_order(order_id)
assert type(res.status) is int
assert type(res.responsetime) is str
assert type(res.responsetime) is datetime
print(res.status)
print(res.responsetime)

Expand All @@ -188,7 +189,7 @@ def test_order_and_cancel(self):
size='0.01')

assert type(res.status) is int
assert type(res.responsetime) is str
assert type(res.responsetime) is datetime
assert type(res.data) is int
print(res.status)
print(res.responsetime)
Expand All @@ -197,7 +198,7 @@ def test_order_and_cancel(self):
time.sleep(TestConst.API_CALL_INTERVAL)
res = client.cancel_order(res.data)
assert type(res.status) is int
assert type(res.responsetime) is str
assert type(res.responsetime) is datetime
print(res.status)
print(res.responsetime)

Expand Down
13 changes: 7 additions & 6 deletions tests/test_public_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from enum import Enum
import time
from decimal import Decimal
from datetime import datetime

from gmocoin.public.api import Client
from gmocoin.common.dto import Status, Symbol, SalesSide
Expand All @@ -15,7 +16,7 @@ def test_get_status(capfd):
res = client.get_status()

assert type(res.status) is int
assert type(res.responsetime) is str
assert type(res.responsetime) is datetime
assert type(res.data.status) is Status

print(res.status)
Expand All @@ -29,15 +30,15 @@ def test_get_ticker(capfd):
res = client.get_ticker(Symbol.BTC_JPY)

assert type(res.status) is int
assert type(res.responsetime) is str
assert type(res.responsetime) is datetime
for d in res.data:
assert type(d.ask) is Decimal
assert type(d.bid) is Decimal
assert type(d.high) is Decimal
assert type(d.last) is Decimal
assert type(d.low) is Decimal
assert type(d.symbol) is Symbol
assert type(d.timestamp) is str
assert type(d.timestamp) is datetime
assert type(d.volume) is Decimal

print(d.ask)
Expand All @@ -64,7 +65,7 @@ def test_get_orderbooks(capfd):
res = client.get_orderbooks(Symbol.BTC_JPY)

assert type(res.status) is int
assert type(res.responsetime) is str
assert type(res.responsetime) is datetime
for ask in res.data.asks:
assert type(ask.price) is Decimal
assert type(ask.size) is Decimal
Expand All @@ -84,15 +85,15 @@ def test_get_trades(capfd):
res = client.get_trades(Symbol.BTC_JPY)

assert type(res.status) is int
assert type(res.responsetime) is str
assert type(res.responsetime) is datetime
assert type(res.data.pagination.current_page) is int
assert type(res.data.pagination.count) is int

for trade in res.data.trades:
assert type(trade.price) is Decimal
assert type(trade.side) is SalesSide
assert type(trade.size) is Decimal
assert type(trade.timestamp) is str
assert type(trade.timestamp) is datetime

time.sleep(TestConst.API_CALL_INTERVAL)
res = client.get_trades(Symbol.BTC_JPY, page=2, count=50)
Expand Down

0 comments on commit 2629a8a

Please sign in to comment.