Skip to content

Commit ce9556d

Browse files
committed
Merge branch 'master' into dev
2 parents 678acf5 + 467c15d commit ce9556d

File tree

3 files changed

+148
-10
lines changed

3 files changed

+148
-10
lines changed

shipane_sdk/client.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -120,14 +120,6 @@ def sell(self, client=None, timeout=None, **kwargs):
120120
kwargs['action'] = 'SELL'
121121
return self.__execute(client, timeout, **kwargs)
122122

123-
def buy_on_margin(self, client=None, timeout=None, **kwargs):
124-
kwargs['action'] = 'BUY_ON_MARGIN'
125-
return self.__execute(client, timeout, **kwargs)
126-
127-
def sell_then_repay(self, client=None, timeout=None, **kwargs):
128-
kwargs['action'] = 'SELL_THEN_REPAY'
129-
return self.__execute(client, timeout, **kwargs)
130-
131123
def ipo(self, client=None, timeout=None, **kwargs):
132124
kwargs['action'] = 'IPO'
133125
return self.__execute(client, timeout, **kwargs)

tests/shipane_sdk/test_client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,15 @@ def test_get_filled_orders(self):
7373

7474
def test_buy_stock(self):
7575
try:
76-
order = self.client.buy(self.client_param, symbol='000001', price=11.11, amount=100)
76+
order = self.client.buy(self.client_param, symbol='000001', price=9, amount=100)
7777
self.assertIsNotNone(order['id'])
7878
except HTTPError as e:
7979
result = e.response.json()
8080
self.assertNotEqual(result['source'], "实盘易")
8181

8282
def test_sell_stock(self):
8383
try:
84-
order = self.client.sell(self.client_param, symbol='000001', price=12.11, amount=100)
84+
order = self.client.sell(self.client_param, symbol='000001', price=9.5, amount=100)
8585
self.assertIsNotNone(order['id'])
8686
except HTTPError as e:
8787
result = e.response.json()
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
# -*- coding: utf-8 -*-
2+
3+
import logging
4+
import os
5+
import unittest
6+
7+
import six
8+
from hamcrest import *
9+
from requests import HTTPError
10+
from six.moves import configparser
11+
12+
from shipane_sdk import Client
13+
from tests.shipane_sdk.matchers.dataframe_matchers import *
14+
15+
if six.PY2:
16+
ConfigParser = configparser.RawConfigParser
17+
else:
18+
ConfigParser = configparser.ConfigParser
19+
20+
21+
class ClientMarginTradingTest(unittest.TestCase):
22+
@classmethod
23+
def setUpClass(cls):
24+
logging.basicConfig(level=logging.DEBUG)
25+
config = ConfigParser()
26+
dir_path = os.path.dirname(os.path.realpath(__file__))
27+
config.read('{}/../config/config.ini'.format(dir_path))
28+
cls.client = Client(logging.getLogger(), **dict(config.items('ShiPanE')))
29+
cls.client_param = config.get('ShiPanE', 'client')
30+
31+
def test_query(self):
32+
try:
33+
df = self.client.query(self.client_param, '融券卖出')
34+
assert_that(df, has_column(u'证券代码'))
35+
except HTTPError as e:
36+
self.fail()
37+
38+
def test_buy_on_margin(self):
39+
try:
40+
order = self.client.execute(
41+
self.client_param,
42+
action='BUY_ON_MARGIN', symbol='000001', type='LIMIT', price=9, amount=100
43+
)
44+
self.assertIsNotNone(order['id'])
45+
except HTTPError as e:
46+
result = e.response.json()
47+
self.assertNotEqual(result['source'], "实盘易")
48+
49+
def test_buy_on_margin_at_market_price(self):
50+
try:
51+
order = self.client.execute(
52+
self.client_param,
53+
action='BUY_ON_MARGIN', symbol='000001', type='MARKET', priceType=4, amount=100
54+
)
55+
self.assertIsNotNone(order['id'])
56+
except HTTPError as e:
57+
result = e.response.json()
58+
self.assertNotEqual(result['source'], "实盘易")
59+
60+
def test_sell_then_repay(self):
61+
try:
62+
order = self.client.execute(
63+
self.client_param,
64+
action='SELL_THEN_REPAY', symbol='000001', type='LIMIT', price=9.5, amount=100
65+
)
66+
self.assertIsNotNone(order['id'])
67+
except HTTPError as e:
68+
result = e.response.json()
69+
self.assertNotEqual(result['source'], "实盘易")
70+
71+
def test_sell_then_repay_at_market_price(self):
72+
try:
73+
order = self.client.execute(
74+
self.client_param,
75+
action='SELL_THEN_REPAY', symbol='000001', type='MARKET', priceType=4, amount=100
76+
)
77+
self.assertIsNotNone(order['id'])
78+
except HTTPError as e:
79+
result = e.response.json()
80+
self.assertNotEqual(result['source'], "实盘易")
81+
82+
def test_sell_on_margin(self):
83+
try:
84+
order = self.client.execute(
85+
self.client_param,
86+
action='SELL_ON_MARGIN', symbol='000003', type='LIMIT', price=9.5, amount=100
87+
)
88+
self.assertIsNotNone(order['id'])
89+
except HTTPError as e:
90+
result = e.response.json()
91+
self.assertNotEqual(result['source'], "实盘易")
92+
93+
def test_sell_on_margin_at_market_price(self):
94+
try:
95+
order = self.client.execute(
96+
self.client_param,
97+
action='SELL_ON_MARGIN', symbol='000001', type='MARKET', priceType=4, amount=100
98+
)
99+
self.assertIsNotNone(order['id'])
100+
except HTTPError as e:
101+
result = e.response.json()
102+
self.assertNotEqual(result['source'], "实盘易")
103+
104+
def test_buy_then_repay(self):
105+
try:
106+
order = self.client.execute(
107+
self.client_param,
108+
action='BUY_THEN_REPAY', symbol='000001', type='LIMIT', price=8.9, amount=100
109+
)
110+
self.assertIsNotNone(order['id'])
111+
except HTTPError as e:
112+
result = e.response.json()
113+
self.assertNotEqual(result['source'], "实盘易")
114+
115+
def test_buy_then_repay_at_market_price(self):
116+
try:
117+
order = self.client.execute(
118+
self.client_param,
119+
action='BUY_THEN_REPAY', symbol='000001', type='MARKET', priceType=4, amount=100
120+
)
121+
self.assertIsNotNone(order['id'])
122+
except HTTPError as e:
123+
result = e.response.json()
124+
self.assertNotEqual(result['source'], "实盘易")
125+
126+
def test_repay_cash(self):
127+
try:
128+
order = self.client.execute(
129+
self.client_param,
130+
action='REPAY_CASH', symbol='', type='LIMIT', price=1.0, amount=1
131+
)
132+
self.assertIsNotNone(order['id'])
133+
except HTTPError as e:
134+
result = e.response.json()
135+
self.assertNotEqual(result['source'], "实盘易")
136+
137+
def test_repay_sec(self):
138+
try:
139+
order = self.client.execute(
140+
self.client_param,
141+
action='REPAY_SEC', symbol='000001', type='LIMIT', price=0.0, amount=100
142+
)
143+
self.assertIsNotNone(order['id'])
144+
except HTTPError as e:
145+
result = e.response.json()
146+
self.assertNotEqual(result['source'], "实盘易")

0 commit comments

Comments
 (0)