fix bug
This commit is contained in:
@@ -1,6 +1,4 @@
|
||||
import ast
|
||||
import sqlite3
|
||||
import tempfile
|
||||
import unittest
|
||||
from dataclasses import asdict, fields
|
||||
from datetime import datetime
|
||||
@@ -8,10 +6,12 @@ from pathlib import Path
|
||||
from types import SimpleNamespace
|
||||
from unittest.mock import Mock
|
||||
from libs.order import OrderBook as ActiveOrders
|
||||
from libs.state import FLAG_BUY, State
|
||||
from sdk.models import Assets, DealItem, OrderItem, PositionItem
|
||||
from sdk.portfolio import PortfolioMixin
|
||||
|
||||
# QMT 委托/成交的 offset_flag:48 买入、49 卖出。
|
||||
FLAG_BUY = 48
|
||||
|
||||
|
||||
class ApiModelTests(unittest.TestCase):
|
||||
def setUp(self):
|
||||
@@ -73,26 +73,6 @@ class ApiModelTests(unittest.TestCase):
|
||||
client.cancel_by_id.assert_called_once_with('sys1')
|
||||
self.assertTrue(book.busy('600000.SH', 'BUY'))
|
||||
|
||||
def test_storage_and_price_fallback(self):
|
||||
deal = self.client.deals()[0]
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
path = Path(tmp) / 'state.db'
|
||||
book = State(path)
|
||||
book.sync_deals([deal])
|
||||
loaded = State(path).deals['sys1']
|
||||
self.assertEqual(loaded['volume'], deal.volume)
|
||||
self.assertEqual(loaded['trade_date'], '2026-09-07')
|
||||
deal.order_sys_id = 'sys2'
|
||||
deal.trade_amount = 0
|
||||
book.sync_deals([deal, deal])
|
||||
self.assertEqual(book.deals['sys2']['trade_amount'], 1000)
|
||||
self.assertEqual(deal.trade_amount, 0)
|
||||
deal.order_sys_id = 'sys3'
|
||||
deal.price = 0
|
||||
with self.assertRaises(sqlite3.IntegrityError):
|
||||
book.sync_deals([deal])
|
||||
self.assertEqual(set(State(path).deals), {'sys1', 'sys2'})
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user