This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
api.update_status() | |
for idx,t in enumerate(api.list_trades()): | |
if t.status.status in [shioaji.constant.Status.PreSubmitted,shioaji.constant.Status.Submitted,shioaji.constant.Status.PartFilled] : | |
api.cancel_order(t,timeout=0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from loguru import logger | |
from dataclasses import dataclass | |
from typing import Optional, Dict, List | |
import math | |
import shioaji as sj | |
from shioaji.constant import OrderState, Action, StockOrderCond | |
@dataclass | |
class StockPosition: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def clear_all(): | |
"""13:25之後用漲跌停價格反向出場""" | |
#只處理今天新增的現股 (現股當沖、不含興櫃) | |
pnls = [one for one in api.list_positions() if abs(one.quantity) - one.yd_quantity!=0] | |
for one_pnl in pnls: | |
contract = api.Contracts.Stocks[one_pnl.code] | |
if contract == None: | |
print(f"無此商品 {one_pnl.code}") | |
continue | |
action = "Buy" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def quote_callback(topic, data): | |
""" | |
# L/TFE/TXFF9 | |
{'Amount': [21088.0], 'AmountSum': [1028165646.0], 'AvgPrice': [10562.513699263414], | |
'Close': [10544.0], 'Code': 'TXFF9', 'Date': '2019/05/16', 'DiffPrice': [-37.0], | |
'DiffRate': [-0.34968339476419996], 'DiffType': [4], 'High': [10574.0], | |
'Low': [10488.0], 'Open': 10537.0, 'TargetKindPrice': 10548.47, 'TickType': [2], | |
'Time': '11:15:11.911000', 'TradeAskVolSum': 52599, 'TradeBidVolSum': 53721, | |
'VolSum': [97341], 'Volume': [2]} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import shioaji as sj | |
import datetime | |
api = sj.Shioaji() | |
def cb_contract(msg): | |
print(datetime.datetime.now(), msg) | |
api.login("USERID","PASSWORD" ,contracts_timeout=0 ,contracts_cb=cb_contract) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
input = document.getElementsByClassName('emojipicker-input')[0] | |
send = document.getElementsByClassName('send')[0] | |
let prev_like_count = document.querySelectorAll('.item.like span.name').length | |
let prev_chat_count = document.querySelectorAll('.item.chat span.name').length | |
let prev_gift_count = document.getElementsByClassName('item gift').length | |
let prev_follow_count = document.querySelectorAll('.item.follow span.name').length | |
inter_like = setInterval(() => { | |
eleLike = document.querySelectorAll('.item.like span.name') | |
if (eleLike.length > prev_like_count) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
input = document.getElementsByClassName('emojipicker-input')[0] | |
send = document.getElementsByClassName('send')[0] | |
let prev_like_count = document.querySelectorAll('.item.like span.name').length | |
let prev_chat_count = document.querySelectorAll('.item.chat span.name').length | |
let prev_gift_count = document.getElementsByClassName('item gift').length | |
let prev_follow_count = document.querySelectorAll('.item.follow span.name').length | |
inter_like = setInterval(() => { | |
eleLike = document.querySelectorAll('.item.like span.name') | |
if (eleLike.length > prev_like_count) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Start Service. | |
sudo launchctl load -w /Applications/Server.app/Contents/ServerRoot/System/Library/LaunchDaemons/com.apple.serviceproxy.plist | |
sudo launchctl load -w /Applications/Server.app/Contents/ServerRoot/System/Library/LaunchDaemons/com.apple.server.httpd.plist | |
Stop Service. | |
sudo launchctl unload -w /Applications/Server.app/Contents/ServerRoot/System/Library/LaunchDaemons/com.apple.serviceproxy.plist | |
sudo launchctl unload -w /Applications/Server.app/Contents/ServerRoot/System/Library/LaunchDaemons/com.apple.server.httpd.plist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
def calc(*_ohlcv): | |
data = dict(list(zip(['open','high','low','close','volume'],_ohlcv))) | |
ohlc = pd.DataFrame(data) | |
stratData = pd.DataFrame(index=ohlc.index) | |
stratData['cc'] = 100*ohlc['close'].pct_change() | |
stratData['co'] = 100*(ohlc['open']/ohlc['close'].shift(1)-1) | |
idx = (stratData['cc']<-0.25).shift(1) & (stratData['co'] < -0.1) | |
idx[0] = False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def decorate_to_utf8(func): | |
"""只要參數是str就要to cp950給t4.dll | |
只要回傳值是bytes就要to utf8給 Api caller""" | |
def func_wrapper(*args): | |
new_args = list(args) | |
for idx, arg in enumerate(args): | |
if isinstance(arg, str): | |
new_args[idx] = args[idx].encode('utf-8') |
NewerOlder